Browse Source

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
maint
Junio C Hamano 14 years ago
parent
commit
2d83abd4b2
  1. 80
      revision.c
  2. 17
      t/t6017-rev-list-stdin.sh

80
revision.c

@ -1074,35 +1074,34 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
return 0; return 0;
} }


static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, const char ***prune_data) struct cmdline_pathspec {
{ int alloc;
const char **prune = *prune_data; int nr;
int prune_nr; const char **path;
int prune_alloc; };


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


static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
struct cmdline_pathspec *prune)
{
while (strbuf_getwholeline(sb, stdin, '\n') != EOF) { while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
int len = sb->len; int len = sb->len;
if (len && sb->buf[len - 1] == '\n') if (len && sb->buf[len - 1] == '\n')
sb->buf[--len] = '\0'; sb->buf[--len] = '\0';
ALLOC_GROW(prune, prune_nr+1, prune_alloc); ALLOC_GROW(prune->path, prune->nr+1, prune->alloc);
prune[prune_nr++] = xstrdup(sb->buf); prune->path[prune->nr++] = xstrdup(sb->buf);
} }
if (prune) {
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
prune[prune_nr] = NULL;
}
*prune_data = prune;
} }


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


static void append_prune_data(const char ***prune_data, const char **av)
{
const char **prune = *prune_data;
int prune_nr;
int prune_alloc;

if (!prune) {
*prune_data = av;
return;
}

/* count existing ones */
for (prune_nr = 0; prune[prune_nr]; prune_nr++)
;
prune_alloc = prune_nr; /* not really, but we do not know */

while (*av) {
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
prune[prune_nr++] = *av;
av++;
}
if (prune) {
ALLOC_GROW(prune, prune_nr+1, prune_alloc);
prune[prune_nr] = NULL;
}
*prune_data = prune;
}

/* /*
* Parse revision information, filling in the "rev_info" structure, * Parse revision information, filling in the "rev_info" structure,
* and removing the used arguments from the argument list. * 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)
int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
{ {
int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0; int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
const char **prune_data = NULL; struct cmdline_pathspec prune_data;
const char *submodule = NULL; const char *submodule = NULL;
const char *optarg; const char *optarg;
int argcount; int argcount;


memset(&prune_data, 0, sizeof(prune_data));

if (opt) if (opt)
submodule = opt->submodule; submodule = opt->submodule;


@ -1500,7 +1473,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
argv[i] = NULL; argv[i] = NULL;
argc = i; argc = i;
if (argv[i + 1]) if (argv[i + 1])
prune_data = argv + i + 1; append_prune_data(&prune_data, argv + i + 1);
seen_dashdash = 1; seen_dashdash = 1;
break; break;
} }
@ -1619,8 +1592,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
got_rev_arg = 1; got_rev_arg = 1;
} }


if (prune_data) if (prune_data.nr) {
revs->prune_data = get_pathspec(revs->prefix, prune_data); ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc);
prune_data.path[prune_data.nr++] = NULL;
revs->prune_data = get_pathspec(revs->prefix, prune_data.path);
}


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

17
t/t6017-rev-list-stdin.sh

@ -58,4 +58,21 @@ check side-3 ^side-4 -- file-3
check side-3 ^side-2 check side-3 ^side-2
check side-3 ^side-2 -- file-1 check side-3 ^side-2 -- file-1


test_expect_success 'not only --stdin' '
cat >expect <<-EOF &&
7

file-1
file-2
EOF
cat >input <<-EOF &&
^master^
--
file-2
EOF
git log --pretty=tformat:%s --name-only --stdin master -- file-1 \
<input >actual &&
test_cmp expect actual
'

test_done test_done

Loading…
Cancel
Save