All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] diff: Add diff.orderfile configuration variable
@ 2013-10-21 10:31 Anders Waldenborg
  2013-10-21 18:40 ` Jonathan Nieder
                   ` (13 more replies)
  0 siblings, 14 replies; 35+ messages in thread
From: Anders Waldenborg @ 2013-10-21 10:31 UTC (permalink / raw)
  To: git

diff.orderfile acts as a default for the -O command line option.

Signed-off-by: Anders Waldenborg <anders@0x63.nu>
---

 Documentation/diff-config.txt |  4 +++
 diff.c                        |  5 +++
 t/t4056-diff-order.sh         | 74 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100755 t/t4056-diff-order.sh

diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index 223b931..51f9190 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -98,6 +98,10 @@ diff.mnemonicprefix::
 diff.noprefix::
  If set, 'git diff' does not show any source or destination prefix.

+diff.orderfile::
+ Path to file to use for ordering the files in the diff, each line
+ is a shell glob pattern; equivalent to the 'git diff' option '-O'.
+
 diff.renameLimit::
  The number of files to consider when performing the copy/rename
  detection; equivalent to the 'git diff' option '-l'.
diff --git a/diff.c b/diff.c
index a04a34d..e66f031 100644
--- a/diff.c
+++ b/diff.c
@@ -30,6 +30,7 @@ static int diff_use_color_default = -1;
 static int diff_context_default = 3;
 static const char *diff_word_regex_cfg;
 static const char *external_diff_cmd_cfg;
+static const char *diff_order_file_cfg;
 int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
 static int diff_no_prefix;
@@ -201,6 +202,8 @@ int git_diff_ui_config(const char *var, const char
*value, void *cb)
  return git_config_string(&external_diff_cmd_cfg, var, value);
  if (!strcmp(var, "diff.wordregex"))
  return git_config_string(&diff_word_regex_cfg, var, value);
+ if (!strcmp(var, "diff.orderfile"))
+ return git_config_string(&diff_order_file_cfg, var, value);

  if (!strcmp(var, "diff.ignoresubmodules"))
  handle_ignore_submodules_arg(&default_diff_options, value);
@@ -3207,6 +3210,8 @@ void diff_setup(struct diff_options *options)
  options->detect_rename = diff_detect_rename_default;
  options->xdl_opts |= diff_algorithm;

