Skip to content

Commit 43bc3b6

Browse files
bk2204gitster
authored andcommitted
refs: simplify parsing of reflog entries
The current code for reflog entries uses a lot of hard-coded constants, making it hard to read and modify. Use parse_oid_hex and two temporary variables to simplify the code and reduce the use of magic constants. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9461d27 commit 43bc3b6

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

refs/files-backend.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,12 +3117,13 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
31173117
char *email_end, *message;
31183118
unsigned long timestamp;
31193119
int tz;
3120+
const char *p = sb->buf;
31203121

31213122
/* old SP new SP name <email> SP time TAB msg LF */
3122-
if (sb->len < 83 || sb->buf[sb->len - 1] != '\n' ||
3123-
get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||
3124-
get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||
3125-
!(email_end = strchr(sb->buf + 82, '>')) ||
3123+
if (!sb->len || sb->buf[sb->len - 1] != '\n' ||
3124+
parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
3125+
parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
3126+
!(email_end = strchr(p, '>')) ||
31263127
email_end[1] != ' ' ||
31273128
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
31283129
!message || message[0] != ' ' ||
@@ -3136,7 +3137,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
31363137
message += 6;
31373138
else
31383139
message += 7;
3139-
return fn(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);
3140+
return fn(&ooid, &noid, p, timestamp, tz, message, cb_data);
31403141
}
31413142

31423143
static char *find_beginning_of_line(char *bob, char *scan)

0 commit comments

Comments
 (0)