@matheusbsbs / matheus-bagliano / commits / 36d56de649
Fork 0

Fix --cherry-pick with given paths

If you say --cherry-pick, you do not want to see patches which are in the upstream. If you specify paths with that, what you usually expect is that only those parts of the patches are looked at which actually touch the given paths. With this patch, that expectation is met. Noticed by Sam Vilain. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 10, 2007 at 14:50 UTC 36d56de649aacdbf555d2c9743c514cc52368f2c
2 files changed +50 -2
revision.c
+7 -2
@@ -437,7 +437,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
437 return 0;
438 }
439
440 -static void cherry_pick_list(struct commit_list *list)
440 +static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
441 {
442 struct commit_list *p;
443 int left_count = 0, right_count = 0;
@@ -458,6 +458,11 @@ static void cherry_pick_list(struct commit_list *list)
458
459 left_first = left_count < right_count;
460 init_patch_ids(&ids);
461 + if (revs->diffopt.nr_paths) {
462 + ids.diffopts.nr_paths = revs->diffopt.nr_paths;
463 + ids.diffopts.paths = revs->diffopt.paths;
464 + ids.diffopts.pathlens = revs->diffopt.pathlens;
465 + }
466
467 /* Compute patch-ids for one side */
468 for (p = list; p; p = p->next) {
@@ -546,7 +551,7 @@ static int limit_list(struct rev_info *revs)
551 p = &commit_list_insert(commit, p)->next;
552 }
553 if (revs->cherry_pick)
549 - cherry_pick_list(newlist);
554 + cherry_pick_list(newlist, revs);
555
556 revs->commits = newlist;
557 return 0;
t/t6007-rev-list-cherry-pick-file.sh new
+43
@@ -0,0 +1,43 @@
1 +#!/bin/sh
2 +
3 +test_description='test git rev-list --cherry-pick -- file'
4 +
5 +. ./test-lib.sh
6 +
7 +# A---B
8 +# \
9 +# \
10 +# C
11 +#
12 +# B changes a file foo.c, adding a line of text. C changes foo.c as
13 +# well as bar.c, but the change in foo.c was identical to change B.
14 +
15 +test_expect_success setup '
16 + echo Hallo > foo &&
17 + git add foo &&
18 + test_tick &&
19 + git commit -m "A" &&
20 + git tag A &&
21 + git checkout -b branch &&
22 + echo Bello > foo &&
23 + echo Cello > bar &&
24 + git add foo bar &&
25 + test_tick &&
26 + git commit -m "C" &&
27 + git tag C &&
28 + git checkout master &&
29 + git checkout branch foo &&
30 + test_tick &&
31 + git commit -m "B" &&
32 + git tag B
33 +'
34 +
35 +test_expect_success '--cherry-pick foo comes up empty' '
36 + test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)"
37 +'
38 +
39 +test_expect_success '--cherry-pick bar does not come up empty' '
40 + ! test -z "$(git rev-list --left-right --cherry-pick B...C -- bar)"
41 +'
42 +
43 +test_done