1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-19 07:24:50 +01:00

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>
This commit is contained in:
Petr Baudis 2006-06-24 04:34:53 +02:00 committed by Junio C Hamano
parent d5c7721d58
commit 8f00660fc1

View file

@ -10,6 +10,7 @@
use warnings; use warnings;
use strict; use strict;
use Getopt::Std; use Getopt::Std;
use Git;
sub usage() { sub usage() {
print <<EOT; print <<EOT;
@ -24,9 +25,7 @@ ()
usage() if $opt_h; usage() if $opt_h;
@ARGV >= 1 or usage; @ARGV >= 1 or usage;
my $GIT_DIR = `git rev-parse --git-dir`; my $repo = Git->repository();
exit 1 if $?; # rev-parse would have given "not a git dir" message.
chomp($GIT_DIR);
my (@srcArgs, @dstArgs, @srcs, @dsts); my (@srcArgs, @dstArgs, @srcs, @dsts);
my ($src, $dst, $base, $dstDir); my ($src, $dst, $base, $dstDir);
@ -62,11 +61,11 @@ ()
$dstDir = ""; $dstDir = "";
} }
my $subdir_prefix = `git rev-parse --show-prefix`; my $subdir_prefix = $repo->wc_subdir();
chomp($subdir_prefix);
# run in git base directory, so that git-ls-files lists all revisioned files # run in git base directory, so that git-ls-files lists all revisioned files
chdir "$GIT_DIR/.."; chdir $repo->wc_path();
$repo->wc_chdir('');
# normalize paths, needed to compare against versioned files and update-index # normalize paths, needed to compare against versioned files and update-index
# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" # also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
@ -84,12 +83,10 @@ ()
my $safesrc; my $safesrc;
my (%overwritten, %srcForDst); my (%overwritten, %srcForDst);
$/ = "\0"; {
open(F, 'git-ls-files -z |') local $/ = "\0";
or die "Failed to open pipe from git-ls-files: " . $!; @allfiles = $repo->command('ls-files', '-z');
}
@allfiles = map { chomp; $_; } <F>;
close(F);
my ($i, $bad); my ($i, $bad);
@ -219,28 +216,28 @@ ()
} }
else { else {
if (@changedfiles) { if (@changedfiles) {
open(H, "| git-update-index -z --stdin") my ($fd, $ctx) = $repo->command_input_pipe('update-index', '-z', '--stdin');
or die "git-update-index failed to update changed files with code $!\n";
foreach my $fileName (@changedfiles) { foreach my $fileName (@changedfiles) {
print H "$fileName\0"; print $fd "$fileName\0";
} }
close(H); git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
'git-update-index failed to update changed files with code %d';
} }
if (@addedfiles) { if (@addedfiles) {
open(H, "| git-update-index --add -z --stdin") my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--add', '-z', '--stdin');
or die "git-update-index failed to add new names with code $!\n";
foreach my $fileName (@addedfiles) { foreach my $fileName (@addedfiles) {
print H "$fileName\0"; print $fd "$fileName\0";
} }
close(H); git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
'git-update-index failed to add new files with code %d';
} }
if (@deletedfiles) { if (@deletedfiles) {
open(H, "| git-update-index --remove -z --stdin") my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--remove', '-z', '--stdin');
or die "git-update-index failed to remove old names with code $!\n";
foreach my $fileName (@deletedfiles) { foreach my $fileName (@deletedfiles) {
print H "$fileName\0"; print $fd "$fileName\0";
} }
close(H); git_cmd_try { $repo->command_close_pipe($fd, $ctx); }
'git-update-index failed to remove old files with code %d';
} }
} }