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

[PATCH 2/2] git-fetch: use fetch--tool pick-rref to avoid local fetch from alternate

From
Junio C Hamano <junkio@cox.net>
Date
Apr 5, 2007, 10:22 UTC
Message-ID
<7v1wizrugw.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0704031427050.6730@woody.linux-foundation.org>

When we are fetching from a repository that is on a local filesystem, first check if we have all the objects that we are going to fetch available locally, by not just checking the tips of what we are fetching, but with a full reachability analysis to our existing refs. In such a case, we do not have to run git-fetch-pack which would send many needless objects. This is especially true when the other repository is an alternate of the current repository (e.g. perhaps the repository was created by running "git clone -l -s" from there).

The useless objects transferred used to be discarded when they were expanded by git-unpack-objects called from git-fetch-pack, but recent git-fetch-pack prefers to keep the data it receives from the other end without exploding them into loose objects, resulting in a pack full of duplicated data when fetching from your own alternate.

This also uses fetch--tool pick-rref on dumb transport side to remove a shell loop to do the same.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * Strictly speaking, there is no need to even check if $remote
   is a local directory for this to operate properly, as
   rev-list would barf and die as soon as it finds something
   unavailable, while limiting the traversal to stop immediately
   after it hits what are known to be reachable locally.  On the
   other hand, if we really want to limit this to the case to a
   repository with an alternate to "clone -l -s" origin, we
   could add 'test -f "$GIT_OBJECT_DIRECTORY/info/alternates"',
   but I chose not to.
 git-fetch.sh |   41 ++++++++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/git-fetch.sh b/git-fetch.sh
index fd70696..5dc3063 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -173,9 +173,32 @@ fetch_all_at_once () {
 	    git-bundle unbundle "$remote" $rref ||
 	    echo failed "$remote"
 	else
-	  git-fetch-pack --thin $exec $keep $shallow_depth $no_progress \
-		"$remote" $rref ||
-	  echo failed "$remote"
+		if	test -d "$remote" &&
+
+			# The remote might be our alternate.  With
+			# this optimization we will bypass fetch-pack
+			# altogether, which means we cannot be doing
+			# the shallow stuff at all.
+			test ! -f "$GIT_DIR/shallow" &&
+			test -z "$shallow_depth" &&
+
+			# See if all of what we are going to fetch are
+			# connected to our repository's tips, in which
+			# case we do not have to do any fetch.
+			theirs=$(git-fetch--tool -s pick-rref \
+					"$rref" "$ls_remote_result") &&
+
+			# This will barf when $theirs reach an object that
+			# we do not have in our repository.  Otherwise,
+			# we already have everything the fetch would bring in.
+			git-rev-list --objects $theirs --not --all 2>/dev/null
+		then
+			git-fetch--tool pick-rref "$rref" "$ls_remote_result"
+		else
+			git-fetch-pack --thin $exec $keep $shallow_depth \
+				$no_progress "$remote" $rref ||
+			echo failed "$remote"
+		fi
 	fi
       ) |
       (
@@ -235,16 +258,8 @@ fetch_per_ref () {
 	  fi
 
 	  # Find $remote_name from ls-remote output.
-	  head=$(
-		IFS='	'
-		echo "$ls_remote_result" |
-		while read sha1 name
-		do
-			test "z$name" = "z$remote_name" || continue
-			echo "$sha1"
-			break
-		done
-	  )
+	  head=$(git-fetch--tool -s pick-rref \
+			"$remote_name" "$ls_remote_result")
 	  expr "z$head" : "z$_x40\$" >/dev/null ||
 		die "No such ref $remote_name at $remote"
 	  echo >&2 "Fetching $remote_name from $remote using $proto"
-- 
1.5.1.45.g1ddb
Previous: Junio C HamanoNext: Shawn O. Pearce
Message 25 of 58 in “git-index-pack really does suck..”
  1. Linus TorvaldsApr 3, 2007
  2. Linus TorvaldsApr 3, 2007
  3. Nicolas PitreApr 3, 2007
  4. Nicolas PitreApr 3, 2007
  5. Chris LeeApr 3, 2007
  6. Nicolas PitreApr 3, 2007
  7. Chris LeeApr 3, 2007
  8. Linus TorvaldsApr 3, 2007
  9. Nicolas PitreApr 3, 2007
  10. Junio C HamanoApr 3, 2007
  11. Linus TorvaldsApr 3, 2007
  12. Nicolas PitreApr 3, 2007
  13. Chris LeeApr 3, 2007
  14. Linus TorvaldsApr 3, 2007
  15. Linus TorvaldsApr 3, 2007
  16. Shawn O. PearceApr 3, 2007
  17. Linus TorvaldsApr 3, 2007
  18. Shawn O. PearceApr 3, 2007
  19. Linus TorvaldsApr 3, 2007
  20. Linus TorvaldsApr 3, 2007
  21. Junio C HamanoApr 3, 2007
  22. Shawn O. PearceApr 3, 2007
  23. Junio C HamanoApr 3, 2007
  24. 1/2 git-fetch--tool pick-rrefJunio C Hamano, Apr 5, 2007
  25. 2/2 git-fetch: use fetch--tool pick-rref to avoid local fetch from alternateJunio C Hamano, Apr 5, 2007
  26. Shawn O. PearceApr 5, 2007
  27. Junio C HamanoApr 5, 2007
  28. Nicolas PitreApr 3, 2007
  29. Shawn O. PearceApr 3, 2007
  30. Junio C HamanoApr 3, 2007
  31. Shawn O. PearceApr 3, 2007
  32. Jeff KingApr 3, 2007
  33. Dana HowApr 3, 2007
  34. Linus TorvaldsApr 3, 2007
  35. David LangApr 3, 2007
  36. Nicolas PitreApr 3, 2007
  37. Nicolas PitreApr 3, 2007
  38. Linus TorvaldsApr 3, 2007
  39. Nicolas PitreApr 3, 2007
  40. Shawn O. PearceApr 3, 2007
  41. Linus TorvaldsApr 3, 2007
  42. Nicolas PitreApr 3, 2007
  43. Junio C HamanoApr 3, 2007
  44. Shawn O. PearceApr 3, 2007
  45. Nicolas PitreApr 3, 2007
  46. Linus TorvaldsApr 3, 2007
  47. Nicolas PitreApr 3, 2007
  48. David LangApr 3, 2007
  49. Alex RiesenApr 4, 2007
  50. David LangApr 6, 2007
  51. Junio C HamanoApr 6, 2007
  52. Junio C HamanoApr 6, 2007
  53. David LangApr 6, 2007
  54. Junio C HamanoApr 6, 2007
  55. David LangApr 6, 2007
  56. Linus TorvaldsApr 3, 2007
  57. Junio C HamanoApr 3, 2007
  58. Nicolas PitreApr 3, 2007

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.