Skip to content

Commit

Permalink
Teach --stdin option to "log" family
Browse files Browse the repository at this point in the history
Move the logic to read revs from standard input that rev-list knows about
from it to revision machinery, so that all the users of setup_revisions()
can feed the list of revs from the standard input when "--stdin" is used
on the command line.

Allow some users of the revision machinery that want different semantics
from the "--stdin" option to disable it by setting an option in the
rev_info structure.

This also cleans up the kludge made to bundle.c via cut and paste.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Nov 20, 2009
1 parent 63d564b commit 8b3dce5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Documentation/rev-list-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ endif::git-rev-list[]
Pretend as if all the refs in `$GIT_DIR/refs/remotes` are listed
on the command line as '<commit>'.

ifdef::git-rev-list[]
--stdin::

In addition to the '<commit>' listed on the command
line, read them from the standard input.

ifdef::git-rev-list[]
--quiet::

Don't print anything to standard output. This form
Expand Down
1 change: 1 addition & 0 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
die_errno("cannot stat path '%s'", path);
}

revs.disable_stdin = 1;
setup_revisions(argc, argv, &revs, NULL);
memset(&sb, 0, sizeof(sb));

Expand Down
1 change: 1 addition & 0 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
opt->abbrev = 0;
opt->diff = 1;
opt->disable_stdin = 1;
argc = setup_revisions(argc, argv, opt, NULL);

while (--argc > 0) {
Expand Down
7 changes: 0 additions & 7 deletions builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
struct rev_info revs;
struct rev_list_info info;
int i;
int read_from_stdin = 0;
int bisect_list = 0;
int bisect_show_vars = 0;
int bisect_find_all = 0;
Expand Down Expand Up @@ -349,12 +348,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
bisect_show_vars = 1;
continue;
}
if (!strcmp(arg, "--stdin")) {
if (read_from_stdin++)
die("--stdin given twice?");
read_revisions_from_stdin(&revs);
continue;
}
usage(rev_list_usage);

}
Expand Down
12 changes: 2 additions & 10 deletions bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ int create_bundle(struct bundle_header *header, const char *path,
int i, ref_count = 0;
char buffer[1024];
struct rev_info revs;
int read_from_stdin = 0;
struct child_process rls;
FILE *rls_fout;

Expand Down Expand Up @@ -256,15 +255,8 @@ int create_bundle(struct bundle_header *header, const char *path,
/* write references */
argc = setup_revisions(argc, argv, &revs, NULL);

for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--stdin")) {
if (read_from_stdin++)
die("--stdin given twice?");
read_revisions_from_stdin(&revs);
continue;
}
return error("unrecognized argument: %s'", argv[i]);
}
if (argc > 1)
return error("unrecognized argument: %s'", argv[1]);

object_array_remove_duplicates(&revs.pending);

Expand Down
15 changes: 13 additions & 2 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs,
return 0;
}

void read_revisions_from_stdin(struct rev_info *revs)
static void read_revisions_from_stdin(struct rev_info *revs)
{
struct strbuf sb;

Expand Down Expand Up @@ -1229,7 +1229,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
*/
int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
{
int i, flags, left, seen_dashdash;
int i, flags, left, seen_dashdash, read_from_stdin;

/* First, search for "--" */
seen_dashdash = 0;
Expand All @@ -1247,6 +1247,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch

/* Second, deal with arguments and options */
flags = 0;
read_from_stdin = 0;
for (left = i = 1; i < argc; i++) {
const char *arg = argv[i];
if (*arg == '-') {
Expand Down Expand Up @@ -1285,6 +1286,16 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
revs->no_walk = 0;
continue;
}
if (!strcmp(arg, "--stdin")) {
if (revs->disable_stdin) {
argv[left++] = arg;
continue;
}
if (read_from_stdin++)
die("--stdin given twice?");
read_revisions_from_stdin(revs);
continue;
}

opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv);
if (opts > 0) {
Expand Down
4 changes: 2 additions & 2 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct rev_info {
use_terminator:1,
missing_newline:1,
date_mode_explicit:1;
unsigned int disable_stdin:1;

enum date_mode date_mode;

unsigned int abbrev;
Expand Down Expand Up @@ -128,8 +130,6 @@ struct rev_info {
#define REV_TREE_DIFFERENT 3 /* Mixed changes */

/* revision.c */
void read_revisions_from_stdin(struct rev_info *revs);

typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
extern volatile show_early_output_fn_t show_early_output;

Expand Down

0 comments on commit 8b3dce5

Please sign in to comment.