summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2017-02-21 23:47:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-22 18:12:15 (GMT)
commit43bc3b6ceeb4cf3ed13741ffe02ed432e743fba5 (patch)
treed493990872d05714404ac127a10ca63d2cca6d37
parent9461d27240c158cf781ce706a077663050179b14 (diff)
downloadgit-43bc3b6ceeb4cf3ed13741ffe02ed432e743fba5.zip
git-43bc3b6ceeb4cf3ed13741ffe02ed432e743fba5.tar.gz
git-43bc3b6ceeb4cf3ed13741ffe02ed432e743fba5.tar.bz2
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>
-rw-r--r--refs/files-backend.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d7a5fd2..fea20e9 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3117,12 +3117,13 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
char *email_end, *message;
unsigned long timestamp;
int tz;
+ const char *p = sb->buf;
/* old SP new SP name <email> SP time TAB msg LF */
- if (sb->len < 83 || sb->buf[sb->len - 1] != '\n' ||
- get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||
- get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||
- !(email_end = strchr(sb->buf + 82, '>')) ||
+ if (!sb->len || sb->buf[sb->len - 1] != '\n' ||
+ parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
+ parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
+ !(email_end = strchr(p, '>')) ||
email_end[1] != ' ' ||
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
!message || message[0] != ' ' ||
@@ -3136,7 +3137,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
message += 6;
else
message += 7;
- return fn(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);
+ return fn(&ooid, &noid, p, timestamp, tz, message, cb_data);
}
static char *find_beginning_of_line(char *bob, char *scan)