Skip to content

Commit

Permalink
Merge branch 'ph/diffopts'
Browse files Browse the repository at this point in the history
* ph/diffopts:
  Reorder diff_opt_parse options more logically per topics.
  Make the diff_options bitfields be an unsigned with explicit masks.
  Use OPT_BIT in builtin-pack-refs
  Use OPT_BIT in builtin-for-each-ref
  Use OPT_SET_INT and OPT_BIT in builtin-branch
  parse-options new features.
  • Loading branch information
Junio C Hamano committed Nov 18, 2007
2 parents 41d8a5f + d054680 commit e6cb314
Show file tree
Hide file tree
Showing 21 changed files with 297 additions and 257 deletions.
10 changes: 5 additions & 5 deletions builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static struct origin *find_origin(struct scoreboard *sb,
* same and diff-tree is fairly efficient about this.
*/
diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.detect_rename = 0;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
paths[0] = origin->path;
Expand Down Expand Up @@ -409,7 +409,7 @@ static struct origin *find_rename(struct scoreboard *sb,
const char *paths[2];

diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.detect_rename = DIFF_DETECT_RENAME;
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_opts.single_follow = origin->path;
Expand Down Expand Up @@ -1075,7 +1075,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
return 1; /* nothing remains for this target */

diff_setup(&diff_opts);
diff_opts.recursive = 1;
DIFF_OPT_SET(&diff_opts, RECURSIVE);
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;

paths[0] = NULL;
Expand All @@ -1093,7 +1093,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
if ((opt & PICKAXE_BLAME_COPY_HARDEST)
|| ((opt & PICKAXE_BLAME_COPY_HARDER)
&& (!porigin || strcmp(target->path, porigin->path))))
diff_opts.find_copies_harder = 1;
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);

if (is_null_sha1(target->commit->object.sha1))
do_diff_cache(parent->tree->object.sha1, &diff_opts);
Expand All @@ -1102,7 +1102,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
target->commit->tree->object.sha1,
"", &diff_opts);

if (!diff_opts.find_copies_harder)
if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
diffcore_std(&diff_opts);

retval = 0;
Expand Down
44 changes: 16 additions & 28 deletions builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,48 +507,36 @@ static void rename_branch(const char *oldname, const char *newname, int force)

int cmd_branch(int argc, const char **argv, const char *prefix)
{
int delete = 0, force_delete = 0, force_create = 0;
int rename = 0, force_rename = 0;
int delete = 0, rename = 0, force_create = 0;
int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
int reflog = 0, track;
int kinds = REF_LOCAL_BRANCH, kind_remote = 0, kind_any = 0;
int kinds = REF_LOCAL_BRANCH;

struct option options[] = {
OPT_GROUP("Generic options"),
OPT__VERBOSE(&verbose),
OPT_BOOLEAN( 0 , "track", &track, "set up tracking mode (see git-pull(1))"),
OPT_BOOLEAN( 0 , "color", &branch_use_color, "use colored output"),
OPT_BOOLEAN('r', NULL, &kind_remote, "act on remote-tracking branches"),
OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches",
REF_REMOTE_BRANCH),
OPT__ABBREV(&abbrev),

OPT_GROUP("Specific git-branch actions:"),
OPT_BOOLEAN('a', NULL, &kind_any, "list both remote-tracking and local branches"),
OPT_BOOLEAN('d', NULL, &delete, "delete fully merged branch"),
OPT_BOOLEAN('D', NULL, &force_delete, "delete branch (even if not merged)"),
OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
OPT_BOOLEAN('m', NULL, &rename, "move/rename a branch and its reflog"),
OPT_BOOLEAN('M', NULL, &force_rename, "move/rename a branch, even if target exists"),
OPT_SET_INT('a', NULL, &kinds, "list both remote-tracking and local branches",
REF_REMOTE_BRANCH | REF_LOCAL_BRANCH),
OPT_BIT('d', NULL, &delete, "delete fully merged branch", 1),
OPT_BIT('D', NULL, &delete, "delete branch (even if not merged)", 2),
OPT_BIT('m', NULL, &rename, "move/rename a branch and its reflog", 1),
OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
OPT_END(),
};

git_config(git_branch_config);
track = branch_track;
argc = parse_options(argc, argv, options, builtin_branch_usage, 0);

delete |= force_delete;
rename |= force_rename;
if (kind_remote)
kinds = REF_REMOTE_BRANCH;
if (kind_any)
kinds = REF_REMOTE_BRANCH | REF_LOCAL_BRANCH;
if (abbrev && abbrev < MINIMUM_ABBREV)
abbrev = MINIMUM_ABBREV;
else if (abbrev > 40)
abbrev = 40;

if ((delete && rename) || (delete && force_create) ||
(rename && force_create))
if (!!delete + !!rename + !!force_create > 1)
usage_with_options(builtin_branch_usage, options);

head = resolve_ref("HEAD", head_sha1, 0, NULL);
Expand All @@ -564,13 +552,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
}

