Skip to content

Commit 91f8f7e

Browse files
rscharfegitster
authored andcommitted
2.36 format-patch regression fix
e900d49 (diff: add an API for deferred freeing, 2021-02-11) added a way to allow reusing diffopts: the no_free bit. 244c272 (diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec), 2022-02-16) made that mechanism mandatory. git format-patch only sets no_free when --output is given, causing it to forget pathspecs after the first commit. Set no_free unconditionally instead. The existing test was unable to detect this breakage because it checks stderr for the absence of a certain string, but format-patch writes to stdout. Also the test was not checking the case of one commit modifying multiple files and a pathspec limiting the diff. Replace it with a more thorough one. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 362f869 commit 91f8f7e

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

builtin/log.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18831883
rev.diff = 1;
18841884
rev.max_parents = 1;
18851885
rev.diffopt.flags.recursive = 1;
1886+
rev.diffopt.no_free = 1;
18861887
rev.subject_prefix = fmt_patch_subject_prefix;
18871888
memset(&s_r_opt, 0, sizeof(s_r_opt));
18881889
s_r_opt.def = "HEAD";
@@ -2008,13 +2009,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20082009

20092010
if (use_stdout) {
20102011
setup_pager();
2011-
} else if (rev.diffopt.close_file) {
2012-
/*
2013-
* The diff code parsed --output; it has already opened the
2014-
* file, but we must instruct it not to close after each diff.
2015-
*/
2016-
rev.diffopt.no_free = 1;
2017-
} else {
2012+
} else if (!rev.diffopt.close_file) {
20182013
int saved;
20192014

20202015
if (!output_directory)

t/t4014-format-patch.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,40 @@ test_expect_success 'format-patch --numstat should produce a patch' '
926926
'
927927

928928
test_expect_success 'format-patch -- <path>' '
929-
git format-patch main..side -- file 2>error &&
930-
! grep "Use .--" error
929+
rm -f *.patch &&
930+
git checkout -b pathspec main &&
931+
932+
echo file_a 1 >file_a &&
933+
echo file_b 1 >file_b &&
934+
git add file_a file_b &&
935+
git commit -m pathspec_initial &&
936+
937+
echo file_a 2 >>file_a &&
938+
git add file_a &&
939+
git commit -m pathspec_a &&
940+
941+
echo file_b 2 >>file_b &&
942+
git add file_b &&
943+
git commit -m pathspec_b &&
944+
945+
echo file_a 3 >>file_a &&
946+
echo file_b 3 >>file_b &&
947+
git add file_a file_b &&
948+
git commit -m pathspec_ab &&
949+
950+
cat >expect <<-\EOF &&
951+
0001-pathspec_initial.patch
952+
0002-pathspec_a.patch
953+
0003-pathspec_ab.patch
954+
EOF
955+
956+
git format-patch main..pathspec -- file_a >output &&
957+
test_cmp expect output &&
958+
! grep file_b *.patch
931959
'
932960

933961
test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
962+
git checkout side &&
934963
git format-patch --ignore-if-in-upstream HEAD
935964
'
936965

0 commit comments

Comments
 (0)