@@ -1858,7 +1858,9 @@ EXAMPLES
1858
1858
messages .add_argument ('--replace-message' , metavar = 'EXPRESSIONS_FILE' ,
1859
1859
help = _ ("A file with expressions that, if found in commit messages, "
1860
1860
"will be replaced. This file uses the same syntax as "
1861
- "--replace-text." ))
1861
+ "--replace-text, with an optional commit ID filter. You can "
1862
+ "end the line with '@commitID#' and a commit ID to "
1863
+ "restrict the replacement expression to a particular commit." ))
1862
1864
messages .add_argument ('--preserve-commit-hashes' , action = 'store_true' ,
1863
1865
help = _ ("By default, since commits are rewritten and thus gain new "
1864
1866
"hashes, references to old commit hashes in commit messages "
@@ -2110,7 +2112,13 @@ EXAMPLES
2110
2112
with open (filename , 'br' ) as f :
2111
2113
for line in f :
2112
2114
line = line .rstrip (b'\r \n ' )
2113
-
2115
+
2116
+ # Determine the commit ID (if available)
2117
+ commitIDfound = False
2118
+ if b'@commitID#' in line :
2119
+ line , commitID = line .rsplit (b'@commitID#' , 1 )
2120
+ commitIDfound = True
2121
+
2114
2122
# Determine the replacement
2115
2123
replacement = FilteringOptions .default_replace_text
2116
2124
if b'==>' in line :
@@ -2123,14 +2131,20 @@ EXAMPLES
2123
2131
elif line .startswith (b'glob:' ):
2124
2132
regex = glob_to_regex (line [5 :])
2125
2133
if regex :
2126
- replace_regexes .append ((re .compile (regex ), replacement ))
2134
+ if (commitIDfound ):
2135
+ replace_regexes .append ((commitID , re .compile (regex ), replacement ))
2136
+ else :
2137
+ replace_regexes .append ((re .compile (regex ), replacement ))
2127
2138
else :
2128
2139
# Otherwise, find the literal we need to replace
2129
2140
if line .startswith (b'literal:' ):
2130
2141
line = line [8 :]
2131
2142
if not line :
2132
2143
continue
2133
- replace_literals .append ((line , replacement ))
2144
+ if (commitIDfound ):
2145
+ replace_literals .append ((commitID , line , replacement ))
2146
+ else :
2147
+ replace_literals .append ((line , replacement ))
2134
2148
return {'literals' : replace_literals , 'regexes' : replace_regexes }
2135
2149
2136
2150
@staticmethod
@@ -3404,13 +3418,22 @@ class RepoFilter(object):
3404
3418
if not self ._args .preserve_commit_hashes :
3405
3419
commit .message = self ._hash_re .sub (self ._translate_commit_hash ,
3406
3420
commit .message )
3407
- if self ._args .replace_message :
3408
- for literal , replacement in self ._args .replace_message ['literals' ]:
3421
+ for expressionTuple in self ._args .replace_message ['literals' ]:
3422
+ if (len (expressionTuple ) == 3 ):
3423
+ (replacementCommitID , literal , replacement ) = expressionTuple
3424
+ if (commit .original_id == replacementCommitID ):
3425
+ commit .message = commit .message .replace (literal , replacement )
3426
+ else :
3427
+ (literal , replacement ) = expressionTuple
3409
3428
commit .message = commit .message .replace (literal , replacement )
3410
- for regex , replacement in self ._args .replace_message ['regexes' ]:
3429
+ for expressionTuple in self ._args .replace_message ['regexes' ]:
3430
+ if (len (expressionTuple ) == 3 ):
3431
+ (replacementCommitID , regex , replacement ) = expressionTuple
3432
+ if (commit .original_id == replacementCommitID ):
3433
+ commit .message = regex .sub (replacement , commit .message )
3434
+ else :
3435
+ (regex , replacement ) = expressionTuple
3411
3436
commit .message = regex .sub (replacement , commit .message )
3412
- if self ._message_callback :
3413
- commit .message = self ._message_callback (commit .message )
3414
3437
3415
3438
# Change the author & committer according to mailmap rules
3416
3439
args = self ._args
0 commit comments