From: Heiko Hund Date: Thu, 12 Nov 2009 10:15:08 +0000 (+0000) Subject: --strip option for tg export X-Git-Tag: topgit-0.9~3 X-Git-Url: https://repo.or.cz/w/topgit.git/commitdiff_plain/4035016bb505479ad6197aed23a54f95c2400609 --strip option for tg export This introduces the '--strip[=N]' option for 'tg export --quilt' to enable export of a flat quilt series, even if the tg branch names are structured hierarchically. It may be useful if you - like me - structure your topgit branches like "t//" to keep the overview in git, but don't want the exported quilt series to be spread across subdirectories. In contrast to '--flatten' this option removes the first 'N' or all subdirectories from the topgit branch name, while keeping compatible with the existing options. The remaining ones can still be flattened. Patch names can still get numbered. Signed-off-by: Heiko Hund Signed-off-by: Robin Green --- diff --git a/README b/README index f32a680..14e9542 100644 --- a/README +++ b/README @@ -469,9 +469,11 @@ tg export 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). With '--numbered' (which implies '--flatten') the patch - names get a number as prefix to allow getting the order without + they end up directly in the output dir (i.e. slashes are substituted by + underscores). With option '--strip[=N]' the first 'N' subdirectories (all + if no 'N' is given) get stripped off. Names are always '--strip'ped + before '--flatten'ed. With option '--numbered' (which implies '--flatten') + the patch names get a number as prefix to allow getting the order without consulting the series file, which eases sending out the patches. Usage: tg export ([(--collapse | --linearize)] BRANCH | --quilt DIR) diff --git a/tg-export.sh b/tg-export.sh index 11842b7..72320af 100644 --- a/tg-export.sh +++ b/tg-export.sh @@ -9,6 +9,8 @@ output= driver=collapse flatten=false numbered=false +strip=false +stripval=0 ## Parse options @@ -23,6 +25,17 @@ while [ -n "$1" ]; do --numbered) flatten=true; numbered=true;; + --strip*) + val=${arg#*=} + if [ "$val" = "--strip" ]; then + strip=true + stripval=9999 + elif [ -n "$val" -a "x$(echo $val | sed -e 's/[0-9]//g')" = "x" ]; then + strip=true + stripval=$val + else + die "invalid parameter $arg" + fi;; --quilt) driver=quilt;; --collapse) @@ -49,6 +62,9 @@ done [ "$driver" = "quilt" ] || ! "$flatten" || die "--flatten works only with the quilt driver" +[ "$driver" = "quilt" ] || ! "$strip" || + die "--strip 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/##')" @@ -152,16 +168,27 @@ quilt() return fi - 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; + _dep_tmp=$_dep + + if "$strip"; then + i=$stripval + while [ "$i" -gt 0 ]; do + [ "$_dep_tmp" = "${_dep_tmp#*/}" ] && break + _dep_tmp=${_dep_tmp#*/} + i=$((i - 1)) + done + fi + + bn="$(basename "$_dep_tmp.diff")" + dn="$(dirname "$_dep_tmp.diff")/" + [ "x$dn" = "x./" ] && dn="" + + if "$flatten" && [ "$dn" ]; then + bn="$(echo "$_dep_tmp.diff" | sed -e 's#_#__#g' -e 's#/#_#g')" + dn="" + fi + + unset _dep_tmp if [ -e "$playground/$_dep" ]; then # We've already seen this dep