diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-02-17 16:25:04 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-02-17 16:25:04 -0800 |
| commit | d077db1df0aef3db479904429e8008d8fc0e3fb3 (patch) | |
| tree | c037ff1fc3775cd70f1a92346417f4024a15d709 /builtin/patch-id.c | |
| parent | 75ff34bcf75b388d720d06c41a3f2952f8395f1c (diff) | |
| parent | 757e75c81e4332e363b90a0534a657b1bb6546fa (diff) | |
| download | git-d077db1df0aef3db479904429e8008d8fc0e3fb3.tar.xz | |
Merge branch 'jz/patch-id-hunk-header-parsing-fix'
Unlike "git apply", "git patch-id" did not handle patches with
hunks that has only 1 line in either preimage or postimage, which
has been corrected.
* jz/patch-id-hunk-header-parsing-fix:
patch-id: fix scan_hunk_header on diffs with 1 line of before/after
patch-id: fix antipatterns in tests
Diffstat (limited to 'builtin/patch-id.c')
| -rw-r--r-- | builtin/patch-id.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/builtin/patch-id.c b/builtin/patch-id.c index 822ffff51f..881fcf3273 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -32,8 +32,12 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after) n = strspn(q, digits); if (q[n] == ',') { q += n + 1; + *p_before = atoi(q); n = strspn(q, digits); + } else { + *p_before = 1; } + if (n == 0 || q[n] != ' ' || q[n+1] != '+') return 0; @@ -41,13 +45,14 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after) n = strspn(r, digits); if (r[n] == ',') { r += n + 1; + *p_after = atoi(r); n = strspn(r, digits); + } else { + *p_after = 1; } if (n == 0) return 0; - *p_before = atoi(q); - *p_after = atoi(r); return 1; } |
