Skip to contentSkip to conversation

Factor out the template generation for the .topmsg file

PATCH In review Bert Wesarg 2 participants 4 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Factor out the template generation for the .topmsg file

Provide a function for the .topmsg template file.

---
 tg-create.sh |   29 ++---------------------------
 tg.sh        |   30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 27 deletions(-)
tg-create.sh +2 -27
index d47959b..e30a014 100644
@@ -100,33 +100,8 @@ git checkout -b "$name"
 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
 git add "$root_dir/.topdeps"
 
-# Print each config value for a key ($1, without "topgit." prefix)
-# with the given prefix ($2)
-get_multi_config()
-{
-	# escape any / in prefix for sed
-	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
-
-	git config --get-all topgit.$1 2>/dev/null |
-		sed -e "s/^/$prefix /g"
-}
-
-author="$(git var GIT_AUTHOR_IDENT)"
-author_addr="${author%> *}>"
-{
-	echo "From: $author_addr"
-	get_multi_config to  "To:"
-	get_multi_config cc  "Cc:"
-	get_multi_config bcc "Bcc:"
-	! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
-	echo "Subject: [${subject_prefix}PATCH] $name"
-	echo
-	cat <<EOT
-<patch description>
-
-Signed-off-by: $author_addr
-EOT
-} >"$root_dir/.topmsg"
+echo "<patch description>" |
+	make_topmsg "$name" >"$root_dir/.topmsg"
 git add "$root_dir/.topmsg"
 
 
tg.sh +30 -0
index 03a392b..8384b79 100644
@@ -148,6 +148,36 @@ switch_to_base()
 	git symbolic-ref HEAD "$_base"
 }
 
