зеркало из https://github.com/microsoft/git.git
diff.c: remove implicit dependency on the_index
A new variant repo_diff_setup() is added that takes 'struct repository *' and diff_setup() becomes a thin macro around it that is protected by NO_THE_REPOSITORY_COMPATIBILITY_MACROS, similar to NO_THE_INDEX_.... The plan is these macros will always be defined for all library files and the macros are only accessible in builtin/ Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
38bbc2ea39
Коммит
e675765235
|
@ -18,8 +18,8 @@ Calling sequence
|
|||
----------------
|
||||
|
||||
* Prepare `struct diff_options` to record the set of diff options, and
|
||||
then call `diff_setup()` to initialize this structure. This sets up
|
||||
the vanilla default.
|
||||
then call `repo_diff_setup()` to initialize this structure. This
|
||||
sets up the vanilla default.
|
||||
|
||||
* Fill in the options structure to specify desired output format, rename
|
||||
detection, etc. `diff_opt_parse()` can be used to parse options given
|
||||
|
|
20
blame.c
20
blame.c
|
@ -541,8 +541,9 @@ static int fill_blob_sha1_and_mode(struct repository *r,
|
|||
* We have an origin -- check if the same path exists in the
|
||||
* parent and return an origin structure to represent it.
|
||||
*/
|
||||
static struct blame_origin *find_origin(struct commit *parent,
|
||||
struct blame_origin *origin)
|
||||
static struct blame_origin *find_origin(struct repository *r,
|
||||
struct commit *parent,
|
||||
struct blame_origin *origin)
|
||||
{
|
||||
struct blame_origin *porigin;
|
||||
struct diff_options diff_opts;
|
||||
|
@ -562,7 +563,7 @@ static struct blame_origin *find_origin(struct commit *parent,
|
|||
* and origin first. Most of the time they are the
|
||||
* same and diff-tree is fairly efficient about this.
|
||||
*/
|
||||
diff_setup(&diff_opts);
|
||||
repo_diff_setup(r, &diff_opts);
|
||||
diff_opts.flags.recursive = 1;
|
||||
diff_opts.detect_rename = 0;
|
||||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
|
@ -629,14 +630,15 @@ static struct blame_origin *find_origin(struct commit *parent,
|
|||
* We have an origin -- find the path that corresponds to it in its
|
||||
* parent and return an origin structure to represent it.
|
||||
*/
|
||||
static struct blame_origin *find_rename(struct commit *parent,
|
||||
struct blame_origin *origin)
|
||||
static struct blame_origin *find_rename(struct repository *r,
|
||||
struct commit *parent,
|
||||
struct blame_origin *origin)
|
||||
{
|
||||
struct blame_origin *porigin = NULL;
|
||||
struct diff_options diff_opts;
|
||||
int i;
|
||||
|
||||
diff_setup(&diff_opts);
|
||||
repo_diff_setup(r, &diff_opts);
|
||||
diff_opts.flags.recursive = 1;
|
||||
diff_opts.detect_rename = DIFF_DETECT_RENAME;
|
||||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
|
@ -1260,7 +1262,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
|
|||
if (!unblamed)
|
||||
return; /* nothing remains for this target */
|
||||
|
||||
diff_setup(&diff_opts);
|
||||
repo_diff_setup(sb->repo, &diff_opts);
|
||||
diff_opts.flags.recursive = 1;
|
||||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
|
||||
|
@ -1442,7 +1444,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
|
|||
* common cases, then we look for renames in the second pass.
|
||||
*/
|
||||
for (pass = 0; pass < 2 - sb->no_whole_file_rename; pass++) {
|
||||
struct blame_origin *(*find)(struct commit *, struct blame_origin *);
|
||||
struct blame_origin *(*find)(struct repository *, struct commit *, struct blame_origin *);
|
||||
find = pass ? find_rename : find_origin;
|
||||
|
||||
for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
|
||||
|
@ -1455,7 +1457,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
|
|||
continue;
|
||||
if (parse_commit(p))
|
||||
continue;
|
||||
porigin = find(p, origin);
|
||||
porigin = find(sb->repo, p, origin);
|
||||
if (!porigin)
|
||||
continue;
|
||||
if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
|
||||
|
|
|
@ -339,7 +339,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
|
|||
}
|
||||
if (no_index)
|
||||
/* If this is a no-index diff, just run it and exit there. */
|
||||
diff_no_index(&rev, argc, argv);
|
||||
diff_no_index(the_repository, &rev, argc, argv);
|
||||
|
||||
/* Otherwise, we are doing the usual "git" diff */
|
||||
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
|
||||
|
|
|
@ -1361,7 +1361,7 @@ static void prepare_bases(struct base_tree_info *bases,
|
|||
return;
|
||||
|
||||
init_commit_base(&commit_base);
|
||||
diff_setup(&diffopt);
|
||||
repo_diff_setup(the_repository, &diffopt);
|
||||
diffopt.flags.recursive = 1;
|
||||
diff_setup_done(&diffopt);
|
||||
|
||||
|
|
|
@ -452,7 +452,7 @@ static void finish(struct commit *head_commit,
|
|||
}
|
||||
if (new_head && show_diffstat) {
|
||||
struct diff_options opts;
|
||||
diff_setup(&opts);
|
||||
repo_diff_setup(the_repository, &opts);
|
||||
opts.stat_width = -1; /* use full terminal width */
|
||||
opts.stat_graph_width = -1; /* respect statGraphWidth config */
|
||||
opts.output_format |=
|
||||
|
|
|
@ -34,7 +34,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
|
|||
|
||||
git_config(git_diff_ui_config, NULL);
|
||||
|
||||
diff_setup(&diffopt);
|
||||
repo_diff_setup(the_repository, &diffopt);
|
||||
diffopt.output_format = DIFF_FORMAT_PATCH;
|
||||
diffopt.flags.suppress_diff_headers = 1;
|
||||
diffopt.output_prefix = output_prefix_cb;
|
||||
|
|
|
@ -233,7 +233,8 @@ static void fixup_paths(const char **path, struct strbuf *replacement)
|
|||
}
|
||||
}
|
||||
|
||||
void diff_no_index(struct rev_info *revs,
|
||||
void diff_no_index(struct repository *r,
|
||||
struct rev_info *revs,
|
||||
int argc, const char **argv)
|
||||
{
|
||||
int i;
|
||||
|
@ -241,7 +242,11 @@ void diff_no_index(struct rev_info *revs,
|
|||
struct strbuf replacement = STRBUF_INIT;
|
||||
const char *prefix = revs->prefix;
|
||||
|
||||
diff_setup(&revs->diffopt);
|
||||
/*
|
||||
* FIXME: --no-index should not look at index and we should be
|
||||
* able to pass NULL repo. Maybe later.
|
||||
*/
|
||||
repo_diff_setup(r, &revs->diffopt);
|
||||
for (i = 1; i < argc - 2; ) {
|
||||
int j;
|
||||
if (!strcmp(argv[i], "--no-index"))
|
||||
|
|
4
diff.c
4
diff.c
|
@ -4390,12 +4390,12 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
|
|||
builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
|
||||
}
|
||||
|
||||
void diff_setup(struct diff_options *options)
|
||||
void repo_diff_setup(struct repository *r, struct diff_options *options)
|
||||
{
|
||||
memcpy(options, &default_diff_options, sizeof(*options));
|
||||
|
||||
options->file = stdout;
|
||||
options->repo->index = &the_index;
|
||||
options->repo = r;
|
||||
|
||||
options->abbrev = DEFAULT_ABBREV;
|
||||
options->line_termination = '\n';
|
||||
|
|
7
diff.h
7
diff.h
|
@ -336,7 +336,10 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);
|
|||
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
|
||||
void init_diff_ui_defaults(void);
|
||||
int git_diff_ui_config(const char *var, const char *value, void *cb);
|
||||
void diff_setup(struct diff_options *);
|
||||
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
|
||||
#define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
|
||||
#endif
|
||||
void repo_diff_setup(struct repository *, struct diff_options *);
|
||||
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
|
||||
void diff_setup_done(struct diff_options *);
|
||||
int git_config_rename(const char *var, const char *value);
|
||||
|
@ -426,7 +429,7 @@ int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
|
|||
|
||||
int diff_result_code(struct diff_options *, int);
|
||||
|
||||
void diff_no_index(struct rev_info *, int, const char **);
|
||||
void diff_no_index(struct repository *, struct rev_info *, int, const char **);
|
||||
|
||||
int index_differs_from(const char *def, const struct diff_flags *flags,
|
||||
int ita_invisible_in_index);
|
||||
|
|
|
@ -1812,7 +1812,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
|
|||
struct diff_queue_struct *ret;
|
||||
struct diff_options opts;
|
||||
|
||||
diff_setup(&opts);
|
||||
repo_diff_setup(the_repository, &opts);
|
||||
opts.flags.recursive = 1;
|
||||
opts.flags.rename_empty = 0;
|
||||
opts.detect_rename = merge_detect_rename(o);
|
||||
|
|
|
@ -126,7 +126,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
|
|||
trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
|
||||
oid_to_hex(base), oid_to_hex(remote));
|
||||
|
||||
diff_setup(&opt);
|
||||
repo_diff_setup(the_repository, &opt);
|
||||
opt.flags.recursive = 1;
|
||||
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
diff_setup_done(&opt);
|
||||
|
@ -189,7 +189,7 @@ static void diff_tree_local(struct notes_merge_options *o,
|
|||
trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
|
||||
len, oid_to_hex(base), oid_to_hex(local));
|
||||
|
||||
diff_setup(&opt);
|
||||
repo_diff_setup(the_repository, &opt);
|
||||
opt.flags.recursive = 1;
|
||||
opt.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
diff_setup_done(&opt);
|
||||
|
|
|
@ -59,7 +59,7 @@ static int patch_id_cmp(const void *cmpfn_data,
|
|||
int init_patch_ids(struct patch_ids *ids)
|
||||
{
|
||||
memset(ids, 0, sizeof(*ids));
|
||||
diff_setup(&ids->diffopts);
|
||||
repo_diff_setup(the_repository, &ids->diffopts);
|
||||
ids->diffopts.detect_rename = 0;
|
||||
ids->diffopts.flags.recursive = 1;
|
||||
diff_setup_done(&ids->diffopts);
|
||||
|
|
|
@ -2137,7 +2137,7 @@ int index_has_changes(struct index_state *istate,
|
|||
if (tree || !get_oid_tree("HEAD", &cmp)) {
|
||||
struct diff_options opt;
|
||||
|
||||
diff_setup(&opt);
|
||||
repo_diff_setup(the_repository, &opt);
|
||||
opt.flags.exit_with_status = 1;
|
||||
if (!sb)
|
||||
opt.flags.quick = 1;
|
||||
|
|
|
@ -1468,7 +1468,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
|
|||
grep_init(&revs->grep_filter, the_repository, prefix);
|
||||
revs->grep_filter.status_only = 1;
|
||||
|
||||
diff_setup(&revs->diffopt);
|
||||
repo_diff_setup(the_repository, &revs->diffopt);
|
||||
if (prefix && !revs->diffopt.prefix) {
|
||||
revs->diffopt.prefix = prefix;
|
||||
revs->diffopt.prefix_length = strlen(prefix);
|
||||
|
|
|
@ -605,7 +605,7 @@ static void try_to_follow_renames(const struct object_id *old_oid,
|
|||
choice = q->queue[0];
|
||||
q->nr = 0;
|
||||
|
||||
diff_setup(&diff_opts);
|
||||
repo_diff_setup(the_repository, &diff_opts);
|
||||
diff_opts.flags.recursive = 1;
|
||||
diff_opts.flags.find_copies_harder = 1;
|
||||
diff_opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
|
|
Загрузка…
Ссылка в новой задаче