git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [TopGit PATCH] prev/next/tsort: commands to explore dependencies
@ 2008-09-19  9:55 Bert Wesarg
  2008-09-19  9:55 ` [TopGit PATCH] tg-patch: add From/Date: line to header and print to file Bert Wesarg
  2008-09-22 15:36 ` [TopGit PATCH] prev/next/tsort: commands to explore dependencies Petr Baudis
  0 siblings, 2 replies; 9+ messages in thread
From: Bert Wesarg @ 2008-09-19  9:55 UTC (permalink / raw)
  To: Petr Baudis, Petr Baudis; +Cc: Bert Wesarg, git

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(-)

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)

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [TopGit PATCH] tg-patch: add From/Date: line to header and print to file
  2008-09-19  9:55 [TopGit PATCH] prev/next/tsort: commands to explore dependencies Bert Wesarg
@ 2008-09-19  9:55 ` Bert Wesarg
  2008-09-22 15:39   ` Petr Baudis
  2008-09-22 15:36 ` [TopGit PATCH] prev/next/tsort: commands to explore dependencies Petr Baudis
  1 sibling, 1 reply; 9+ messages in thread
From: Bert Wesarg @ 2008-09-19  9:55 UTC (permalink / raw)
  To: Petr Baudis, Petr Baudis; +Cc: Bert Wesarg, git

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(-)

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)

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies
  2008-09-19  9:55 [TopGit PATCH] prev/next/tsort: commands to explore dependencies Bert Wesarg
  2008-09-19  9:55 ` [TopGit PATCH] tg-patch: add From/Date: line to header and print to file Bert Wesarg
@ 2008-09-22 15:36 ` Petr Baudis
  2008-09-22 17:32   ` Bert Wesarg
  1 sibling, 1 reply; 9+ messages in thread
From: Petr Baudis @ 2008-09-22 15:36 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: git

  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...

> 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).

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] tg-patch: add From/Date: line to header and print to file
  2008-09-19  9:55 ` [TopGit PATCH] tg-patch: add From/Date: line to header and print to file Bert Wesarg
@ 2008-09-22 15:39   ` Petr Baudis
  2008-09-22 18:10     ` Bert Wesarg
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Baudis @ 2008-09-22 15:39 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: git

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.

-- 
				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] 9+ messages in thread

* Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies
  2008-09-22 15:36 ` [TopGit PATCH] prev/next/tsort: commands to explore dependencies Petr Baudis
@ 2008-09-22 17:32   ` Bert Wesarg
  2008-09-22 20:10     ` Uwe Kleine-König
  2008-09-24 15:23     ` Petr Baudis
  0 siblings, 2 replies; 9+ messages in thread
From: Bert Wesarg @ 2008-09-22 17:32 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

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."

I thought that this would be needed.

Bert
>
> --
>                                Petr "Pasky" Baudis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] tg-patch: add From/Date: line to header and print to file
  2008-09-22 15:39   ` Petr Baudis
@ 2008-09-22 18:10     ` Bert Wesarg
  0 siblings, 0 replies; 9+ messages in thread
From: Bert Wesarg @ 2008-09-22 18:10 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

On Mon, Sep 22, 2008 at 17:39, Petr Baudis <pasky@suse.cz> wrote:
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies
  2008-09-22 17:32   ` Bert Wesarg
@ 2008-09-22 20:10     ` Uwe Kleine-König
  2008-09-22 20:18       ` Bert Wesarg
  2008-09-24 15:23     ` Petr Baudis
  1 sibling, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2008-09-22 20:10 UTC (permalink / raw)
  To: Bert Wesarg, g; +Cc: Petr Baudis, git

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?

Best regards
Uwe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies
  2008-09-22 20:10     ` Uwe Kleine-König
@ 2008-09-22 20:18       ` Bert Wesarg
  0 siblings, 0 replies; 9+ messages in thread
From: Bert Wesarg @ 2008-09-22 20:18 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: g, Petr Baudis, git

On Mon, Sep 22, 2008 at 22:10, Uwe Kleine-König <ukleinek@strlen.de> wrote:
> 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
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [TopGit PATCH] prev/next/tsort: commands to explore dependencies
  2008-09-22 17:32   ` Bert Wesarg
  2008-09-22 20:10     ` Uwe Kleine-König
@ 2008-09-24 15:23     ` Petr Baudis
  1 sibling, 0 replies; 9+ messages in thread
From: Petr Baudis @ 2008-09-24 15:23 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: git

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'.

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'?).

> >
> >> 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.

> >> +                                     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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-09-24 15:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-19  9:55 [TopGit PATCH] prev/next/tsort: commands to explore dependencies Bert Wesarg
2008-09-19  9:55 ` [TopGit PATCH] tg-patch: add From/Date: line to header and print to file Bert Wesarg
2008-09-22 15:39   ` Petr Baudis
2008-09-22 18:10     ` Bert Wesarg
2008-09-22 15:36 ` [TopGit PATCH] prev/next/tsort: commands to explore dependencies Petr Baudis
2008-09-22 17:32   ` Bert Wesarg
2008-09-22 20:10     ` Uwe Kleine-König
2008-09-22 20:18       ` Bert Wesarg
2008-09-24 15:23     ` 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).