+# Print each config value for a key ($1, without "topgit." prefix)
+# with the given prefix ($2)
+get_multi_config()
+{
+	# escape any / in prefix for sed
+	prefix="$(echo "$2" | sed -e 's/\//\\\\\//g')"
+
+	git config --get-all topgit.$1 2>/dev/null |
+		sed -e "s/^/$prefix /g"
+}
+
+# Make initial .topmsg template with content from stdin
+# optional first argument is subject line
+make_topmsg()
+{
+	author="$(git var GIT_AUTHOR_IDENT)"
+	author_addr="${author%> *}>"
+
+	echo "From: $author_addr"
+	get_multi_config to  "To:"
+	get_multi_config cc  "Cc:"
+	get_multi_config bcc "Bcc:"
+	! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix "
+	echo "Subject: [${subject_prefix}PATCH] $1"
+	echo
+	cat
+	echo
+	echo "Signed-off-by: $author_addr"
+}
+
 # Show the help messages.
 do_help()
 {
Signature · 1 line
tg: (2a28314..) t/make-.topmsg-gen-a-function (depends on: t/support-for-multiple-to-cc-bcc-options)
#1 lore raw

PATCH 2/2 tg-import.sh: A dump quilt queue importer

A simple, non smart, quilt importer.

---
 .gitignore   |    2 +
 Makefile     |    3 +-
 README       |   15 ++++++++
 tg-import.sh |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 134 insertions(+), 1 deletions(-)
.gitignore +2 -0
index 6f0727f..5f1831b 100644
@@ -3,6 +3,8 @@ tg-create
 tg-create.txt
 tg-delete
 tg-delete.txt
+tg-import
+tg-import.txt
 tg-info
 tg-info.txt
 tg-patch
Makefile +2 -1
index dba5f20..671beab 100644
@@ -6,7 +6,8 @@ sharedir = $(PREFIX)/share/topgit
 hooksdir = $(cmddir)/hooks
 
 
-commands_in = tg-create.sh tg-delete.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh
+commands_in = tg-create.sh tg-delete.sh tg-info.sh tg-patch.sh tg-summary.sh \
+              tg-update.sh tg-import.sh
 hooks_in = hooks/pre-commit.sh
 
 commands_out = $(patsubst %.sh,%,$(commands_in))
README +15 -0
index dc0045f..3fc6d18 100644
@@ -275,6 +275,21 @@ tg update
 
 	TODO: tg update -a for updating all topic branches
 
+tg import
+~~~~~~~~~
+	Import a quilt queue into TopGit. First argument is the series
+	file from quilt. Second is the prefix for the topic names
+	(i.e. "t/"). All remaining arguments are the dependencies for
+	the first patch in the series. Use '-s' if you want to strip
+	common patch suffixes from the patch file name (like .diff and
+	.patch).
+
+	TODO: be smart (merge conflicts, patch rejects, ...)
+	TODO: be interactive, let the user edit .topmsg for first commit
+	TODO: be resumable
+	TODO: use a dependency file, for creating non linear dependencies
+	      of the patches (maybe generated from quilt graph)
+
 TODO: Some infrastructure for sharing topic branches between
 	repositories easily
 TODO: tg depend for adding/removing dependencies smoothly
tg-import.sh new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
tg: (63c1934..) t/tg-import (depends on: t/auto-generate-command-list-for-tg.sh t/check-read-permissions-of-help-files t/mkdir-bindir t/make-.topmsg-gen-a-function t/its-info-attributes)
#2 lore raw

Re: [TopGit PATCH 2/2] tg-import.sh: A dump quilt queue importer

Quoted 43 lines · Bert Wesarg

A simple, non smart, quilt importer.

---
 .gitignore   |    2 +
 Makefile     |    3 +-
 README       |   15 ++++++++
 tg-import.sh |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 134 insertions(+), 1 deletions(-)
.gitignore +2 -0
index 6f0727f..5f1831b 100644
@@ -3,6 +3,8 @@ tg-create
 tg-create.txt
 tg-delete
 tg-delete.txt
+tg-import
+tg-import.txt
 tg-info
 tg-info.txt
 tg-patch
Makefile +2 -1
index dba5f20..671beab 100644
@@ -6,7 +6,8 @@ sharedir = $(PREFIX)/share/topgit
 hooksdir = $(cmddir)/hooks
 
 
-commands_in = tg-create.sh tg-delete.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh
+commands_in = tg-create.sh tg-delete.sh tg-info.sh tg-patch.sh tg-summary.sh \
+              tg-update.sh tg-import.sh
 hooks_in = hooks/pre-commit.sh
 
 commands_out = $(patsubst %.sh,%,$(commands_in))
README +0 -0
index dc0045f..3fc6d18 100644

README tg update · line 283

Quoted 9 lines
README +6 -0
@@ -275,6 +275,21 @@ tg update
 
 	TODO: tg update -a for updating all topic branches
 
+tg import
+~~~~~~~~~
+	Import a quilt queue into TopGit. First argument is the series
+	file from quilt. Second is the prefix for the topic names
+	(i.e. "t/"). All remaining arguments are the dependencies for
+	the first patch in the series.

Sensible usage, but I'm not happy with making tg import quilt-only; what if we will say want to import to topgit from existing branches, or from StGIT or something else? The command name is good, but maybe I'd add a required --quilt switch. After all, this is not a command you run three times a day by hand.

README tg update · line 285

Quoted 3 lines
README +3 -0
+ Use '-s' if you want to strip
+	common patch suffixes from the patch file name (like .diff and
+	.patch).

When *wouldn't* we want to do this? Doesn't it make sense to make this the default?

tg-import.sh

Quoted 5 lines
tg-import.sh new file +0 -0
new file mode 100644
index 0000000..f9403b9

I think the functionality is good to have, but you are also reinventing the wheel here. Git can already import quilt series by git-quiltimport. So what about a more general approach?

* Build tg-import so that it primarily just imports given set of existing commits.
* Then, StGIT and Quilt importers are trivial extensions?

tg-import.sh line 83

Quoted 6 lines
tg-import.sh new file +6 -0
+		# strip suffixes
+		name="$patch"
+		[ -n "$strip_suffixes" ] && {
+			name="${name%.patch}"
+			name="${name%.diff}"
+		}

I think in these cases, it's better style to use plain if.

Quoted 10 lines
tg-import.sh new file +10 -0
+		# apply patch
+		# be stupid, hard coded -p1
+		# currently no support for compressed patch files
+		patch -p1 -d "$root_dir" < "$patchfile"
+
+		# extract header from patch file and feed it into .topmsg
+		# TODO: extract mail headers
+		cat "$patchfile" |
+			patch_header |
+			strip_diffstat |

tg-import.sh line 108

Quoted 10 lines
tg-import.sh new file +10 -0
+			make_topmsg "$name" > "$root_dir/.topmsg"
+		# overwrite .topmsg from tg create in index
+		git add "$root_dir/.topmsg"
+
+		# add all modified files from patch to index
+		# (and prepending it with $root_dir)
+		# be stupid, hard coded -p1 --strip=1
+		lsdiff --strip=1 "$patchfile" |
+			sed -e "s/^/$root_dir_esc\//" |
+			xargs git add

lsdiff? I don't have this tool. And this won't work with file removals properly anyway.

I guess git add -u is too new for us, so you might opt for this snippet I've used in git-filter-branch:

	(
		git diff-index -r --name-only HEAD
		git ls-files --others
	) |
	git update-index --add --replace --remove --stdin

Or even better, use git apply?

Signature · 3 lines
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates
#3 lore raw

Re: [TopGit PATCH 2/2] tg-import.sh: A dump quilt queue importer

Quoted 8 lines · Petr Baudis

README tg update

Quoted 6 lines · Bert Wesarg
README +6 -0
+tg import
+~~~~~~~~~
+     Import a quilt queue into TopGit. First argument is the series
+     file from quilt. Second is the prefix for the topic names
+     (i.e. "t/"). All remaining arguments are the dependencies for
+     the first patch in the series.
Quoted 5 lines

Sensible usage, but I'm not happy with making tg import quilt-only; what if we will say want to import to topgit from existing branches, or from StGIT or something else? The command name is good, but maybe I'd add a required --quilt switch. After all, this is not a command you run three times a day by hand.

Your absolutly right, that import should not be quilt specific. It was just what I currently need, so I made it.

Quoted 7 lines

README tg update · line 285

Quoted 4 lines

+ Use '-s' if you want to strip

README +2 -0
+     common patch suffixes from the patch file name (like .diff and
+     .patch).

When *wouldn't* we want to do this? Doesn't it make sense to make this the default?

I suggest never ;-)

Quoted 9 lines

tg-import.sh line 108

Quoted 6 lines
tg-import.sh new file +6 -0
+             # add all modified files from patch to index
+             # (and prepending it with $root_dir)
+             # be stupid, hard coded -p1 --strip=1
+             lsdiff --strip=1 "$patchfile" |
+                     sed -e "s/^/$root_dir_esc\//" |
+                     xargs git add

lsdiff? I don't have this tool. And this won't work with file removals properly anyway.

lsdiff comes with the patchutils package.

Quoted 11 lines

I guess git add -u is too new for us, so you might opt for this snippet I've used in git-filter-branch:

       (
               git diff-index -r --name-only HEAD
               git ls-files --others
       ) |
       git update-index --add --replace --remove --stdin

Or even better, use git apply?

Ohh yeah, that sounds reasonable. Sometimes it an be so easy.

Thanks for the comments and input.

Bert

Quoted 3 lines

--
Petr "Pasky" Baudis