Skip to content

Commit

Permalink
Merge branch 'jc/1.7.0-diff-whitespace-only-status'
Browse files Browse the repository at this point in the history
* jc/1.7.0-diff-whitespace-only-status:
  diff.c: fix typoes in comments
  Make test case number unique
  diff: Rename QUIET internal option to QUICK
  diff: change semantics of "ignore whitespace" options

Conflicts:
	diff.h
  • Loading branch information
Junio C Hamano committed Dec 26, 2009
2 parents 7ad9cec + 97bf2a0 commit 3cc3fb7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 13 deletions.
2 changes: 1 addition & 1 deletion builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ static int reopen_stdout(struct commit *commit, struct rev_info *rev)

get_patch_filename(commit, rev->nr, fmt_patch_suffix, &filename);

if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
if (!DIFF_OPT_TST(&rev->diffopt, QUICK))
fprintf(realstdout, "%s\n", filename.buf + outdir_offset);

if (freopen(filename.buf, "w", stdout) == NULL)
Expand Down
2 changes: 1 addition & 1 deletion builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if (revs.bisect)
bisect_list = 1;

quiet = DIFF_OPT_TST(&revs.diffopt, QUIET);
quiet = DIFF_OPT_TST(&revs.diffopt, QUICK);
for (i = 1 ; i < argc; i++) {
const char *arg = argv[i];

Expand Down
4 changes: 2 additions & 2 deletions diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
struct cache_entry *ce = active_cache[i];
int changed;

if (DIFF_OPT_TST(&revs->diffopt, QUIET) &&
if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
break;

Expand Down Expand Up @@ -507,7 +507,7 @@ int index_differs_from(const char *def, int diff_flags)

init_revisions(&rev, NULL);
setup_revisions(0, NULL, &rev, def);
DIFF_OPT_SET(&rev.diffopt, QUIET);
DIFF_OPT_SET(&rev.diffopt, QUICK);
DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
rev.diffopt.flags |= diff_flags;
run_diff_index(&rev, 1);
Expand Down
38 changes: 33 additions & 5 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,20 @@ int diff_setup_done(struct diff_options *options)
if (count > 1)
die("--name-only, --name-status, --check and -s are mutually exclusive");

/*
* Most of the time we can say "there are changes"
* only by checking if there are changed paths, but
* --ignore-whitespace* options force us to look
* inside contents.
*/

if (DIFF_XDL_TST(options, IGNORE_WHITESPACE) ||
DIFF_XDL_TST(options, IGNORE_WHITESPACE_CHANGE) ||
DIFF_XDL_TST(options, IGNORE_WHITESPACE_AT_EOL))
DIFF_OPT_SET(options, DIFF_FROM_CONTENTS);
else
DIFF_OPT_CLR(options, DIFF_FROM_CONTENTS);

if (DIFF_OPT_TST(options, FIND_COPIES_HARDER))
options->detect_rename = DIFF_DETECT_COPY;

Expand Down Expand Up @@ -2611,7 +2625,7 @@ int diff_setup_done(struct diff_options *options)
* to have found. It does not make sense not to return with
* exit code in such a case either.
*/
if (DIFF_OPT_TST(options, QUIET)) {
if (DIFF_OPT_TST(options, QUICK)) {
options->output_format = DIFF_FORMAT_NO_OUTPUT;
DIFF_OPT_SET(options, EXIT_WITH_STATUS);
}
Expand Down Expand Up @@ -2802,7 +2816,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
else if (!strcmp(arg, "--exit-code"))
DIFF_OPT_SET(options, EXIT_WITH_STATUS);
else if (!strcmp(arg, "--quiet"))
DIFF_OPT_SET(options, QUIET);
DIFF_OPT_SET(options, QUICK);
else if (!strcmp(arg, "--ext-diff"))
DIFF_OPT_SET(options, ALLOW_EXTERNAL);
else if (!strcmp(arg, "--no-ext-diff"))
Expand Down Expand Up @@ -3509,6 +3523,18 @@ void diff_flush(struct diff_options *options)
q->nr = q->alloc = 0;
if (options->close_file)
fclose(options->file);

/*
* Report the content-level differences with HAS_CHANGES;
* diff_addremove/diff_change does not set the bit when
* DIFF_FROM_CONTENTS is in effect (e.g. with -w).
*/
if (DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
if (options->found_changes)
DIFF_OPT_SET(options, HAS_CHANGES);
else
DIFF_OPT_CLR(options, HAS_CHANGES);
}
}

static void diffcore_apply_filter(const char *filter)
Expand Down Expand Up @@ -3645,7 +3671,7 @@ void diffcore_std(struct diff_options *options)
diff_resolve_rename_copy();
diffcore_apply_filter(options->filter);

if (diff_queued_diff.nr)
if (diff_queued_diff.nr && !DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))
DIFF_OPT_SET(options, HAS_CHANGES);
else
DIFF_OPT_CLR(options, HAS_CHANGES);
Expand Down Expand Up @@ -3705,7 +3731,8 @@ void diff_addremove(struct diff_options *options,
fill_filespec(two, sha1, mode);

diff_queue(&diff_queued_diff, one, two);
DIFF_OPT_SET(options, HAS_CHANGES);
if (!DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))
DIFF_OPT_SET(options, HAS_CHANGES);
}

