Skip to content

Commit 8f2d4b1

Browse files
committed
Merge branch 'jc/maint-1.7.4-pathspec-stdin-and-cmdline'
Update the fix for 1.7.5 maintenance track. * jc/maint-1.7.4-pathspec-stdin-and-cmdline: setup_revisions(): take pathspec from command line and --stdin correctly
2 parents 4c007ae + 2d83abd commit 8f2d4b1

File tree

2 files changed

+45
-52
lines changed

2 files changed

+45
-52
lines changed

revision.c

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,35 +1096,34 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
10961096
return 0;
10971097
}
10981098

1099-
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, const char ***prune_data)
1100-
{
1101-
const char **prune = *prune_data;
1102-
int prune_nr;
1103-
int prune_alloc;
1099+
struct cmdline_pathspec {
1100+
int alloc;
1101+
int nr;
1102+
const char **path;
1103+
};
11041104

1105-
/* count existing ones */
1106-
if (!prune)
1107-
prune_nr = 0;
1108-
else
1109-
for (prune_nr = 0; prune[prune_nr]; prune_nr++)
1110-
;
1111-
prune_alloc = prune_nr; /* not really, but we do not know */
1105+
static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
1106+
{
1107+
while (*av) {
1108+
ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
1109+
prune->path[prune->nr++] = *(av++);
1110+
}
1111+
}
11121112

1113+
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
1114+
struct cmdline_pathspec *prune)
1115+
{
11131116
while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
11141117
int len = sb->len;
11151118
if (len && sb->buf[len - 1] == '\n')
11161119
sb->buf[--len] = '\0';
1117-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1118-
prune[prune_nr++] = xstrdup(sb->buf);
1120+
ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
1121+
prune->path[prune->nr++] = xstrdup(sb->buf);
11191122
}
1120-
if (prune) {
1121-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1122-
prune[prune_nr] = NULL;
1123-
}
1124-
*prune_data = prune;
11251123
}
11261124

1127-
static void read_revisions_from_stdin(struct rev_info *revs, const char ***prune)
1125+
static void read_revisions_from_stdin(struct rev_info *revs,
1126+
struct cmdline_pathspec *prune)
11281127
{
11291128
struct strbuf sb;
11301129
int seen_dashdash = 0;
@@ -1498,34 +1497,6 @@ static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void
14981497
return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
14991498
}
15001499

1501-
static void append_prune_data(const char ***prune_data, const char **av)
1502-
{
1503-
const char **prune = *prune_data;
1504-
int prune_nr;
1505-
int prune_alloc;
1506-
1507-
if (!prune) {
1508-
*prune_data = av;
1509-
return;
1510-
}
1511-
1512-
/* count existing ones */
1513-
for (prune_nr = 0; prune[prune_nr]; prune_nr++)
1514-
;
1515-
prune_alloc = prune_nr; /* not really, but we do not know */
1516-
1517-
while (*av) {
1518-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1519-
prune[prune_nr++] = *av;
1520-
av++;
1521-
}
1522-
if (prune) {
1523-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1524-
prune[prune_nr] = NULL;
1525-
}
1526-
*prune_data = prune;
1527-
}
1528-
15291500
/*
15301501
* Parse revision information, filling in the "rev_info" structure,
15311502
* and removing the used arguments from the argument list.
@@ -1536,11 +1507,12 @@ static void append_prune_data(const char ***prune_data, const char **av)
15361507
int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
15371508
{
15381509
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
1539-
const char **prune_data = NULL;
1510+
struct cmdline_pathspec prune_data;
15401511
const char *submodule = NULL;
15411512
const char *optarg;
15421513
int argcount;
15431514

1515+
memset(&prune_data, 0, sizeof(prune_data));
15441516
if (opt)
15451517
submodule = opt->submodule;
15461518

@@ -1553,7 +1525,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
15531525
argv[i] = NULL;
15541526
argc = i;
15551527
if (argv[i + 1])
1556-
prune_data = argv + i + 1;
1528+
append_prune_data(&prune_data, argv + i + 1);
15571529
seen_dashdash = 1;
15581530
break;
15591531
}
@@ -1672,8 +1644,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
16721644
got_rev_arg = 1;
16731645
}
16741646

1675-
if (prune_data)
1676-
init_pathspec(&revs->prune_data, get_pathspec(revs->prefix, prune_data));
1647+
if (prune_data.nr) {
1648+
ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc);
1649+
prune_data.path[prune_data.nr++] = NULL;
1650+
init_pathspec(&revs->prune_data,
1651+
get_pathspec(revs->prefix, prune_data.path));
1652+
}
16771653

16781654
if (revs->def == NULL)
16791655
revs->def = opt ? opt->def : NULL;

t/t6017-rev-list-stdin.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,21 @@ check side-3 ^side-4 -- file-3
5858
check side-3 ^side-2
5959
check side-3 ^side-2 -- file-1
6060

61+
test_expect_success 'not only --stdin' '
62+
cat >expect <<-EOF &&
63+
7
64+
65+
file-1
66+
file-2
67+
EOF
68+
cat >input <<-EOF &&
69+
^master^
70+
--
71+
file-2
72+
EOF
73+
git log --pretty=tformat:%s --name-only --stdin master -- file-1 \
74+
<input >actual &&
75+
test_cmp expect actual
76+
'
77+
6178
test_done

0 commit comments

Comments
 (0)