git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Baudis <pasky@suse.cz>
To: Junio C Hamano <junkio@cox.net>
Cc: <git@vger.kernel.org>
Subject: [PATCH 12/12] Convert git-mv to use Git.pm
Date: Sat, 24 Jun 2006 04:34:53 +0200	[thread overview]
Message-ID: <20060624023453.32751.73126.stgit@machine.or.cz> (raw)
In-Reply-To: <20060624023429.32751.80619.stgit@machine.or.cz>

Fairly straightforward.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---

 git-mv.perl |   46 ++++++++++++++++++++++------------------------
 1 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/git-mv.perl b/git-mv.perl
index 75aa8fe..b9e3537 100755
--- a/git-mv.perl
+++ b/git-mv.perl
@@ -10,6 +10,8 @@ # at the discretion of Linus Torvalds.
 use warnings;
 use strict;
 use Getopt::Std;
+use Git;
+use Error qw(:try);
 
 sub usage() {
 	print <<EOT;
@@ -24,9 +26,7 @@ getopts("hnfkv") || usage;
 usage() if $opt_h;
 @ARGV >= 1 or usage;
 
-my $GIT_DIR = `git rev-parse --git-dir`;
-exit 1 if $?; # rev-parse would have given "not a git dir" message.
-chomp($GIT_DIR);
+my $repo = Git->repository();
 
 my (@srcArgs, @dstArgs, @srcs, @dsts);
 my ($src, $dst, $base, $dstDir);
@@ -62,11 +62,11 @@ else {
     $dstDir = "";
 }
 
-my $subdir_prefix = `git rev-parse --show-prefix`;
-chomp($subdir_prefix);
+my $subdir_prefix = $repo->wc_subdir();
 
 # 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
 # also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
@@ -84,12 +84,10 @@ my (@allfiles,@srcfiles,@dstfiles);
 my $safesrc;
 my (%overwritten, %srcForDst);
 
-$/ = "\0";
-open(F, 'git-ls-files -z |')
-        or die "Failed to open pipe from git-ls-files: " . $!;
-
-@allfiles = map { chomp; $_; } <F>;
-close(F);
+{
+	local $/ = "\0";
+	@allfiles = $repo->command('ls-files', '-z');
+}
 
 
 my ($i, $bad);
@@ -219,28 +217,28 @@ if ($opt_n) {
 }
 else {
     if (@changedfiles) {
-	open(H, "| git-update-index -z --stdin")
-		or die "git-update-index failed to update changed files with code $!\n";
+	my ($fd, $ctx) = $repo->command_input_pipe('update-index', '-z', '--stdin');
 	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) {
-	open(H, "| git-update-index --add -z --stdin")
-		or die "git-update-index failed to add new names with code $!\n";
+	my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--add', '-z', '--stdin');
 	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) {
-	open(H, "| git-update-index --remove -z --stdin")
-		or die "git-update-index failed to remove old names with code $!\n";
+	my ($fd, $ctx) = $repo->command_input_pipe('update-index', '--remove', '-z', '--stdin');
 	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';
     }
 }
 

  parent reply	other threads:[~2006-06-24  2:35 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-24  2:34 [PATCH 01/12] Introduce Git.pm (v4) Petr Baudis
2006-06-24  2:34 ` [PATCH 02/12] Git.pm: Implement Git::exec_path() Petr Baudis
2006-06-24  2:34 ` [PATCH 03/12] Git.pm: Call external commands using execv_git_cmd() Petr Baudis
2006-06-24  2:34 ` [PATCH 04/12] Git.pm: Implement Git::version() Petr Baudis
2006-06-24  2:34 ` [PATCH 05/12] Customizable error handlers Petr Baudis
2006-06-24  2:34 ` [PATCH 06/12] Add Error.pm to the distribution Petr Baudis
2006-06-24  2:34 ` [PATCH 07/12] Git.pm: Better error handling Petr Baudis
2006-06-24  8:37   ` Junio C Hamano
2006-06-24 13:17     ` Petr Baudis
2006-06-25  1:13       ` Petr Baudis
2006-06-25  1:30       ` Junio C Hamano
2006-06-24  2:34 ` [PATCH 08/12] Git.pm: Handle failed commands' output Petr Baudis
2006-06-24  2:34 ` [PATCH 09/12] Git.pm: Enhance the command_pipe() mechanism Petr Baudis
2006-06-24  2:34 ` [PATCH 10/12] Git.pm: Implement options for the command interface Petr Baudis
2006-06-24  2:34 ` [PATCH 11/12] Git.pm: Add support for subdirectories inside of working copies Petr Baudis
2006-06-24  2:34 ` Petr Baudis [this message]
2006-06-24  2:39   ` [PATCH 12/12] Convert git-mv to use Git.pm Petr Baudis
2006-06-24  2:46 ` [PATCH 01/12] Introduce Git.pm (v4) Junio C Hamano
2006-06-24  3:14   ` Petr Baudis
2006-06-24  8:33   ` Junio C Hamano
2006-06-24 11:16     ` Petr Baudis
2006-06-24 11:52       ` Petr Baudis
2006-06-24 11:57       ` Junio C Hamano
2006-06-24 13:02         ` Petr Baudis
2006-06-25  3:12           ` Junio C Hamano

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=20060624023453.32751.73126.stgit@machine.or.cz \
    --to=pasky@suse.cz \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).