Skip to content

Commit

Permalink
Simplify parsing branch switching events in reflog
Browse files Browse the repository at this point in the history
We only accept "checkout: moving from A to B" newer style reflog entries,
in order to pick up A.  There is no point computing where B begins at
after running strstr to locate " to ", nor adding 4 and then subtracting 4
from the same pointer.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jan 21, 2009
1 parent 101d15e commit d7c03c1
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,17 +723,13 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,

if (!prefixcmp(message, "checkout: moving from ")) {
match = message + strlen("checkout: moving from ");
if ((target = strstr(match, " to ")) != NULL)
target += 4;
target = strstr(match, " to ");
}

if (!match || !target)
return 0;

len = target - match - 4;
if (target[len] == '\n' && !strncmp(match, target, len))
return 0;

len = target - match;
nth = cb->cnt++ % cb->alloc;
strbuf_reset(&cb->buf[nth]);
strbuf_add(&cb->buf[nth], match, len);
Expand Down

0 comments on commit d7c03c1

Please sign in to comment.