# [PATCH 2/4] Fix cg-{diff,mkpatch} with HEAD^

6 messages from 2005-09-02 to 2005-09-13. Participants: Paolo 'Blaisorblade' Giarrusso, Petr Baudis, Blaisorblade.
Thread: https://gitlist.dev/t/1716

## Paolo 'Blaisorblade' Giarrusso, 2005-09-02 10:31

Subject: [PATCH 1/4] Fix txt installation
Message-ID: <20050902103125.24918.905.stgit@zion.home.lan>
URL: https://gitlist.dev/e/20050902103125.24918.905.stgit%40zion.home.lan

```
Avoid make removing the txt files. They are removed because there's no
explicit dependance on them, thus they are intermediate files and thus get
removed by make.

Also, while at this, avoid listing all those build-generated files in
cg-status (i.e. edit .gitignore).
---

 .gitignore             |    2 ++
 Documentation/Makefile |    7 +++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 cg-version
+Documentation/*.[17]
+Documentation/*.txt
diff --git a/Documentation/Makefile b/Documentation/Makefile
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -29,16 +29,19 @@ INSTALL=install
 # yourself - yes, all 6 characters of it!
 #
 
-all: html man
+all: html txt man
 
 html: $(DOC_HTML)
 
+txt: txt1 txt7
+txt1: $(MAN1_TXT)
+txt7: $(MAN7_TXT)
 
 man: man1 man7
 man1: $(DOC_MAN1)
 man7: $(DOC_MAN7)
 
-install: man
+install: man txt
 	$(INSTALL) -m755 -d $(DESTDIR)/$(txtdir)
 	$(INSTALL) $(MAN1_TXT) $(MAN7_TXT) $(DESTDIR)/$(txtdir)
 	$(INSTALL) -m755 -d $(DESTDIR)/$(man1) $(DESTDIR)/$(man7)

```

## Paolo 'Blaisorblade' Giarrusso, 2005-09-02 10:31

Subject: [PATCH 2/4] Fix cg-{diff,mkpatch} with HEAD^
Message-ID: <20050902103128.24918.77004.stgit@zion.home.lan>
URL: https://gitlist.dev/e/20050902103128.24918.77004.stgit%40zion.home.lan
In-Reply-To: <20050902103125.24918.905.stgit@zion.home.lan>

```
Supplying "HEAD^" to commit-id gives a failure; I saw this with the failure of:

$ cg-mkpatch -r HEAD^:HEAD

I wonder whether we should remove commit-id and switch to git-rev-parse
entirely, but in the meanwhile, fix it.

The problems are two ones:
*) there's an extra space at the end of the return string of cg-Xnormid.

Verify by running the command:
echo "\"$normid\""

*) the space remotion in commit-id can remove only one space, and forgets
that when calling git-cat-file -t.

Fixing either one is sufficient, but I've decided to fix both.

Also, when doing cg-diff -r HEAD^:HEAD, I've noticed that tree-id has the
same problems, and fixed it too.
I checked parent-id, and it's safe.

FIXME: I didn't add a testcase in the t/ directory.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 cg-Xnormid |    4 +++-
 commit-id  |   13 +++++++++++--
 tree-id    |   13 +++++++++++--
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/cg-Xnormid b/cg-Xnormid
--- a/cg-Xnormid
+++ b/cg-Xnormid
@@ -11,6 +11,8 @@
 # 	short SHA1 (4 or more hex digits)
 #
 # Takes the ID to normalize and returns the normalized ID.
+# Output format:
+# 40 hex digits ID, followed by _one_ space, followed by the optional ID type.
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
@@ -19,7 +21,7 @@ id="$1"
 if [ "${id:(-1):1}" = "^" ]; then
 	# parent-id
 	id=$(commit-id "${id%^}") || exit 1
-	git-cat-file commit "$id" | awk '/^parent/{print $2," "};/^$/{exit}' || exit 1
+	git-cat-file commit "$id" | awk '/^parent/{print $2 " "};/^$/{exit}' || exit 1
 	exit
 fi
 
diff --git a/commit-id b/commit-id
--- a/commit-id
+++ b/commit-id
@@ -9,8 +9,17 @@
 
 id="$1"
 normid=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1
-type=${normid#* }; [ "$type" ] || type=$(git-cat-file -t "$normid")
-normid=${normid% *}
+# Trim beginning space; leave end one because it means we must get the type
+# ourselves.
+normid=${normid# }
+type=${normid#* }
+#Trim type.
+type=${type# }
+type=${type% }
+# Trim end space (and everything after the space) when passing to
+# git-cat-file
+normid=${normid%% *}
+[ "$type" ] || type=$(git-cat-file -t "$normid")
 
 if [ "$type" != "commit" ]; then
 	echo "Invalid commit id: $normid" >&2
diff --git a/tree-id b/tree-id
--- a/tree-id
+++ b/tree-id
@@ -7,8 +7,17 @@
 
 id="$1"
 normid=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1
-type=${normid#* }; [ "$type" ] || type=$(git-cat-file -t "$normid")
-normid=${normid% *}
+# Trim beginning space; leave end one because it means we must get the type
+# ourselves.
+normid=${normid# }
+type=${normid#* }
+#Trim type.
+type=${type# }
+type=${type% }
+# Trim end space (and everything after the space) when passing to
+# git-cat-file
+normid=${normid%% *}
+[ "$type" ] || type=$(git-cat-file -t "$normid")
 
 if [ "$type" = "commit" ]; then
 	normid=$(git-cat-file commit "$normid" | sed -e 's/tree //;q')

```

