* [PATCH] topgit: Implement tg-import
@ 2008-08-12 16:35 aneesh.kumar
2008-08-12 17:31 ` Petr Baudis
0 siblings, 1 reply; 3+ messages in thread
From: aneesh.kumar @ 2008-08-12 16:35 UTC (permalink / raw)
To: pasky; +Cc: git, Aneesh Kumar K.V
From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
This can be used to import a set of commits
between range specified by range1..range2
This should help us to convert an already
existing quilt, stgit branches to topgit
managed one
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
tg-import.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 tg-import.sh
diff --git a/tg-import.sh b/tg-import.sh
new file mode 100644
index 0000000..0158f3b
--- /dev/null
+++ b/tg-import.sh
@@ -0,0 +1,97 @@
+#!/bin/bash
+#derived out of git-format-patch.sh
+
+function die()
+{
+ echo >&2 "$@"
+ exit 1
+}
+
+function tg_get_commit_msg
+{
+ commit=$1
+commitScript='
+ 1,/^$/d
+ : loop
+ /^$/b loop
+ : body
+ p
+ n
+ b body'
+ author=$(git cat-file commit "$commit" | grep author |
+ cut -d ">" -f 1 | sed -ne "s/author//gp")
+ echo "From: "$author">"
+ git cat-file commit "$commit" | sed -ne "$commitScript"
+}
+
+function tg_get_patch
+{
+ git show $1
+}
+
+function tg_get_branch_name
+{
+
+titleScript='
+ 1,/^$/d
+ : loop
+ /^$/b loop
+ s/[^-a-z.A-Z_0-9]/-/g
+ s/\.\.\.*/\./g
+ s/\.*$//
+ s/--*/-/g
+ s/^-//
+ s/-$//
+ q
+'
+ commit=$1
+ title=$(git cat-file commit "$commit" | sed -e "$titleScript")
+ echo ${title}
+}
+
+tmp=.tmp-series$$
+trap 'rm -f $tmp-*' 0 1 2 3 15
+
+series=$tmp-series
+# Now we have what we want in $@
+for revpair
+do
+ case "$revpair" in
+ ?*..?*)
+ rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
+ rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
+ ;;
+ *)
+ echo >&2 "Unknow range spec $revpair"
+ exit
+ ;;
+ esac
+ git rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
+ die "Not a valid rev $rev1 ($revpair)"
+ git rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
+ die "Not a valid rev $rev2 ($revpair)"
+ git cherry -v "$rev1" "$rev2" |
+ while read sign rev comment
+ do
+ case "$sign" in
+ '-')
+ echo >&2 "Merged already: $comment"
+ ;;
+ *)
+ echo $rev
+ ;;
+ esac
+ done
+done >$series
+
+while read commit
+do
+ branch_name=$(tg_get_branch_name $commit)
+ echo "Importing $commit to $branch_name"
+ tg create tp/$branch_name
+ tg_get_commit_msg $commit > .topmsg
+ git add .topmsg
+ git commit -a -m "Add the commit message for the topic branch"
+ tg_get_patch $commit | patch -p1
+ git commit -a -m "Import the initial patch to the topic branch"
+done < $series
--
1.6.0.rc0.42.g186458.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] topgit: Implement tg-import
2008-08-12 16:35 aneesh.kumar
@ 2008-08-12 17:31 ` Petr Baudis
0 siblings, 0 replies; 3+ messages in thread
From: Petr Baudis @ 2008-08-12 17:31 UTC (permalink / raw)
To: aneesh.kumar; +Cc: git
Hi,
On Tue, Aug 12, 2008 at 10:05:43PM +0530, aneesh.kumar@gmail.com wrote:
> From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
>
> This can be used to import a set of commits
> between range specified by range1..range2
> This should help us to convert an already
> existing quilt, stgit branches to topgit
> managed one
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
thanks, unfortunately this script still needs work.
> ---
> tg-import.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 97 insertions(+), 0 deletions(-)
> create mode 100644 tg-import.sh
There seems to be no documentation.
> diff --git a/tg-import.sh b/tg-import.sh
> new file mode 100644
> index 0000000..0158f3b
> --- /dev/null
> +++ b/tg-import.sh
> @@ -0,0 +1,97 @@
> +#!/bin/bash
> +#derived out of git-format-patch.sh
I feel this is a wrong approach - it should be derived from some of
the tg scripts instead. Please use the common header and options
parsing infrastructure. Also, please adjust your script to be non-bash
specific.
> +function die()
> +{
> + echo >&2 "$@"
> + exit 1
> +}
We already have this function.
> +function tg_get_commit_msg
> +{
> + commit=$1
Please quote variables use; this also applies to the rest of the
script.
> +commitScript='
Indentation?
> + 1,/^$/d
> + : loop
> + /^$/b loop
> + : body
> + p
> + n
> + b body'
> + author=$(git cat-file commit "$commit" | grep author |
> + cut -d ">" -f 1 | sed -ne "s/author//gp")
> + echo "From: "$author">"
> + git cat-file commit "$commit" | sed -ne "$commitScript"
> +}
Wouldn't it be much more convenient to just use
git log -1 --pretty=format:"From: %an <%ae>%nSubject: %s%n%n%b"
> +function tg_get_patch
> +{
> + git show $1
> +}
> +
> +function tg_get_branch_name
> +{
> +
> +titleScript='
> + 1,/^$/d
> + : loop
> + /^$/b loop
> + s/[^-a-z.A-Z_0-9]/-/g
> + s/\.\.\.*/\./g
> + s/\.*$//
> + s/--*/-/g
> + s/^-//
> + s/-$//
> + q
> +'
You should document the origin of this snippet.
> + commit=$1
> + title=$(git cat-file commit "$commit" | sed -e "$titleScript")
> + echo ${title}
> +}
> +
> +tmp=.tmp-series$$
Please use mktemp.
Do you actually need the tmp file at all?
> +trap 'rm -f $tmp-*' 0 1 2 3 15
> +
> +series=$tmp-series
> +# Now we have what we want in $@
We didn't before?
> +for revpair
> +do
> + case "$revpair" in
> + ?*..?*)
> + rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
> + rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
> + ;;
> + *)
> + echo >&2 "Unknow range spec $revpair"
> + exit
die?
> + ;;
> + esac
> + git rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
> + die "Not a valid rev $rev1 ($revpair)"
> + git rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
> + die "Not a valid rev $rev2 ($revpair)"
> + git cherry -v "$rev1" "$rev2" |
> + while read sign rev comment
> + do
> + case "$sign" in
> + '-')
> + echo >&2 "Merged already: $comment"
info?
> + ;;
> + *)
> + echo $rev
Does it make sense to print it all out now?
> + ;;
> + esac
> + done
> +done >$series
Why do we need all the rev-parses? Is the git cherry checking really
useful?
This flattens the commit structure, which is another problem; the commit
relationships should rather be described in the .topdeps files. Using
git log --parents should give us that information?
> +while read commit
> +do
Why do you actually loop twice?
> + branch_name=$(tg_get_branch_name $commit)
> + echo "Importing $commit to $branch_name"
> + tg create tp/$branch_name
Make this configurable?
> + tg_get_commit_msg $commit > .topmsg
> + git add .topmsg
> + git commit -a -m "Add the commit message for the topic branch"
> + tg_get_patch $commit | patch -p1
Also, I don't think reimplementing git rebase here is good idea at all.
I would just imagine the script to do something like
git rev-list ^HEAD lastcommit | while read commit; do
tg create tp/$branch_name
git read-tree $commit
git add .top*
git commit -C $commit
done
So allow only to import commits that are _on top_ of the same commit the
topic branches system is going to be based on.
> + git commit -a -m "Import the initial patch to the topic branch"
Why two commits?
> +done < $series
--
Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC. -- Bill Gates
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] topgit: Implement tg-import
@ 2008-08-13 15:15 Aneesh Kumar K.V
0 siblings, 0 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2008-08-13 15:15 UTC (permalink / raw)
To: pasky; +Cc: git, Aneesh Kumar K.V
From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
This can be used to import a set of commits
between range specified by range1..range2
This should help us to convert an already
existing quilt, stgit branches to topgit
managed one
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
Makefile | 2 +-
README | 7 ++++++
tg-import.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 1 deletions(-)
create mode 100644 tg-import.sh
diff --git a/Makefile b/Makefile
index 6eade1e..95624ac 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ sharedir = $(PREFIX)/share/topgit
hooksdir = $(cmddir)/hooks
-commands_in = tg-create.sh tg-delete.sh tg-export.sh tg-info.sh tg-patch.sh tg-summary.sh tg-update.sh
+commands_in = tg-create.sh tg-delete.sh tg-export.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))
diff --git a/README b/README
index b58a1b4..8b8f4d7 100644
--- a/README
+++ b/README
@@ -330,6 +330,13 @@ tg export
TODO: Make stripping of [PATCH] and other prefixes configurable
TODO: --mbox option for other mode of operation
+tg import
+~~~~~~~~
+ Import the commits between the given revision range into
+ a topgit managed branch
+
+ Usage: tg import rev1..rev2
+
tg update
~~~~~~~~~
Update the current topic branch wrt. changes in the branches
diff --git a/tg-import.sh b/tg-import.sh
new file mode 100644
index 0000000..6c991c5
--- /dev/null
+++ b/tg-import.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# GPLv2
+
+
+tg_get_commit_msg()
+{
+ commit="$1"
+ git log -1 --pretty=format:"From: %an <%ae>%n%n%s%n%n%b" "$commit"
+}
+
+tg_get_branch_name()
+{
+ # nice sed script from git-format-patch.sh
+ commit="$1"
+ titleScript='
+ s/[^-a-z.A-Z_0-9]/-/g
+ s/\.\.\.*/\./g
+ s/\.*$//
+ s/--*/-/g
+ s/^-//
+ s/-$//
+ q
+'
+ git log -1 --pretty=format:"%s" "$commit" | sed -e "$titleScript"
+}
+
+tg_process_commit()
+{
+ commit="$1"
+ branch_name=$(tg_get_branch_name "$commit")
+ echo "Importing $commit to $branch_name"
+ tg create tp/"$branch_name"
+ git read-tree "$commit"
+ tg_get_commit_msg "$commit" > .topmsg
+ git add -f .topmsg .topdeps
+ git commit -C "$commit"
+}
+
+# nice arg verification stolen from git-format-patch.sh
+for revpair
+do
+ case "$revpair" in
+ ?*..?*)
+ rev1=`expr "z$revpair" : 'z\(.*\)\.\.'`
+ rev2=`expr "z$revpair" : 'z.*\.\.\(.*\)'`
+ ;;
+ *)
+ die "Unknow range spec $revpair"
+ ;;
+ esac
+ git rev-parse --verify "$rev1^0" >/dev/null 2>&1 ||
+ die "Not a valid rev $rev1 ($revpair)"
+ git rev-parse --verify "$rev2^0" >/dev/null 2>&1 ||
+ die "Not a valid rev $rev2 ($revpair)"
+ git cherry -v "$rev1" "$rev2" |
+ while read sign rev comment
+ do
+ case "$sign" in
+ '-')
+ info "Merged already: $comment"
+ ;;
+ *)
+ tg_process_commit "$rev"
+ ;;
+ esac
+ done
+done
--
1.6.0.rc0.42.g186458.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-08-13 15:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-13 15:15 [PATCH] topgit: Implement tg-import Aneesh Kumar K.V
-- strict thread matches above, loose matches on Subject: below --
2008-08-12 16:35 aneesh.kumar
2008-08-12 17:31 ` Petr Baudis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).