From: Uwe Kleine-König Date: Fri, 19 Dec 2008 21:40:33 +0000 (+0100) Subject: tg export (quilt): Implement flattening patch paths X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=99df827e21e8c36214b57c3d4cd7c16453c3439f;hp=7e24a4aafda160b0715436034d5c8bf6f62ad8bd;p=topgit.git tg export (quilt): Implement flattening patch paths 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 Signed-off-by: martin f. krafft --- diff --git a/README b/README index 8be0d17..0b1800e 100644 --- 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 diff --git a/tg-export.sh b/tg-export.sh index 95aa346..b367aaf 100644 --- a/tg-export.sh +++ b/tg-export.sh @@ -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 }