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 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

ZheNing Hu committed Feb 19, 2021 at 12:53 UTC 1c881026a1eebadd1eae8cc3a4418b010df35bee
2 files changed +40
Documentation/git-difftool.txt
+8
@@ -34,6 +34,14 @@ OPTIONS
34 This is the default behaviour; the option is provided to
35 override any configuration settings.
36
37 +--rotate-to=<file>::
38 + Start showing the diff for the given path,
39 + the paths before it will move to end and output.
40 +
41 +--skip-to=<file>::
42 + Start showing the diff for the given path, skipping all
43 + the paths before it.
44 +
45 -t <tool>::
46 --tool=<tool>::
47 Use the diff tool specified by <tool>. Valid values include
t/t7800-difftool.sh
+32
@@ -762,4 +762,36 @@ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive'
762 test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
763 '
764
765 +test_expect_success 'difftool --rotate-to' '
766 + difftool_test_setup &&
767 + test_when_finished git reset --hard &&
768 + echo 1 >1 &&
769 + echo 2 >2 &&
770 + echo 4 >4 &&
771 + git add 1 2 4 &&
772 + git commit -a -m "124" &&
773 + git difftool --no-prompt --extcmd=cat --rotate-to="2" HEAD^ >output&&
774 + cat >expect <<-\EOF &&
775 + 2
776 + 4
777 + 1
778 + EOF
779 + test_cmp output expect
780 +'
781 +
782 +test_expect_success 'difftool --skip-to' '
783 + difftool_test_setup &&
784 + test_when_finished git reset --hard &&
785 + git difftool --no-prompt --extcmd=cat --skip-to="2" HEAD^ >output &&
786 + cat >expect <<-\EOF &&
787 + 2
788 + 4
789 + EOF
790 + test_cmp output expect
791 +'
792 +
793 +test_expect_success 'difftool --rotate/skip-to error condition' '
794 + test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
795 + test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
796 +'
797 test_done