threads / discuss / 26043

how to create a diff in old file new file format (for code reviews)

Subject: how to create a diff in old file new file format (for code reviews)

## tl;dr

5 messages between Dec 14, 2010 and Dec 16, 2010.

replies: 4people: 2as markdown or json

aerosmith· Dec 14, 2010, 00:07 UTC · lore
Hi,

I am trying to create a diff such that the original file (entire file) is saved something like file1.h.old and the new modified file as file1.h.new. I have read the various options for git-diff* tools but could not find one such utility. All I get is the removals and additions as a diff. Does anyone know how to create one with the help the available git utils? The only method that I can think of is to do everything manually. Any help w.r.t. this is really appreciated. Thanks in advance.

-- 
View this message in context: http://git.661346.n2.nabble.com/how-to-create-a-diff-in-old-file-new-file-format-for-code-reviews-tp5832810p5832810.html
Sent from the git mailing list archive at Nabble.com.
Michael J Gruber· Dec 14, 2010, 09:17 UTC · re: aerosmith · lore

Re: how to create a diff in old file new file format (for code reviews)

aerosmith venit, vidit, dixit 14.12.2010 01:07:
Show 10 quoted lines
> 
> Hi,
> 
> I am trying to create a diff such that the original file (entire file) is
> saved something like file1.h.old and the new modified file as file1.h.new. I
> have read the various options for git-diff* tools but could not find one
> such utility. All I get is the removals and additions as a diff. Does anyone
> know how to create one with the help the available git utils? The only
> method that I can think of is to do everything manually. Any help w.r.t.
> this is really appreciated. Thanks in advance.

You could script around this e.g. with an external diff-helper. The easiest way is to reuse difftool. For example,

git difftool -y -x echo <revexpression>

will give you pairs of names of temporary files for old/new, where <revexpression> is what you would give to "git diff" to specify what to diff.

With the patch I'm sending in a minute, the helper you specify with "-x" can also access the basename easily, so that you could use "-x oldnew" with a script "oldnew" containing

#!/bin/sh cp "$1" "$BASE".old cp "$2" "$BASE".new

Even without the patch, you could use

git difftool -y -x 'cp "$LOCAL" "$BASE".old; cp "$REMOTE" "$BASE.new"; #' <revexpression>

(all on one line) directly. But this requires insider knowledge and may break some day.

Cheers, Michael

Michael J Gruber· Dec 14, 2010, 09:18 UTC · re: Michael J Gruber · lore

[PATCH 1/2] git-difftool.txt: correct the description of $BASE and describe $MERGED

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 Documentation/git-difftool.txt |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 6fffbc7..756d95d 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -56,8 +56,9 @@ the configured command line will be invoked with the following
 variables available: `$LOCAL` is set to the name of the temporary
 file containing the contents of the diff pre-image and `$REMOTE`
 is set to the name of the temporary file containing the contents
-of the diff post-image.  `$BASE` is provided for compatibility
-with custom merge tool commands and has the same value as `$LOCAL`.
+of the diff post-image.  `$MERGED` is the name of the file which is
+being compared. `$BASE` is provided for compatibility
+with custom merge tool commands and has the same value as `$MERGED`.
 
 -x <command>::
 --extcmd=<command>::
-- 
1.7.3.3.739.g52f77.dirty
Michael J Gruber· Dec 14, 2010, 09:18 UTC · re: Michael J Gruber · lore

[PATCH 2/2] difftool: provide basename to external tools

Currently, only configured diff helpers get the basename of the file being compared. Tools specified with "git difftool -x" only get the names of temporary files for the different versions.

Export BASE so that an external tool can read the name from the environment. Rather than using a third argument, this avoids breaking existing scripts which may somewhat carelessly be using "$@" rather than "$1" "$2".

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 Documentation/git-difftool.txt |    1 +
 git-difftool--helper.sh        |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 756d95d..db87f1d 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -65,6 +65,7 @@ with custom merge tool commands and has the same value as `$MERGED`.
 	Specify a custom command for viewing diffs.
 	'git-difftool' ignores the configured defaults and runs
 	`$command $LOCAL $REMOTE` when this option is specified.
+	Additionally, `$BASE` is set in the environment.
 
 -g::
 --gui::
diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh
index 524f5ea..0594bf7 100755
--- a/git-difftool--helper.sh
+++ b/git-difftool--helper.sh
@@ -49,6 +49,7 @@ launch_merge_tool () {
 	fi
 
 	if use_ext_cmd; then
+		export BASE
 		eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"'
 	else
 		run_merge_tool "$merge_tool"
-- 
1.7.3.3.739.g52f77.dirty
Seshu Parvataneni· Dec 16, 2010, 03:33 UTC · re: Michael J Gruber · lore

Re: [solved] how to create a diff in old file new file format (for code reviews)

Hi Michael,
Thanks very much for the reply. Your example with the difftool worked. This was what I was looking for.
--- On Tue, 12/14/10, Michael J Gruber <git@drmicha.warpmail.net> wrote:
Show 64 quoted lines
> From: Michael J Gruber <git@drmicha.warpmail.net>
> Subject: Re: how to create a diff in old file new file format (for code reviews)
> To: "aerosmith" <parvata@rocketmail.com>
> Cc: git@vger.kernel.org
> Date: Tuesday, December 14, 2010, 1:17 AM
> aerosmith venit, vidit, dixit
> 14.12.2010 01:07:
> > 
> > Hi,
> > 
> > I am trying to create a diff such that the original
> file (entire file) is
> > saved something like file1.h.old and the new modified
> file as file1.h.new. I
> > have read the various options for git-diff* tools but
> could not find one
> > such utility. All I get is the removals and additions
> as a diff. Does anyone
> > know how to create one with the help the available git
> utils? The only
> > method that I can think of is to do everything
> manually. Any help w.r.t.
> > this is really appreciated. Thanks in advance.
> 
> You could script around this e.g. with an external
> diff-helper. The
> easiest way is to reuse difftool. For example,
> 
> git difftool -y -x echo <revexpression>
> 
> will give you pairs of names of temporary files for
> old/new, where
> <revexpression> is what you would give to "git diff"
> to specify what to
> diff.
> 
> With the patch I'm sending in a minute, the helper you
> specify with "-x"
> can also access the basename easily, so that you could use
> "-x oldnew"
> with a script "oldnew" containing
> 
> #!/bin/sh
> cp "$1" "$BASE".old
> cp "$2" "$BASE".new
> 
> Even without the patch, you could use
> 
> git difftool -y -x 'cp "$LOCAL" "$BASE".old; cp "$REMOTE"
> "$BASE.new";
> #' <revexpression>
> 
> (all on one line) directly. But this requires insider
> knowledge and may
> break some day.
> 
> Cheers,
> Michael
> --
> To unsubscribe from this list: send the line "unsubscribe
> git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

← back to recent threads