chiark / gitweb /
tg export (quilt): Implement flattening patch paths
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 19 Dec 2008 21:40:33 +0000 (22:40 +0100)
committermartin f. krafft <madduck@debian.org>
Mon, 5 Jan 2009 15:46:58 +0000 (16:46 +0100)
The result of providing the new flag --flatten is that the exported
patches are all placed directly in the output directory, not in
subdirectories below it.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: martin f. krafft <madduck@debian.org>
README
tg-export.sh

diff --git a/README b/README
index 8be0d17..0b1800e 100644 (file)
--- a/README
+++ b/README
@@ -409,6 +409,12 @@ tg export
        a comma-separated explicit list of branches to export. This
        mode of operation is currently not supported with collapse.
 
+       In '--quilt' mode the patches are named like the originating topgit
+       branch.  So usually they end up in subdirectories of the output
+       directory.  With option '--flatten' the names are mangled such that
+       they end up directly in the output dir (i.e. slashed are substituted by
+       underscores).
+
        Usage: tg export ([--collapse] BRANCH | --quilt DIR)
 
        TODO: Make stripping of non-essential headers configurable
index 95aa346..b367aaf 100644 (file)
@@ -7,6 +7,7 @@ name=
 branches=
 output=
 driver=collapse
+flatten=false
 
 
 ## Parse options
@@ -16,6 +17,8 @@ while [ -n "$1" ]; do
        case "$arg" in
        -b)
                branches="$1"; shift;;
+       --flatten)
+               flatten=true;;
        --quilt)
                driver=quilt;;
        --collapse)
@@ -34,6 +37,9 @@ done
 [ -z "$branches" -o "$driver" = "quilt" ] ||
        die "-b works only with the quilt driver"
 
+[ "$driver" = "quilt" ] || ! "$flatten" ||
+       die "--flatten works only with the quilt driver"
+
 if [ -z "$branches" ]; then
        # this check is only needed when no branches have been passed
        name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
@@ -138,7 +144,18 @@ quilt()
                return
        fi
 
-       filename="$output/$_dep.diff"
+       if "$flatten"; then
+               bn="$(echo "$_dep.diff" | sed -e 's#_#__#g' -e 's#/#_#g')";
+               dn="";
+       else
+               bn="$(basename "$_dep.diff")";
+               dn="$(dirname "$_dep.diff")/";
+               if [ "x$dn" = "x./" ]; then
+                       dn="";
+               fi;
+       fi;
+
+       filename="$output/$dn$bn";
        if [ -e "$filename" ]; then
                # We've already seen this dep
                return
@@ -148,9 +165,9 @@ quilt()
                echo "Skip empty patch $_dep";
        else
                echo "Exporting $_dep"
-               mkdir -p "$(dirname "$filename")"
+               mkdir -p "$output/$dn";
                $tg patch "$_dep" >"$filename"
-               echo "$_dep.diff -p1" >>"$output/series"
+               echo "$dn$bn -p1" >>"$output/series"
        fi
 }