threads / patch / 15622

patchRe: [TopGit PATCH] prev/next/tsort: commands to explore dependencies

Subject: Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies

## tl;dr

9 messages between Sep 19, 2008 and Sep 24, 2008. Diffs are folded; open one to read it.

replies: 8people: 3as markdown or json

Bert Wesarg· Sep 19, 2008, 09:55 UTC · lore

[TopGit PATCH] prev/next/tsort: commands to explore dependencies

I hacked 3 commands to explore the dependencies of TopGit patches:
  I) tg prev [NAME]
     outputs the dependencies of NAME
 II) tg next [NAME]
     outputs patches that depends on NAME
III) tg tsort [PATTERN]
     outputs a topological order of all patches starting with PATTERN
I'm more than open for improvments.
Regards
Bert
   
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 .gitignore  |    6 ++++++
 tg-next.sh  |   33 +++++++++++++++++++++++++++++++++
 tg-prev.sh  |   27 +++++++++++++++++++++++++++
 tg-tsort.sh |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 123 insertions(+), 0 deletions(-)
Show changes to 4 files +123 −0

.gitignore, tg-next.sh, tg-prev.sh, tg-tsort.sh

diff --git a/.gitignore b/.gitignore
index 8868f2d..b7fb70b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,9 @@ tg-import.txt
 tg-remote
 tg-remote.txt
 tg
+tg-next
+tg-next.txt
+tg-prev
+tg-prev.txt
+tg-tsort
+tg-tsort.txt
diff --git a/tg-next.sh b/tg-next.sh
new file mode 100644
index 0000000..8e17226
--- /dev/null
+++ b/tg-next.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# (c) Petr Baudis <pasky@suse.cz>  2008
+# GPLv2
+
+name=
+
+
+## Parse options
+
+while [ -n "$1" ]; do
+	arg="$1"; shift
+	case "$arg" in
+	-*)
+		echo "Usage: tg next [NAME]" >&2
+		exit 1;;
+	*)
+		[ -z "$name" ] || die "name already specified ($name)"
+		name="$arg";;
+	esac
+done
+
+[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
+base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+	die "not a TopGit-controlled branch"
+
+git for-each-ref --format='%(refname)' refs/top-bases |
+	while read topic; do
+		topic="${topic#refs/top-bases/}"
+		if git show "${topic}":.topdeps 2>/dev/null | grep -q "^${name}\$"; then
+			echo "${topic}"
+		fi
+	done
diff --git a/tg-prev.sh b/tg-prev.sh
new file mode 100644
index 0000000..801fb3e
--- /dev/null
+++ b/tg-prev.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# (c) Petr Baudis <pasky@suse.cz>  2008
+# GPLv2
+
+name=
+
+
+## Parse options
+
+while [ -n "$1" ]; do
+	arg="$1"; shift
+	case "$arg" in
+	-*)
+		echo "Usage: tg next [NAME]" >&2
+		exit 1;;
+	*)
+		[ -z "$name" ] || die "name already specified ($name)"
+		name="$arg";;
+	esac
+done
+
+[ -n "$name" ] || name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
+base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+	die "not a TopGit-controlled branch"
+
+git show "$name:.topdeps"
diff --git a/tg-tsort.sh b/tg-tsort.sh
new file mode 100644
index 0000000..8a7376a
--- /dev/null
+++ b/tg-tsort.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# (c) Petr Baudis <pasky@suse.cz>  2008
+# GPLv2
+
+pattern=
+
+## Parse options
+
+while [ -n "$1" ]; do
+	arg="$1"; shift
+	case "$arg" in
+	-*)
+		echo "Usage: tg tsort [PATTERN]" >&2
+		exit 1;;
+	*)
+		[ -z "$pattern" ] || die "pattern already specified ($pattern)"
+		pattern="$arg";;
+	esac
+done
+
+# remove trailing /, they wont work with for-each-ref
+pattern="$(echo "refs/top-bases/$pattern" | sed -re 's#/+$##g')"
+
+name="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
+base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
+	die "not a TopGit-controlled branch"
+
+rev_map="$(mktemp)"
+rev_map_uniq="$(mktemp)"
+rev_map_sed="$(mktemp)"
+tsort_out="$(mktemp)"
+trap 'rm -f "$rev_map" "$rev_map_uniq" "$rev_map_sed" "$tsort_out"' EXIT
+
+(
+	exec 3>"$rev_map"
+	cd "$git_dir"
+	git for-each-ref --format='%(refname)' $pattern |
+		while read topic; do
+			topic="${topic#refs/top-bases/}"
+			topic_rev="$(git rev-parse --verify "${topic}" 2>/dev/null)"
+			printf "%s\t%q\n" "${topic_rev}" "${topic}" >&3
+			git show "${topic}":.topdeps 2>/dev/null |
+				while read dep; do
+					dep_rev="$(git rev-parse --verify "${dep}" 2>/dev/null)"
+					printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
+					printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
+				done
+		done
+) | tsort | tac > "$tsort_out"
+
+LC_ALL=C sort "$rev_map" | uniq > "$rev_map_uniq"
+while read sha1 rev; do
+	printf "s#%s#%s#\n" "$sha1" "$rev"
+done < "$rev_map_uniq" > "$rev_map_sed"
+
+sed -f "$rev_map_sed" "$tsort_out"
-- 
tg: (370a0fd..) t/queue-movement (depends on: master)
Bert Wesarg· Sep 19, 2008, 09:55 UTC · re: Bert Wesarg · lore

