diff options
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 89 |
1 files changed, 66 insertions, 23 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")) { @@ -2993,6 +3007,24 @@ static int dirstat_compare(const void *_a, const void *_b) return strcmp(a->name, b->name); } +static void conclude_dirstat(struct diff_options *options, + struct dirstat_dir *dir, + unsigned long changed) +{ + struct dirstat_file *to_free = dir->files; + + if (!changed) { + /* This can happen even with many files, if everything was renames */ + ; + } else { + /* Show all directories with more than x% of the changes */ + QSORT(dir->files, dir->nr, dirstat_compare); + gather_dirstat(options, dir, changed, "", 0); + } + + free(to_free); +} + static void show_dirstat(struct diff_options *options) { int i; @@ -3082,13 +3114,7 @@ found_damage: dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *options) @@ -3126,13 +3152,7 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void free_diffstat_file(struct diffstat_file *f) @@ -3374,6 +3394,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 +4382,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 +4705,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 +5018,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 +5291,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 +5595,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 +6903,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); |