void diff_change(struct diff_options *options,
Expand Down Expand Up @@ -3737,7 +3764,8 @@ void diff_change(struct diff_options *options,
fill_filespec(two, new_sha1, new_mode);

diff_queue(&diff_queued_diff, one, two);
DIFF_OPT_SET(options, HAS_CHANGES);
if (!DIFF_OPT_TST(options, DIFF_FROM_CONTENTS))
DIFF_OPT_SET(options, HAS_CHANGES);
}

void diff_unmerge(struct diff_options *options,
Expand Down
4 changes: 2 additions & 2 deletions diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
#define DIFF_OPT_COLOR_DIFF (1 << 8)
#define DIFF_OPT_COLOR_DIFF_WORDS (1 << 9)
#define DIFF_OPT_HAS_CHANGES (1 << 10)
#define DIFF_OPT_QUIET (1 << 11)
#define DIFF_OPT_QUICK (1 << 11)
#define DIFF_OPT_NO_INDEX (1 << 12)
#define DIFF_OPT_ALLOW_EXTERNAL (1 << 13)
#define DIFF_OPT_EXIT_WITH_STATUS (1 << 14)
Expand All @@ -66,7 +66,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
#define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)

#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
#define DIFF_OPT_SUBMODULE_LOG (1 << 23)

#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
Expand Down
2 changes: 1 addition & 1 deletion revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
revs->ignore_merges = 1;
revs->simplify_history = 1;
DIFF_OPT_SET(&revs->pruning, RECURSIVE);
DIFF_OPT_SET(&revs->pruning, QUIET);
DIFF_OPT_SET(&revs->pruning, QUICK);
revs->pruning.add_remove = file_add_remove;
revs->pruning.change = file_change;
revs->lifo = 1;
Expand Down
63 changes: 63 additions & 0 deletions t/t4040-whitespace-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh

test_description='diff --exit-code with whitespace'
. ./test-lib.sh

test_expect_success setup '
mkdir a b &&
echo >c &&
echo >a/d &&
echo >b/e &&
git add . &&
test_tick &&
git commit -m initial &&
echo " " >a/d &&
test_tick &&
git commit -a -m second &&
echo " " >a/d &&
echo " " >b/e &&
git add a/d
'

test_expect_success 'diff-tree --exit-code' '
test_must_fail git diff --exit-code HEAD^ HEAD &&
test_must_fail git diff-tree --exit-code HEAD^ HEAD
'

test_expect_success 'diff-tree -b --exit-code' '
git diff -b --exit-code HEAD^ HEAD &&
git diff-tree -b -p --exit-code HEAD^ HEAD &&
git diff-tree -b --exit-code HEAD^ HEAD
'

test_expect_success 'diff-index --cached --exit-code' '
test_must_fail git diff --cached --exit-code HEAD &&
test_must_fail git diff-index --cached --exit-code HEAD
'

test_expect_success 'diff-index -b -p --cached --exit-code' '
git diff -b --cached --exit-code HEAD &&
git diff-index -b -p --cached --exit-code HEAD
'

test_expect_success 'diff-index --exit-code' '
test_must_fail git diff --exit-code HEAD &&
test_must_fail git diff-index --exit-code HEAD
'

test_expect_success 'diff-index -b -p --exit-code' '
git diff -b --exit-code HEAD &&
git diff-index -b -p --exit-code HEAD
'

test_expect_success 'diff-files --exit-code' '
test_must_fail git diff --exit-code &&
test_must_fail git diff-files --exit-code
'

test_expect_success 'diff-files -b -p --exit-code' '
git diff -b --exit-code &&
git diff-files -b -p --exit-code
'

test_done
3 changes: 2 additions & 1 deletion tree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, stru
int baselen = strlen(base);

for (;;) {
if (DIFF_OPT_TST(opt, QUIET) && DIFF_OPT_TST(opt, HAS_CHANGES))
if (DIFF_OPT_TST(opt, QUICK) &&
DIFF_OPT_TST(opt, HAS_CHANGES))
break;
if (opt->nr_paths) {
skip_uninteresting(t1, base, baselen, opt);
Expand Down

0 comments on commit 3cc3fb7

Please sign in to comment.