From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tim Henigan <tim.henigan@gmail.com>, git@vger.kernel.org
Subject: [PATCH] difftool: Do not remove temporary files on error
Date: Tue, 24 Jul 2012 23:14:36 -0700 [thread overview]
Message-ID: <1343196876-59195-1-git-send-email-davvid@gmail.com> (raw)
Keep the temporary directory around when either compare() or
the difftool returns a non-zero exit status.
Tell the user about the location of the temporary files so that
they can recover from the failure.
Signed-off-by: David Aguilar <davvid@gmail.com>
---
git-difftool.perl | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index 10d3d97..f4f7d4a 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -18,7 +18,7 @@ use File::Copy;
use File::Compare;
use File::Find;
use File::stat;
-use File::Path qw(mkpath);
+use File::Path qw(mkpath rmtree);
use File::Temp qw(tempdir);
use Getopt::Long qw(:config pass_through);
use Git;
@@ -119,7 +119,7 @@ sub setup_dir_diff
exit(0) if (length($diffrtn) == 0);
# Setup temp directories
- my $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 1, TMPDIR => 1);
+ my $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 0, TMPDIR => 1);
my $ldir = "$tmpdir/left";
my $rdir = "$tmpdir/right";
mkpath($ldir) or die $!;
@@ -257,7 +257,7 @@ sub setup_dir_diff
}
}
- return ($ldir, $rdir, @working_tree);
+ return ($ldir, $rdir, $tmpdir, @working_tree);
}
sub write_to_file
@@ -349,20 +349,23 @@ sub main
sub dir_diff
{
my ($extcmd, $symlinks) = @_;
-
my $rc;
+ my $error = 0;
my $repo = Git->repository();
-
my $workdir = find_worktree($repo);
- my ($a, $b, @worktree) = setup_dir_diff($repo, $workdir, $symlinks);
+ my ($a, $b, $tmpdir, @worktree) =
+ setup_dir_diff($repo, $workdir, $symlinks);
+
if (defined($extcmd)) {
$rc = system($extcmd, $a, $b);
} else {
$ENV{GIT_DIFFTOOL_DIRDIFF} = 'true';
$rc = system('git', 'difftool--helper', $a, $b);
}
-
- exit($rc | ($rc >> 8)) if ($rc != 0);
+ if ($rc != 0) {
+ dir_diff_tmpdir_warning($tmpdir);
+ exit($rc | ($rc >> 8));
+ }
# If the diff including working copy files and those
# files were modified during the diff, then the changes
@@ -377,16 +380,29 @@ sub dir_diff
if ($diff == 0) {
next;
} elsif ($diff == -1 ) {
- my $errmsg = "warning: could not compare ";
+ my $errmsg = "warning: Could not compare ";
$errmsg += "'$b/$file' with '$workdir/$file'\n";
warn $errmsg;
+ $error = 1;
} elsif ($diff == 1) {
copy("$b/$file", "$workdir/$file") or die $!;
my $mode = stat("$b/$file")->mode;
chmod($mode, "$workdir/$file") or die $!;
}
}
- exit(0);
+ if ($error) {
+ dir_diff_tmpdir_warning($tmpdir);
+ } else {
+ rmtree($tmpdir);
+ }
+ exit($error);
+}
+
+sub dir_diff_tmpdir_warning
+{
+ my ($tmpdir) = @_;
+ warn "warning: Temporary files exist in '$tmpdir'.\n";
+ warn "warning: You may want to cleanup or recover these.\n";
}
sub file_diff
--
1.7.11.9.g2b1cfc7.dirty
next reply other threads:[~2012-07-25 6:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 6:14 David Aguilar [this message]
2012-07-25 16:49 ` [PATCH] difftool: Do not remove temporary files on error Junio C Hamano
2012-07-25 18:28 ` David Aguilar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343196876-59195-1-git-send-email-davvid@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=tim.henigan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).