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

Re: [PATCH v2] git-difftool-helper.sh: learn a new way go back to last save point

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2021, 20:13 UTC
Message-ID
<xmqqczxa5nct.fsf@gitster.c.googlers.com>
In-Reply-To
<pull.870.v2.git.1612803744188.gitgitgadget@gmail.com>
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> 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"

Do we need this constant? I do not think it makes the resulting code easier to follow.

Show 13 quoted lines
>  . 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

No need to push the subsequent lines that far to the right, especially when your variable names are already overly long. It just makes things harder to read.

			if test -r "$GIT_DIFFTOOL_LAST_POSITION" &&
			   SAVE_POINT_NUM=$(cat "$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]?"

Where does that "possible" come from? If the reason is "We might have miscomputed or misrecorded an incorrect last position", we probably should work harder to make sure we don't ;-)

At this point in the code, do we have the _name_ of the file we are going to skip to readily available, or do we actually need to seek to that position before we can find it out?

	You were looking at 'hello-world.txt' the last time.
	Do you want to restart from there [Y/n]?

would be far easier to answer for an end-user than an unspecified "possible last file".

> +		fi
> +		if test -z "$SAVE_POINT_NUM" ||
> +			test "$SAVE_POINT_NUM" -ne "$GIT_DIFF_PATH_COUNTER"
Ditto about indentation.

Is this behaviour something we can write a test for in t/t7800-difftool.sh, by the way?

Other than these, i.e. (cosmetic) indentation and overly long lines (ui) giving filename is easier to work with for the users and (dev) lack of tests, looking quite good.

Thanks.
Previous: ZheNing Hu via GitGitGadgetNext: David Aguilar
Message 6 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.