if (delete)
return delete_branches(argc, argv, force_delete, kinds);
return delete_branches(argc, argv, delete > 1, kinds);
else if (argc == 0)
print_ref_list(kinds, detached, verbose, abbrev);
else if (rename && (argc == 1))
rename_branch(head, argv[0], force_rename);
rename_branch(head, argv[0], rename > 1);
else if (rename && (argc == 2))
rename_branch(argv[0], argv[1], force_rename);
rename_branch(argv[0], argv[1], rename > 1);
else if (argc <= 2)
create_branch(argv[0], (argc == 2) ? argv[1] : head,
force_create, reflog, track);
Expand Down
4 changes: 3 additions & 1 deletion builtin-diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
result = run_diff_files_cmd(&rev, argc, argv);
return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
return result;
}
4 changes: 3 additions & 1 deletion builtin-diff-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
return -1;
}
result = run_diff_index(&rev, cached);
return rev.diffopt.exit_with_status ? rev.diffopt.has_changes: result;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
return result;
}
7 changes: 4 additions & 3 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
}

if (!read_stdin)
return opt->diffopt.exit_with_status ?
opt->diffopt.has_changes: 0;
return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)
&& DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES);

if (opt->diffopt.detect_rename)
opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
Expand All @@ -134,5 +134,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
else
diff_tree_stdin(line);
}
return opt->diffopt.exit_with_status ? opt->diffopt.has_changes: 0;
return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)
&& DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES);
}
12 changes: 6 additions & 6 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void stuff_change(struct diff_options *opt,
!hashcmp(old_sha1, new_sha1) && (old_mode == new_mode))
return;

if (opt->reverse_diff) {
if (DIFF_OPT_TST(opt, REVERSE_DIFF)) {
unsigned tmp;
const unsigned char *tmp_u;
const char *tmp_c;
Expand Down Expand Up @@ -253,13 +253,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (diff_setup_done(&rev.diffopt) < 0)
die("diff_setup_done failed");
}
rev.diffopt.allow_external = 1;
rev.diffopt.recursive = 1;
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);

/* If the user asked for our exit code then don't start a
* pager or we would end up reporting its exit code instead.
*/
if (!rev.diffopt.exit_with_status)
if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
setup_pager();

