diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-12-13 10:01:15 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-14 16:50:45 -0800 |
commit | 32574b68c57f3b34e58216a4c9c6d570d11ec47b (patch) | |
tree | ecadd84fa1d6fe7e15c77969b32257a7baf26de2 /sha1_name.c | |
parent | 84baa31bcb6925b06dd1b9aaa1ed6f7a725e64cc (diff) | |
download | git-32574b68c57f3b34e58216a4c9c6d570d11ec47b.tar.gz |
get_sha1: support $commit^{/regex} syntax
This works like ":/regex" syntax that finds a recently created commit
starting from all refs, but limits the discovery to those reachable from
the named commit.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/sha1_name.c b/sha1_name.c index aefae1f524..1ba4bc3b68 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -7,6 +7,8 @@ #include "refs.h" #include "remote.h" +static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *); + static int find_short_object_filename(int len, const char *name, unsigned char *sha1) { struct alternate_object_database *alt; @@ -562,6 +564,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1) expected_type = OBJ_BLOB; else if (sp[0] == '}') expected_type = OBJ_NONE; + else if (sp[0] == '/') + expected_type = OBJ_COMMIT; else return -1; @@ -576,19 +580,30 @@ static int peel_onion(const char *name, int len, unsigned char *sha1) if (!o || (!o->parsed && !parse_object(o->sha1))) return -1; hashcpy(sha1, o->sha1); + return 0; } - else { - /* - * At this point, the syntax look correct, so - * if we do not get the needed object, we should - * barf. - */ - o = peel_to_type(name, len, o, expected_type); - if (o) { - hashcpy(sha1, o->sha1); - return 0; - } + + /* + * At this point, the syntax look correct, so + * if we do not get the needed object, we should + * barf. + */ + o = peel_to_type(name, len, o, expected_type); + if (!o) return -1; + + hashcpy(sha1, o->sha1); + if (sp[0] == '/') { + /* "$commit^{/foo}" */ + char *prefix; + int ret; + struct commit_list *list = NULL; + + prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1)); + commit_list_insert((struct commit *)o, &list); + ret = get_sha1_oneline(prefix, sha1, list); + free(prefix); + return ret; } return 0; } |