@matheusbsbs / matheus-bagliano / commits / 84baa31bcb
Fork 0

get_sha1_oneline: make callers prepare the commit list to traverse

This gives callers more control, i.e. which ref will be searched from. They must prepare the list ordered by committer date. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Dec 13, 2010 at 10:01 UTC 84baa31bcb6925b06dd1b9aaa1ed6f7a725e64cc
1 file changed +11 -8
sha1_name.c
+11 -8
@@ -686,13 +686,13 @@ static int handle_one_ref(const char *path,
686 if (object->type != OBJ_COMMIT)
687 return 0;
688 insert_by_date((struct commit *)object, list);
689 - object->flags |= ONELINE_SEEN;
689 return 0;
690 }
691
693 -static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
692 +static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
693 + struct commit_list *list)
694 {
695 - struct commit_list *list = NULL, *backup = NULL, *l;
695 + struct commit_list *backup = NULL, *l;
696 int found = 0;
697 regex_t regex;
698
@@ -705,9 +705,10 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
705 if (regcomp(&regex, prefix, REG_EXTENDED))
706 die("Invalid search pattern: %s", prefix);
707
708 - for_each_ref(handle_one_ref, &list);
709 - for (l = list; l; l = l->next)
708 + for (l = list; l; l = l->next) {
709 + l->item->object.flags |= ONELINE_SEEN;
710 commit_list_insert(l->item, &backup);
711 + }
712 while (list) {
713 char *p, *to_free = NULL;
714 struct commit *commit;
@@ -1090,9 +1091,11 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
1091 int stage = 0;
1092 struct cache_entry *ce;
1093 int pos;
1093 - if (namelen > 2 && name[1] == '/')
1094 - /* don't need mode for commit */
1095 - return get_sha1_oneline(name + 2, sha1);
1094 + if (namelen > 2 && name[1] == '/') {
1095 + struct commit_list *list = NULL;
1096 + for_each_ref(handle_one_ref, &list);
1097 + return get_sha1_oneline(name + 2, sha1, list);
1098 + }
1099 if (namelen < 3 ||
1100 name[2] != ':' ||
1101 name[1] < '0' || '3' < name[1])