diff options
Diffstat (limited to 'builtin/diff.c')
| -rw-r--r-- | builtin/diff.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/builtin/diff.c b/builtin/diff.c index 9b6cdabe15..0b23c41456 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -4,6 +4,9 @@ * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_REPOSITORY_VARIABLE +#define DISABLE_SIGN_COMPARE_WARNINGS + #include "builtin.h" #include "config.h" #include "ewah/ewok.h" @@ -32,7 +35,7 @@ static const char builtin_diff_usage[] = " or: git diff [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...]\n" " or: git diff [<options>] <commit>...<commit> [--] [<path>...]\n" " or: git diff [<options>] <blob> <blob>\n" -" or: git diff [<options>] --no-index [--] <path> <path>" +" or: git diff [<options>] --no-index [--] <path> <path> [<pathspec>...]" "\n" COMMON_DIFF_OPTIONS_HELP; @@ -101,7 +104,7 @@ static void builtin_diff_b_f(struct rev_info *revs, stuff_change(&revs->diffopt, blob[0]->mode, canon_mode(st.st_mode), - &blob[0]->item->oid, null_oid(), + &blob[0]->item->oid, null_oid(the_hash_algo), 1, 0, blob[0]->path ? blob[0]->path : path, path); @@ -388,7 +391,15 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym) sym->skip = map; } -int cmd_diff(int argc, const char **argv, const char *prefix) +static void symdiff_release(struct symdiff *sdiff) +{ + bitmap_free(sdiff->skip); +} + +int cmd_diff(int argc, + const char **argv, + const char *prefix, + struct repository *repo UNUSED) { int i; struct rev_info rev; @@ -472,10 +483,25 @@ int cmd_diff(int argc, const char **argv, const char *prefix) * configurable via a command line option. */ if (nongit) - repo_set_hash_algo(the_repository, GIT_HASH_SHA1); + repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT); init_diff_ui_defaults(); - git_config(git_diff_ui_config, NULL); + repo_config(the_repository, git_diff_ui_config, NULL); + + /* + * If we are ignoring the fact that our current directory may + * be part of a working tree controlled by a Git repository to + * pretend to be a "better GNU diff", we should undo the + * effect of the setup code that did a chdir() to the top of + * the working tree. Where we came from is recorded in the + * prefix. + */ + if (no_index && prefix) { + if (chdir(prefix)) + die(_("cannot come back to cwd")); + prefix = NULL; + } + prefix = precompose_argv_prefix(argc, argv, prefix); repo_init_revisions(the_repository, &rev, prefix); @@ -487,7 +513,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) /* If this is a no-index diff, just run it and exit there. */ if (no_index) - exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT, + exit(diff_no_index(&rev, the_repository->hash_algo, + no_index == DIFF_NO_INDEX_IMPLICIT, argc, argv)); @@ -614,11 +641,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix) builtin_diff_combined(&rev, argc, argv, ent.objects, ent.nr, first_non_parent); - result = diff_result_code(&rev.diffopt); + result = diff_result_code(&rev); if (1 < rev.diffopt.skip_stat_unmatch) refresh_index_quietly(); release_revisions(&rev); object_array_clear(&ent); - UNLEAK(blob); + symdiff_release(&sdiff); return result; } |