[TopGit PATCH] tg-patch: add From/Date: line to header and print to file

To make this more similar to git format-patch, I added a 'From' and a 'Date:' header and let 'tg patch' print to a file (which is shown as output).

Regards Bert

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg-patch.sh |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)
Show changes to tg-patch.sh +24 −1
diff --git a/tg-patch.sh b/tg-patch.sh
index 7a24718..5fc5cfd 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -24,7 +24,26 @@ done
 base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)" ||
 	die "not a TopGit-controlled branch"
 
-git cat-file blob "$name:.topmsg"
+subject="$(git cat-file blob "$name:.topmsg" | grep '^Subject: ' | sed -e 's/^Subject: //' -e 's/\[.*\] //')"
+file_name="$(echo "$subject" | tr -c '[[:alnum:]_.]' '_').patch"
+rev="$(git rev-parse --verify "refs/heads/$name" 2>/dev/null)"
+
+echo "$file_name"
+exec 3>&1
+exec 1>"$file_name"
+
+printf "From %s Mon Sep 17 00:00:00 2001\n" "$rev"
+now="$(date --rfc-2822)"
+git cat-file blob "$name:.topmsg" |
+	awk '
+		{
+			print
+			if (/^From:/ && !date_printed) {
+				printf "Date: %s\n", "'"$now"'"
+				date_printed = 1
+			}
+		}
+	'
 echo
 [ -n "$(git grep '^[-]--' "$name" -- ".topmsg")" ] || echo '---'
 
@@ -42,5 +61,9 @@ rm "$git_is_stupid"
 
 echo '-- '
 echo "tg: ($base_rev..) $name (depends on: $(git cat-file blob "$name:.topdeps" | paste -s -d' '))"
+
+exec 1>&3
+exec 3>&-
+
 branch_contains "$name" "$base_rev" ||
 	echo "tg: The patch is out-of-date wrt. the base! Run \`$tg update\`."
-- 
tg: (7ec3927..) t/patch (depends on: t/queue-movement)
Petr Baudis· Sep 22, 2008, 15:39 UTC · re: Bert Wesarg · lore

Re: [TopGit PATCH] tg-patch: add From/Date: line to header and print to file

On Fri, Sep 19, 2008 at 11:55:01AM +0200, Bert Wesarg wrote:
Show 7 quoted lines
> To make this more similar to git format-patch, I added a 'From' and
> a 'Date:' header and let 'tg patch' print to a file (which is shown as output).
> 
> Regards
> Bert
> 
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>

I dislike the anyway completely bogus From line. If you want mbox format, you should call (hypothetical) tg mail. Also, IMHO Date: should be simply always printed at the end of the header, it's distracting if it is higher.

Also, the writing to file is confusing to me. What are you trying to achieve? If you want to export patches, why not use 'tg export' which already has this functionality? To me, 'tg patch' is basically equivalent of 'git show' for the whole branch.

-- 
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates
Bert Wesarg· Sep 22, 2008, 18:10 UTC · re: Petr Baudis · lore

