]> err.no Git - systemd/commitdiff
Expand source hook to use git diff over git format-patch
authorTollef Fog Heen <tfheen@err.no>
Mon, 27 Feb 2012 21:36:06 +0000 (22:36 +0100)
committerTollef Fog Heen <tfheen@err.no>
Mon, 27 Feb 2012 21:37:02 +0000 (22:37 +0100)
debian/systemd-hack-up-the-source.hook

index 1a932124d9b68787075ad4b389728ffacb7bb4c1..62eea54e96a47c5615ffe4a0e96f80d442936518 100755 (executable)
@@ -4,6 +4,70 @@ set -e
 
 set -x
 
+. /usr/share/gitpkg/hooks/repo-config-helper
+
 find -name Makefile -type l -print -delete
 #rm -r  src/Makefile
-. /usr/share/gitpkg/hooks/quilt-patches-deb-export-hook
+#. /usr/share/gitpkg/hooks/quilt-patches-deb-export-hook
+
+patch_list=debian/source/git-patches
+patch_dir=debian/patches
+
+if [ ! -r "$patch_list" ]; then
+    echo "No $patch_list file, I guess you've pushed them all upstream."
+    echo "Good Work!"
+    exit 0
+fi
+
+if [ -e "$patch_dir" ]; then
+    echo "Uh oh.  You already have a $patch_dir here."
+    echo "You probably don't want us to scribble on that without asking."
+    exit 1
+fi
+
+if [ -z "$REPO_DIR" ]; then
+    # support running as a free-standing script, without gitpkg
+    DEB_VERSION="$(dpkg-parsechangelog | sed -rne 's/^Version: ([^:]+:)?//p')"
+    UPSTREAM_VERSION="${DEB_VERSION%-*}"
+    REPO_DIR=.
+fi
+
+DEB_REF=$(sanitise_git_ref $DEB_VERSION)
+UPSTREAM_REF="${DEB_REF%-*}"
+
+do_patches (){
+    while read -r line
+    do
+       [ -n "$line" ] || continue
+       case $line in
+           \#*)
+               ;;
+           *)
+               count=$(wc -l "$patch_dir/series" | cut -f1 -d' ')
+               if PATCHES="$(git --git-dir "$REPO_DIR/.git" diff "$line" > "$patch_dir/$line")"; then
+                   if [ -n "$PATCHES" ]; then
+                       echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >> "$patch_dir/series"
+                   else
+                       echo "Warning: no patches from $line"
+                   fi
+               else
+                   echo "git --git-dir '$REPO_DIR/.git' diff '$line'"
+                   echo "failed."
+                   exit 1
+               fi
+       esac
+    done
+}
+
+mkdir -p "$patch_dir" || exit 1
+echo "# $patch_list exported from git by export-hook" > "$patch_dir/series"
+
+(sed -e "s/\$DEB_VERSION/$DEB_VERSION/g"               \
+    -e "s/\${DEB_VERSION}/$DEB_VERSION/g"              \
+    -e "s/\$UPSTREAM_VERSION/$UPSTREAM_VERSION/g"      \
+    -e "s/\${UPSTREAM_VERSION}/$UPSTREAM_VERSION/g"    \
+    -e "s/\$DEB_REF/$DEB_REF/g"                                \
+    -e "s/\${DEB_REF}/$DEB_REF/g"                      \
+    -e "s/\$UPSTREAM_REF/$UPSTREAM_REF/g"              \
+    -e "s/\${UPSTREAM_REF}/$UPSTREAM_REF/g"            \
+    < "$patch_list" ; echo ) | do_patches || exit 1