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

Re: PATCH: git-p4 optional handling of RCS keywords

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 10, 2008, 05:35 UTC
Message-ID
<7vabegzhpl.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<201191.94038.qm@web95010.mail.in2.yahoo.com>
dhruva <dhruva@ymail.com> writes:
Show 13 quoted lines
> @@ -975,10 +978,11 @@ class P4Sync(Command):
>                  sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
>                  continue
>
> -            if stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
> -                text = re.sub(r'(?i)\$(Id|Header):[^$]*\$',r'$\1$', text)
> -            elif stat['type'] in ('text+k', 'ktext', 'kxtext', 'unicode+k', 'binary+k'):
> -                text = re.sub(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$',r'$\1$', text)
> +            if kwstrip:
> +                if stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
> +                    text = re.sub(r'(?i)\$(Id|Header):[^$]*\$',r'$\1$', text)
> +                elif stat['type'] in ('text+k', 'ktext', 'kxtext', 'unicode+k', 'binary+k'):
> +                    text = re.sub(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$',r'$\1$', text)
A style tip.

It makes it easier to convince others that you didn't screw up in the conversion if you cascade the code this way instead:

-	if stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
+	if not kwstrip:
+		pass
+	elif stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
 		text = re.sub(r'(?i)\$(Id|Header):[^$]*\$',r'$\1$', text)
 	elif stat['type'] in ('text+k', 'ktext', 'kxtext', 'unicode+k', 'binary+k'):
 		text = re.sub(r'\$(Id|Header|Author|Date|DateTime|Change|...

This technique not just only makes the patch smaller and easier to review, it also makes the result less deeply nested and easier to read as well.

Previous: dhruva
Message 2 of 2 in “PATCH: git-p4 optional handling of RCS keywords [was: Re: git-p4 and keyword expansion]”
  1. dhruvaSep 10, 2008
  2. Junio C HamanoSep 10, 2008

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.