git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH v2 6/7] submodule update: Don't fetch when the submodule commit is already present
Date: Wed, 02 Mar 2011 00:04:21 +0100	[thread overview]
Message-ID: <4D6D7B75.9040300@web.de> (raw)
In-Reply-To: <4D6D7A50.5090802@web.de>

If the commit to be checked out on "git submodule update" has already been
fetched in the submodule there is no need to run "git fetch" again. Since
"git fetch" recently learned recursion (and the new on-demand mode to
fetch commits recorded in the superproject is enabled by default) this
will happen pretty often, thereby making the unconditional fetch during
"git submodule update" unnecessary.

If the commit is not present in the submodule (e.g. the user disabled the
fetch on-demand mode) the fetch will be run as before.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
 git-submodule.sh            |    5 ++++-
 t/t7406-submodule-update.sh |   20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 3a13397..c16e275 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -466,8 +466,11 @@ cmd_update()

 			if test -z "$nofetch"
 			then
+				# Run fetch only if $sha1 isn't present or it
+				# is not reachable from a ref.
 				(clear_local_git_env; cd "$path" &&
-					git-fetch) ||
+					((rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
+					 test -z "$rev") || git-fetch)) ||
 				die "Unable to fetch in submodule path '$path'"
 			fi

diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index fa9d23a..bf7c788 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -74,6 +74,26 @@ test_expect_success 'submodule update detaching the HEAD ' '
 	)
 '

+apos="'";
+test_expect_success 'submodule update does not fetch already present commits' '
+	(cd submodule &&
+	  echo line3 >> file &&
+	  git add file &&
+	  test_tick &&
+	  git commit -m "upstream line3"
+	) &&
+	(cd super/submodule &&
+	  head=$(git rev-parse --verify HEAD) &&
+	  echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
+	  git reset --hard HEAD~1
+	) &&
+	(cd super &&
+	  git submodule update > ../actual 2> ../actual.err
+	) &&
+	test_cmp expected actual &&
+	! test -s actual.err
+'
+
 test_expect_success 'submodule update --rebase staying on master' '
 	(cd super/submodule &&
 	  git checkout master
-- 
1.7.4.1.291.g6060

  parent reply	other threads:[~2011-03-01 23:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01 22:59 [PATCH v2 0/7] Teach fetch/pull the on-demand mode and make it the default Jens Lehmann
2011-03-01 23:01 ` [PATCH v2 1/7] fetch/pull: recurse into submodules when necessary Jens Lehmann
2011-03-02 15:42   ` Marc Branchaud
2011-03-01 23:01 ` [PATCH v2 2/7] fetch/pull: Add the 'on-demand' value to the --recurse-submodules option Jens Lehmann
2011-03-02 16:00   ` Marc Branchaud
2011-03-02 16:02     ` Marc Branchaud
2011-03-01 23:02 ` [PATCH v3 3/7] config: teach the fetch.recurseSubmodules option the 'on-demand' value Jens Lehmann
2011-03-02 16:02   ` Marc Branchaud
2011-03-01 23:03 ` [PATCH v2 4/7] Submodules: Add 'on-demand' value for the 'fetchRecurseSubmodule' option Jens Lehmann
2011-03-01 23:03 ` [PATCH v2 5/7] fetch/pull: Don't recurse into a submodule when commits are already present Jens Lehmann
2011-03-02 16:08   ` Marc Branchaud
2011-03-01 23:04 ` Jens Lehmann [this message]
2011-03-01 23:04 ` [PATCH v2 7/7] fetch/pull: Describe --recurse-submodule restrictions in the BUGS section Jens Lehmann
2011-03-02 20:53   ` Jens Lehmann
2011-03-02 16:09 ` [PATCH v2 0/7] Teach fetch/pull the on-demand mode and make it the default Marc Branchaud
2011-03-02 23:35   ` Jens Lehmann

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=4D6D7B75.9040300@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@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).