git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Levedahl <mdl123@verizon.net>
To: git@vger.kernel.org
Cc: Mark Levedahl <mdl123@verizon.net>
Subject: [PATCH] Add git-bundle - pack objects and references for disconnected transfer
Date: Fri, 16 Feb 2007 01:39:44 -0500	[thread overview]
Message-ID: <11716079843500-git-send-email-mdl123@verizon.net> (raw)
In-Reply-To: <7vodnuc0me.fsf@assigned-by-dhcp.cox.net>

Some workflows require coordinated development between repositories on
machines that can never be connected. This utility creates a bundle
containing a pack of objects and associated references (heads or tags)
that can be independently transferred to another machine, effectively
supporting git-push like operations between disconnected systems.

Signed-off-by: Mark Levedahl <mdl123@verizon.net>
---
 git-bundle.sh |  112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)
 create mode 100755 git-bundle.sh

diff --git a/git-bundle.sh b/git-bundle.sh
new file mode 100755
index 0000000..f56f499
--- /dev/null
+++ b/git-bundle.sh
@@ -0,0 +1,112 @@
+#!/bin/sh
+# Create a bundle to carry from one git repo to another
+# (e.g., "sneaker-net" based push)
+# git-bundle <git-rev-list args>
+# git-bundle --bare <git-rev-list args>
+# creates bundle.tar in current directory (can rename of course)
+#
+# The bundle includes all refs given (--all selects every ref in the repo).
+# and all of the commit objects needed subject to the list given.
+#
+# Objects to be packed are limited by specifying one or more of
+#   ^commit-ish    - indicated commits already at the target
+#                    (can have more than one ^commit-ish)
+#   --since=xxx    - Assume target repo has all relevant commits
+#                    earlier than xxx
+
+USAGE='git-bundle [-o file | --output=file] <git-rev-list arguments>'
+SUBDIRECTORY_OK=1
+. git-sh-setup
+
+bfile=bundle.tar
+args=
+while test -n "$1" ; do
+    case $1 in
+        -h|--h|--he|--hel|--help)
+            echo "$USAGE"
+            exit;;
+        --output=*)
+            bfile=${1##--output=};;
+        -o|--output)
+            shift
+            bfile=$1;;
+        *)
+            args="$args $1"
+    esac
+    shift
+done
+
+unknown=$(git-rev-parse --no-revs $args)
+test -z "$unknown" || die "unknown option: $unknown"
+gitrevargs=$(git-rev-parse --symbolic --revs-only $args) || exit 1
+
+# find the refs to carry along and get sha1s for each.
+refs=
+fullrevargs=
+for arg in $gitrevargs ; do
+    #ignore options and basis refs, get unambiguous ref name for things
+    # we will transport (e.g., user gives master, have heads/master and
+    # remotes/origin/master, we keep the former).
+    case "$arg" in
+        -*) fullrevargs="$fullrevargs $arg";;
+        ^*) fullrevargs="$fullrevargs $arg";;
+        *)  ref=$(git-show-ref "$arg")
+            test "$(echo $ref | wc -w)" = "2" || die "Ambigous reference: $arg
+$ref"
+            fullrevargs="$fullrevargs ${ref#* }"
+            refs="$refs $ref"
+            ;;
+    esac
+done
+test -z "$refs" && die "No references specified, I don't know what to bundle."
+
+# git-rev-list cannot determine edge objects if a date restriction is
+# given...  we do things a slow way if max-age or min-age are given
+case "$fullrevargs" in
+    *--max-age* | *--min-age*)
+    # get a list of all commits that will be packed along with
+    # parents of each.  A fixed git-rev-list --boundary should
+    # replace all of this.
+    echo "Finding prerequisites and commits to bundle..."
+    commits=$(git-rev-list $fullrevargs)
+
+    # get immediate parents of each commit to include
+    parents=
+    for c in $commits ; do
+        parents="$parents $(git-rev-list --parents --max-count=1 $c | cut -b42-)"
+    done
+    parents=$(printf "%s\n" $parents | sort | uniq)
+
+    # factor out what will be in this bundle, the remainder are the
+    # bundle's prerequisites.  double up commits in this as we only
+    # want things that are only in parents to appear once
+    prereqs=$(printf "%s\n" $parents $commits $commits | \
+        sort | uniq -c | sed -ne 's/^ *1 //p');;
+    *)
+        prereqs=$(git-rev-list --objects-edge $fullrevargs | sed -ne 's/^-//p');;
+esac
+
+# create refs and pack
+tmp=$GIT_DIR/bundle_tmp$$
+references="$tmp-references"
+pack="$tmp-pack"
+trap 'rm -f "$references" "$pack"' 0 1 2 3 15
+
+echo "v1" > "$references" &&
+echo "prerequisites" >> "$references" &&
+printf "%s\n" $prereqs >> "$references" &&
+echo "references" >> "$references" &&
+git-show-ref $refs >> "$references" &&
+(git-rev-list --objects $fullrevargs | \
+    cut -b-40 | \
+    git pack-objects --all-progress --stdout >> "$pack" ) \
+    || exit
+
+# create the tar file, clean up
+tar cf "$bfile" --absolute-names --transform="s,$tmp-,," \
+    --verbose --show-transformed-names \
+    "$references" "$pack"
+rm -f "$pack" "$references"
+
+# done
+echo "Created $bfile"
-- 
1.5.0.rc4.375.gd0938-dirty

  parent reply	other threads:[~2007-02-16  6:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-16  0:19 Respun - Scripts to use bundles to move data between repos Mark Levedahl
2007-02-16  0:19 ` [PATCH] Add git-bundle - pack objects and references for disconnected transfer Mark Levedahl
2007-02-16  0:19   ` [PATCH] Add git-unbundle - unpack " Mark Levedahl
2007-02-16  0:19     ` [PATCH] Include git-bundle and git-unbundle in Makefile Mark Levedahl
2007-02-16  0:19       ` [PATCH] Create documentation for git-bundle Mark Levedahl
2007-02-16  0:19         ` [PATCH] Create documentation for git-unbundle Mark Levedahl
2007-02-16  0:19           ` [PATCH] Link git-bundle and git-unbundle docs from git(7) Mark Levedahl
2007-02-16  2:24     ` [PATCH] Add git-unbundle - unpack objects and references for disconnected transfer Junio C Hamano
2007-02-16  2:40       ` Linus Torvalds
2007-02-16  6:38         ` Mark Levedahl
2007-02-16  6:48           ` Shawn O. Pearce
2007-02-16  7:31             ` Junio C Hamano
2007-02-16  7:45               ` Shawn O. Pearce
2007-02-16  6:22       ` Mark Levedahl
2007-02-16  7:24         ` Junio C Hamano
2007-02-16  2:11   ` [PATCH] Add git-bundle - pack " Junio C Hamano
2007-02-16  4:41     ` Shawn O. Pearce
2007-02-16  7:28       ` Junio C Hamano
2007-02-16  6:39     ` Mark Levedahl [this message]
2007-02-16  6:54       ` Shawn O. Pearce
2007-02-16 11:57         ` Simon 'corecode' Schubert
2007-02-16  4:37 ` Respun - Scripts to use bundles to move data between repos Shawn O. Pearce
  -- strict thread matches above, loose matches on Subject: below --
2007-02-16 12:45 Re: [PATCH] Add git-bundle - pack objects and references for disconnected transfer Mark Levedahl
2007-02-16 13:25 ` Simon 'corecode' Schubert
2007-02-16 13:44 ` Johannes Schindelin
2007-02-16 23:25   ` Mark Levedahl

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11716079843500-git-send-email-mdl123@verizon.net \
    --to=mdl123@verizon.net \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).