Package: gitpkg
Version: 0.14
Severity: wishlist
File: /usr/bin/git-debimport
Tags: patch

git-debimport cannot handle 3.0 (quilt) source package format. This is
because its only looking for diff.gz files and not debian.tar.gz ones

This patch, while a little rough, seems to handle the new source format
ok.  You might want to add some more error checking but it got me going
with my packages.

 - Craig


-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-trunk-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages gitpkg depends on:
ii  dpkg-dev                      1.15.5.4   Debian package development tools
ii  git-core                      1:1.6.6-1  fast, scalable, distributed revisi

gitpkg recommends no packages.

Versions of packages gitpkg suggests:
ii  devscripts                    2.10.59    scripts to make the life of a Debi

-- no debconf information
--- /usr/bin/git-debimport	2010-01-01 07:42:16.000000000 +1100
+++ ./git-debimport	2010-01-17 00:29:33.000000000 +1100
@@ -120,9 +120,10 @@
 fi
 
 PACKAGE_DIFFS="$(find $PACKAGES_DIR -type f -name "${PACKAGE_NAME}_*.diff.gz" 2>/dev/null | sort)"
-PACKAGE_TARS="$(find $PACKAGES_DIR -type f -name "${PACKAGE_NAME}_*.tar.gz" \! -name "*.orig.tar.gz" 2>/dev/null | sort)"
+PACKAGE_DEBTARS="$(find $PACKAGES_DIR type f -name "${PACKAGE_NAME}_*.debian.tar.gz" 2>/dev/null | sort)"
+PACKAGE_TARS="$(find $PACKAGES_DIR -type f -name "${PACKAGE_NAME}_*.tar.gz" \! -name "*.orig.tar.gz" \! -name "*.debian.tar.gz" 2>/dev/null | sort)"
 
-if [ -z "$PACKAGE_DIFFS" ] && [ -z "$PACKAGE_TARS" ]; then
+if [ -z "$PACKAGE_DIFFS" ] && [ -z "$PACKAGE_TARS" ] && [ -z "$PACKAGE_DEBTARS" ]; then
 
     if [ -z "$fetch_snapshots" ]; then
 	echo "No ${package_path}_* diff.gz or tar.gz files found, aborting."
@@ -255,18 +256,20 @@
 # Maybe output a warning that this could take a while if $count > N.
 # Determine N.
 
-P=( $PACKAGE_DIFFS )
-count=${#P[*]}
+if [ -n "$PACKAGE_DIFFS" ] ; then
+    P=( $PACKAGE_DIFFS )
+    count=${#P[*]}
 
-for(( i=1; i < count; ++i )) do
-    j=i
-    #echo "was $i: ${P[i]}"
-    while (($j)) && $COMPARE "${P[j-1]%.diff.gz}" gt "${P[i]%.diff.gz}"; do ((--j)); done
-    ((i==j)) || P=( $...@]:0:j} ${P[i]} ${P[j]} $...@]:j+1:i-(j+1)} $...@]:i+1} )
-done
+    for(( i=1; i < count; ++i )) do
+        j=i
+        #echo "was $i: ${P[i]}"
+        while (($j)) && $COMPARE "${P[j-1]%.diff.gz}" gt "${P[i]%.diff.gz}"; do ((--j)); done
+        ((i==j)) || P=( $...@]:0:j} ${P[i]} ${P[j]} $...@]:j+1:i-(j+1)} $...@]:i+1} )
+    done
 #for(( i=1; i < count; ++i )) do echo "now $i: ${P[i]}"; done
 
 PACKAGE_DIFFS="$...@]}"
+
 CACHE_DIR="../${PACKAGE_NAME}-import-cache"
 
 for f in $PACKAGE_DIFFS; do
@@ -367,6 +370,123 @@
 rm -rf "$CACHE_DIR"
 [ -z "$late_merge" ] || git merge -s ours "$UPSTREAM_BRANCH"
 
