threads / discuss / 38444

[GUILT 0/2] Teach "guilt graph" to ignore some files.

Subject: [GUILT 0/2] Teach "guilt graph" to ignore some files.

## tl;dr

5 messages between Jan 23, 2015 and Jan 23, 2015.

replies: 4people: 2as markdown or json

Per Cederqvist· Jan 23, 2015, 14:21 UTC · lore

If you use a ChangeLog, all output from "guilt graph" will be a boring line of commits. By using "guilt graph -x ChangeLog" things will look more interesting.

Also: simplify getfiles.

(This work is also available on the guilt-graph-ignore-2015-v1 branch of the git://repo.or.cz/guilt/ceder.git repository. (That branch is based on the doc-dash-2015-v1 branch that contains my documentation fixes, so if you just want these two commits you will have to cherry-pick.))

    /ceder
Per Cederqvist (2):
  guilt graph: Simplify getfiles.
  Teach "guilt graph" the "-x exclude-pattern" option.
 Documentation/guilt-graph.txt |  5 +++++
 guilt-graph                   | 26 +++++++++++++++++++-------
 regression/t-033.out          | 12 ++++++++++++
 regression/t-033.sh           |  3 +++
 4 files changed, 39 insertions(+), 7 deletions(-)
-- 
2.1.0
Per Cederqvist· Jan 23, 2015, 14:21 UTC · re: Per Cederqvist · lore

[GUILT 1/2] guilt graph: Simplify getfiles.

git diff-tree by default emits TAB-separated fields. cut by defaults processes TAB-separated fields. Simplify getfiles() by using TAB as the separator.

Signed-off-by: Per Cederqvist <cederp@opera.com>
---
 guilt-graph | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/guilt-graph b/guilt-graph
index 0857e0d..d90c2f1 100755
--- a/guilt-graph
+++ b/guilt-graph
@@ -36,7 +36,7 @@ fi
 
 getfiles()
 {
-	git diff-tree -r "$1^" "$1" | tr '\t' ' ' | cut -d' ' -f6
+	git diff-tree -r "$1^" "$1" | cut -f2
 }
 
 cache="$GUILT_DIR/$branch/.graphcache.$$"
-- 
2.1.0
Jeff Sipek· Jan 23, 2015, 14:36 UTC · re: Per Cederqvist · lore

Re: [GUILT 1/2] guilt graph: Simplify getfiles.

Neat.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
On Fri, Jan 23, 2015 at 03:21:06PM +0100, Per Cederqvist wrote:
Show 25 quoted lines
> git diff-tree by default emits TAB-separated fields.  cut by defaults
> processes TAB-separated fields.  Simplify getfiles() by using TAB as
> the separator.
> 
> Signed-off-by: Per Cederqvist <cederp@opera.com>
> ---
>  guilt-graph | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/guilt-graph b/guilt-graph
> index 0857e0d..d90c2f1 100755
> --- a/guilt-graph
> +++ b/guilt-graph
> @@ -36,7 +36,7 @@ fi
>  
>  getfiles()
>  {
> -	git diff-tree -r "$1^" "$1" | tr '\t' ' ' | cut -d' ' -f6
> +	git diff-tree -r "$1^" "$1" | cut -f2
>  }
>  
>  cache="$GUILT_DIR/$branch/.graphcache.$$"
> -- 
> 2.1.0
> 
-- 
C is quirky, flawed, and an enormous success.
		- Dennis M. Ritchie.
Per Cederqvist· Jan 23, 2015, 14:21 UTC · re: Per Cederqvist · lore

[GUILT 2/2] Teach "guilt graph" the "-x exclude-pattern" option.

Some projects keep a ChangeLog which every commit modifies. This makes the graph a very uninteresting single line of commits. It is sometimes useful to see how the graph would look if we ignore the ChangeLog file.

The new -x option is useful in situations like this. It can be repeated several times to ignore many files. Each argument is saved to a temporary file and "grep -v -f $TEMPORARY" is used to filter out the file names you want to ignore.

Also added a minimal test case and documentation.
Signed-off-by: Per Cederqvist <cederp@opera.com>
---
 Documentation/guilt-graph.txt |  5 +++++
 guilt-graph                   | 24 ++++++++++++++++++------
 regression/t-033.out          | 12 ++++++++++++
 regression/t-033.sh           |  3 +++
 4 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/Documentation/guilt-graph.txt b/Documentation/guilt-graph.txt
index f43206e..eeed321 100644
--- a/Documentation/guilt-graph.txt
+++ b/Documentation/guilt-graph.txt
@@ -16,6 +16,11 @@ patches.
 
 OPTIONS
 -------
+-x <pattern>::
+	Ignore files that matches the given grep pattern. Can be
+	repeated to ignore several files. This can be useful to ignore
+	for instance ChangeLog files that every commit modifies.
+
 <patchname>::
 	Instead of starting with the topmost applied patch, start with
 	<patchname>.
diff --git a/guilt-graph b/guilt-graph
index d90c2f1..4d5fe46 100755
--- a/guilt-graph
+++ b/guilt-graph
@@ -3,7 +3,7 @@
 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
 #
 
-USAGE="[<patchname>]"
+USAGE="[-x exclude-pattern]... [<patchname>]"
 if [ -z "$GUILT_VERSION" ]; then
 	echo "Invoking `basename "$0"` directly is no longer supported." >&2
 	exit 1
@@ -11,6 +11,22 @@ fi
 
 _main() {
 
+cache="$GUILT_DIR/$branch/.graphcache.$$"
+xclude="$GUILT_DIR/$branch/.graphexclude.$$"
+trap "rm -rf \"$cache\" \"$xclude\"" 0
+mkdir "$cache"
+>"$xclude"
+
+while [ $# -gt 0 ]; do
+    if [ "$1" = "-x" ] && [ $# -ge 2 ]; then
+	echo "$2" >> "$xclude"
+	shift
+	shift
+    else
+	break
+    fi
+done
+
 if [ $# -gt 1 ]; then
 	usage
 fi
@@ -39,10 +55,6 @@ getfiles()
 	git diff-tree -r "$1^" "$1" | cut -f2
 }
 
-cache="$GUILT_DIR/$branch/.graphcache.$$"
-mkdir "$cache"
-trap "rm -rf \"$cache\"" 0
-
 disp "digraph G {"
 
 current="$top"
@@ -66,7 +78,7 @@ while [ "$current" != "$base" ]; do
 	rm -f "$cache/dep"
 	touch "$cache/dep"
 
-	getfiles $current | while read f; do
+	getfiles $current | grep -v -f "$xclude" | while read f; do
 		# hash the filename
 		fh=`echo "$f" | sha1 | cut -d' ' -f1`
 		if [ -e "$cache/$fh" ]; then
diff --git a/regression/t-033.out b/regression/t-033.out
index c120d4f..1ed371f 100644
--- a/regression/t-033.out
+++ b/regression/t-033.out
@@ -88,3 +88,15 @@ digraph G {
 	"ff2775f8d1dc753f635830adcc3a067e0b681e2d" [label="a.patch"]
 	"891bc14b5603474c9743fd04f3da888644413dc5" -> "ff2775f8d1dc753f635830adcc3a067e0b681e2d"; // ?
 }
+%% The same graph, but excluding deps introduced by file.txt.
+% guilt graph -x file.txt
+digraph G {
+# checking rev bc7df666a646739eaf559af23cab72f2bfd01f0e
+	"bc7df666a646739eaf559af23cab72f2bfd01f0e" [label="a-\"better&quicker'-patch.patch"]
+# checking rev 891bc14b5603474c9743fd04f3da888644413dc5
+	"891bc14b5603474c9743fd04f3da888644413dc5" [label="c.patch"]
+# checking rev c7014443c33d2b0237293687ceb9cbd38313df65
+	"c7014443c33d2b0237293687ceb9cbd38313df65" [label="b.patch"]
+# checking rev ff2775f8d1dc753f635830adcc3a067e0b681e2d
+	"ff2775f8d1dc753f635830adcc3a067e0b681e2d" [label="a.patch"]
+}
diff --git a/regression/t-033.sh b/regression/t-033.sh
index 9fe1827..ae22914 100755
--- a/regression/t-033.sh
+++ b/regression/t-033.sh
@@ -59,3 +59,6 @@ cmd git add file.txt
 cmd guilt refresh
 fixup_time_info "a-\"better&quicker'-patch.patch"
 cmd guilt graph
+
+echo "%% The same graph, but excluding deps introduced by file.txt."
+cmd guilt graph -x file.txt
-- 
2.1.0
Jeff Sipek· Jan 23, 2015, 14:49 UTC · re: Per Cederqvist · lore

Re: [GUILT 2/2] Teach "guilt graph" the "-x exclude-pattern" option.

On Fri, Jan 23, 2015 at 03:21:07PM +0100, Per Cederqvist wrote:
Show 9 quoted lines
> Some projects keep a ChangeLog which every commit modifies.  This
> makes the graph a very uninteresting single line of commits.  It is
> sometimes useful to see how the graph would look if we ignore the
> ChangeLog file.
> 
> The new -x option is useful in situations like this.  It can be
> repeated several times to ignore many files.  Each argument is saved
> to a temporary file and "grep -v -f $TEMPORARY" is used to filter out
> the file names you want to ignore.
Cool idea.
Show 57 quoted lines
> Also added a minimal test case and documentation.
> 
> Signed-off-by: Per Cederqvist <cederp@opera.com>
> ---
>  Documentation/guilt-graph.txt |  5 +++++
>  guilt-graph                   | 24 ++++++++++++++++++------
>  regression/t-033.out          | 12 ++++++++++++
>  regression/t-033.sh           |  3 +++
>  4 files changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/guilt-graph.txt b/Documentation/guilt-graph.txt
> index f43206e..eeed321 100644
> --- a/Documentation/guilt-graph.txt
> +++ b/Documentation/guilt-graph.txt
> @@ -16,6 +16,11 @@ patches.
>  
>  OPTIONS
>  -------
> +-x <pattern>::
> +	Ignore files that matches the given grep pattern. Can be
> +	repeated to ignore several files. This can be useful to ignore
> +	for instance ChangeLog files that every commit modifies.
> +
>  <patchname>::
>  	Instead of starting with the topmost applied patch, start with
>  	<patchname>.
> diff --git a/guilt-graph b/guilt-graph
> index d90c2f1..4d5fe46 100755
> --- a/guilt-graph
> +++ b/guilt-graph
> @@ -3,7 +3,7 @@
>  # Copyright (c) Josef "Jeff" Sipek, 2007-2013
>  #
>  
> -USAGE="[<patchname>]"
> +USAGE="[-x exclude-pattern]... [<patchname>]"
>  if [ -z "$GUILT_VERSION" ]; then
>  	echo "Invoking `basename "$0"` directly is no longer supported." >&2
>  	exit 1
> @@ -11,6 +11,22 @@ fi
>  
>  _main() {
>  
> +cache="$GUILT_DIR/$branch/.graphcache.$$"
> +xclude="$GUILT_DIR/$branch/.graphexclude.$$"
> +trap "rm -rf \"$cache\" \"$xclude\"" 0
> +mkdir "$cache"
> +>"$xclude"
> +
> +while [ $# -gt 0 ]; do
> +    if [ "$1" = "-x" ] && [ $# -ge 2 ]; then
> +	echo "$2" >> "$xclude"
> +	shift
> +	shift
> +    else
> +	break
> +    fi
Spaces used for indentation.  Otherwise looks good.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Show 59 quoted lines
> +done
> +
>  if [ $# -gt 1 ]; then
>  	usage
>  fi
> @@ -39,10 +55,6 @@ getfiles()
>  	git diff-tree -r "$1^" "$1" | cut -f2
>  }
>  
> -cache="$GUILT_DIR/$branch/.graphcache.$$"
> -mkdir "$cache"
> -trap "rm -rf \"$cache\"" 0
> -
>  disp "digraph G {"
>  
>  current="$top"
> @@ -66,7 +78,7 @@ while [ "$current" != "$base" ]; do
>  	rm -f "$cache/dep"
>  	touch "$cache/dep"
>  
> -	getfiles $current | while read f; do
> +	getfiles $current | grep -v -f "$xclude" | while read f; do
>  		# hash the filename
>  		fh=`echo "$f" | sha1 | cut -d' ' -f1`
>  		if [ -e "$cache/$fh" ]; then
> diff --git a/regression/t-033.out b/regression/t-033.out
> index c120d4f..1ed371f 100644
> --- a/regression/t-033.out
> +++ b/regression/t-033.out
> @@ -88,3 +88,15 @@ digraph G {
>  	"ff2775f8d1dc753f635830adcc3a067e0b681e2d" [label="a.patch"]
>  	"891bc14b5603474c9743fd04f3da888644413dc5" -> "ff2775f8d1dc753f635830adcc3a067e0b681e2d"; // ?
>  }
> +%% The same graph, but excluding deps introduced by file.txt.
> +% guilt graph -x file.txt
> +digraph G {
> +# checking rev bc7df666a646739eaf559af23cab72f2bfd01f0e
> +	"bc7df666a646739eaf559af23cab72f2bfd01f0e" [label="a-\"better&quicker'-patch.patch"]
> +# checking rev 891bc14b5603474c9743fd04f3da888644413dc5
> +	"891bc14b5603474c9743fd04f3da888644413dc5" [label="c.patch"]
> +# checking rev c7014443c33d2b0237293687ceb9cbd38313df65
> +	"c7014443c33d2b0237293687ceb9cbd38313df65" [label="b.patch"]
> +# checking rev ff2775f8d1dc753f635830adcc3a067e0b681e2d
> +	"ff2775f8d1dc753f635830adcc3a067e0b681e2d" [label="a.patch"]
> +}
> diff --git a/regression/t-033.sh b/regression/t-033.sh
> index 9fe1827..ae22914 100755
> --- a/regression/t-033.sh
> +++ b/regression/t-033.sh
> @@ -59,3 +59,6 @@ cmd git add file.txt
>  cmd guilt refresh
>  fixup_time_info "a-\"better&quicker'-patch.patch"
>  cmd guilt graph
> +
> +echo "%% The same graph, but excluding deps introduced by file.txt."
> +cmd guilt graph -x file.txt
> -- 
> 2.1.0
> 
-- 
Computer Science is no more about computers than astronomy is about
telescopes.
		- Edsger Dijkstra

← back to recent threads