git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6] difftool.c: learn a new way start at specified file

From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 19, 2021, 12:53 UTC
Message-ID
<pull.870.v6.git.1613739235241.gitgitgadget@gmail.com>
In-Reply-To
<pull.870.v5.git.1613480198.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>

`git difftool` only allow us to select file to view in turn. If there is a commit with many files and we exit in the middle, we will have to traverse list again to get the file diff which we want to see. Therefore,teach the command an option `--skip-to=<path>` to allow the user to say that diffs for earlier paths are not interesting (because they were already seen in an earlier session) and start this session with the named path.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
    difftool.c: learn a new way start at specified file
    
     * The patch of the previous version implemented the jump through
       environment variables. The current version is based on the "diff
       --skip-to=" feature implemented by gitster, which implements a
       possible solution for the jump of difftool.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-870%2Fadlternative%2Fdifftool_save_point-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-870/adlternative/difftool_save_point-v6
Pull-Request: https://github.com/gitgitgadget/git/pull/870
Range-diff vs v5:
 1:  fb4bfd0f8b16 < -:  ------------ diff: --{rotate,skip}-to=<path>
 2:  98e2707ee2fa ! 1:  4377a917ca9e difftool.c: learn a new way start at specified file
     @@ Commit message
          difftool.c: learn a new way start at specified file
      
          `git difftool` only allow us to select file to view in turn.
     -    If there is a commit with many files and we exit in the search,
     -    We will have to traverse list again to get the file diff which
     -    we want to see. Therefore, here is a new method: user can use
     -    `git difftool --rotate-to=<filename>` or `git difftool --skip-to=<filename>`
     -    to start viewing from the specified file, This will improve the
     -    user experience.
     -
     -    `git difftool --rotate-to=<file>` or `git difftool --skip-to=<filename>`
     -    will pass the path to `diffcore-rotate`, and diff-core will
     -    adjust the order of files, make the specified file sorted to
     -    the first.`git difftool --rotate-to=<file>` will move files before
     -    the  specified path to the last output, and
     -    `git difftool --skip-to=<filename>`  will ignore these files output.
     -    It is an error when there is no patch for specified file is shown.
     +    If there is a commit with many files and we exit in the middle,
     +    we will have to traverse list again to get the file diff which
     +    we want to see. Therefore,teach the command an option
     +    `--skip-to=<path>` to allow the user to say that diffs for earlier
     +    paths are not interesting (because they were already seen in an
     +    earlier session) and start this session with the named path.
      
          Signed-off-by: ZheNing Hu <adlternative@gmail.com>
      
     - ## Documentation/diff-options.txt ##
     -@@ Documentation/diff-options.txt: components matches the pattern.  For example, the pattern "`foo*bar`"
     - matches "`fooasdfbar`" and "`foo/bar/baz/asdf`" but not "`foobarx`".
     - 
     - --skip-to=<file>::
     ----rotate-to=<file::
     -+--rotate-to=<file>::
     - 	Discard the files before the named <file> from the output
     - 	(i.e. 'skip to'), or move them to the end of the output
     - 	(i.e. 'rotate to').  These were invented primarily for use
     -
       ## Documentation/git-difftool.txt ##
      @@ Documentation/git-difftool.txt: OPTIONS
       	This is the default behaviour; the option is provided to
       	override any configuration settings.
       
      +--rotate-to=<file>::
     -+	Internally call `git diff --rotate-to=<file>`,
     -+	show the change in the specified path first.
     -+	Files before the specified path will be moved to the last output.
     ++	Start showing the diff for the given path,
     ++	the paths before it will move to end and output.
      +
      +--skip-to=<file>::
     -+	Internally call `git diff --skip-to=<file>`,
     -+	skip the output to the specified path.
     -+	Files before the specified path will not output.
     ++	Start showing the diff for the given path, skipping all
     ++	the paths before it.
      +
       -t <tool>::
       --tool=<tool>::
     @@ t/t7800-difftool.sh: test_expect_success 'difftool --gui, --tool and --extcmd ar
      +	4
      +	1
      +	EOF
     -+	test_cmp output expect &&
     -+	test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^
     ++	test_cmp output expect
      +'
      +
      +test_expect_success 'difftool --skip-to' '
     @@ t/t7800-difftool.sh: test_expect_success 'difftool --gui, --tool and --extcmd ar
      +	2
      +	4
      +	EOF
     -+	test_cmp output expect &&
     -+	test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
     ++	test_cmp output expect
      +'
      +
     ++test_expect_success 'difftool --rotate/skip-to error condition' '
     ++	test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
     ++	test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
     ++'
       test_done
 Documentation/git-difftool.txt |  8 ++++++++
 t/t7800-difftool.sh            | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 484c485fd06c..143b0c49d739 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -34,6 +34,14 @@ OPTIONS
 	This is the default behaviour; the option is provided to
 	override any configuration settings.
 
