Skip to contentSkip to conversation

Add git-unbundle - unpack objects and references for disconnected transfer

PATCH In review Mark Levedahl 3 participants 12 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 3 lines
Quoted 1 line

Also as Shawn pointed out, the script too heavily depends on GNU tar. Can we do something about it?

Let me ponder, I'm sure I can do something. As I noted in another response, Cygwin won't let me reliably pipe the pack file through bash, so I'm forced to use some archiver.

Mark

#1 lore raw
Quoted 3 lines · Mark Levedahl
Quoted 3 lines

Also as Shawn pointed out, the script too heavily depends on GNU tar. Can we do something about it

This one is easy, make tmp a directory, then build the tar file in that directory so the archive members don't include the tmp name, then just move the tar file to where it is needed...

tmp="$GIT_DIR/bundle_tmp$$"
references="$tmp/references"
pack="$tmp/pack"
trap 'rm -rf "$tmp"' 0 1 2 3 15

mkdir "$tmp" &&
echo "v1 git-bundle" > "$version" &&
------

# create the tar file, clean up
cd "$tmp" &&
tar cf bundle prerequisites references version pack &&
cd - &&
mv "$tmp/bundle" "$bfile" &&
rm -rf "$tmp"

I believe that as this works, tar needs only to understand c, f, and -O. It is easy enough to search for gtar and use that, or allow user to define TAR. So, I think this is a non-issue.

Mark

#2 lore raw

Hi,

Quoted 7 lines · Mark Levedahl
Quoted 3 lines · Mark Levedahl
Quoted 3 lines

Also as Shawn pointed out, the script too heavily depends on GNU tar. Can we do something about it

This one is easy, make tmp a directory, then build the tar file in that directory so the archive members don't include the tmp name, then just move the tar file to where it is needed...

Why not just get rid of this unneeded dependency? It is _unneeded_. Maybe you never suffered dependency hell (this is the only way I can explain your resistance). It is _good_ to get rid of dependencies.

Ah whatever, if you don't just get rid of that tar dependency, I'll just do it.

Ciao,
Dscho

#3 lore raw
In reply to Mark Levedahl
Quoted 7 lines · Mark Levedahl
Quoted 3 lines
Quoted 1 line

Also as Shawn pointed out, the script too heavily depends on GNU tar. Can we do something about it?

Let me ponder, I'm sure I can do something. As I noted in another response, Cygwin won't let me reliably pipe the pack file through bash, so I'm forced to use some archiver.

Mark, how urgent do you want to have "bundle" in my tree? As I understand it, this came out of your working zip based implementation your group already use, so I am suspecting that you do not have urgent need to have a different one in git.git in a half-baked shape.

The reason I say this is because I very much in favor of the general idea of an archive file that can be used to sneakernet repository updates, but I find the current bundle-unbundle interface a bit awkward to integrate into the rest of the system.

Wouldn't it be nice if you can treat a bundle as just a different kind of git URL that you can "git fetch"?

	$ git fetch file.bdl 'refs/heads/*:refs/heads/*'

As the way I read the current implementation of git-unbundle is that it is designed to only overwrite (with fast-forward check not to lose changes from the target) all the refs in place. It does not, for example, allow extracting only one branch, nor storing the branch in a tracking branch by renaming. I think it would be nicer to change the external interface from the bundle subsystem to the calling scripts, so that it behaves closer to git-fetch-pack.

I haven't thought things through, but I think something like this would be sufficient:

	# create a bundle.
	$ git bundle --create v1.5.0..maint master next >file.bdl
	# you can view the tips of refs it contains.  This is
        # similar to "ls-remote" output.
	$ git bundle --list-heads file.bdl
        efa13f7b7ea1605deab3a6478fa0d0706c828170 refs/heads/maint
        af99711cd84c30a16450f73dbc21ba9f9f9803e6 refs/heads/master
        664e83a22b604fc5af1a84ddd48549b005cf4bc9 refs/heads/next
        # optionally allow checking if the pre-requisites of the
        # bundle are available.
	$ git bundle --verify file.bdl
	error: file.bdl depends on the following commits you lack
	in the repository:
        82bf92f9846326a743102e27fa9827422dddfada v1.5.0-564-g82bf92f
	4d462883de41190afd23672c8236361c61a9e6bd v1.5.0-34-g4d46288
	# extract the packfile part, run index-pack and report
        # the result the same way as git-fetch-pack
        $ git bundle --unbundle file.bdl
	pack	340e3faa26616ca8c38b369a6d323ecf7a34f4fb
        efa13f7b7ea1605deab3a6478fa0d0706c828170 refs/heads/maint
        af99711cd84c30a16450f73dbc21ba9f9f9803e6 refs/heads/master
        664e83a22b604fc5af1a84ddd48549b005cf4bc9 refs/heads/next

Then git-ls-remote can be taught about a bundle file and use the 'git bundle --list-heads'. Also, with something like this in your config:

