{"thread":{"id":"21590","subject":"[TopGit PATCH] --strip option for tg export","startedAt":"2009-11-12T10:15:08Z","lastAt":"2009-11-12T10:15:08Z","messageCount":1,"participants":["Heiko Hund"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"127436","messageId":"1258020908-31714-1-git-send-email-hhund@astaro.com","threadId":"21590","inReplyTo":null,"subject":"[TopGit PATCH] --strip option for tg export","fromName":"Heiko Hund","fromEmail":"hhund@astaro.com","sentAt":"2009-11-12T10:15:08Z","receivedAt":"2009-11-12T10:15:08Z","isPatch":true,"sender":{"key":"hhund@astaro.com","avatar":null},"body":"This introduces the '--strip[=N]' option for 'tg export --quilt' to enable\nexport of a flat quilt series, even if the tg branch names are structured\nhierarchically.\n\nIt may be useful if you - like me - structure your topgit branches like\n\"t/<NN>/<NAME>\" to keep the overview in git, but don't want the exported\nquilt series to be spread across subdirectories.\n\nIn contrast to '--flatten' this option removes the first 'N' or all\nsubdirectories from the topgit branch name, while keeping compatible with\nthe existing options. The remaining ones can still be flattened. Patch\nnames can still get numbered.\n\nSigned-off-by: Heiko Hund <hhund@astaro.com>\n\n---\n README       |    8 +++++---\n tg-export.sh |   47 +++++++++++++++++++++++++++++++++++++----------\n 2 files changed, 42 insertions(+), 13 deletions(-)\n\ndiff --git a/README b/README\nindex 495c70b..44b60e1 100644\n--- a/README\n+++ b/README\n@@ -429,9 +429,11 @@ tg export\n \tIn '--quilt' mode the patches are named like the originating topgit\n \tbranch.  So usually they end up in subdirectories of the output\n \tdirectory.  With option '--flatten' the names are mangled such that\n-\tthey end up directly in the output dir (i.e. slashed are substituted by\n-\tunderscores).  With '--numbered' (which implies '--flatten') the patch\n-\tnames get a number as prefix to allow getting the order without\n+\tthey end up directly in the output dir (i.e. slashes are substituted by\n+\tunderscores).  With option '--strip[=N]' the first 'N' subdirectories (all\n+\tif no 'N' is given) get stripped off.  Names are always '--strip'ped\n+\tbefore '--flatten'ed.  With option '--numbered' (which implies '--flatten')\n+\tthe patch names get a number as prefix to allow getting the order without\n \tconsulting the series file, which eases sending out the patches.\n \n \tUsage: tg export ([(--collapse | --linearize)] BRANCH | --quilt DIR)\ndiff --git a/tg-export.sh b/tg-export.sh\nindex a16c290..a65c731 100644\n--- a/tg-export.sh\n+++ b/tg-export.sh\n@@ -9,6 +9,8 @@ output=\n driver=collapse\n flatten=false\n numbered=false\n+strip=false\n+stripval=0\n \n \n ## Parse options\n@@ -23,6 +25,17 @@ while [ -n \"$1\" ]; do\n \t--numbered)\n \t\tflatten=true;\n \t\tnumbered=true;;\n+\t--strip*)\n+\t\tval=${arg#*=}\n+\t\tif [ \"$val\" = \"--strip\" ]; then\n+\t\t\tstrip=true\n+\t\t\tstripval=9999\n+\t\telif [ -n \"$val\" -a \"x$(echo $val | sed -e 's/[0-9]//g')\" = \"x\" ]; then\n+\t\t\tstrip=true\n+\t\t\tstripval=$val\n+\t\telse\n+\t\t\tdie \"invalid parameter $arg\"\n+\t\tfi;;\n \t--quilt)\n \t\tdriver=quilt;;\n \t--collapse)\n@@ -49,6 +62,9 @@ done\n [ \"$driver\" = \"quilt\" ] || ! \"$flatten\" ||\n \tdie \"--flatten works only with the quilt driver\"\n \n+[ \"$driver\" = \"quilt\" ] || ! \"$strip\" ||\n+\tdie \"--strip works only with the quilt driver\"\n+\n if [ -z \"$branches\" ]; then\n \t# this check is only needed when no branches have been passed\n \tname=\"$(git symbolic-ref HEAD | sed 's#^refs/heads/##')\"\n@@ -162,16 +178,27 @@ quilt()\n \t\treturn\n \tfi\n \n-\tif \"$flatten\"; then\n-\t\tbn=\"$(echo \"$_dep.diff\" | sed -e 's#_#__#g' -e 's#/#_#g')\";\n-\t\tdn=\"\";\n-\telse\n-\t\tbn=\"$(basename \"$_dep.diff\")\";\n-\t\tdn=\"$(dirname \"$_dep.diff\")/\";\n-\t\tif [ \"x$dn\" = \"x./\" ]; then\n-\t\t\tdn=\"\";\n-\t\tfi;\n-\tfi;\n+\t_dep_tmp=$_dep\n+\n+\tif \"$strip\"; then\n+\t\ti=$stripval\n+\t\twhile [ \"$i\" -gt 0 ]; do\n+\t\t\t[ \"$_dep_tmp\" = \"${_dep_tmp#*/}\" ] && break\n+\t\t\t_dep_tmp=${_dep_tmp#*/}\n+\t\t\ti=$((i - 1))\n+\t\tdone\n+\tfi\n+\n+\tbn=\"$(basename \"$_dep_tmp.diff\")\"\n+\tdn=\"$(dirname \"$_dep_tmp.diff\")/\"\n+\t[ \"x$dn\" = \"x./\" ] && dn=\"\"\n+\n+\tif \"$flatten\" && [ \"$dn\" ]; then\n+\t\tbn=\"$(echo \"$_dep_tmp.diff\" | sed -e 's#_#__#g' -e 's#/#_#g')\"\n+\t\tdn=\"\"\n+\tfi\n+\n+\tunset _dep_tmp\n \n \tif [ -e \"$playground/$_dep\" ]; then\n \t\t# We've already seen this dep\n-- \ntg: (f59e4f9..) strip_param_for_export (depends on: 0.8)\n"}]}