git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Make git-rename-script behave much better when faced with input contain Perl regular expression metacharacters.

From
RARyan Anderson <ryan@michonline.com>
Date
Jul 26, 2005, 06:56 UTC
Message-ID
<20050726065657.GI6098@mythryan2.michonline.com>
In-Reply-To
<7vpst7z9r9.fsf@assigned-by-dhcp.cox.net>
Also, restore support for the GIT_DIR
Signed-off-by: Ryan Anderson <ryan@michonline.com>
---
 git-rename-script |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)
1ed66638c7ce328d882639447b80099f096c2993
diff --git a/git-rename-script b/git-rename-script
--- a/git-rename-script
+++ b/git-rename-script
@@ -12,11 +12,8 @@ use strict;
 sub usage($);
 
 # Sanity checks:
-my $GIT_DIR = $$ENV{'GIT_DIR'};
-$GIT_DIR = ".git" unless defined $GIT_DIR;
-
-unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" && 
-	-d $GIT_DIR . "/objects/00" && -d $GIT_DIR . "/refs") {
+unless ( -d ".git" && -d ".git/objects" && 
+	-d ".git/objects/00" && -d ".git/refs") {
 	usage("Git repository not found.");
 }
 
@@ -34,26 +31,23 @@ if (-e $dst) {
 
 my (@allfiles,@srcfiles,@dstfiles);
 
-$/ = "\0";
-open(F,"-|","git-ls-files","-z")
+open(F,"-|","git-ls-files")
 	or die "Failed to open pipe from git-ls-files: " . $!;
 
-@allfiles = map { chomp; $_; } <F>;
+@allfiles = <F>;
 close(F);
+chomp for @allfiles;
+
 
-my $safesrc = quotemeta($src);
-@srcfiles = grep /^$safesrc/, @allfiles;
+@srcfiles = grep /^$src/, @allfiles;
 @dstfiles = @srcfiles;
-s#^$safesrc(/|$)#$dst$1# for @dstfiles;
+s#^$src(/|$)#$dst$1# for @dstfiles;
 
 rename($src,$dst)
 	or die "rename failed: $!";
 
-my $rc = system("git-update-cache","--add","--",@dstfiles);
-die "git-update-cache failed to add new name with code $?\n" if $rc;
-
-$rc = system("git-update-cache","--remove","--",@srcfiles);
-die "git-update-cache failed to remove old name with code $?\n" if $rc;
+system("git-update-cache","--remove","--",@srcfiles);
+system("git-update-cache","--add","--",@dstfiles);
 
 
 sub usage($) {
-- 
Ryan Anderson
  sometimes Pug Majere
Previous: Junio C HamanoNext: Ryan Anderson
Message 4 of 5 in “Add support for directories to git-rename-script.”
  1. Add support for directories to git-rename-script.Ryan Anderson, Jul 25, 2005
  2. Add documentation for git-rename-scriptRyan Anderson, Jul 25, 2005
  3. Junio C HamanoJul 25, 2005
  4. Make git-rename-script behave much better when faced with input contain Perl regular expression metacharacters.Ryan Anderson, Jul 26, 2005
  5. Make git-rename-script behave better with input containing Perl regexp metachars.Ryan Anderson, Jul 26, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.