@@ -37,14 +37,6 @@ sub usage
37
37
exit ($exitcode );
38
38
}
39
39
40
- sub find_worktree
41
- {
42
- # Git->repository->wc_path() does not honor changes to the working
43
- # tree location made by $ENV{GIT_WORK_TREE} or the 'core.worktree'
44
- # config variable.
45
- return Git::command_oneline(' rev-parse' , ' --show-toplevel' );
46
- }
47
-
48
40
sub print_tool_help
49
41
{
50
42
# See the comment at the bottom of file_diff() for the reason behind
@@ -67,14 +59,14 @@ sub exit_cleanup
67
59
68
60
sub use_wt_file
69
61
{
70
- my ($repo , $ workdir , $file , $sha1 ) = @_ ;
62
+ my ($workdir , $file , $sha1 ) = @_ ;
71
63
my $null_sha1 = ' 0' x 40 ;
72
64
73
65
if (-l " $workdir /$file " || ! -e _) {
74
66
return (0, $null_sha1 );
75
67
}
76
68
77
- my $wt_sha1 = $repo -> command_oneline(' hash-object' , " $workdir /$file " );
69
+ my $wt_sha1 = Git:: command_oneline(' hash-object' , " $workdir /$file " );
78
70
my $use = ($sha1 eq $null_sha1 ) || ($sha1 eq $wt_sha1 );
79
71
return ($use , $wt_sha1 );
80
72
}
@@ -83,20 +75,17 @@ sub changed_files
83
75
{
84
76
my ($repo_path , $index , $worktree ) = @_ ;
85
77
$ENV {GIT_INDEX_FILE } = $index ;
86
- $ENV {GIT_WORK_TREE } = $worktree ;
87
- my $must_unset_git_dir = 0;
88
- if (not defined ($ENV {GIT_DIR })) {
89
- $must_unset_git_dir = 1;
90
- $ENV {GIT_DIR } = $repo_path ;
91
- }
92
78
93
- my @refreshargs = qw/ update-index --really-refresh -q --unmerged/ ;
94
- my @gitargs = qw/ diff-files --name-only -z/ ;
79
+ my @gitargs = (' --git-dir' , $repo_path , ' --work-tree' , $worktree );
80
+ my @refreshargs = (
81
+ @gitargs , ' update-index' ,
82
+ ' --really-refresh' , ' -q' , ' --unmerged' );
95
83
try {
96
84
Git::command_oneline(@refreshargs );
97
85
} catch Git::Error::Command with {};
98
86
99
- my $line = Git::command_oneline(@gitargs );
87
+ my @diffargs = (@gitargs , ' diff-files' , ' --name-only' , ' -z' );
88
+ my $line = Git::command_oneline(@diffargs );
100
89
my @files ;
101
90
if (defined $line ) {
102
91
@files = split (' \0' , $line );
@@ -105,26 +94,15 @@ sub changed_files
105
94
}
106
95
107
96
delete ($ENV {GIT_INDEX_FILE });
108
- delete ($ENV {GIT_WORK_TREE });
109
- delete ($ENV {GIT_DIR }) if ($must_unset_git_dir );
110
97
111
98
return map { $_ => 1 } @files ;
112
99
}
113
100
114
101
sub setup_dir_diff
115
102
{
116
- my ($repo , $workdir , $symlinks ) = @_ ;
117
-
118
- # Run the diff; exit immediately if no diff found
119
- # 'Repository' and 'WorkingCopy' must be explicitly set to insure that
120
- # if $GIT_DIR and $GIT_WORK_TREE are set in ENV, they are actually used
121
- # by Git->repository->command*.
122
- my $repo_path = $repo -> repo_path();
123
- my %repo_args = (Repository => $repo_path , WorkingCopy => $workdir );
124
- my $diffrepo = Git-> repository(%repo_args );
125
-
103
+ my ($workdir , $symlinks ) = @_ ;
126
104
my @gitargs = (' diff' , ' --raw' , ' --no-abbrev' , ' -z' , @ARGV );
127
- my $diffrtn = $diffrepo -> command_oneline(@gitargs );
105
+ my $diffrtn = Git:: command_oneline(@gitargs );
128
106
exit (0) unless defined ($diffrtn );
129
107
130
108
# Build index info for left and right sides of the diff
@@ -176,12 +154,12 @@ sub setup_dir_diff
176
154
177
155
if ($lmode eq $symlink_mode ) {
178
156
$symlink {$src_path }{left } =
179
- $diffrepo -> command_oneline(' show' , " $lsha1 " );
157
+ Git:: command_oneline(' show' , $lsha1 );
180
158
}
181
159
182
160
if ($rmode eq $symlink_mode ) {
183
161
$symlink {$dst_path }{right } =
184
- $diffrepo -> command_oneline(' show' , " $rsha1 " );
162
+ Git:: command_oneline(' show' , $rsha1 );
185
163
}
186
164
187
165
if ($lmode ne $null_mode and $status !~ / ^C/ ) {
@@ -193,8 +171,8 @@ sub setup_dir_diff
193
171
if ($working_tree_dups {$dst_path }++) {
194
172
next ;
195
173
}
196
- my ($use , $wt_sha1 ) = use_wt_file( $repo , $workdir ,
197
- $dst_path , $rsha1 );
174
+ my ($use , $wt_sha1 ) =
175
+ use_wt_file( $workdir , $dst_path , $rsha1 );
198
176
if ($use ) {
199
177
push @working_tree , $dst_path ;
200
178
$wtindex .= " $rmode $wt_sha1 \t $dst_path \0 " ;
@@ -211,44 +189,34 @@ sub setup_dir_diff
211
189
mkpath($ldir ) or exit_cleanup($tmpdir , 1);
212
190
mkpath($rdir ) or exit_cleanup($tmpdir , 1);
213
191
214
- # If $GIT_DIR is not set prior to calling 'git update-index' and
215
- # 'git checkout-index', then those commands will fail if difftool
216
- # is called from a directory other than the repo root.
217
- my $must_unset_git_dir = 0;
218
- if (not defined ($ENV {GIT_DIR })) {
219
- $must_unset_git_dir = 1;
220
- $ENV {GIT_DIR } = $repo_path ;
221
- }
222
-
223
192
# Populate the left and right directories based on each index file
224
193
my ($inpipe , $ctx );
225
194
$ENV {GIT_INDEX_FILE } = " $tmpdir /lindex" ;
226
195
($inpipe , $ctx ) =
227
- $repo -> command_input_pipe(qw( update-index -z --index-info) );
196
+ Git:: command_input_pipe(' update-index' , ' -z ' , ' --index-info' );
228
197
print ($inpipe $lindex );
229
- $repo -> command_close_pipe($inpipe , $ctx );
198
+ Git:: command_close_pipe($inpipe , $ctx );
230
199
231
200
my $rc = system (' git' , ' checkout-index' , ' --all' , " --prefix=$ldir /" );
232
201
exit_cleanup($tmpdir , $rc ) if $rc != 0;
233
202
234
203
$ENV {GIT_INDEX_FILE } = " $tmpdir /rindex" ;
235
204
($inpipe , $ctx ) =
236
- $repo -> command_input_pipe(qw( update-index -z --index-info) );
205
+ Git:: command_input_pipe(' update-index' , ' -z ' , ' --index-info' );
237
206
print ($inpipe $rindex );
238
- $repo -> command_close_pipe($inpipe , $ctx );
207
+ Git:: command_close_pipe($inpipe , $ctx );
239
208
240
209
$rc = system (' git' , ' checkout-index' , ' --all' , " --prefix=$rdir /" );
241
210
exit_cleanup($tmpdir , $rc ) if $rc != 0;
242
211
243
212
$ENV {GIT_INDEX_FILE } = " $tmpdir /wtindex" ;
244
213
($inpipe , $ctx ) =
245
- $repo -> command_input_pipe(qw( update-index --info-only -z --index-info) );
214
+ Git:: command_input_pipe(' update-index' , ' --info-only' , ' -z ' , ' --index-info' );
246
215
print ($inpipe $wtindex );
247
- $repo -> command_close_pipe($inpipe , $ctx );
216
+ Git:: command_close_pipe($inpipe , $ctx );
248
217
249
218
# If $GIT_DIR was explicitly set just for the update/checkout
250
219
# commands, then it should be unset before continuing.
251
- delete ($ENV {GIT_DIR }) if ($must_unset_git_dir );
252
220
delete ($ENV {GIT_INDEX_FILE });
253
221
254
222
# Changes in the working tree need special treatment since they are
@@ -415,9 +383,9 @@ sub dir_diff
415
383
my $rc ;
416
384
my $error = 0;
417
385
my $repo = Git-> repository();
418
- my $workdir = find_worktree ();
419
- my ( $a , $b , $tmpdir , @worktree ) =
420
- setup_dir_diff( $repo , $workdir , $symlinks );
386
+ my $repo_path = $repo -> repo_path ();
387
+ my $workdir = $repo -> wc_path();
388
+ my ( $a , $b , $tmpdir , @worktree ) = setup_dir_diff( $workdir , $symlinks );
421
389
422
390
if (defined ($extcmd )) {
423
391
$rc = system ($extcmd , $a , $b );
@@ -443,10 +411,10 @@ sub dir_diff
443
411
next if ! -f " $b /$file " ;
444
412
445
413
if (!$indices_loaded ) {
446
- %wt_modified = changed_files($repo -> repo_path(),
447
- " $tmpdir /wtindex" , " $workdir " );
448
- %tmp_modified = changed_files($repo -> repo_path(),
449
- " $tmpdir /wtindex" , " $b " );
414
+ %wt_modified = changed_files(
415
+ $repo_path , " $tmpdir /wtindex" , $workdir );
416
+ %tmp_modified = changed_files(
417
+ $repo_path , " $tmpdir /wtindex" , $b );
450
418
$indices_loaded = 1;
451
419
}
452
420
0 commit comments