@matheusbsbs / matheus-bagliano / commits / 8f00660fc1
Fork 0

Convert git-mv to use Git.pm

Fairly straightforward. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Jun 24, 2006 at 04:34 UTC 8f00660fc13df9ed22f059f032a65c60168a2057
1 file changed +21 -24
git-mv.perl
+21 -24
@@ -10,6 +10,7 @@
10 use warnings;
11 use strict;
12 use Getopt::Std;
13 +use Git;
14
15 sub usage() {
16 print <<EOT;
@@ -24,9 +25,7 @@ getopts("hnfkv") || usage;
25 usage() if $opt_h;
26 @ARGV >= 1 or usage;
27
27 -my $GIT_DIR = `git rev-parse --git-dir`;
28 -exit 1 if $?; # rev-parse would have given "not a git dir" message.
29 -chomp($GIT_DIR);
28 +my $repo = Git->repository();
29
30 my (@srcArgs, @dstArgs, @srcs, @dsts);
31 my ($src, $dst, $base, $dstDir);
@@ -62,11 +61,11 @@ else {
61 $dstDir = "";
62 }
63
65 -my $subdir_prefix = `git rev-parse --show-prefix`;
66 -chomp($subdir_prefix);
64 +my $subdir_prefix = $repo->wc_subdir();
65
66 # run in git base directory, so that git-ls-files lists all revisioned files
69 -chdir "$GIT_DIR/..";
67 +chdir $repo->wc_path();
68 +$repo->wc_chdir('');
69
70 # normalize paths, needed to compare against versioned files and update-index
71 # also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
@@ -84,12 +83,10 @@ my (@allfiles,@srcfiles,@dstfiles);
83 my $safesrc;
84 my (%overwritten, %srcForDst);
85
87 -$/ = "\0";
88 -open(F, 'git-ls-files -z |')
89 - or die "Failed to open pipe from git-ls-files: " . $!;
90 -
91 -@allfiles = map { chomp; $_; } <F>;
92 -close(F);
86 +{
87 + local $/ = "\0";
88 + @allfiles = $repo->command('ls-files', '-z');
89 +}
90
91
92 my ($i, $bad);
@@ -219,28 +216,28 @@ if ($opt_n) {
216 }
217 else {
218 if (@changedfiles) {
222 - open(H, "| git-update-index -z --stdin")
223 - or die "git-update-index failed to update changed files with code $!\n";
219 + my ($fd, $ctx) = $repo->command_input_pipe('update-index', '-z', '--stdin');
220 foreach my $fileName (@changedfiles) {
225 - print H "$fileName\0";
221 + print $fd "$fileName\0";
222 }
227 - close(H);
223 + git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
224 + 'git-update-index failed to update changed files with code %d';
225 }
226 if (@addedfiles) {
230 - open(H, "| git-update-index --add -z --stdin")
231 - or die "git-update-index failed to add new names with code $!\n";
227 + my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--add', '-z', '--stdin');
228 foreach my $fileName (@addedfiles) {
233 - print H "$fileName\0";
229 + print $fd "$fileName\0";
230 }
235 - close(H);
231 + git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
232 + 'git-update-index failed to add new files with code %d';
233 }
234 if (@deletedfiles) {
238 - open(H, "| git-update-index --remove -z --stdin")
239 - or die "git-update-index failed to remove old names with code $!\n";
235 + my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--remove', '-z', '--stdin');
236 foreach my $fileName (@deletedfiles) {
241 - print H "$fileName\0";
237 + print $fd "$fileName\0";
238 }
243 - close(H);
239 + git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
240 + 'git-update-index failed to remove old files with code %d';
241 }
242 }
243