Skip to content

Commit 25197eb

Browse files
committed
Merge branch 'jc/maint-1.6.6-pathspec-stdin-and-cmdline'
* jc/maint-1.6.6-pathspec-stdin-and-cmdline: setup_revisions(): take pathspec from command line and --stdin correctly
2 parents 6fd09f5 + 4da5af3 commit 25197eb

2 files changed

Lines changed: 45 additions & 52 deletions

File tree

revision.c

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

1074-
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, const char ***prune_data)
1075-
{
1076-
const char **prune = *prune_data;
1077-
int prune_nr;
1078-
int prune_alloc;
1074+
struct cmdline_pathspec {
1075+
int alloc;
1076+
int nr;
1077+
const char **path;
1078+
};
10791079

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

1088+
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
1089+
struct cmdline_pathspec *prune)
1090+
{
10881091
while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
10891092
int len = sb->len;
10901093
if (len && sb->buf[len - 1] == '\n')
10911094
sb->buf[--len] = '\0';
1092-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1093-
prune[prune_nr++] = xstrdup(sb->buf);
1095+
ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
1096+
prune->path[prune->nr++] = xstrdup(sb->buf);
10941097
}
1095-
if (prune) {
1096-
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
1097-
prune[prune_nr] = NULL;
1098-
}
1099-
*prune_data = prune;
11001098
}
11011099

1102-
static void read_revisions_from_stdin(struct rev_info *revs, const char ***prune)
1100+
static void read_revisions_from_stdin(struct rev_info *revs,
1101+
struct cmdline_pathspec *prune)
11031102
{
11041103
struct strbuf sb;
11051104
int seen_dashdash = 0;
@@ -1442,34 +1441,6 @@ static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void
14421441
return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
14431442
}
14441443

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

1459+
memset(&prune_data, 0, sizeof(prune_data));
14881460
if (opt)
14891461
submodule = opt->submodule;
14901462

@@ -1497,7 +1469,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
14971469
argv[i] = NULL;
14981470
argc = i;
14991471
if (argv[i + 1])
1500-
prune_data = argv + i + 1;
1472+
append_prune_data(&prune_data, argv + i + 1);
15011473
seen_dashdash = 1;
15021474
break;
15031475
}
@@ -1616,8 +1588,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
16161588
got_rev_arg = 1;
16171589
}
16181590

1619-
if (prune_data)
1620-
init_pathspec(&revs->prune_data, get_pathspec(revs->prefix, prune_data));
1591+
if (prune_data.nr) {
1592+
ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc);
1593+
prune_data.path[prune_data.nr++] = NULL;
1594+
init_pathspec(&revs->prune_data,
1595+
get_pathspec(revs->prefix, prune_data.path));
1596+
}
16211597

16221598
if (revs->def == NULL)
16231599
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)