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

Re: [PATCH] Add support for directories to git-rename-script.

From
Junio C Hamano <junkio@cox.net>
Date
Jul 25, 2005, 06:21 UTC
Message-ID
<7vpst7z9r9.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20050725052646.GB6098@mythryan2.michonline.com>
Ryan Anderson <ryan@michonline.com> writes:
Show 5 quoted lines
> +open(F,"-|","git-ls-files")
> +	or die "Failed to open pipe from git-ls-files: " . $!;
> +
> +@allfiles = <F>;
> +close(F);

We can afford to handle funny characters in the filename right without pain in Perl, so let's do it right:

    use vars qw($/);
    $/ = "\0";
    open F, '-|', 'git-ls-files', '-z'
    	or die "Failed to open pipe from git-ls-files: " . $!;
    @allfiles = map { chomp; $_} <F>;
> +@srcfiles = grep /^$src/, @allfiles;
> +@dstfiles = @srcfiles;
> +s#^$src(/|$)#$dst$1# for @dstfiles;
Be careful with these regexps.  Perhaps something like this?
    @dstfiles = @srcfiles = grep /^\Q$src\E/, @allfiles;
    s#^\Q$src\E(/|$)#$dst$1# for @dstfiles;
or perhaps a bit more readable:
    my $qsrc = quotemeta($src);
    @dstfiles = @srcfiles = grep /^$qsrc/, @allfiles;
    for (@dstfiles) { s/^$qsrc(/|$)/$dst$1/; }
> +rename($src,$dst)
> +	or die "rename failed: $!";
Making sure leading directories for $dst exists, perhaps?
Otherwise looks good.
> +sub usage($) {

This is just a style thing, but do you really care to force a scalar contect when "usage" is used?

Previous: Ryan AndersonNext: Ryan Anderson
Message 3 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.