diff options
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 55 |
1 files changed, 46 insertions, 9 deletions
@@ -2,12 +2,19 @@ * Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "abspath.h" +#include "alloc.h" +#include "base85.h" #include "config.h" +#include "convert.h" +#include "environment.h" +#include "gettext.h" #include "tempfile.h" #include "quote.h" #include "diff.h" #include "diffcore.h" #include "delta.h" +#include "hex.h" #include "xdiff-interface.h" #include "color.h" #include "attr.h" @@ -23,12 +30,19 @@ #include "string-list.h" #include "strvec.h" #include "graph.h" +#include "oid-array.h" #include "packfile.h" +#include "pager.h" #include "parse-options.h" #include "help.h" #include "promisor-remote.h" #include "dir.h" +#include "object-file.h" +#include "object-name.h" +#include "setup.h" #include "strmap.h" +#include "ws.h" +#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -127,7 +141,7 @@ static int parse_dirstat_params(struct diff_options *options, const char *params int i; if (*params_copy) - string_list_split_in_place(¶ms, params_copy, ',', -1); + string_list_split_in_place(¶ms, params_copy, ",", -1); for (i = 0; i < params.nr; i++) { const char *p = params.items[i].string; if (!strcmp(p, "changes")) { @@ -3374,6 +3388,17 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const options->b_prefix = b; } +void diff_set_noprefix(struct diff_options *options) +{ + options->a_prefix = options->b_prefix = ""; +} + +void diff_set_default_prefix(struct diff_options *options) +{ + options->a_prefix = "a/"; + options->b_prefix = "b/"; +} + struct userdiff_driver *get_textconv(struct repository *r, struct diff_filespec *one) { @@ -4351,7 +4376,7 @@ static int similarity_index(struct diff_filepair *p) static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev) { if (startup_info->have_repository) - return find_unique_abbrev(oid, abbrev); + return repo_find_unique_abbrev(the_repository, oid, abbrev); else { char *hex = oid_to_hex(oid); if (abbrev < 0) @@ -4674,10 +4699,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options) options->flags.ignore_untracked_in_submodules = 1; if (diff_no_prefix) { - options->a_prefix = options->b_prefix = ""; + diff_set_noprefix(options); } else if (!diff_mnemonic_prefix) { - options->a_prefix = "a/"; - options->b_prefix = "b/"; + diff_set_default_prefix(options); } options->color_moved = diff_color_moved_default; @@ -4988,7 +5012,7 @@ static int diff_opt_find_object(const struct option *option, struct object_id oid; BUG_ON_OPT_NEG(unset); - if (get_oid(arg, &oid)) + if (repo_get_oid(the_repository, arg, &oid)) return error(_("unable to resolve '%s'"), arg); if (!opt->objfind) @@ -5261,8 +5285,18 @@ static int diff_opt_no_prefix(const struct option *opt, BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(optarg); - options->a_prefix = ""; - options->b_prefix = ""; + diff_set_noprefix(options); + return 0; +} + +static int diff_opt_default_prefix(const struct option *opt, + const char *optarg, int unset) +{ + struct diff_options *options = opt->value; + + BUG_ON_OPT_NEG(unset); + BUG_ON_OPT_ARG(optarg); + diff_set_default_prefix(options); return 0; } @@ -5555,6 +5589,9 @@ struct option *add_diff_options(const struct option *opts, OPT_CALLBACK_F(0, "no-prefix", options, NULL, N_("do not show any source or destination prefix"), PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_no_prefix), + OPT_CALLBACK_F(0, "default-prefix", options, NULL, + N_("use default prefixes a/ and b/"), + PARSE_OPT_NONEG | PARSE_OPT_NOARG, diff_opt_default_prefix), OPT_INTEGER_F(0, "inter-hunk-context", &options->interhunkcontext, N_("show context between diff hunks up to the specified number of lines"), PARSE_OPT_NONEG), @@ -6860,7 +6897,7 @@ void diffcore_std(struct diff_options *options) * If no prefetching occurs, diffcore_rename() will prefetch if it * decides that it needs inexact rename detection. */ - if (options->repo == the_repository && has_promisor_remote() && + if (options->repo == the_repository && repo_has_promisor_remote(the_repository) && (options->output_format & output_formats_to_prefetch || options->pickaxe_opts & DIFF_PICKAXE_KINDS_MASK)) diff_queued_diff_prefetch(options->repo); |