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>
brian m. carlson committed
Feb 21, 2017 at 23:47 UTC
43bc3b6ceeb4cf3ed13741ffe02ed432e743fba5
1 file changed
+6
-5
refs/files-backend.c
+6
-5
@@ -3117,12 +3117,13 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
3117
char *email_end, *message;
3118
unsigned long timestamp;
3119
int tz;
3120
+ const char *p = sb->buf;
3121
3122
/* 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, '>')) ||
3127
email_end[1] != ' ' ||
3128
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
3129
!message || message[0] != ' ' ||
@@ -3136,7 +3137,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
3137
message += 6;
3138
else
3139
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);
3141
}
3142
3143
static char *find_beginning_of_line(char *bob, char *scan)