+--rotate-to=<file>::
+	Start showing the diff for the given path,
+	the paths before it will move to end and output.
+
+--skip-to=<file>::
+	Start showing the diff for the given path, skipping all
+	the paths before it.
+
 -t <tool>::
 --tool=<tool>::
 	Use the diff tool specified by <tool>.  Valid values include
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 9192c141ffc6..3e041e83aede 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -762,4 +762,36 @@ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive'
 	test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
 '
 
+test_expect_success 'difftool --rotate-to' '
+	difftool_test_setup &&
+	test_when_finished git reset --hard &&
+	echo 1 >1 &&
+	echo 2 >2 &&
+	echo 4 >4 &&
+	git add 1 2 4 &&
+	git commit -a -m "124" &&
+	git difftool --no-prompt --extcmd=cat --rotate-to="2" HEAD^ >output&&
+	cat >expect <<-\EOF &&
+	2
+	4
+	1
+	EOF
+	test_cmp output expect
+'
+
+test_expect_success 'difftool --skip-to' '
+	difftool_test_setup &&
+	test_when_finished git reset --hard &&
+	git difftool --no-prompt --extcmd=cat --skip-to="2" HEAD^ >output &&
+	cat >expect <<-\EOF &&
+	2
+	4
+	EOF
+	test_cmp output expect
+'
+
+test_expect_success 'difftool --rotate/skip-to error condition' '
+	test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
+	test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
+'
 test_done

base-commit: 1eb4136ac2a24764257567b930535fcece01719f
-- 
gitgitgadget
Previous: Junio C HamanoNext: ZheNing Hu
Message 35 of 37 in “git-difftool-helper.sh: learn a new way skip to save point”
  1. git-difftool-helper.sh: learn a new way skip to save point阿德烈 via GitGitGadget, Feb 7, 2021
  2. Junio C HamanoFeb 7, 2021
  3. Junio C HamanoFeb 7, 2021
  4. 胡哲宁Feb 8, 2021
  5. git-difftool-helper.sh: learn a new way go back to last save pointZheNing Hu via GitGitGadget, Feb 8, 2021
  6. Junio C HamanoFeb 8, 2021
  7. David AguilarFeb 8, 2021
  8. Junio C HamanoFeb 8, 2021
  9. 胡哲宁Feb 9, 2021
  10. 胡哲宁Feb 9, 2021
  11. difftool.c: learn a new way start from specified fileZheNing Hu via GitGitGadget, Feb 9, 2021
  12. Junio C HamanoFeb 9, 2021
  13. 胡哲宁Feb 10, 2021
  14. Junio C HamanoFeb 10, 2021
  15. Junio C HamanoFeb 10, 2021
  16. ZheNing HuFeb 14, 2021
  17. difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 14, 2021
  18. Junio C HamanoFeb 16, 2021
  19. 0/2 difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 16, 2021
  20. 1/2 diff: --{rotate,skip}-to=<path>Junio C Hamano via GitGitGadget, Feb 16, 2021
  21. 2/2 difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 16, 2021
  22. Junio C HamanoFeb 17, 2021
  23. ZheNing HuFeb 17, 2021
  24. Junio C HamanoFeb 16, 2021
  25. ZheNing HuFeb 17, 2021
  26. Denton LiuFeb 17, 2021
  27. ZheNing HuFeb 17, 2021
  28. Junio C HamanoFeb 17, 2021
  29. ZheNing HuFeb 18, 2021
  30. ZheNing HuFeb 18, 2021
  31. Junio C HamanoFeb 18, 2021
  32. ZheNing HuFeb 19, 2021
  33. Johannes SchindelinFeb 25, 2021
  34. Junio C HamanoFeb 25, 2021
  35. difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 19, 2021
  36. ZheNing HuFeb 22, 2021
  37. Junio C HamanoFeb 22, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.