|
56 | 56 |
|
57 | 57 | p4_access_checked = False
|
58 | 58 |
|
| 59 | +re_ko_keywords = re.compile(r'\$(Id|Header)(:[^$\n]+)?\$') |
| 60 | +re_k_keywords = re.compile(r'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$') |
| 61 | + |
59 | 62 | def p4_build_cmd(cmd):
|
60 | 63 | """Build a suitable p4 command line.
|
61 | 64 |
|
@@ -577,20 +580,12 @@ def p4_type(f):
|
577 | 580 | #
|
578 | 581 | def p4_keywords_regexp_for_type(base, type_mods):
|
579 | 582 | if base in ("text", "unicode", "binary"):
|
580 |
| - kwords = None |
581 | 583 | if "ko" in type_mods:
|
582 |
| - kwords = 'Id|Header' |
| 584 | + return re_ko_keywords |
583 | 585 | elif "k" in type_mods:
|
584 |
| - kwords = 'Id|Header|Author|Date|DateTime|Change|File|Revision' |
| 586 | + return re_k_keywords |
585 | 587 | else:
|
586 | 588 | return None
|
587 |
| - pattern = r""" |
588 |
| - \$ # Starts with a dollar, followed by... |
589 |
| - (%s) # one of the keywords, followed by... |
590 |
| - (:[^$\n]+)? # possibly an old expansion, followed by... |
591 |
| - \$ # another dollar |
592 |
| - """ % kwords |
593 |
| - return pattern |
594 | 589 | else:
|
595 | 590 | return None
|
596 | 591 |
|
@@ -1753,15 +1748,13 @@ def prepareLogMessage(self, template, message, jobs):
|
1753 | 1748 |
|
1754 | 1749 | return result
|
1755 | 1750 |
|
1756 |
| - def patchRCSKeywords(self, file, pattern): |
1757 |
| - # Attempt to zap the RCS keywords in a p4 controlled file matching the given pattern |
| 1751 | + def patchRCSKeywords(self, file, regexp): |
| 1752 | + # Attempt to zap the RCS keywords in a p4 controlled file matching the given regex |
1758 | 1753 | (handle, outFileName) = tempfile.mkstemp(dir='.')
|
1759 | 1754 | try:
|
1760 | 1755 | with os.fdopen(handle, "w+") as outFile, open(file, "r") as inFile:
|
1761 |
| - regexp = re.compile(pattern, re.VERBOSE) |
1762 | 1756 | for line in inFile.readlines():
|
1763 |
| - line = regexp.sub(r'$\1$', line) |
1764 |
| - outFile.write(line) |
| 1757 | + outFile.write(regexp.sub(r'$\1$', line)) |
1765 | 1758 | # Forcibly overwrite the original file
|
1766 | 1759 | os.unlink(file)
|
1767 | 1760 | shutil.move(outFileName, file)
|
@@ -2088,25 +2081,22 @@ def applyCommit(self, id):
|
2088 | 2081 | # the patch to see if that's possible.
|
2089 | 2082 | if gitConfigBool("git-p4.attemptRCSCleanup"):
|
2090 | 2083 | file = None
|
2091 |
| - pattern = None |
2092 | 2084 | kwfiles = {}
|
2093 | 2085 | for file in editedFiles | filesToDelete:
|
2094 | 2086 | # did this file's delta contain RCS keywords?
|
2095 |
| - pattern = p4_keywords_regexp_for_file(file) |
2096 |
| - |
2097 |
| - if pattern: |
| 2087 | + regexp = p4_keywords_regexp_for_file(file) |
| 2088 | + if regexp: |
2098 | 2089 | # this file is a possibility...look for RCS keywords.
|
2099 |
| - regexp = re.compile(pattern, re.VERBOSE) |
2100 | 2090 | for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]):
|
2101 | 2091 | if regexp.search(line):
|
2102 | 2092 | if verbose:
|
2103 |
| - print("got keyword match on %s in %s in %s" % (pattern, line, file)) |
2104 |
| - kwfiles[file] = pattern |
| 2093 | + print("got keyword match on %s in %s in %s" % (regex.pattern, line, file)) |
| 2094 | + kwfiles[file] = regexp |
2105 | 2095 | break
|
2106 | 2096 |
|
2107 |
| - for file in kwfiles: |
| 2097 | + for file, regexp in kwfiles.items(): |
2108 | 2098 | if verbose:
|
2109 |
| - print("zapping %s with %s" % (line,pattern)) |
| 2099 | + print("zapping %s with %s" % (line, regexp.pattern)) |
2110 | 2100 | # File is being deleted, so not open in p4. Must
|
2111 | 2101 | # disable the read-only bit on windows.
|
2112 | 2102 | if self.isWindows and file not in editedFiles:
|
@@ -3026,12 +3016,10 @@ def streamOneP4File(self, file, contents):
|
3026 | 3016 |
|
3027 | 3017 | # Note that we do not try to de-mangle keywords on utf16 files,
|
3028 | 3018 | # even though in theory somebody may want that.
|
3029 |
| - pattern = p4_keywords_regexp_for_type(type_base, type_mods) |
3030 |
| - if pattern: |
3031 |
| - regexp = re.compile(pattern, re.VERBOSE) |
3032 |
| - text = ''.join(decode_text_stream(c) for c in contents) |
3033 |
| - text = regexp.sub(r'$\1$', text) |
3034 |
| - contents = [ encode_text_stream(text) ] |
| 3019 | + regexp = p4_keywords_regexp_for_type(type_base, type_mods) |
| 3020 | + if regexp: |
| 3021 | + contents = [encode_text_stream(regexp.sub( |
| 3022 | + r'$\1$', ''.join(decode_text_stream(c) for c in contents)))] |
3035 | 3023 |
|
3036 | 3024 | if self.largeFileSystem:
|
3037 | 3025 | (git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents)
|
|
0 commit comments