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

Subsystems: the rest

STALE3683d

9 messages, 3 authors, 2016-08-13 · open the first message on its own page

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

From: Bert Wesarg <hidden>
Date: 2016-08-13 23:23:35

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

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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:23

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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:23

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

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

From: Bert Wesarg <hidden>
Date: 2016-06-15 22:45:23

On Mon, Sep 22, 2008 at 17:36, Petr Baudis [off-list ref] wrote:
 Hi,

On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
quoted
I hacked 3 commands to explore the dependencies of TopGit patches:
 thanks, the idea of all three commands is good,
quoted
  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'.
quoted
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?
quoted
+                                     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

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

From: Bert Wesarg <hidden>
Date: 2016-06-15 22:45:23

On Mon, Sep 22, 2008 at 17:39, Petr Baudis [off-list ref] wrote:
On Fri, Sep 19, 2008 at 11:55:01AM +0200, Bert Wesarg wrote:
quoted
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 <redacted>
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

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

From: Uwe Kleine-König <hidden>
Date: 2016-06-15 22:45:23

On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
On Mon, Sep 22, 2008 at 17:36, Petr Baudis [off-list ref] wrote:
quoted
 Hi,

On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
quoted
I hacked 3 commands to explore the dependencies of TopGit patches:
 thanks, the idea of all three commands is good,
quoted
  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'.
quoted
quoted
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?
quoted
quoted
+                                     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

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

From: Bert Wesarg <hidden>
Date: 2016-06-15 22:45:23

On Mon, Sep 22, 2008 at 22:10, Uwe Kleine-König [off-list ref] wrote:
On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
quoted
On Mon, Sep 22, 2008 at 17:36, Petr Baudis [off-list ref] wrote:
quoted
 Hi,

On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
quoted
I hacked 3 commands to explore the dependencies of TopGit patches:
 thanks, the idea of all three commands is good,
quoted
  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'.
quoted
quoted
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?
quoted
quoted
+                                     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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:24

On Mon, Sep 22, 2008 at 07:32:50PM +0200, Bert Wesarg wrote:
On Mon, Sep 22, 2008 at 17:36, Petr Baudis [off-list ref] wrote:
quoted
 Hi,

On Fri, Sep 19, 2008 at 11:55:00AM +0200, Bert Wesarg wrote:
quoted
I hacked 3 commands to explore the dependencies of TopGit patches:
 thanks, the idea of all three commands is good,
quoted
  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'?).
quoted
quoted
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.
quoted
quoted
+                                     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.

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

From: Bert Wesarg <hidden>
Date: 2016-08-13 23:23:36

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

---
 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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help