[remote "bundle"]
url = /home/me/tmp/file.bdl
fetch = refs/heads/*:refs/remotes/origin/*

You can first sneakernet the bundle file to ~/tmp/file.bdl and then these commands:

	$ git ls-remote bundle
        $ git fetch bundle
	$ git pull bundle

would treat it as if it is talking with a remote side over the network.

Hmm?

#4 lore raw
Quoted 6 lines · Junio C Hamano

Mark, how urgent do you want to have "bundle" in my tree? As I understand it, this came out of your working zip based implementation your group already use, so I am suspecting that you do not have urgent need to have a different one in git.git in a half-baked shape.

I can get my work done today with what I have. However, I really believe bundle is a good addition to git, and I don't want to maintain an out-of-tree patch to git to add this capability.

Quoted 5 lines

Wouldn't it be nice if you can treat a bundle as just a different kind of git URL that you can "git fetch"?

	$ git fetch file.bdl 'refs/heads/*:refs/heads/*'

yes

Quoted 12 lines

Then git-ls-remote can be taught about a bundle file and use the 'git bundle --list-heads'. Also, with something like this in your config:

[remote "bundle"]
url = /home/me/tmp/file.bdl
fetch = refs/heads/*:refs/remotes/origin/*

You can first sneakernet the bundle file to ~/tmp/file.bdl and then these commands:

Quoted 10 lines
	$ git ls-remote bundle
        $ git fetch bundle
	$ git pull bundle

would treat it as if it is talking with a remote side over the network.

Hmm?

As long as I can still do a "git fetch file.bdl" and without having to do the config stuff. I'm happy. Integrating this bundle with basic git approaches to things is obviously good. The frontend you outlined seems a trivial rearrangement of what I already have, but I'll let this discussion progress a bit further before I start doing that.

Mark

#5 lore raw
Quoted 10 lines · Mark Levedahl
Quoted 5 lines

Wouldn't it be nice if you can treat a bundle as just a different kind of git URL that you can "git fetch"?

	$ git fetch file.bdl 'refs/heads/*:refs/heads/*'

yes
...

As long as I can still do a "git fetch file.bdl" and without having to do the config stuff. I'm happy.

I do not think your patch (original or respun) checks if it is overwriting the current branch. Even if it is a fast forward, it should check this condition and prevent the end user from getting confused. The above sample command line you quoted from my message can potentially have the same problem, but "git fetch" checks and refuses.

Even when the "remote" is not a bundle file, it sometimes is useful to store the refs as they are without mapping them to remotes hierarchy as the separate-remote layout does. An obvious use case is to mirror another repository as is. So it may make sense to teach --mirror to "git-fetch" so that you can say:

	$ git fetch --mirror file.bdl

which would be a short-hand to say:

	$ git fetch file.bdl 'refs/*:refs/*'

A final note. A real 'mirror' mode should also remove stale refs that do not exist on the remote side anymore, which is a different use case as your bundle, which presumably is primarily meant to carry not all but only selected set of refs, and most likely not the 'master' branch head (and I am guessing that that is why you forgot to make sure you are not overwriting the current branch in the unbundle script). A real 'mirror' mode would use a separate option to remove a ref that does not exist on the remote end anymore, like:

	$ git fetch --mirror-all git://git.kernel.org/pub/scm/git/git.git/
#6 lore raw
Quoted 7 lines · Junio C Hamano

I do not think your patch (original or respun) checks if it is overwriting the current branch. Even if it is a fast forward, it should check this condition and prevent the end user from getting confused. The above sample command line you quoted from my message can potentially have the same problem, but "git fetch" checks and refuses.

True. I've been using this to mirror remote/* and tags. Making this just an alternate transport behind fetch and pull is clearly the cleanest way to deal with non-remote branches.

Quoted 10 lines

A final note. A real 'mirror' mode should also remove stale refs that do not exist on the remote side anymore, which is a different use case as your bundle, which presumably is primarily meant to carry not all but only selected set of refs, and most likely not the 'master' branch head (and I am guessing that that is why you forgot to make sure you are not overwriting the current branch in the unbundle script). A real 'mirror' mode would use a separate option to remove a ref that does not exist on the remote end anymore, like:

Quoted 2 lines
	$ git fetch --mirror-all git://git.kernel.org/pub/scm/git/git.git

Perhaps "git fetch --mirror --delete" would be more suggestive of the difference to "git fetch --mirror"?

Mark

#7 lore raw
Quoted 9 lines · Mark Levedahl

Junio C Hamano wrote:
...

Quoted 7 lines

A final note. A real 'mirror' mode should also remove stale refs that do not exist on the remote side anymore, which is a different use case as your bundle,...
... A real 'mirror' mode
would use a separate option to remove a ref that does not exist on the remote end anymore, like:

Quoted 4 lines
Quoted 2 lines
	$ git fetch --mirror-all git://git.kernel.org/pub/scm/git/git.git

Perhaps "git fetch --mirror --delete" would be more suggestive of the difference to "git fetch --mirror"?

I think that is a good suggestion, as people familiar with rsync already know what --delete means in such a context.

#8 lore raw
In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano

I haven't thought things through, but I think something like this would be sufficient:

	# create a bundle.
	$ git bundle --create v1.5.0..maint master next >file.bdl

In this vein, would it make sense to let git-push be the front end to create the bundle? I'm not sure git-push really contributes anything, but the interface would then be consistent across all transports. Just a thought.

Mark

#9 lore raw
Quoted 4 lines · Mark Levedahl
Quoted 3 lines · Junio C Hamano

I haven't thought things through, but I think something like this would be sufficient:

Quoted 8 lines
Quoted 4 lines
	# create a bundle.
	$ git bundle --create v1.5.0..maint master next >file.bdl

In this vein, would it make sense to let git-push be the front end to create the bundle? I'm not sure git-push really contributes anything, but the interface would then be consistent across all transports. Just a thought.

I am not sure. For the "fetch" case, the UI will be exactly the same (URL and then refspecs), but we never say bottom commits for git-push. When you are creating a bundle, unless you are including everything, you want a way to say which bottom commits to be excluded from the resulting pack, so they are different. I had an impression bundle creation is similar to archive.

#10 lore raw

PATCH 1/1 Add git-bundle: move objects and references by archive.

Some workflows require use of repositories on machines that cannot be connected, preventing use of git-fetch / git-push to transport objects and references between the repositories.

git-bundle provides an alternate transport mechanism, effectively allowing git-fetch and git-pull to operate using sneakernet transport. git-bundle --create allows the user to create a bundle containing one or more branches or tags, but with specified basis assumed to exist on the target repository. At the receiving end, git-bundle acts like git-fetch-pack, allowing the user to invoke git-fetch or git-pull using the bundle file as the URL. git-fetch and git-ls-remote determine they have a bundle URL by checking that the URL points to a file, but are otherwise unchanged in operation with bundles.

---
 Documentation/cmd-list.perl  |    1 +
 Documentation/git-bundle.txt |  146 +++++++++++++++++++++++++++++++++++
 Makefile                     |    3 +-
 git-bundle.sh                |  174 ++++++++++++++++++++++++++++++++++++++++++
 git-fetch.sh                 |   11 ++-
 git-ls-remote.sh             |    7 ++-
 6 files changed, 338 insertions(+), 4 deletions(-)
 mode change 100755 => 100644 Documentation/cmd-list.perl
 create mode 100644 Documentation/git-bundle.txt
 create mode 100755 git-bundle.sh
Documentation/cmd-list.perl +1 -0
old mode 100755
new mode 100644
index a2d6268..f61c77a
@@ -70,6 +70,7 @@ git-archive                             mainporcelain
 git-bisect                              mainporcelain
 git-blame                               ancillaryinterrogators
 git-branch                              mainporcelain
+git-bundle                              mainporcelain
 git-cat-file                            plumbinginterrogators
 git-checkout-index                      plumbingmanipulators
 git-checkout                            mainporcelain
Documentation/git-bundle.txt new file +146 -0

146 lines not on this page · raw message

Makefile +2 -1
index ebecbbd..c6d540e 100644
@@ -177,7 +177,8 @@ SCRIPT_SH = \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
-	git-lost-found.sh git-quiltimport.sh
+	git-lost-found.sh git-quiltimport.sh \
+	git-bundle.sh
 
 SCRIPT_PERL = \
 	git-add--interactive.perl \
git-bundle.sh new file +174 -0

174 lines not on this page · raw message

git-fetch.sh +9 -2
index ca984e7..4cb4009 100755
@@ -377,8 +377,15 @@ fetch_main () {
     ( : subshell because we muck with IFS
       IFS=" 	$LF"
       (
-	  git-fetch-pack --thin $exec $keep $shallow_depth "$remote" $rref ||
-	  echo failed "$remote"
+	if test -r "$remote" ; then
+	    test -n "$shallow_depth" &&
+		die "shallow clone with bundle is not supported"
+	    git-bundle --unbundle "$remote" $rref ||
+	    echo failed "$remote"
+	else
+	    git-fetch-pack --thin $exec $keep $shallow_depth "$remote" $rref ||
+	    echo failed "$remote"
+	fi
       ) |
       (
 	trap '
git-ls-remote.sh +6 -1
index 8ea5c5e..73b745d 100755
@@ -89,8 +89,13 @@ rsync://* )
 	;;
 
 * )
-	git-peek-remote $exec "$peek_repo" ||
+	if test -r "$peek_repo" ; then
+		git bundle --list-heads "$peek_repo" ||
 		echo "failed	slurping"
+	else
+		git-peek-remote $exec "$peek_repo" ||
+		echo "failed	slurping"
+	fi
 	;;
 esac |
 sort -t '	' -k 2 |
Signature · 1 line
1.5.0.rc4.375.gd0938-dirty
#11 lore raw

Re: [PATCH] Add git-bundle: move objects and references by archive.

git-ls-remote.sh rsync://* ) · line 92

Quoted 3 lines · Mark Levedahl
git-ls-remote.sh +1 -1
-	git-peek-remote $exec "$peek_repo" ||
+	if test -r "$peek_repo" ; then

oops: test -f
actually works. Corrected patch follows.

Mark