git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] difftool: Make directory diff symlink working tree

From
Matt McClure <matthewlmcclure@gmail.com>
Date
Mar 13, 2013, 15:21 UTC
Message-ID
<CAJELnLEbYrDWUjZH6iWnovEFDh8xFvpJL5wtEcPGOpkhPo+XEA@mail.gmail.com>
On Wed, Mar 13, 2013 at 4:24 AM, David Aguilar <davvid@gmail.com> wrote:
Show 8 quoted lines
> This is a nice straightforward approach.
>
> As Junio mentioned, a good next step would be this patch
> in combination with making the truly temporary files
> created by dir-diff readonly.
>
> Will that need a win32 platform check?
> Does anyone want to take this and whip it into a proper patch?
An attempt:
>From 429ae282ffd7202b6d2fb024a92dea543b8af376 Mon Sep 17 00:00:00 2001
From: Matt McClure <matthewlmcclure@gmail.com>
Date: Wed, 13 Mar 2013 11:14:22 -0400
Subject: [PATCH] difftool: Make directory diff symlink working tree
...primarily so that a user can edit working tree files in his difftool.

difftool -d formerly knew how to symlink to the working tree when the work tree contains uncommitted changes. In practice, prior to this change, it would not symlink to the working tree in case there were no uncommitted changes, even when the user invoked difftool with the form:

    git difftool -d [--options] <commit> [--] [<path>...]
        This form is to view the changes you have in your working tree
        relative to the named <commit>. You can use HEAD to compare it
        with the latest commit, or a branch name to compare with the tip
        of a different branch.

Instead, prior to this change, difftool would use the file's blob SHA1 to find its content in the index rather than use the working tree content. This change teaches `git difftool` to compare the blob SHA1 to the file's working tree blob SHA1 and use the working tree file if the SHA1s are the same.

Author: John Keeping <john@keeping.me.uk>
Conversation:
http://thread.gmane.org/gmane.comp.version-control.git/217979/focus=218014
---
 git-difftool.perl | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index 0a90de4..5f093ae 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -83,6 +83,21 @@ sub exit_cleanup
 	exit($status | ($status >> 8));
 }

+sub use_wt_file
+{
+	my ($repo, $workdir, $file, $sha1, $symlinks) = @_;
+	my $null_sha1 = '0' x 40;
+
+	if ($sha1 eq $null_sha1) {
+		return 1;
+	} elsif (not $symlinks) {
+		return 0;
+	}
+
+	my $wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
+	return $sha1 eq $wt_sha1;
+}
+
 sub setup_dir_diff
 {
 	my ($repo, $workdir, $symlinks) = @_;
@@ -159,10 +174,10 @@ EOF
 		}

 		if ($rmode ne $null_mode) {
-			if ($rsha1 ne $null_sha1) {
-				$rindex .= "$rmode $rsha1\t$dst_path\0";
-			} else {
+			if (use_wt_file($repo, $workdir, $dst_path, $rsha1, $symlinks)) {
 				push(@working_tree, $dst_path);
+			} else {
+				$rindex .= "$rmode $rsha1\t$dst_path\0";
 			}
 		}
 	}
-- 
1.8.1.5



-- 
Matt McClure
http://www.matthewlmcclure.com
http://www.mapmyfitness.com/profile/matthewlmcclure
Next: John Keeping
Message 1 of 2 in “difftool: Make directory diff symlink working tree”
  1. difftool: Make directory diff symlink working treeMatt McClure, Mar 13, 2013
  2. John KeepingMar 13, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.