Re: [TopGit PATCH] tg-patch: add From/Date: line to header and print to file

On Mon, Sep 22, 2008 at 17:39, Petr Baudis <pasky@suse.cz> wrote:
Show 18 quoted lines
> On Fri, Sep 19, 2008 at 11:55:01AM +0200, Bert Wesarg wrote:
>> To make this more similar to git format-patch, I added a 'From' and
>> a 'Date:' header and let 'tg patch' print to a file (which is shown as output).
>>
>> Regards
>> Bert
>>
>> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>
> I dislike the anyway completely bogus From line. If you want mbox
> format, you should call (hypothetical) tg mail. Also, IMHO Date: should
> be simply always printed at the end of the header, it's distracting if
> it is higher.
>
> Also, the writing to file is confusing to me. What are you trying to
> achieve? If you want to export patches, why not use 'tg export' which
> already has this functionality? To me, 'tg patch' is basically
> equivalent of 'git show' for the whole branch.

You're right. I'm not familiar what is needed as a header to be used with git send-email.

But the additional indirection with tg export/git format-patch is overkill for one patch.

Therefore I would leave the writing to file, but drop the additional headers for me.

Bert
>
> --
>                                Petr "Pasky" Baudis
Petr Baudis· Sep 22, 2008, 15:36 UTC · re: Bert Wesarg · lore
  Hi,
On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
> I hacked 3 commands to explore the dependencies of TopGit patches:
  thanks, the idea of all three commands is good,
Show 5 quoted lines
>   I) tg prev [NAME]
>      outputs the dependencies of NAME
> 
>  II) tg next [NAME]
>      outputs patches that depends on NAME
  but I think it would be cleaner to add this functionality to
tg info...
> III) tg tsort [PATTERN]
>      outputs a topological order of all patches starting with PATTERN
...and tg summary (overally, to have a tree view of branches).
Show 5 quoted lines
> diff --git a/tg-tsort.sh b/tg-tsort.sh
> new file mode 100644
> index 0000000..8a7376a
> --- /dev/null
> +++ b/tg-tsort.sh
..snip..
> +					printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
> +					printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
%q?
-- 
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates
Bert Wesarg· Sep 22, 2008, 17:32 UTC · re: Petr Baudis · lore
On Mon, Sep 22, 2008 at 17:36, Petr Baudis <pasky@suse.cz> wrote:
Show 15 quoted lines
>  Hi,
>
> On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
>> I hacked 3 commands to explore the dependencies of TopGit patches:
>
>  thanks, the idea of all three commands is good,
>
>>   I) tg prev [NAME]
>>      outputs the dependencies of NAME
>>
>>  II) tg next [NAME]
>>      outputs patches that depends on NAME
>
>  but I think it would be cleaner to add this functionality to
> tg info...
Right, but 'tg next' is shorter than any 'tg info --next'.
Show 5 quoted lines
>
>> III) tg tsort [PATTERN]
>>      outputs a topological order of all patches starting with PATTERN
>
> ...and tg summary (overally, to have a tree view of branches).
Maybe something like the graph output from git rev-log --graph?
>> +                                     printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
>> +                                     printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
>
> %q?

"and %q causes printf to output the corresponding argument in a format that can be reused as shell input."

I thought that this would be needed.
Bert
>
> --
>                                Petr "Pasky" Baudis
Uwe Kleine-König· Sep 22, 2008, 20:10 UTC · re: Bert Wesarg · lore
On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
Show 32 quoted lines
> On Mon, Sep 22, 2008 at 17:36, Petr Baudis <pasky@suse.cz> wrote:
> >  Hi,
> >
> > On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
> >> I hacked 3 commands to explore the dependencies of TopGit patches:
> >
> >  thanks, the idea of all three commands is good,
> >
> >>   I) tg prev [NAME]
> >>      outputs the dependencies of NAME
> >>
> >>  II) tg next [NAME]
> >>      outputs patches that depends on NAME
> >
> >  but I think it would be cleaner to add this functionality to
> > tg info...
> Right, but 'tg next' is shorter than any 'tg info --next'.
> 
> >
> >> III) tg tsort [PATTERN]
> >>      outputs a topological order of all patches starting with PATTERN
> >
> > ...and tg summary (overally, to have a tree view of branches).
> Maybe something like the graph output from git rev-log --graph?
> 
> >> +                                     printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
> >> +                                     printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
> >
> > %q?
> 
> "and %q causes printf to output the corresponding argument in  a
> format that can be reused as shell input."

