summaryrefslogtreecommitdiff
path: root/builtin/patch-id.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-06-03 21:38:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-03 21:38:03 (GMT)
commit29e54b019f55f48af3f0d4c62eede86058c16b52 (patch)
treedb03b09aea4d26d3946f9a1ff99f5ab6c573a79c /builtin/patch-id.c
parentfb14575e10c0628af6219426736dec71b95bc1b0 (diff)
parent2bb73ae8037ae6fd82f002257d04f8cda2a721cd (diff)
downloadgit-29e54b019f55f48af3f0d4c62eede86058c16b52.zip
git-29e54b019f55f48af3f0d4c62eede86058c16b52.tar.gz
git-29e54b019f55f48af3f0d4c62eede86058c16b52.tar.bz2
Merge branch 'rs/patch-id-use-skip-prefix'
Code clean-up. * rs/patch-id-use-skip-prefix: patch-id: use starts_with() and skip_prefix()
Diffstat (limited to 'builtin/patch-id.c')
-rw-r--r--builtin/patch-id.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 366ce5a..a84d000 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -81,16 +81,13 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
- char *p = line;
+ const char *p = line;
int len;
- if (!memcmp(line, "diff-tree ", 10))
- p += 10;
- else if (!memcmp(line, "commit ", 7))
- p += 7;
- else if (!memcmp(line, "From ", 5))
- p += 5;
- else if (!memcmp(line, "\\ ", 2) && 12 < strlen(line))
+ if (!skip_prefix(line, "diff-tree ", &p) &&
+ !skip_prefix(line, "commit ", &p) &&
+ !skip_prefix(line, "From ", &p) &&
+ starts_with(line, "\\ ") && 12 < strlen(line))
continue;
if (!get_oid_hex(p, next_oid)) {
@@ -99,14 +96,14 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
}
/* Ignore commit comments */
- if (!patchlen && memcmp(line, "diff ", 5))
+ if (!patchlen && !starts_with(line, "diff "))
continue;
/* Parsing diff header? */
if (before == -1) {
- if (!memcmp(line, "index ", 6))
+ if (starts_with(line, "index "))
continue;
- else if (!memcmp(line, "--- ", 4))
+ else if (starts_with(line, "--- "))
before = after = 1;
else if (!isalpha(line[0]))
break;
@@ -114,14 +111,14 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,
/* Looking for a valid hunk header? */
if (before == 0 && after == 0) {
- if (!memcmp(line, "@@ -", 4)) {
+ if (starts_with(line, "@@ -")) {
/* Parse next hunk, but ignore line numbers. */
scan_hunk_header(line, &before, &after);
continue;
}
/* Split at the end of the patch. */
- if (memcmp(line, "diff ", 5))
+ if (!starts_with(line, "diff "))
break;
/* Else we're parsing another header. */