{"thread":{"id":"1332","subject":"[PATCH] Add support for directories to git-rename-script.","startedAt":"2005-07-25T05:26:47Z","lastAt":"2005-07-26T07:40:28Z","messageCount":5,"participants":["Ryan Anderson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6419","messageId":"20050725052646.GB6098@mythryan2.michonline.com","threadId":"1332","inReplyTo":null,"subject":"[PATCH] Add support for directories to git-rename-script.","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2005-07-25T05:26:47Z","receivedAt":"2005-07-25T05:26:47Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"\nOh, and in the process, rewrite it in Perl.\n\nSigned-off-by: Ryan Anderson <ryan@michonline.com>\n---\n\n git-rename-script |   68 +++++++++++++++++++++++++++++++++++++++++++++++++----\n 1 files changed, 63 insertions(+), 5 deletions(-)\n\nf46717f9116bba7efb6a10ed99cd2fcea00fe5da\ndiff --git a/git-rename-script b/git-rename-script\n--- a/git-rename-script\n+++ b/git-rename-script\n@@ -1,7 +1,65 @@\n-#!/bin/sh\n+#!/usr/bin/perl\n+#\n+# Copyright 2005, Ryan Anderson <ryan@michonline.com>\n+#\n+# This file is licensed under the GPL v2, or a later version\n+# at the discretion of Linus Torvalds.\n \n-. git-sh-setup-script || die \"Not a git archive\"\n \n-[ -f \"$1\" ] || [ -h \"$1\" ] || die \"git rename: bad source\"\n-[ -e \"$2\" ] && die \"git rename: destination already exists\"\n-mv -- \"$1\" \"$2\" && git-update-cache --add --remove -- \"$1\" \"$2\"\n+use warnings;\n+use strict;\n+\n+sub usage($);\n+\n+# Sanity checks:\n+unless ( -d \".git\" && -d \".git/objects\" && \n+\t-d \".git/objects/00\" && -d \".git/refs\") {\n+\tusage(\"Git repository not found.\");\n+}\n+\n+usage(\"\") if scalar @ARGV != 2;\n+\n+my ($src,$dst) = @ARGV;\n+\n+unless (-f $src || -l $src || -d $src) {\n+\tusage(\"git rename: bad source '$src'\");\n+}\n+\n+if (-e $dst) {\n+\tusage(\"git rename: destinations '$dst' already exists\");\n+}\n+\n+my (@allfiles,@srcfiles,@dstfiles);\n+\n+open(F,\"-|\",\"git-ls-files\")\n+\tor die \"Failed to open pipe from git-ls-files: \" . $!;\n+\n+@allfiles = <F>;\n+close(F);\n+chomp for @allfiles;\n+\n+\n+@srcfiles = grep /^$src/, @allfiles;\n+@dstfiles = @srcfiles;\n+s#^$src(/|$)#$dst$1# for @dstfiles;\n+\n+rename($src,$dst)\n+\tor die \"rename failed: $!\";\n+\n+system(\"git-update-cache\",\"--remove\",\"--\",@srcfiles);\n+system(\"git-update-cache\",\"--add\",\"--\",@dstfiles);\n+\n+\n+sub usage($) {\n+\tmy $s = shift;\n+\tprint $s, \"\\n\" if (length $s != 0);\n+\tprint <<EOT;\n+$0 <source> <dest>\n+source must exist and be either a file, symlink or directory.\n+dest must NOT exist.\n+\n+Renames source to dest, and updates the git cache to reflect the change.\n+Use \"git commit\" to make record the change permanently.\n+EOT\n+\texit(1);\n+}\n\n-- \n\nRyan Anderson\n  sometimes Pug Majere\n"},{"id":"6421","messageId":"20050725061311.GD6098@mythryan2.michonline.com","threadId":"1332","inReplyTo":"20050725052646.GB6098@mythryan2.michonline.com","subject":"[PATCH] Add documentation for git-rename-script","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2005-07-25T06:13:11Z","receivedAt":"2005-07-25T06:13:11Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"\nSigned-off-by: Ryan Anderson <ryan@michonline.com>\n---\n\n Documentation/git-rename-script.txt |   34 ++++++++++++++++++++++++++++++++++\n 1 files changed, 34 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-rename-script.txt\n\n715924203401309ceb2f696e507b8b2c18244d08\ndiff --git a/Documentation/git-rename-script.txt b/Documentation/git-rename-script.txt\nnew file mode 100644\n--- /dev/null\n+++ b/Documentation/git-rename-script.txt\n@@ -0,0 +1,34 @@\n+\n+git-rename-script(1)\n+=====================\n+v0.1, May 2005\n+\n+NAME\n+----\n+git-rename-script - Script used to rename a file, directory or symlink.\n+\n+\n+SYNOPSIS\n+--------\n+'git-rename-script' <source> <destination>\n+\n+DESCRIPTION\n+-----------\n+This script is used to rename a file, directory or symlink.\n+\n+The index is updated after successful completion, but the change must still be\n+committed.\n+\n+Author\n+------\n+Written by Linus Torvalds <torvalds@osdl.org>\n+Rewritten by Ryan Anderson <ryan@michonline.com>\n+\n+Documentation\n+--------------\n+Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.\n+\n+GIT\n+---\n+Part of the link:git.html[git] suite\n+\n"},{"id":"6423","messageId":"7vpst7z9r9.fsf@assigned-by-dhcp.cox.net","threadId":"1332","inReplyTo":"20050725052646.GB6098@mythryan2.michonline.com","subject":"Re: [PATCH] Add support for directories to git-rename-script.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-25T06:21:14Z","receivedAt":"2005-07-25T06:21:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ryan Anderson <ryan@michonline.com> writes:\n\n> +open(F,\"-|\",\"git-ls-files\")\n> +\tor die \"Failed to open pipe from git-ls-files: \" . $!;\n> +\n> +@allfiles = <F>;\n> +close(F);\n\nWe can afford to handle funny characters in the filename right\nwithout pain in Perl, so let's do it right:\n\n    use vars qw($/);\n    $/ = \"\\0\";\n    open F, '-|', 'git-ls-files', '-z'\n    \tor die \"Failed to open pipe from git-ls-files: \" . $!;\n    @allfiles = map { chomp; $_} <F>;\n\n> +@srcfiles = grep /^$src/, @allfiles;\n> +@dstfiles = @srcfiles;\n> +s#^$src(/|$)#$dst$1# for @dstfiles;\n\nBe careful with these regexps.  Perhaps something like this?\n\n    @dstfiles = @srcfiles = grep /^\\Q$src\\E/, @allfiles;\n    s#^\\Q$src\\E(/|$)#$dst$1# for @dstfiles;\n\nor perhaps a bit more readable:\n\n    my $qsrc = quotemeta($src);\n    @dstfiles = @srcfiles = grep /^$qsrc/, @allfiles;\n    for (@dstfiles) { s/^$qsrc(/|$)/$dst$1/; }\n\n> +rename($src,$dst)\n> +\tor die \"rename failed: $!\";\n\nMaking sure leading directories for $dst exists, perhaps?\n\nOtherwise looks good.\n\n> +sub usage($) {\n\nThis is just a style thing, but do you really care to force a\nscalar contect when \"usage\" is used?\n"},{"id":"6459","messageId":"20050726065657.GI6098@mythryan2.michonline.com","threadId":"1332","inReplyTo":"7vpst7z9r9.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Make git-rename-script behave much better when faced with input contain Perl regular expression metacharacters.","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2005-07-26T06:56:57Z","receivedAt":"2005-07-26T06:56:57Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"\nAlso, restore support for the GIT_DIR\n\nSigned-off-by: Ryan Anderson <ryan@michonline.com>\n---\n\n git-rename-script |   26 ++++++++++----------------\n 1 files changed, 10 insertions(+), 16 deletions(-)\n\n1ed66638c7ce328d882639447b80099f096c2993\ndiff --git a/git-rename-script b/git-rename-script\n--- a/git-rename-script\n+++ b/git-rename-script\n@@ -12,11 +12,8 @@ use strict;\n sub usage($);\n \n # Sanity checks:\n-my $GIT_DIR = $$ENV{'GIT_DIR'};\n-$GIT_DIR = \".git\" unless defined $GIT_DIR;\n-\n-unless ( -d $GIT_DIR && -d $GIT_DIR . \"/objects\" && \n-\t-d $GIT_DIR . \"/objects/00\" && -d $GIT_DIR . \"/refs\") {\n+unless ( -d \".git\" && -d \".git/objects\" && \n+\t-d \".git/objects/00\" && -d \".git/refs\") {\n \tusage(\"Git repository not found.\");\n }\n \n@@ -34,26 +31,23 @@ if (-e $dst) {\n \n my (@allfiles,@srcfiles,@dstfiles);\n \n-$/ = \"\\0\";\n-open(F,\"-|\",\"git-ls-files\",\"-z\")\n+open(F,\"-|\",\"git-ls-files\")\n \tor die \"Failed to open pipe from git-ls-files: \" . $!;\n \n-@allfiles = map { chomp; $_; } <F>;\n+@allfiles = <F>;\n close(F);\n+chomp for @allfiles;\n+\n \n-my $safesrc = quotemeta($src);\n-@srcfiles = grep /^$safesrc/, @allfiles;\n+@srcfiles = grep /^$src/, @allfiles;\n @dstfiles = @srcfiles;\n-s#^$safesrc(/|$)#$dst$1# for @dstfiles;\n+s#^$src(/|$)#$dst$1# for @dstfiles;\n \n rename($src,$dst)\n \tor die \"rename failed: $!\";\n \n-my $rc = system(\"git-update-cache\",\"--add\",\"--\",@dstfiles);\n-die \"git-update-cache failed to add new name with code $?\\n\" if $rc;\n-\n-$rc = system(\"git-update-cache\",\"--remove\",\"--\",@srcfiles);\n-die \"git-update-cache failed to remove old name with code $?\\n\" if $rc;\n+system(\"git-update-cache\",\"--remove\",\"--\",@srcfiles);\n+system(\"git-update-cache\",\"--add\",\"--\",@dstfiles);\n \n \n sub usage($) {\n\n-- \n\nRyan Anderson\n  sometimes Pug Majere\n"},{"id":"6462","messageId":"20050726074028.GL6098@mythryan2.michonline.com","threadId":"1332","inReplyTo":"20050726065657.GI6098@mythryan2.michonline.com","subject":"[PATCH] Make git-rename-script behave better with input containing Perl regexp metachars.","fromName":"Ryan Anderson","fromEmail":"ryan@michonline.com","sentAt":"2005-07-26T07:40:28Z","receivedAt":"2005-07-26T07:40:28Z","isPatch":true,"sender":{"key":"ryan@michonline.com","avatar":null},"body":"Make git-rename-script behave much better when faced with input contain Perl\nregular expression metacharacters.\n\nAlso, restore support for the GIT_DIR\n\nSigned-off-by: Ryan Anderson <ryan@michonline.com>\n---\n\n git-rename-script |   26 ++++++++++++++++----------\n 1 files changed, 16 insertions(+), 10 deletions(-)\n\n28d2bb7cbb38424c4c6879110bf8aff1e3e5ac42\ndiff --git a/git-rename-script b/git-rename-script\n--- a/git-rename-script\n+++ b/git-rename-script\n@@ -12,8 +12,11 @@ use strict;\n sub usage($);\n \n # Sanity checks:\n-unless ( -d \".git\" && -d \".git/objects\" && \n-\t-d \".git/objects/00\" && -d \".git/refs\") {\n+my $GIT_DIR = $$ENV{'GIT_DIR'};\n+$GIT_DIR = \".git\" unless defined $GIT_DIR;\n+\n+unless ( -d $GIT_DIR && -d $GIT_DIR . \"/objects\" && \n+\t-d $GIT_DIR . \"/objects/00\" && -d $GIT_DIR . \"/refs\") {\n \tusage(\"Git repository not found.\");\n }\n \n@@ -31,23 +34,26 @@ if (-e $dst) {\n \n my (@allfiles,@srcfiles,@dstfiles);\n \n-open(F,\"-|\",\"git-ls-files\")\n+$/ = \"\\0\";\n+open(F,\"-|\",\"git-ls-files\",\"-z\")\n \tor die \"Failed to open pipe from git-ls-files: \" . $!;\n \n-@allfiles = <F>;\n+@allfiles = map { chomp; $_; } <F>;\n close(F);\n-chomp for @allfiles;\n-\n \n-@srcfiles = grep /^$src/, @allfiles;\n+my $safesrc = quotemeta($src);\n+@srcfiles = grep /^$safesrc/, @allfiles;\n @dstfiles = @srcfiles;\n-s#^$src(/|$)#$dst$1# for @dstfiles;\n+s#^$safesrc(/|$)#$dst$1# for @dstfiles;\n \n rename($src,$dst)\n \tor die \"rename failed: $!\";\n \n-system(\"git-update-cache\",\"--remove\",\"--\",@srcfiles);\n-system(\"git-update-cache\",\"--add\",\"--\",@dstfiles);\n+my $rc = system(\"git-update-cache\",\"--add\",\"--\",@dstfiles);\n+die \"git-update-cache failed to add new name with code $?\\n\" if $rc;\n+\n+$rc = system(\"git-update-cache\",\"--remove\",\"--\",@srcfiles);\n+die \"git-update-cache failed to remove old name with code $?\\n\" if $rc;\n \n \n sub usage($) {\n"}]}