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

[PATCH 7/11] Avoid git-fetch in `git-pull .` when possible.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 28, 2006, 07:35 UTC
Message-ID
<20061228073517.GG17867@spearce.org>
In-Reply-To
<9847899e4ba836980dbfed6d0ea1c82f31f21456.1167290864.git.spearce@spearce.org>

Users who merge frequently from remote repositories tend to prefer `git-pull .` over `git-merge` for local merges, as the pull interface is then consistent with how the user performs merges from remote repositories.

Unfortunately `git-pull .` has a (small) amount of overhead on top of `git-merge` as it needs to first invoke git-fetch to prepare the FETCH_HEAD file. However we can easily detect this special case of a local merge and jump directly into git-merge, bypassing that overhead.

This change also allows users of `git-pull .` to take advantage of the change made in commit e0ec1819, where git-merge uses the local branch name in conflict hunks if it is invoked as a porcelain, rather than as a plumbing.

Users may also now use `git-pull . foo~3` to merge the early part of branch foo. This was not previously possible as git-fetch does not know how to fetch foo~3 from a repository.

Unfortunately we cannot use this git-fetch bypass if the user is also updating some sort of tracking branch in the local repository as part of the pull from the local repository. This however is a rather crazy usage of `git-pull .`, but we used to support it, so we issue a silly warning message and use the older-style git-fetch path to continue supporting it.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-pull.sh |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index 28d0819..8c94fef 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -45,6 +45,33 @@ do
 	shift
 done
 
+if test "X$1" = X.
+then
+	# We are merging from this repository.  We can avoid fetch
+	# and go right into merge if the user isn't doing something
+	# odd like asking us to also update tracking branches in
+	# this repository as part of the pull.  Yeah, they probably
+	# shouldn't do that - but we allowed it in the past...
+	#
+	direct_merge=1
+	for remote
+	do
+		case "$remote" in
+		*:*) direct_merge=0; break;;
+		esac
+	done
+	if test $direct_merge = 1
+	then
+		shift
+		exec git-merge \
+			$no_summary $no_commit $squash $strategy_args \
+			"$@"
+	else
+		echo >&2 "Clever... Updating tracking branch while pulling from yourself."
+		echo >&2
+	fi
+fi
+
 orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
 git-fetch --update-head-ok "$@" || exit 1
 
-- 
1.4.4.3.gd2e4
Previous: Shawn O. PearceNext: Junio C Hamano
Message 6 of 17 in “Honor GIT_REFLOG_ACTION in git-rebase.”
  1. 2/11 Honor GIT_REFLOG_ACTION in git-rebase.Shawn O. Pearce, Dec 28, 2006
  2. 3/11 Use branch names in 'git-rebase -m' conflict hunks.Shawn O. Pearce, Dec 28, 2006
  3. 4/11 Ensure `git-pull` fails if `git-merge` fails.Shawn O. Pearce, Dec 28, 2006
  4. 5/11 Honor pull.{twohead,octopus} in git-merge.Shawn O. Pearce, Dec 28, 2006
  5. 6/11 Allow git-merge to select the default strategy.Shawn O. Pearce, Dec 28, 2006
  6. 7/11 Avoid git-fetch in `git-pull .` when possible.Shawn O. Pearce, Dec 28, 2006
  7. Junio C HamanoDec 28, 2006
  8. Shawn PearceDec 28, 2006
  9. Junio C HamanoDec 28, 2006
  10. 8/11 Move better_branch_name above get_ref in merge-recursive.Shawn O. Pearce, Dec 28, 2006
  11. 9/11 Allow merging bare trees in merge-recursive.Shawn O. Pearce, Dec 28, 2006
  12. Junio C HamanoDec 28, 2006
  13. 10/11 Use merge-recursive in git-am -3.Shawn O. Pearce, Dec 28, 2006
  14. 11/11 Improve merge performance by avoiding in-index merges.Shawn O. Pearce, Dec 28, 2006
  15. Junio C HamanoDec 28, 2006
  16. Shawn PearceDec 28, 2006
  17. Johannes SchindelinDec 29, 2006

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.