Skip to content

Commit 84baa31

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 28042db commit 84baa31

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

sha1_name.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,13 @@ static int handle_one_ref(const char *path,
686686
if (object->type != OBJ_COMMIT)
687687
return 0;
688688
insert_by_date((struct commit *)object, list);
689-
object->flags |= ONELINE_SEEN;
690689
return 0;
691690
}
692691

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)
694694
{
695-
struct commit_list *list = NULL, *backup = NULL, *l;
695+
struct commit_list *backup = NULL, *l;
696696
int found = 0;
697697
regex_t regex;
698698

@@ -705,9 +705,10 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
705705
if (regcomp(&regex, prefix, REG_EXTENDED))
706706
die("Invalid search pattern: %s", prefix);
707707

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;
710710
commit_list_insert(l->item, &backup);
711+
}
711712
while (list) {
712713
char *p, *to_free = NULL;
713714
struct commit *commit;
@@ -1090,9 +1091,11 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
10901091
int stage = 0;
10911092
struct cache_entry *ce;
10921093
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+
}
10961099
if (namelen < 3 ||
10971100
name[2] != ':' ||
10981101
name[1] < '0' || '3' < name[1])

0 commit comments

Comments
 (0)