git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Denton Liu <liu.denton@gmail.com>,
	David Aguilar <davvid@gmail.com>,
	John Keeping <john@keeping.me.uk>,
	Junio C Hamano <gitster@pobox.com>,
	ZheNing Hu <adlternative@gmail.com>,
	ZheNing Hu <adlternative@gmail.com>
Subject: [PATCH v2] git-difftool-helper.sh: learn a new way go back to last save point
Date: Mon, 08 Feb 2021 17:02:23 +0000	[thread overview]
Message-ID: <pull.870.v2.git.1612803744188.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.870.git.1612711153591.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 search,
We will have to traverse list again to get the file diff which
we want to see. Therefore, here is a new method: every time before
we view the file diff, the current coordinates will be stored in
`GIT_DIR/difftool-last-position`, this file will be deleted after
successful traversing. But if an unexpected exit occurred midway or
users similar to using "ctrl+c" kill the process,and the user wants
to redo the same `git difftoool`, git will view the coordinates in
the save point, ask user if they want continue from the last position.
This will improve the user experience.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
---
    git-difftool-helper.sh: learn a new way skip to save point
    
    git user may should travel the diff list to choice file diff to view, if
    they exit in midway,they must travel it again. By saving current
    coordinates in GIT_DIR/difftool-last-position method, provides a
    possibility for this user-friendly solution.
    
    this patch's origin discuss is here:
    https://lore.kernel.org/git/gOXOaoqn-E9A2ob7ykWEcDc7ZxmSwAjcP5CCFKfr5ejCOWZQ1lfAUZcbgYT9AyQCcDgJvCrnrtziXiels-Hxol3xlkGTVHk24SvAdaSUtKQ=@rtzoeller.com/
    
    Thanks!

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-870%2Fadlternative%2Fdifftool_save_point-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-870/adlternative/difftool_save_point-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/870

