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
This commit is contained in:
@ -32,8 +32,12 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
|
|||||||
n = strspn(q, digits);
|
n = strspn(q, digits);
|
||||||
if (q[n] == ',') {
|
if (q[n] == ',') {
|
||||||
q += n + 1;
|
q += n + 1;
|
||||||
|
*p_before = atoi(q);
|
||||||
n = strspn(q, digits);
|
n = strspn(q, digits);
|
||||||
|
} else {
|
||||||
|
*p_before = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == 0 || q[n] != ' ' || q[n+1] != '+')
|
if (n == 0 || q[n] != ' ' || q[n+1] != '+')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -41,13 +45,14 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
|
|||||||
n = strspn(r, digits);
|
n = strspn(r, digits);
|
||||||
if (r[n] == ',') {
|
if (r[n] == ',') {
|
||||||
r += n + 1;
|
r += n + 1;
|
||||||
|
*p_after = atoi(r);
|
||||||
n = strspn(r, digits);
|
n = strspn(r, digits);
|
||||||
|
} else {
|
||||||
|
*p_after = 1;
|
||||||
}
|
}
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*p_before = atoi(q);
|
|
||||||
*p_after = atoi(r);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ calc_patch_id () {
|
|||||||
shift
|
shift
|
||||||
git patch-id "$@" >patch-id.output &&
|
git patch-id "$@" >patch-id.output &&
|
||||||
sed "s/ .*//" patch-id.output >patch-id_"$patch_name" &&
|
sed "s/ .*//" patch-id.output >patch-id_"$patch_name" &&
|
||||||
test_line_count -gt 0 patch-id_"$patch_name"
|
test_line_count -eq 1 patch-id_"$patch_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_top_diff () {
|
get_top_diff () {
|
||||||
@ -166,7 +166,8 @@ test_expect_success 'patch-id respects config from subdir' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >nonl <<\EOF
|
test_expect_success 'patch-id handles no-nl-at-eof markers' '
|
||||||
|
cat >nonl <<-\EOF &&
|
||||||
diff --git i/a w/a
|
diff --git i/a w/a
|
||||||
index e69de29..2e65efe 100644
|
index e69de29..2e65efe 100644
|
||||||
--- i/a
|
--- i/a
|
||||||
@ -181,8 +182,7 @@ index e69de29..6178079 100644
|
|||||||
@@ -0,0 +1 @@
|
@@ -0,0 +1 @@
|
||||||
+b
|
+b
|
||||||
EOF
|
EOF
|
||||||
|
cat >withnl <<-\EOF &&
|
||||||
cat >withnl <<\EOF
|
|
||||||
diff --git i/a w/a
|
diff --git i/a w/a
|
||||||
index e69de29..7898192 100644
|
index e69de29..7898192 100644
|
||||||
--- i/a
|
--- i/a
|
||||||
@ -196,10 +196,37 @@ index e69de29..6178079 100644
|
|||||||
@@ -0,0 +1 @@
|
@@ -0,0 +1 @@
|
||||||
+b
|
+b
|
||||||
EOF
|
EOF
|
||||||
|
calc_patch_id nonl <nonl &&
|
||||||
test_expect_success 'patch-id handles no-nl-at-eof markers' '
|
calc_patch_id withnl <withnl &&
|
||||||
cat nonl | calc_patch_id nonl &&
|
|
||||||
cat withnl | calc_patch_id withnl &&
|
|
||||||
test_cmp patch-id_nonl patch-id_withnl
|
test_cmp patch-id_nonl patch-id_withnl
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'patch-id handles diffs with one line of before/after' '
|
||||||
|
cat >diffu1 <<-\EOF &&
|
||||||
|
diff --git a/bar b/bar
|
||||||
|
index bdaf90f..31051f6 100644
|
||||||
|
--- a/bar
|
||||||
|
+++ b/bar
|
||||||
|
@@ -2 +2,2 @@
|
||||||
|
b
|
||||||
|
+c
|
||||||
|
diff --git a/car b/car
|
||||||
|
index 00750ed..2ae5e34 100644
|
||||||
|
--- a/car
|
||||||
|
+++ b/car
|
||||||
|
@@ -1 +1,2 @@
|
||||||
|
3
|
||||||
|
+d
|
||||||
|
diff --git a/foo b/foo
|
||||||
|
index e439850..7146eb8 100644
|
||||||
|
--- a/foo
|
||||||
|
+++ b/foo
|
||||||
|
@@ -2 +2,2 @@
|
||||||
|
a
|
||||||
|
+e
|
||||||
|
EOF
|
||||||
|
calc_patch_id diffu1 <diffu1 &&
|
||||||
|
test_config patchid.stable true &&
|
||||||
|
calc_patch_id diffu1stable <diffu1
|
||||||
|
'
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user