## Paolo 'Blaisorblade' Giarrusso, 2005-09-02 10:31

Subject: [PATCH 3/4] commit-id micro cleanup
Message-ID: <20050902103133.24918.46625.stgit@zion.home.lan>
URL: https://gitlist.dev/e/20050902103133.24918.46625.stgit%40zion.home.lan
In-Reply-To: <20050902103125.24918.905.stgit@zion.home.lan>

```
Resync commit-id and tree-id: cg-Xlib is not needed in either.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 commit-id |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/commit-id b/commit-id
--- a/commit-id
+++ b/commit-id
@@ -5,8 +5,6 @@
 #
 # Takes the appropriate ID, defaults to HEAD.
 
-. ${COGITO_LIB}cg-Xlib
-
 id="$1"
 normid=$(. ${COGITO_LIB}cg-Xnormid "$id") || exit 1
 # Trim beginning space; leave end one because it means we must get the type

```

## Paolo 'Blaisorblade' Giarrusso, 2005-09-02 10:31

Subject: [PATCH 4/4] cg-{diff,mkpatch}: rename/copy optional detection
Message-ID: <20050902103135.24918.7990.stgit@zion.home.lan>
URL: https://gitlist.dev/e/20050902103135.24918.7990.stgit%40zion.home.lan
In-Reply-To: <20050902103125.24918.905.stgit@zion.home.lan>

