git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Lars Hjemli" <hjemli@gmail.com>
To: "P. Christeas" <p_christ@hol.gr>
Cc: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: Git submodule enhancements
Date: Wed, 24 Sep 2008 11:13:59 +0200	[thread overview]
Message-ID: <8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com> (raw)
In-Reply-To: <200809241100.30758.p_christ@hol.gr>

On Wed, Sep 24, 2008 at 10:00 AM, P. Christeas <p_christ@hol.gr> wrote:
> In my attempt to take some source off a submoduled repo, I tried writting a
> few lines of code into git-submodule.

Thanks, but please also send this to git@vger.kernel.org. And please
try do inline the patches, it makes it much easier to review; I've
pasted the patches below and inserted a few comments prefixed with
'lh>'.


>From 9edad86468933a21264ab7bed4608ea8a6e992e4 Mon Sep 17 00:00:00 2001
From: P. Christeas <p_christ@hol.gr>
Date: Wed, 24 Sep 2008 10:05:45 +0300
Subject: [PATCH] Git submodule archive: create series of archives, for
each module

This is a temporary solution to creating archives from repos
containing submodules. It will just create a series of archives,
each named after the name of the submodule.
---
 git-submodule.sh |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 86 insertions(+), 1 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 1c39b59..2bce7f9 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -602,6 +602,91 @@ cmd_status()
 		fi
 	done
 }
+
+cmd_archive() {
+	# parse $args after "submodule ... archive".
+	smodules=""
+	verbose=""
+	format=tar
+	do_exec=
+	base_prefix=""
+	outname=
+	while test $# -ne 0
+	do
+		case "$1" in
+		-q|--quiet)
+			quiet=1
+			;;
+		-m|--module)
+			shift
+			smodules+="$1 "
+			;;

lh> Other submodule commands take optional module paths as final
lh> arguments. Why not use the same for `archive`?


+		--format)
+			shift
+			format="$1"
+			;;
+		--exec)
+			shift
+			do_exec="--exec=$1"
+			;;
+		--prefix)
+			shift
+			base_prefix="$1"
+			;;
+		-v|--verbose)
+			verbose="-v"
+			;;
+		-o|--output)
+			shift
+			outname="$1"
+			;;
+		--)
+			shift
+			break
+			;;
+		-*)
+			usage
+			;;
+		*)
+			break
+			;;
+		esac
+		shift
+	done
+	if [ -z $outname ] ; then
+		outname=$(basename $(pwd))-%m.$format
+	fi
+
+	if ! (echo $outname | grep '%m') > /dev/null  ; then
+		outname+="-%m"
+	fi
+	if ! (echo $outname | grep '^/') > /dev/null  ; then
+		outname=$(pwd)/"$outname"
+	fi
+	
+	#echo "Modules: $smodules"
+	#echo "Params: $@"
+	#echo "Outname: $outname"

lh> Please remove debug comments.


+	
+	module_list "$smodules" |
+	while read mode sha1 stage path
+	do
+		name=$(module_name "$path") || exit
+# 		url=$(git config submodule."$name".url)
+# 		if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
+# 		then
+# 			say "-$sha1 $path"
+# 			continue;
+# 		fi

lh> This should probably work similar to `update`, i.e. exit
lh> with an error if a submodule path is explicitly specified
lh> and the submodule isn't registered in .git/config, and
lh> silently skip any non-registered submodules if no
lh> paths were specified. And if the submodule is not
lh> skipped it probably should be an error if the submodule
lh>  isn't checked out.


+		
+		fname=$(echo $outname |sed 's/%m/'$name'/')

lh> This should probably be documented ;-)


+		say $fname
+		pushd "$path" > /dev/null
+		git archive --format=$format $do_exec $verbose
--prefix="$base_prefix$path/" $sha1 > \
+			"$fname"
+		popd > /dev/null

lh> What does `git archive` do when --exec is specified without
lh> --remote? What about error checking?


+	done
+}
 #
 # Sync remote urls for submodules
 # This makes the value for remote.$remote.url match the value
@@ -656,7 +741,7 @@ cmd_sync()
 while test $# != 0 && test -z "$command"
 do
 	case "$1" in
-	add | foreach | init | update | status | summary | sync)
+	add | foreach | init | update | status | summary | sync | archive)
 		command=$1
 		;;
 	-q|--quiet)
--
1.6.0.1



>From 87b75f003d31994d0de6502342e4d0ad68665e80 Mon Sep 17 00:00:00 2001
From: P. Christeas <p_christ@hol.gr>
Date: Wed, 24 Sep 2008 10:48:04 +0300
Subject: [PATCH] Submodule init: cloned mode

If we try to clone a repo with git submodules, the 'submodule init'
command should bind the submodules to the source repo, rather than
the source's origin.

Signed-off-by: P. Christeas <p_christ@hol.gr>
---
 git-submodule.sh |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 2bce7f9..df5fcac 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -241,6 +241,12 @@ cmd_init()
 		-q|--quiet)
 			quiet=1
 			;;
+		-f|--force)
+			force=1
+			;;
+		--cloned)
+			cloned=1
+			;;
 		--)
 			shift
 			break
@@ -261,19 +267,26 @@ cmd_init()
 		# Skip already registered paths
 		name=$(module_name "$path") || exit
 		url=$(git config submodule."$name".url)
-		test -z "$url" || continue
-
-		url=$(git config -f .gitmodules submodule."$name".url)
-		test -z "$url" &&
-		die "No url found for submodule path '$path' in .gitmodules"
-
-		# Possibly a url relative to parent
-		case "$url" in
-		./*|../*)
-			url=$(resolve_relative_url "$url") || exit
-			;;
-		esac
+		test -z "$url" || test -n "$force" || continue

+		if [ "x$cloned" != "x1" ] ; then
+			url=$(git config -f .gitmodules submodule."$name".url)
+			test -z "$url" &&
+			die "No url found for submodule path '$path' in .gitmodules"
+	
+			# Possibly a url relative to parent
+			case "$url" in
+			./*|../*)
+				url=$(resolve_relative_url "$url") || exit
+				;;
+			esac
+		else
+			# Cloned mode: we try to figure out the submodule
+			# path in the remote origin.
+			# FIXME: we do use "../" because the remote is the .git/
+			url=$(resolve_relative_url "../$path/.git")
+		fi
+		
 		git config submodule."$name".url "$url" ||
 		die "Failed to register url for submodule path '$path'"
--
1.6.0.1


It looks like --cloned requires the downstream to know which
submodules are available from the same remote as the supermodule (and
with the same path as registered in the supermodule), i.e. quite a
specific configuration. Is this really common enough to justify a
special option to `submodule init`?

Maybe the .gitmodules file could be extended to contain multiple urls
instead (i.e. both absolute and relative ones)? Then `submodule init`
could get options like --prefer-relative-url, --prefer-absolute-url
and --interactive. What do you think?

--
larsh

       reply	other threads:[~2008-09-24  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200809241100.30758.p_christ@hol.gr>
2008-09-24  9:13 ` Lars Hjemli [this message]
2008-09-24  9:25   ` Git submodule enhancements Lars Hjemli
2008-09-24  9:46   ` Lars Hjemli
2008-09-24 10:14   ` P. Christeas
2008-09-24 16:39     ` René Scharfe

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=8c5c35580809240213v5198d2abh489915dc1133c75@mail.gmail.com \
    --to=hjemli@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=p_christ@hol.gr \
    /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).