/* Do we have --cached and not have a pending object, then
Expand Down Expand Up @@ -363,8 +363,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
else
result = builtin_diff_combined(&rev, argc, argv,
ent, ents);
if (rev.diffopt.exit_with_status)
result = rev.diffopt.has_changes;
if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
result = DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;

if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();
Expand Down
19 changes: 10 additions & 9 deletions builtin-for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,16 +833,19 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
int i, num_refs;
const char *format = "%(objectname) %(objecttype)\t%(refname)";
struct ref_sort *sort = NULL, **sort_tail = &sort;
int maxcount = 0, quote_style;
int quote_shell = 0, quote_perl = 0, quote_python = 0, quote_tcl = 0;
int maxcount = 0, quote_style = 0;
struct refinfo **refs;
struct grab_ref_cbdata cbdata;

struct option opts[] = {
OPT_BOOLEAN('s', "shell", &quote_shell, "quote placeholders suitably for shells"),
OPT_BOOLEAN('p', "perl", &quote_perl, "quote placeholders suitably for perl"),
OPT_BOOLEAN( 0 , "python", &quote_python, "quote placeholders suitably for python"),
OPT_BOOLEAN( 0 , "tcl", &quote_tcl, "quote placeholders suitably for tcl"),
OPT_BIT('s', "shell", &quote_style,
"quote placeholders suitably for shells", QUOTE_SHELL),
OPT_BIT('p', "perl", &quote_style,
"quote placeholders suitably for perl", QUOTE_PERL),
OPT_BIT(0 , "python", &quote_style,
"quote placeholders suitably for python", QUOTE_PYTHON),
OPT_BIT(0 , "tcl", &quote_style,
"quote placeholders suitably for tcl", QUOTE_TCL),

OPT_GROUP(""),
OPT_INTEGER( 0 , "count", &maxcount, "show only <n> matched refs"),
Expand All @@ -857,15 +860,13 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
error("invalid --count argument: `%d'", maxcount);
usage_with_options(for_each_ref_usage, opts);
}
if (quote_shell + quote_perl + quote_python + quote_tcl > 1) {
if (HAS_MULTI_BITS(quote_style)) {
error("more than one quoting style ?");
usage_with_options(for_each_ref_usage, opts);
}
if (verify_format(format))
usage_with_options(for_each_ref_usage, opts);

quote_style = QUOTE_SHELL * quote_shell + QUOTE_PERL * quote_perl +
QUOTE_PYTHON * quote_python + QUOTE_TCL * quote_tcl;
if (!sort)
sort = default_sort();
sort_atom_limit = used_atom_cnt;
Expand Down
24 changes: 10 additions & 14 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
rev->abbrev = DEFAULT_ABBREV;
rev->commit_format = CMIT_FMT_DEFAULT;
rev->verbose_header = 1;
rev->diffopt.recursive = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->show_root_diff = default_show_root;
rev->subject_prefix = fmt_patch_subject_prefix;
argc = setup_revisions(argc, argv, rev, "HEAD");
if (rev->diffopt.pickaxe || rev->diffopt.filter)
rev->always_show_header = 0;
if (rev->diffopt.follow_renames) {
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
rev->always_show_header = 0;
if (rev->diffopt.nr_paths != 1)
usage("git logs can only follow renames on one pathname at a time");
Expand Down Expand Up @@ -185,23 +185,19 @@ int cmd_show(int argc, const char **argv, const char *prefix)
struct tag *t = (struct tag *)o;

printf("%stag %s%s\n\n",
diff_get_color(rev.diffopt.color_diff,
DIFF_COMMIT),
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
t->tag,
diff_get_color(rev.diffopt.color_diff,
DIFF_RESET));
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
ret = show_object(o->sha1, 1);
objects[i].item = (struct object *)t->tagged;
i--;
break;
}
case OBJ_TREE:
printf("%stree %s%s\n\n",
diff_get_color(rev.diffopt.color_diff,
DIFF_COMMIT),
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
name,
diff_get_color(rev.diffopt.color_diff,
DIFF_RESET));
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
show_tree_object);
break;
Expand Down Expand Up @@ -497,7 +493,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.combine_merges = 0;
rev.ignore_merges = 1;
rev.diffopt.msg_sep = "";
rev.diffopt.recursive = 1;
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);

rev.subject_prefix = fmt_patch_subject_prefix;
rev.extra_headers = extra_headers;
Expand Down Expand Up @@ -605,8 +601,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;

if (!rev.diffopt.text)
rev.diffopt.binary = 1;
if (!DIFF_OPT_TST(&rev.diffopt, TEXT))
DIFF_OPT_SET(&rev.diffopt, BINARY);

if (!output_directory && !use_stdout)
output_directory = prefix;
Expand Down Expand Up @@ -764,7 +760,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
revs.diff = 1;
revs.combine_merges = 0;
revs.ignore_merges = 1;
revs.diffopt.recursive = 1;
DIFF_OPT_SET(&revs.diffopt, RECURSIVE);

if (add_pending_commit(head, &revs, 0))
die("Unknown commit %s", head);
Expand Down
12 changes: 3 additions & 9 deletions builtin-pack-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,13 @@ static char const * const pack_refs_usage[] = {

int cmd_pack_refs(int argc, const char **argv, const char *prefix)
{
int all = 0, prune = 1;
unsigned int flags = 0;
unsigned int flags = PACK_REFS_PRUNE;
struct option opts[] = {
OPT_BOOLEAN(0, "all", &all, "pack everything"),
OPT_BOOLEAN(0, "prune", &prune, "prune loose refs (default)"),
OPT_BIT(0, "all", &flags, "pack everything", PACK_REFS_ALL),
OPT_BIT(0, "prune", &flags, "prune loose refs (default)", PACK_REFS_PRUNE),
OPT_END(),
};

if (parse_options(argc, argv, opts, pack_refs_usage, 0))
usage_with_options(pack_refs_usage, opts);
if (prune)
flags |= PACK_REFS_PRUNE;
if (all)
flags |= PACK_REFS_ALL;
return pack_refs(flags);
}
10 changes: 5 additions & 5 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
int mode_differs = 0;
int i, show_hunks;
int working_tree_file = is_null_sha1(elem->sha1);
int abbrev = opt->full_index ? 40 : DEFAULT_ABBREV;
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
mmfile_t result_file;

context = opt->context;
Expand Down Expand Up @@ -784,7 +784,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,

if (show_hunks || mode_differs || working_tree_file) {
const char *abb;
int use_color = opt->color_diff;
int use_color = DIFF_OPT_TST(opt, COLOR_DIFF);
const char *c_meta = diff_get_color(use_color, DIFF_METAINFO);
const char *c_reset = diff_get_color(use_color, DIFF_RESET);
int added = 0;
Expand Down Expand Up @@ -836,7 +836,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
dump_quoted_path("+++ /dev/", "null", c_meta, c_reset);
else
dump_quoted_path("+++ b/", elem->path, c_meta, c_reset);
dump_sline(sline, cnt, num_parent, opt->color_diff);
dump_sline(sline, cnt, num_parent, DIFF_OPT_TST(opt, COLOR_DIFF));
}
free(result);

Expand Down Expand Up @@ -929,8 +929,8 @@ void diff_tree_combined(const unsigned char *sha1,

diffopts = *opt;
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diffopts.recursive = 1;
diffopts.allow_external = 0;
DIFF_OPT_SET(&diffopts, RECURSIVE);
DIFF_OPT_CLR(&diffopts, ALLOW_EXTERNAL);

show_log_first = !!rev->loginfo && !rev->no_commit_id;
needsep = 0;
Expand Down
Loading

0 comments on commit e6cb314

Please sign in to comment.