git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[TopGit PATCH] --strip option for tg export

From
HHHeiko Hund <hhund@astaro.com>
Date
Nov 12, 2009, 10:15 UTC
Message-ID
<1258020908-31714-1-git-send-email-hhund@astaro.com>

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/<NN>/<NAME>" 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 <hhund@astaro.com>
---
 README       |    8 +++++---
 tg-export.sh |   47 +++++++++++++++++++++++++++++++++++++----------
 2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/README b/README
index 495c70b..44b60e1 100644
--- a/README
+++ b/README
@@ -429,9 +429,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 a16c290..a65c731 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/##')"
@@ -162,16 +178,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
-- 
tg: (f59e4f9..) strip_param_for_export (depends on: 0.8)
Message 1 of 1 in “--strip option for tg export”
  1. --strip option for tg exportHeiko Hund, Nov 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.