+ options->orderfile = diff_order_file_cfg;
+
  if (diff_no_prefix) {
  options->a_prefix = options->b_prefix = "";
  } else if (!diff_mnemonic_prefix) {
diff --git a/t/t4056-diff-order.sh b/t/t4056-diff-order.sh
new file mode 100755
index 0000000..fd005d6
--- /dev/null
+++ b/t/t4056-diff-order.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+test_description='diff order'
+
+. ./test-lib.sh
+
+_test_create_files () {
+ mkdir c
+ echo "$1" >a.h
+ echo "$1" >b.c
+ echo "$1" >c/Makefile
+ echo "$1" >d.txt
+ git add a.h b.c c/Makefile d.txt && \
+ git commit -m"$1"
+}
+
+cat >order_file_1 <<EOF
+*Makefile
+*.txt
+*.h
+*
+EOF
+cat >order_file_2 <<EOF
+*.h
+*.c
+*Makefile
+*
+EOF
+
+cat >expect_diff_headers_none <<EOF
+diff --git a/a.h b/a.h
+diff --git a/b.c b/b.c
+diff --git a/c/Makefile b/c/Makefile
+diff --git a/d.txt b/d.txt
+EOF
+
+cat >expect_diff_headers_1 <<EOF
+diff --git a/c/Makefile b/c/Makefile
+diff --git a/d.txt b/d.txt
+diff --git a/a.h b/a.h
+diff --git a/b.c b/b.c
+EOF
+
+cat >expect_diff_headers_2 <<EOF
+diff --git a/a.h b/a.h
+diff --git a/b.c b/b.c
+diff --git a/c/Makefile b/c/Makefile
+diff --git a/d.txt b/d.txt
+EOF
+
+test_expect_success "setup" '_test_create_files 1 && _test_create_files 2'
+
+test_expect_success "no order (=tree object order)" '
+ git diff HEAD^..HEAD | grep ^diff >actual_diff_headers &&
+ test_debug actual_diff_headers
+ test_cmp expect_diff_headers_none actual_diff_headers'
+
+test_expect_success "orderfile using option" '
+ git diff -Oorder_file_1 HEAD^..HEAD | grep ^diff >actual_diff_headers &&
+ test_debug actual_diff_headers
+ test_cmp expect_diff_headers_1 actual_diff_headers &&
+ git diff -Oorder_file_2 HEAD^..HEAD | grep ^diff >actual_diff_headers &&
+ test_debug actual_diff_headers
+ test_cmp expect_diff_headers_2 actual_diff_headers'
+
+test_expect_success "orderfile using config" '
+ git -c diff.orderfile=order_file_1 diff HEAD^..HEAD | grep ^diff
>actual_diff_headers &&
+ test_debug actual_diff_headers
+ test_cmp expect_diff_headers_1 actual_diff_headers &&
+ git -c diff.orderfile=order_file_2 diff HEAD^..HEAD | grep ^diff
>actual_diff_headers &&
+ test_debug actual_diff_headers
+ test_cmp expect_diff_headers_2 actual_diff_headers'
+
+test_done
-- 
1.8.4.1.559.gdb9bdfb.dirty

^ permalink raw reply related	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2014-01-10 23:30 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-21 10:31 [PATCH] diff: Add diff.orderfile configuration variable Anders Waldenborg
2013-10-21 18:40 ` Jonathan Nieder
2013-10-25 10:24   ` Anders Waldenborg
2013-12-06  6:48 ` [PATCH v2] " Samuel Bronson
2013-12-06 18:11   ` Junio C Hamano
2013-12-07  2:43     ` Samuel Bronson
2013-12-09 19:23       ` Junio C Hamano
2013-12-14 22:18 ` [PATCH v3 0/3] " Samuel Bronson
2013-12-14 22:18 ` [PATCH v3 1/3] diff: Tests for "git diff -O" Samuel Bronson
2013-12-14 22:18 ` [PATCH v3 2/3] diff: Let "git diff -O" read orderfile from any file, failing when appropriate Samuel Bronson
2013-12-16 18:43   ` Junio C Hamano
2013-12-14 22:18 ` [RFC v3 3/3] diff: Add diff.orderfile configuration variable Samuel Bronson
2013-12-16 18:53   ` Junio C Hamano
2013-12-16 19:21     ` Samuel Bronson
2013-12-16 20:09 ` [PATCH v4 0/3] " Samuel Bronson
2013-12-16 20:09 ` [PATCH v4 1/3] diff: Tests for "git diff -O" Samuel Bronson
2013-12-16 20:09 ` [PATCH v4 2/3] diff: Let "git diff -O" read orderfile from any file, fail properly Samuel Bronson
2013-12-16 21:09   ` Junio C Hamano
2013-12-17  4:06     ` Samuel Bronson
2013-12-16 21:32   ` Junio C Hamano
2013-12-17  5:03     ` Samuel Bronson
2013-12-17 17:54       ` Junio C Hamano
2013-12-17 20:37         ` Antoine Pelisse
2013-12-17 22:09           ` Junio C Hamano
2013-12-18  4:28             ` Samuel Bronson
2013-12-18  5:47               ` Junio C Hamano
2013-12-17 23:11           ` Junio C Hamano
2013-12-16 20:09 ` [PATCH v4 3/3] diff: Add diff.orderfile configuration variable Samuel Bronson
2013-12-19  0:08 ` [PATCH v5 0/3] " Samuel Bronson
2013-12-19  0:40   ` Junio C Hamano
2013-12-19  0:08 ` [PATCH v5 1/3] diff: Tests for "git diff -O" Samuel Bronson
2013-12-19  0:08 ` [PATCH v5 2/3] diff: Let "git diff -O" read orderfile from any file, fail properly Samuel Bronson
2014-01-10 20:10   ` [PATCH sb/diff-orderfile-config] diff test: reading a directory as a file need not error out Jonathan Nieder
2014-01-10 23:30     ` Junio C Hamano
2013-12-19  0:08 ` [PATCH v5 3/3] diff: Add diff.orderfile configuration variable Samuel Bronson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.