Skip to content

Commit 2d83abd

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

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
@@ -1074,35 +1074,34 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
10741074
return 0;
10751075
}
10761076

1077-
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, const char ***prune_data)
1078-
{
1079-
const char **prune = *prune_data;
1080-
int prune_nr;
1081-
int prune_alloc;
1077+
struct cmdline_pathspec {
1078+
int alloc;
1079+
int nr;
1080+
const char **path;
1081+
};
10821082

1083-
/* count existing ones */
1084-
if (!prune)
1085-
prune_nr = 0;
1086-
else
1087-
for (prune_nr = 0; prune[prune_nr]; prune_nr++)
1088-
;
1089-
prune_alloc = prune_nr; /* not really, but we do not know */
1083+
static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
1084+
{
1085+
while (*av) {
1086+
ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
1087+
prune->path[prune->nr++] = *(av++);
1088+
}
1089+
}
10901090

1091+
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
1092+
struct cmdline_pathspec *prune)
1093+
{
10911094
while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
10921095
int len = sb->len;
10931096
if (len && sb->buf[len - 1] == '\n')
10941097
sb->buf[--len] = '\0';
1095-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1096-
prune[prune_nr++] = xstrdup(sb->buf);
1098+
ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
1099+
prune->path[prune->nr++] = xstrdup(sb->buf);
10971100
}
1098-
if (prune) {
1099-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1100-
prune[prune_nr] = NULL;
1101-
}
1102-
*prune_data = prune;
11031101
}
11041102

1105-
static void read_revisions_from_stdin(struct rev_info *revs, const char ***prune)
1103+
static void read_revisions_from_stdin(struct rev_info *revs,
1104+
struct cmdline_pathspec *prune)
11061105
{
11071106
struct strbuf sb;
11081107
int seen_dashdash = 0;
@@ -1445,34 +1444,6 @@ static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void
14451444
return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
14461445
}
14471446

1448-
static void append_prune_data(const char ***prune_data, const char **av)
1449-
{
1450-
const char **prune = *prune_data;
1451-
int prune_nr;
1452-
int prune_alloc;
1453-
1454-
if (!prune) {
1455-
*prune_data = av;
1456-
return;
1457-
}
1458-
1459-
/* count existing ones */
1460-
for (prune_nr = 0; prune[prune_nr]; prune_nr++)
1461-
;
1462-
prune_alloc = prune_nr; /* not really, but we do not know */
1463-
1464-
while (*av) {
1465-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1466-
prune[prune_nr++] = *av;
1467-
av++;
1468-
}
1469-
if (prune) {
1470-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1471-
prune[prune_nr] = NULL;
1472-
}
1473-
*prune_data = prune;
1474-
}
1475-
14761447
/*
14771448
* Parse revision information, filling in the "rev_info" structure,
14781449
* and removing the used arguments from the argument list.
@@ -1483,11 +1454,13 @@ static void append_prune_data(const char ***prune_data, const char **av)
14831454
int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
14841455
{
14851456
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
1486-
const char **prune_data = NULL;
1457+
struct cmdline_pathspec prune_data;
14871458
const char *submodule = NULL;
14881459
const char *optarg;
14891460
int argcount;
14901461

1462+
memset(&prune_data, 0, sizeof(prune_data));
1463+
14911464
if (opt)
14921465
submodule = opt->submodule;
14931466

@@ -1500,7 +1473,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
15001473
argv[i] = NULL;
15011474
argc = i;
15021475
if (argv[i + 1])
1503-
prune_data = argv + i + 1;
1476+
append_prune_data(&prune_data, argv + i + 1);
15041477
seen_dashdash = 1;
15051478
break;
15061479
}
@@ -1619,8 +1592,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
16191592
got_rev_arg = 1;
16201593
}
16211594

1622-
if (prune_data)
1623-
revs->prune_data = get_pathspec(revs->prefix, prune_data);
1595+
if (prune_data.nr) {
1596+
ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc);
1597+
prune_data.path[prune_data.nr++] = NULL;
1598+
revs->prune_data = get_pathspec(revs->prefix, prune_data.path);
1599+
}
16241600

16251601
if (revs->def == NULL)
16261602
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)