```
Add -B, -M and -C options to detect content rewrites, renames and changes
to cg-diff and cg-mkpatch, to be passed right down to git-diff-*.
I've not added a way to pass down any option, since not everything may make
sense, and a shell script colorizing --name-only-z output would not play so
nice (and I mean "unreliable behaviour" - not tested obviously).

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 cg-diff    |   17 +++++++++++++++--
 cg-mkpatch |   15 ++++++++++++++-
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/cg-diff b/cg-diff
--- a/cg-diff
+++ b/cg-diff
@@ -28,6 +28,12 @@
 #	Base the diff at the merge base of the -r arguments (defaulting
 #	to HEAD and origin).
 #
+# -M::
+# -C::
+# -B::
+#	Passed down to git-diff-*, to mean respectively "detect renames",
+#	"detect copies", "detect file rewriting".
+#
 # ENVIRONMENT VARIABLES
 # ---------------------
 # PAGER::
@@ -92,6 +98,7 @@ id2=" "
 parent=
 opt_color=
 mergebase=
+gitflags=
 
 while optparse; do
 	if optparse -c; then
@@ -115,6 +122,12 @@ while optparse; do
 		fi
 	elif optparse -m; then
 		mergebase=1
+	elif optparse -M; then
+		gitflags="$gitflags -M"
+	elif optparse -C; then
+		gitflags="$gitflags -C"
+	elif optparse -B; then
+		gitflags="$gitflags -B"
 	else
 		optfail
 	fi
@@ -155,7 +168,7 @@ if [ "$id2" = " " ]; then
 	# FIXME: Update ret based on what did we match. And take "$@"
 	# to account after all.
 	ret=
-	cat $filter | xargs git-diff-cache -r -p $tree | colorize | pager
+	cat $filter | xargs git-diff-cache $gitflags -r -p $tree | colorize | pager
 
 	rm $filter
 
@@ -169,7 +182,7 @@ id2=$(tree-id "$id2") || exit 1
 
 [ "$id1" = "$id2" ] && die "trying to diff $id1 against itself"
 
-cat $filter | xargs git-diff-tree -r -p $id1 $id2 | colorize | pager
+cat $filter | xargs git-diff-tree $gitflags -r -p $id1 $id2 | colorize | pager
 
 rm $filter
 exit 0
diff --git a/cg-mkpatch b/cg-mkpatch
--- a/cg-mkpatch
+++ b/cg-mkpatch
@@ -22,6 +22,12 @@
 # -m::
 #	Base the patches at the merge base of the -r arguments
 #	(defaulting to HEAD and origin).
+
+# -M::
+# -C::
+# -B::
+#	Passed down to git-diff-*, to mean respectively "detect renames",
+#	"detect copies", "detect file rewriting".
 #
 # EXAMPLE USAGE
 # -------------
@@ -45,7 +51,7 @@ showpatch()
 	header=$(mktemp -t gitpatch.XXXXXX)
 	patch=$(mktemp -t gitpatch.XXXXXX)
 	id=$1
-	cg-diff -p -r $id >$patch
+	cg-diff $gitflags -p -r $id >$patch
 	git-cat-file commit $id | while read key rest; do
 		case "$key" in
 		"author"|"committer")
@@ -81,6 +87,7 @@ omit_header=
 log_start=
 log_end=
 mergebase=
+gitflags=
 
 while optparse; do
 	if optparse -s; then
@@ -101,6 +108,12 @@ while optparse; do
 		fi
 	elif optparse -m; then
 		mergebase=1
+	elif optparse -M; then
+		gitflags="$gitflags -M"
+	elif optparse -C; then
+		gitflags="$gitflags -C"
+	elif optparse -B; then
+		gitflags="$gitflags -B"
 	else
 		optfail
 	fi

```

## Petr Baudis, 2005-09-12 00:45

Subject: Re: [PATCH 4/4] cg-{diff,mkpatch}: rename/copy optional detection
Message-ID: <20050912004502.GH15630@pasky.or.cz>
URL: https://gitlist.dev/e/20050912004502.GH15630%40pasky.or.cz
In-Reply-To: <20050902103135.24918.7990.stgit@zion.home.lan>

```
Dear diary, on Fri, Sep 02, 2005 at 12:31:38PM CEST, I got a letter
where Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> told me that...
> Add -B, -M and -C options to detect content rewrites, renames and changes
> to cg-diff and cg-mkpatch, to be passed right down to git-diff-*.
> I've not added a way to pass down any option, since not everything may make
> sense, and a shell script colorizing --name-only-z output would not play so
> nice (and I mean "unreliable behaviour" - not tested obviously).

What about just by default doing full-blown detection, with an optional
flag to do no detection (to produce patch-compatible diffs)? I don't
think Cogito users usually need a more fine-tuned settings.

Obviously in that case we also have to fix cg-patch to process renames
and stuff - but we should do that anyway. :-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox

```

## Blaisorblade, 2005-09-13 17:41

Subject: Re: [PATCH 4/4] cg-{diff,mkpatch}: rename/copy optional detection
Message-ID: <200509131941.26001.blaisorblade@yahoo.it>
URL: https://gitlist.dev/e/200509131941.26001.blaisorblade%40yahoo.it
In-Reply-To: <20050912004502.GH15630@pasky.or.cz>

```
On Monday 12 September 2005 02:45, Petr Baudis wrote:
> Dear diary, on Fri, Sep 02, 2005 at 12:31:38PM CEST, I got a letter
> where Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> told me
> that...
>
> > Add -B, -M and -C options to detect content rewrites, renames and changes
> > to cg-diff and cg-mkpatch, to be passed right down to git-diff-*.
> > I've not added a way to pass down any option, since not everything may
> > make sense, and a shell script colorizing --name-only-z output would not
> > play so nice (and I mean "unreliable behaviour" - not tested obviously).
>
> What about just by default doing full-blown detection, with an optional
> flag to do no detection (to produce patch-compatible diffs)? I don't
> think Cogito users usually need a more fine-tuned settings.
No problem for me, as long git is fast enough in handling that (guess yes).
> Obviously in that case we also have to fix cg-patch to process renames
> and stuff - but we should do that anyway. :-)

-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade

	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it

```
