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

Re: [PATCH v2 3/7] subtree: persist cache between split runs

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 7, 2020, 16:06 UTC
Message-ID
<nycvar.QRO.7.76.6.2010071750310.50@tvgsbejvaqbjf.bet>
In-Reply-To
<8eec18388c86071db47512b84118e3b9111bd34d.1602021913.git.gitgitgadget@gmail.com>
Hi Tom,
On Tue, 6 Oct 2020, Tom Clarkson via GitGitGadget wrote:
Show 5 quoted lines
> @@ -48,6 +49,7 @@ annotate=
>  squash=
>  message=
>  prefix=
> +clearcache=

It might be more consistent to call it `clear_cache` (i.e. with an underscore), just like `ignore_joins`.

Show 21 quoted lines
>
>  debug () {
>  	if test -n "$debug"
> @@ -131,6 +133,9 @@ do
>  	--no-rejoin)
>  		rejoin=
>  		;;
> +	--clear-cache)
> +		clearcache=1
> +		;;
>  	--ignore-joins)
>  		ignore_joins=1
>  		;;
> @@ -206,9 +211,13 @@ debug "opts: {$*}"
>  debug
>
>  cache_setup () {
> -	cachedir="$GIT_DIR/subtree-cache/$$"
> -	rm -rf "$cachedir" ||
> -		die "Can't delete old cachedir: $cachedir"
> +	cachedir="$GIT_DIR/subtree-cache/$prefix"
Excellent, the `prefix` should be "unique enough".
Show 16 quoted lines
> +	if test -n "$clearcache"
> +	then
> +		debug "Clearing cache"
> +		rm -rf "$cachedir" ||
> +			die "Can't delete old cachedir: $cachedir"
> +	fi
>  	mkdir -p "$cachedir" ||
>  		die "Can't create new cachedir: $cachedir"
>  	mkdir -p "$cachedir/notree" ||
> @@ -266,6 +275,16 @@ cache_set () {
>  	echo "$newrev" >"$cachedir/$oldrev"
>  }
>
> +cache_set_if_unset () {
> +	oldrev="$1"
> +	newrev="$2"
`local`? ;-)
Show 5 quoted lines
> +	if test -e "$cachedir/$oldrev"
> +	then
> +		return
> +	fi
> +	echo "$newrev" >"$cachedir/$oldrev"

So that directory contains commit mappings, a file for each mapped revision.

Thinking back to patch 2/11, I am now no longer that sure that it makes sense to fill it up with every commit in that commit range: performance suffers when directories contain too many files.

For example, I had a case in the past where it took a minute just to enumerate a directory, and even looking whether a file existed in that directory was not exactly fun.

In any case, I would write it slightly shorter:
	test -e "$cachedir/$oldrev" ||
	echo "$newrev" >"$cachedir/$oldrev"
Show 28 quoted lines
> +}
> +
>  rev_exists () {
>  	if git rev-parse "$1" >/dev/null 2>&1
>  	then
> @@ -375,13 +394,13 @@ find_existing_splits () {
>  			then
>  				# squash commits refer to a subtree
>  				debug "  Squash: $sq from $sub"
> -				cache_set "$sq" "$sub"
> +				cache_set_if_unset "$sq" "$sub"
>  			fi
>  			if test -n "$main" -a -n "$sub"
>  			then
>  				debug "  Prior: $main -> $sub"
> -				cache_set $main $sub
> -				cache_set $sub $sub
> +				cache_set_if_unset $main $sub
> +				cache_set_if_unset $sub $sub
>  				try_remove_previous "$main"
>  				try_remove_previous "$sub"
>  			fi
> @@ -688,6 +707,8 @@ process_split_commit () {
>  		if test -n "$newparents"
>  		then
>  			cache_set "$rev" "$rev"
> +		else
> +			cache_set "$rev" ""

Was this hunk intended to be snuck in here? I can understand the s/cache_set/cache_set_if_unset/ changes, of course, but not this hunk.

Show 18 quoted lines
>  		fi
>  		return
>  	fi
> @@ -785,7 +806,7 @@ cmd_split () {
>  			# the 'onto' history is already just the subdir, so
>  			# any parent we find there can be used verbatim
>  			debug "  cache: $rev"
> -			cache_set "$rev" "$rev"
> +			cache_set_if_unset "$rev" "$rev"
>  		done
>  	fi
>
> @@ -798,7 +819,7 @@ cmd_split () {
>  		git rev-list --topo-order --skip=1 $mainline |
>  		while read rev
>  		do
> -			cache_set "$rev" ""
> +			cache_set_if_unset "$rev" ""

Okay. A quite interesting question now would be: are there any callers of `cache_set` left? If so, why?

Thanks, Dscho

Show 7 quoted lines
>  		done || exit $?
>  	fi
>
> --
> gitgitgadget
>
>
Previous: Tom Clarkson via GitGitGadgetNext: Tom Clarkson via GitGitGadget
Message 23 of 28 in “subtree: Fix handling of complex history”
  1. 0/7 subtree: Fix handling of complex historyTom Clarkson via GitGitGadget, May 11, 2020
  2. 1/7 subtree: handle multiple parents passed to cache_missTom Clarkson via GitGitGadget, May 11, 2020
  3. 2/7 subtree: exclude commits predating add from recursive processingTom Clarkson via GitGitGadget, May 11, 2020
  4. 4/7 subtree: add git subtree map commandTom Clarkson via GitGitGadget, May 11, 2020
  5. 3/7 subtree: persist cache between split runsTom Clarkson via GitGitGadget, May 11, 2020
  6. 5/7 subtree: add git subtree use and ignore commandsTom Clarkson via GitGitGadget, May 11, 2020
  7. 7/7 subtree: document new subtree commandsTom Clarkson via GitGitGadget, May 11, 2020
  8. 6/7 subtree: more robustly distinguish subtree and mainline commitsTom Clarkson via GitGitGadget, May 11, 2020
  9. Ed MasteOct 4, 2020
  10. Johannes SchindelinOct 4, 2020
  11. Junio C HamanoOct 5, 2020
  12. Ed MasteOct 5, 2020
  13. Johannes SchindelinOct 7, 2020
  14. 0/7 subtree: Fix handling of complex historyTom Clarkson via GitGitGadget, Oct 6, 2020
  15. 4/7 subtree: add git subtree map commandTom Clarkson via GitGitGadget, Oct 6, 2020
  16. 1/7 subtree: handle multiple parents passed to cache_missTom Clarkson via GitGitGadget, Oct 6, 2020
  17. Ed MasteOct 7, 2020
  18. 5/7 subtree: add git subtree use and ignore commandsTom Clarkson via GitGitGadget, Oct 6, 2020
  19. Johannes SchindelinOct 7, 2020
  20. 6/7 subtree: more robustly distinguish subtree and mainline commitsTom Clarkson via GitGitGadget, Oct 6, 2020
  21. Johannes SchindelinOct 7, 2020
  22. 3/7 subtree: persist cache between split runsTom Clarkson via GitGitGadget, Oct 6, 2020
  23. Johannes SchindelinOct 7, 2020
  24. 2/7 subtree: exclude commits predating add from recursive processingTom Clarkson via GitGitGadget, Oct 6, 2020
  25. Johannes SchindelinOct 7, 2020
  26. 7/7 subtree: document new subtree commandsTom Clarkson via GitGitGadget, Oct 6, 2020
  27. Johannes SchindelinOct 7, 2020
  28. Johannes SchindelinOct 7, 2020

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.