With /bin/sh == dash this doesn't work. I havn't looked where and how this is used, but rev-parse has an --sq option that results in the output being shell quoted. Maybe this can help?

Best regards Uwe

Bert Wesarg· Sep 22, 2008, 20:18 UTC · re: Uwe Kleine-König · lore
On Mon, Sep 22, 2008 at 22:10, Uwe Kleine-König <ukleinek@strlen.de> wrote:
Show 36 quoted lines
> On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
>> On Mon, Sep 22, 2008 at 17:36, Petr Baudis <pasky@suse.cz> wrote:
>> >  Hi,
>> >
>> > On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
>> >> I hacked 3 commands to explore the dependencies of TopGit patches:
>> >
>> >  thanks, the idea of all three commands is good,
>> >
>> >>   I) tg prev [NAME]
>> >>      outputs the dependencies of NAME
>> >>
>> >>  II) tg next [NAME]
>> >>      outputs patches that depends on NAME
>> >
>> >  but I think it would be cleaner to add this functionality to
>> > tg info...
>> Right, but 'tg next' is shorter than any 'tg info --next'.
>>
>> >
>> >> III) tg tsort [PATTERN]
>> >>      outputs a topological order of all patches starting with PATTERN
>> >
>> > ...and tg summary (overally, to have a tree view of branches).
>> Maybe something like the graph output from git rev-log --graph?
>>
>> >> +                                     printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
>> >> +                                     printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
>> >
>> > %q?
>>
>> "and %q causes printf to output the corresponding argument in  a
>> format that can be reused as shell input."
> With /bin/sh == dash this doesn't work.  I havn't looked where and how
> this is used, but rev-parse has an --sq option that results in the
> output being shell quoted.  Maybe this can help?
I'm unsure if this quoting is actually needed.
I build a map from revision (sha1) to topic name:
  abc..\tt/topic

and use this file (after |sort|uniq) to build a sed script which replaces sha1 with the topic name in the output from tsort:

 s#abc...#t/topic#
Maybe the quoting is not needed.
Bert
>
> Best regards
> Uwe
>
Petr Baudis· Sep 24, 2008, 15:23 UTC · re: Bert Wesarg · lore
On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
Show 17 quoted lines
> On Mon, Sep 22, 2008 at 17:36, Petr Baudis <pasky@suse.cz> wrote:
> >  Hi,
> >
> > On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
> >> I hacked 3 commands to explore the dependencies of TopGit patches:
> >
> >  thanks, the idea of all three commands is good,
> >
> >>   I) tg prev [NAME]
> >>      outputs the dependencies of NAME
> >>
> >>  II) tg next [NAME]
> >>      outputs patches that depends on NAME
> >
> >  but I think it would be cleaner to add this functionality to
> > tg info...
> Right, but 'tg next' is shorter than any 'tg info --next'.

So, an alias? ;-) I wouldn't really like to clutter the UI with many trivial commands for getting various sort of info. And I mean, ideally you could just see all this in default 'tg info' output (or for computationally expensive operations, maybe 'tg info -l'?).

Show 6 quoted lines
> >
> >> III) tg tsort [PATTERN]
> >>      outputs a topological order of all patches starting with PATTERN
> >
> > ...and tg summary (overally, to have a tree view of branches).
> Maybe something like the graph output from git rev-log --graph?
That would be excellent.
Show 9 quoted lines
> >> +                                     printf "%s\t%q\n" "${dep_rev}" "${dep}" >&3
> >> +                                     printf "%s\t%s\n" "${topic_rev}" "${dep_rev}"
> >
> > %q?
> 
> "and %q causes printf to output the corresponding argument in  a
> format that can be reused as shell input."
> 
> I thought that this would be needed.

Interesting, I didn't find that in my documentation. But as said later, this quoting is probably unnecessary.

-- 
				Petr "Pasky" Baudis
People who take cold baths never have rheumatism,
but they have cold baths.

← back to recent threads