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

Re: [PATCH] cvsimport: strip all inappropriate tag strings

From
Alex Vandiver <alex@chmrr.net>
Date
Sep 5, 2012, 06:44 UTC
Message-ID
<1346827469.1137.22.camel@umgah.localdomain>
In-Reply-To
<1346819164-8116-1-git-send-email-ktdreyer@ktdreyer.com>
On Tue, 2012-09-04 at 22:26 -0600, Ken Dreyer wrote:
Show 32 quoted lines
> When importing CVS tags, strip all the inappropriate strings from the
> tag names as we translate them to git tag names.
>
> [snip]
> diff --git a/git-cvsimport.perl b/git-cvsimport.perl
> index 8d41610..0dc598d 100755
> --- a/git-cvsimport.perl
> +++ b/git-cvsimport.perl
> @@ -889,7 +889,25 @@ sub commit {
>  		$xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
>  		$xtag =~ tr/_/\./ if ( $opt_u );
>  		$xtag =~ s/[\/]/$opt_s/g;
> -		$xtag =~ s/\[//g;
> +
> +		# See ref.c for these rules.
> +		# Tag cannot end with a '/' - this is already handled above.
> +		# Tag cannot contain bad chars. See bad_ref_char in ref.c.
> +		$xtag =~ s/[ ~\^:\\\*\?\[]//g;
> +		# Tag cannot contain '..'.
> +		$xtag =~ s/\.\.//g;
> +		# Tag cannot contain '@{'.
> +		$xtag =~ s/\@{//g;
> +		# Tag cannot end with '.lock'.
> +		$xtag =~ s/(?:\.lock)+$//;
> +		# Tag cannot begin or end with '.'.
> +		$xtag =~ s/^\.+//;
> +		$xtag =~ s/\.+$//;
> +		# Tag cannot consist of a single '.' - already handled above.
> +		# Tag cannot be empty.
> +		if ($xtag eq '') {
> +			return;
> +		}

Unfortunately, this isn't quite sufficient. Consider the case of a tag named "foo.lock." The .lock rule doesn't match, because it's not at the end of the string -- but after s/\.+$// runs, it _is_ at the end, and hence invalid. A similar problem exists with a tag named "a.@{.b", given the ordering of @{ and .. removal.

Something like the following would suffice:
    1 while $xtag =~ s/
               (?: \.\.        # Tag cannot contain '..'.
               |   \@{         # Tag cannot contain '@{'.
               |   \.lock $    # Tag cannot end with '.lock'.
               | ^ \.          # Tag cannot begin...
               |   \. $        # ...or end with '.'
               )//xg;
 - Alex
Previous: Junio C HamanoNext: Ken Dreyer
Message 5 of 11 in “cvsimport: strip question marks from tags”
  1. cvsimport: strip question marks from tagsKen Dreyer, Sep 5, 2012
  2. Junio C HamanoSep 5, 2012
  3. cvsimport: strip all inappropriate tag stringsKen Dreyer, Sep 5, 2012
  4. Junio C HamanoSep 5, 2012
  5. Alex VandiverSep 5, 2012
  6. cvsimport: strip all inappropriate tag stringsKen Dreyer, Sep 5, 2012
  7. Junio C HamanoSep 6, 2012
  8. cvsimport: strip all inappropriate tag stringsKen Dreyer, Sep 6, 2012
  9. Andreas SchwabSep 6, 2012
  10. cvsimport: strip all inappropriate tag stringsKen Dreyer, Sep 6, 2012
  11. Junio C HamanoSep 6, 2012

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.