Range-diff vs v1:

 1:  e77c3e33ba85 ! 1:  2468eaff322b git-difftool-helper.sh: learn a new way skip to save point
     @@ Metadata
      Author: ZheNing Hu <adlternative@gmail.com>
      
       ## Commit message ##
     -    git-difftool-helper.sh: learn a new way skip to save point
     +    git-difftool-helper.sh: learn a new way go back to last save point
      
     -    `git difftool` only allow us to select file to view In turn.
     -    If there is a commit with many files and we exit in search,
     +    `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:every time before
     -    we view the file diff,the current coordinates will be stored in
     -    `GIT_DIR/difftool_skip_to`,this file will be deleted after
     -    successful traversing.But if an unexpected exit occurred midway,
     -    git will view the coordinates in the save point,ask user if they
     -    want continue from the last saved point.This will improve the
     -    user experience.
     +    we want to see. Therefore, here is a new method: every time before
     +    we view the file diff, the current coordinates will be stored in
     +    `GIT_DIR/difftool-last-position`, this file will be deleted after
     +    successful traversing. But if an unexpected exit occurred midway or
     +    users similar to using "ctrl+c" kill the process,and the user wants
     +    to redo the same `git difftoool`, git will view the coordinates in
     +    the save point, ask user if they want continue from the last position.
     +    This will improve the user experience.
      
          Signed-off-by: ZheNing Hu <adlternative@gmail.com>
      
     @@ git-difftool--helper.sh
       # Copyright (c) 2009, 2010 David Aguilar
       
       TOOL_MODE=diff
     -+GIT_DIFFTOOL_SKIP_TO_FILE="$GIT_DIR/difftool-skip-to"
     ++GIT_DIFFTOOL_LAST_POSITION="$GIT_DIR/difftool-last-position"
     ++DIFFTOOL_FIRST_NUM="1"
       . git-mergetool--lib
       
       # difftool.prompt controls the default prompt/no-prompt behavior
     @@ git-difftool--helper.sh: launch_merge_tool () {
       	# the user with the real $MERGED name before launching $merge_tool.
       	if should_prompt
       	then
     -+		if test -f "$GIT_DIFFTOOL_SKIP_TO_FILE"
     ++		if test -f "$GIT_DIFFTOOL_LAST_POSITION"
      +		then
     -+			SAVE_POINT_NUM=$(cat "$GIT_DIFFTOOL_SKIP_TO_FILE")
     -+			if test $SAVE_POINT_NUM -le $GIT_DIFF_PATH_TOTAL &&
     -+				test $SAVE_POINT_NUM -gt $GIT_DIFF_PATH_COUNTER
     ++			if SAVE_POINT_NUM=$(cat 2>/dev/null "$GIT_DIFFTOOL_LAST_POSITION") &&
     ++				test "$SAVE_POINT_NUM" -le "$GIT_DIFF_PATH_TOTAL" &&
     ++					test "$SAVE_POINT_NUM" -gt "$GIT_DIFF_PATH_COUNTER"
      +			then
     -+				# choice skip or not skip when check first file.
     -+				if test $GIT_DIFF_PATH_COUNTER -eq "1"
     ++				if test "$GIT_DIFF_PATH_COUNTER" -eq "$DIFFTOOL_FIRST_NUM"
      +				then
     -+					printf "do you want to skip to last time difftool save point($SAVE_POINT_NUM) [Y/n]?"
     ++					printf "Do you want to start from the possible last file you were viewing? [Y/n]?"
      +					read skip_ans || return
      +					if test "$skip_ans" = y
      +					then
     @@ git-difftool--helper.sh: launch_merge_tool () {
      +				fi
      +			fi
      +		fi
     -+		# write the current coordinates to .git/difftool-skip-to
     -+		if test !$SAVE_POINT_NUM || $SAVE_POINT_NUM -ne $GIT_DIFF_PATH_COUNTER
     ++		if test -z "$SAVE_POINT_NUM" ||
     ++			test "$SAVE_POINT_NUM" -ne "$GIT_DIFF_PATH_COUNTER"
      +		then
     -+			echo $GIT_DIFF_PATH_COUNTER > $GIT_DIFFTOOL_SKIP_TO_FILE
     ++			echo "$GIT_DIFF_PATH_COUNTER" >"$GIT_DIFFTOOL_LAST_POSITION"
      +		fi
       		printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
       			"$GIT_DIFF_PATH_TOTAL" "$MERGED"
     @@ git-difftool--helper.sh: else
       	done
       fi
       
     -+if test -f $GIT_DIFFTOOL_SKIP_TO_FILE &&
     -+	test $GIT_DIFF_PATH_COUNTER -eq $GIT_DIFF_PATH_TOTAL
     ++if test "$GIT_DIFF_PATH_COUNTER" -eq "$GIT_DIFF_PATH_TOTAL"
      +then
     -+	rm $GIT_DIFFTOOL_SKIP_TO_FILE
     ++	rm -f "$GIT_DIFFTOOL_LAST_POSITION"
      +
      +fi
       exit 0


 git-difftool--helper.sh | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
index 46af3e60b718..a01aa7c9d551 100755
--- a/git-difftool--helper.sh
+++ b/git-difftool--helper.sh
@@ -6,6 +6,8 @@
 # Copyright (c) 2009, 2010 David Aguilar
 
 TOOL_MODE=diff
+GIT_DIFFTOOL_LAST_POSITION="$GIT_DIR/difftool-last-position"
+DIFFTOOL_FIRST_NUM="1"
 . git-mergetool--lib
 
 # difftool.prompt controls the default prompt/no-prompt behavior
@@ -40,6 +42,30 @@ launch_merge_tool () {
 	# the user with the real $MERGED name before launching $merge_tool.
 	if should_prompt
 	then
+		if test -f "$GIT_DIFFTOOL_LAST_POSITION"
+		then
+			if SAVE_POINT_NUM=$(cat 2>/dev/null "$GIT_DIFFTOOL_LAST_POSITION") &&
+				test "$SAVE_POINT_NUM" -le "$GIT_DIFF_PATH_TOTAL" &&
+					test "$SAVE_POINT_NUM" -gt "$GIT_DIFF_PATH_COUNTER"
+			then
+				if test "$GIT_DIFF_PATH_COUNTER" -eq "$DIFFTOOL_FIRST_NUM"
+				then
+					printf "Do you want to start from the possible last file you were viewing? [Y/n]?"
+					read skip_ans || return
+					if test "$skip_ans" = y
+					then
+						return
+					fi
+				else
+					return
+				fi
+			fi
+		fi
+		if test -z "$SAVE_POINT_NUM" ||
+			test "$SAVE_POINT_NUM" -ne "$GIT_DIFF_PATH_COUNTER"
+		then
+			echo "$GIT_DIFF_PATH_COUNTER" >"$GIT_DIFFTOOL_LAST_POSITION"
+		fi
 		printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
 			"$GIT_DIFF_PATH_TOTAL" "$MERGED"
 		if use_ext_cmd
@@ -102,4 +128,9 @@ else
 	done
 fi
 
+if test "$GIT_DIFF_PATH_COUNTER" -eq "$GIT_DIFF_PATH_TOTAL"
+then
+	rm -f "$GIT_DIFFTOOL_LAST_POSITION"
+
+fi
 exit 0

base-commit: e6362826a0409539642a5738db61827e5978e2e4
-- 
gitgitgadget

  parent reply	other threads:[~2021-02-08 17:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-07 15:19 [PATCH] git-difftool-helper.sh: learn a new way skip to save point 阿德烈 via GitGitGadget
2021-02-07 18:29 ` Junio C Hamano
2021-02-07 19:04 ` Junio C Hamano
2021-02-08  8:06   ` 胡哲宁
2021-02-08 17:02 ` ZheNing Hu via GitGitGadget [this message]
2021-02-08 20:13   ` [PATCH v2] git-difftool-helper.sh: learn a new way go back to last " Junio C Hamano
2021-02-08 22:15   ` David Aguilar
2021-02-08 23:34     ` Junio C Hamano
2021-02-09  6:19       ` 胡哲宁
2021-02-09  6:04     ` 胡哲宁
2021-02-09 15:30   ` [PATCH v3] difftool.c: learn a new way start from specified file ZheNing Hu via GitGitGadget
2021-02-09 18:17     ` Junio C Hamano
2021-02-10 17:00       ` 胡哲宁
2021-02-10 18:16         ` Junio C Hamano
2021-02-10 20:05           ` Junio C Hamano
2021-02-14  7:53           ` ZheNing Hu
2021-02-14 13:09     ` [PATCH v4] difftool.c: learn a new way start at " ZheNing Hu via GitGitGadget
2021-02-16  1:46       ` Junio C Hamano
2021-02-16 12:56       ` [PATCH v5 0/2] " ZheNing Hu via GitGitGadget
2021-02-16 12:56         ` [PATCH v5 1/2] diff: --{rotate,skip}-to=<path> Junio C Hamano via GitGitGadget
2021-02-16 12:56         ` [PATCH v5 2/2] difftool.c: learn a new way start at specified file ZheNing Hu via GitGitGadget
2021-02-17 10:31           ` Junio C Hamano
2021-02-17 16:18             ` ZheNing Hu
2021-02-16 18:45         ` [PATCH v5 0/2] " Junio C Hamano
2021-02-17  4:12           ` ZheNing Hu
2021-02-17 11:14             ` Denton Liu
2021-02-17 11:40               ` ZheNing Hu
2021-02-17 18:56                 ` Junio C Hamano
2021-02-18  5:20                   ` ZheNing Hu
2021-02-18 15:04                   ` ZheNing Hu
2021-02-18 19:11                     ` Junio C Hamano
2021-02-19 10:59                       ` ZheNing Hu
2021-02-25 11:08                   ` Johannes Schindelin
2021-02-25 19:01                     ` Junio C Hamano
2021-02-19 12:53         ` [PATCH v6] " ZheNing Hu via GitGitGadget
2021-02-22 15:11           ` ZheNing Hu
2021-02-22 21:40           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.870.v2.git.1612803744188.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=john@keeping.me.uk \
    --cc=liu.denton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).