Skip to content

Commit f7bff00

Browse files
committed
sha1_name.c: fix parsing of ":/token" syntax
The parser tried to clean up the object flags it used while finding commits with matching string, but was not doing a very good job at it. This caused "checkout -b new ':/token'", which internally tries to parse ':/token' twice as an object name, to fail when the commit in question was reachable from only one ref. The mask bits given to pop_most_recent_commit(&list, MASK) means "I have already been on the list to be processed, so please do not place me again even if I am found to be a parent of some other commit on the list." So mark them when we add them to the list at the beginning. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 593ce2b commit f7bff00

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

sha1_name.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,16 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
659659
return get_short_sha1(name, len, sha1, 0);
660660
}
661661

662+
/*
663+
* This interprets names like ':/Initial revision of "git"' by searching
664+
* through history and returning the first commit whose message starts
665+
* with the given string.
666+
*
667+
* For future extension, ':/!' is reserved. If you want to match a message
668+
* beginning with a '!', you have to repeat the exclamation mark.
669+
*/
670+
#define ONELINE_SEEN (1u<<20)
671+
662672
static int handle_one_ref(const char *path,
663673
const unsigned char *sha1, int flag, void *cb_data)
664674
{
@@ -674,19 +684,10 @@ static int handle_one_ref(const char *path,
674684
if (object->type != OBJ_COMMIT)
675685
return 0;
676686
insert_by_date((struct commit *)object, list);
687+
object->flags |= ONELINE_SEEN;
677688
return 0;
678689
}
679690

680-
/*
681-
* This interprets names like ':/Initial revision of "git"' by searching
682-
* through history and returning the first commit whose message starts
683-
* with the given string.
684-
*
685-
* For future extension, ':/!' is reserved. If you want to match a message
686-
* beginning with a '!', you have to repeat the exclamation mark.
687-
*/
688-
689-
#define ONELINE_SEEN (1u<<20)
690691
static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
691692
{
692693
struct commit_list *list = NULL, *backup = NULL, *l;

0 commit comments

Comments
 (0)