summaryrefslogtreecommitdiff
path: root/git-rename.perl
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-09-08 00:26:23 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-09-08 00:45:20 (GMT)
commit215a7ad1ef790467a4cd3f0dcffbd6e5f04c38f7 (patch)
tree6bc7aa4f652d0ef49108d9e30a7ea7fbf8e44639 /git-rename.perl
parent99977bd5fdeabbd0608a70e9411c243007ec4ea2 (diff)
downloadgit-215a7ad1ef790467a4cd3f0dcffbd6e5f04c38f7.zip
git-215a7ad1ef790467a4cd3f0dcffbd6e5f04c38f7.tar.gz
git-215a7ad1ef790467a4cd3f0dcffbd6e5f04c38f7.tar.bz2
Big tool rename.
As promised, this is the "big tool rename" patch. The primary differences since 0.99.6 are: (1) git-*-script are no more. The commands installed do not have any such suffix so users do not have to remember if something is implemented as a shell script or not. (2) Many command names with 'cache' in them are renamed with 'index' if that is what they mean. There are backward compatibility symblic links so that you and Porcelains can keep using the old names, but the backward compatibility support is expected to be removed in the near future. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-rename.perl')
-rwxr-xr-xgit-rename.perl70
1 files changed, 70 insertions, 0 deletions
diff --git a/git-rename.perl b/git-rename.perl
new file mode 100755
index 0000000..a28c8c8
--- /dev/null
+++ b/git-rename.perl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+#
+# Copyright 2005, Ryan Anderson <ryan@michonline.com>
+#
+# This file is licensed under the GPL v2, or a later version
+# at the discretion of Linus Torvalds.
+
+
+use warnings;
+use strict;
+
+sub usage($);
+
+# Sanity checks:
+my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";
+
+unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" &&
+ -d $GIT_DIR . "/objects/00" && -d $GIT_DIR . "/refs") {
+ usage("Git repository not found.");
+}
+
+usage("") if scalar @ARGV != 2;
+
+my ($src,$dst) = @ARGV;
+
+unless (-f $src || -l $src || -d $src) {
+ usage("git rename: bad source '$src'");
+}
+
+if (-e $dst) {
+ usage("git rename: destinations '$dst' already exists");
+}
+
+my (@allfiles,@srcfiles,@dstfiles);
+
+$/ = "\0";
+open(F,"-|","git-ls-files","-z")
+ or die "Failed to open pipe from git-ls-files: " . $!;
+
+@allfiles = map { chomp; $_; } <F>;
+close(F);
+
+my $safesrc = quotemeta($src);
+@srcfiles = grep /^$safesrc/, @allfiles;
+@dstfiles = @srcfiles;
+s#^$safesrc(/|$)#$dst$1# for @dstfiles;
+
+rename($src,$dst)
+ or die "rename failed: $!";
+
+my $rc = system("git-update-index","--add","--",@dstfiles);
+die "git-update-index failed to add new name with code $?\n" if $rc;
+
+$rc = system("git-update-index","--remove","--",@srcfiles);
+die "git-update-index failed to remove old name with code $?\n" if $rc;
+
+
+sub usage($) {
+ my $s = shift;
+ print $s, "\n" if (length $s != 0);
+ print <<EOT;
+$0 <source> <dest>
+source must exist and be either a file, symlink or directory.
+dest must NOT exist.
+
+Renames source to dest, and updates the git cache to reflect the change.
+Use "git commit" to make record the change permanently.
+EOT
+ exit(1);
+}