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

Re: [PATCHv3] git-p4: add initial support for RCS keywords

From
PWPete Wyckoff <pw@padd.com>
Date
Feb 21, 2012, 12:18 UTC
Message-ID
<20120221121834.GB18317@padd.com>
In-Reply-To
<1329258835-17223-2-git-send-email-luke@diamand.org>
luke@diamand.org wrote on Tue, 14 Feb 2012 22:33 +0000:
> diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
[..]
Show 5 quoted lines
> +git-p4.attemptRCSCleanup:
> +    If enabled, 'git p4 submit' will attempt to sort cleanup RCS keywords
> +    ($Header$, etc). These would otherwise cause merge conflicts and prevent
> +    the submit going ahead. This option should be considered experimental at
> +    present.
=> "attempt to cleanup"
> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
[..]
Show 14 quoted lines
> +#
> +# return the raw p4 type of a file (text, text+ko, etc)
> +#
> +def p4_type(file):
> +    files = p4_read_pipe_lines(["files", file])
> +    info = files[0]
> +    m = re.search(r'\(([a-z0-9A-Z+]+)\)\s*$', info)
> +    if m:
> +        ret = m.group(1)
> +        if verbose:
> +            print "%s => %s" % (file, ret)
> +        return ret
> +    else:
> +        die("Could not extract file type from '%s'" % info)

p4 fstat -T headType gives just the type, no need to parse the info string

Show 10 quoted lines
> +#
> +# Given a type base and modifier, return a regexp matching
> +# the keywords that can be expanded in the file
> +#
> +def p4_keywords_regexp_for_type(base, type_mods):
> +    if base in ("text", "unicode", "binary"):
> +        if "ko" in type_mods:
> +            return r'\$(Id|Header)[^$]*\$'
> +        elif "k" in type_mods:
> +            return r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)[^$]*\$'
Still no ":"?  Won't that match too much?
> +    def patchRCSKeywords(self, file, pattern):
Nice, clean.
>      def p4UserForCommit(self,id):
[..]
Show 5 quoted lines
> +                for line in read_pipe_lines(diffcmd):
> +                    # read diff lines: for each file reported, if it can have
> +                    # keywords expanded, and the diff contains keywords, then
> +                    # try zapping the p4 file.
> +                    m = re.match(r'^diff --git a/(.*)\s+b/(.*)', line)

I'm still sort of iffy on this. You have editedFiles, and could just use that directly. Grepping through the diff won't give you any more information.

> +                    if pattern:
> +                        print line
Debugging?  Maybe add a leading comment saying why this line.
Show 18 quoted lines
> @@ -1585,15 +1685,11 @@ class P4Sync(Command, P4UserMap):
>  
>          # Note that we do not try to de-mangle keywords on utf16 files,
>          # even though in theory somebody may want that.
> -        if type_base in ("text", "unicode", "binary"):
> -            if "ko" in type_mods:
> -                text = ''.join(contents)
> -                text = re.sub(r'\$(Id|Header):[^$]*\$', r'$\1$', text)
> -                contents = [ text ]
> -            elif "k" in type_mods:
> -                text = ''.join(contents)
> -                text = re.sub(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$', r'$\1$', text)
> -                contents = [ text ]
> +        pattern = p4_keywords_regexp_for_type(type_base, type_mods)
> +        if pattern:
> +            text = ''.join(contents)
> +            text = re.sub(pattern, r'$\1$', text)
> +            contents = [ text ]
Nice.  Glad you refactored this.
Fix the colon thing at least, then happy to add my Acked-By.
Sorry for the delay.
		-- Pete
Previous: Junio C HamanoNext: Eric Scouten
Message 4 of 7 in “[PATCHv3] git-p4: RCS keyword handling”
  1. Luke DiamandFeb 14, 2012
  2. [PATCHv3] git-p4: add initial support for RCS keywordsLuke Diamand, Feb 14, 2012
  3. Junio C HamanoFeb 14, 2012
  4. Pete WyckoffFeb 21, 2012
  5. Eric ScoutenFeb 21, 2012
  6. Junio C HamanoFeb 21, 2012
  7. Eric ScoutenFeb 21, 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.