+fi
+
+# *debian.tar.gz handing
+if [ -n "$PACKAGE_DEBTARS" ] ; then
+    P=( $PACKAGE_DEBTARS )
+    count=${#P[*]}
+
+    for(( i=1; i < count; ++i )) do
+        j=i
+        #echo "was $i: ${P[i]}"
+        while (($j)) && $COMPARE "${P[j-1]%.debian.tar.gz}" gt "${P[i]%.debian.tar.gz}"; do ((--j)); done
+        ((i==j)) || P=( $...@]:0:j} ${P[i]} ${P[j]} $...@]:j+1:i-(j+1)} $...@]:i+1} )
+    done
+#for(( i=1; i < count; ++i )) do echo "now $i: ${P[i]}"; done
+
+PACKAGE_DEBTARS="$...@]}"
+CACHE_DIR="../${PACKAGE_NAME}-import-cache"
+for f in $PACKAGE_DEBTARS; do
+
+    DEBIAN_VERSION="${f%.debian.tar.gz}"
+    DEBIAN_VERSION="${DEBIAN_VERSION##*_}"
+    UPSTREAM_VERSION="${DEBIAN_VERSION%-*}"
+
+    if [ -z "$LAST_UPSTREAM_VERSION" ]; then
+    	echo "Initial import of $PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+
+	rm -rf "$CACHE_DIR"
+	mkdir -p "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig"
+	tar -xf "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz" \
+	     -C "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig" --strip 1
+	find "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig" \
+	     -maxdepth 1 -mindepth 1 -exec cp -al '{}' . \;
+
+	DATE=$(file -L $PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz | sed -n "s/.*, last modified: \([^,]*\),*.*/\1/p")
+
+	git add .
+	if git --no-pager status -a > /dev/null 2>&1; then
+	    GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \
+		git commit -a -m "git-debimport ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+	else
+	    # This particular case probably should still crap out, if the
+	    # initial orig is empty that doesn't bode well for things to come
+	    echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+	fi
+	git checkout -b "$UPSTREAM_BRANCH"
+	git tag $(sanitise_git_ref "$UPSTREAM_TAG_PREFIX$UPSTREAM_VERSION")
+
+	LAST_UPSTREAM_VERSION="$UPSTREAM_VERSION"
+
+	git checkout "$DEBIAN_BRANCH"
+    fi
+
+    if [ "$LAST_UPSTREAM_VERSION" != "$UPSTREAM_VERSION" ]; then
+    	echo "Importing $PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+
+	git checkout "$UPSTREAM_BRANCH"
+
+	find -maxdepth 1 -mindepth 1 \! -name ".git" -exec rm -rf '{}' +
+	rm -rf "$CACHE_DIR"
+	mkdir -p "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig"
+	tar -xf "$PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz" \
+	     -C "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig" --strip 1
+	find "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig" \
+	     -maxdepth 1 -mindepth 1 -exec cp -al '{}' . \;
+
+	DATE=$(file -L $PKG_ROOT$PACKAGES_DIR/${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz | sed -n "s/.*, last modified: \([^,]*\),*.*/\1/p")
+
+	git add .
+	if git --no-pager status -a > /dev/null 2>&1; then
+	    GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \
+		git commit -a -m "git-debimport ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+	else
+	    echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz"
+	fi
+	git tag $(sanitise_git_ref "$UPSTREAM_TAG_PREFIX$UPSTREAM_VERSION")
+
+	LAST_UPSTREAM_VERSION="$UPSTREAM_VERSION"
+
+	git checkout "$DEBIAN_BRANCH"
+	[ -n "$late_merge" ] || git merge "$UPSTREAM_BRANCH"
+
+	#XXX If we were to just always merge here with -s ours, would that
+	#    avoid the chance of merge conflicts but still keep the accurate
+	#    history once we've fixed up the branch below?
+	#    Try this when we find a set of packages that do have conflicts.
+    fi
+
+    echo "Importing $f"
+
+    find -maxdepth 1 -mindepth 1 \! -name ".git" -exec rm -rf '{}' +
+    find "$CACHE_DIR/${PACKAGE_NAME}-${UPSTREAM_VERSION}.orig" \
+	 -maxdepth 1 -mindepth 1 -exec cp -al '{}' . \;
+	 tar -xf "$PKG_ROOT$f"
+    #zcat "$PKG_ROOT$f" | patch -p1
+    chmod 755 debian/rules
+
+    DATE=$(dpkg-parsechangelog | sed -n 's/Date: //p')
+    AUTHOR=$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f1)
+    EMAIL=\<$(dpkg-parsechangelog | sed -n 's/Maintainer: //p' | cut -d\< -f2)
+
+    git add .
+    if git --no-pager status -a > /dev/null 2>&1; then
+	GIT_AUTHOR_NAME="$AUTHOR" GIT_COMMITTER_NAME="$AUTHOR" \
+	GIT_AUTHOR_EMAIL="$EMAIL" GIT_COMMITTER_EMAIL="$EMAIL" \
+	GIT_AUTHOR_DATE="$DATE" GIT_COMMITTER_DATE="$DATE" \
+	    git commit -a -m "git-debimport ${PACKAGE_NAME}_${DEBIAN_VERSION}.diff.gz"
+    else
+	echo "WARNING: nothing to commit for ${PACKAGE_NAME}_${DEBIAN_VERSION}.diff.gz"
+    fi
+    git tag $(sanitise_git_ref "$DEBIAN_TAG_PREFIX$DEBIAN_VERSION")
+
+done
+
+rm -rf "$CACHE_DIR"
+[ -z "$late_merge" ] || git merge -s ours "$UPSTREAM_BRANCH"
+
+fi
 echo "All done!"
 
 # vi:sts=4:sw=4:noet:foldmethod=marker

Reply via email to