@@ -58,6 +58,10 @@ def __init__(self, config, cache_root):
58
58
self .try_syntax = config .get ("try_syntax" )
59
59
self .try_name = config .get ("try_name" , "try" )
60
60
self .default_revision = config .get ("default_revision" , "tip" )
61
+
62
+ # Apply patches to the latest revision when `True`.
63
+ self .use_latest_revision = config .get ("use_latest_revision" , False )
64
+
61
65
if self .try_mode == TryMode .syntax :
62
66
assert self .try_syntax , "Missing try syntax"
63
67
self ._repo = None
@@ -124,6 +128,15 @@ def has_revision(self, revision):
124
128
except hglib .error .CommandError :
125
129
return False
126
130
131
+ def get_base_identifier (self , needed_stack : list [PhabricatorPatch ]) -> str :
132
+ """Return the base identifier to apply patches against."""
133
+ if self .use_latest_revision :
134
+ # Use `tip` when `use_latest_revision` is `True`.
135
+ return "tip"
136
+
137
+ # Otherwise use the base/parent revision of first revision in the stack.
138
+ return needed_stack [0 ].base_revision
139
+
127
140
def apply_build (self , build ):
128
141
"""
129
142
Apply a stack of patches to mercurial repo
@@ -147,8 +160,9 @@ def apply_build(self, build):
147
160
logger .info ("All the patches are already applied" )
148
161
return
149
162
163
+ hg_base = self .get_base_identifier (needed_stack )
164
+
150
165
# When base revision is missing, update to default revision
151
- hg_base = needed_stack [0 ].base_revision
152
166
build .base_revision = hg_base
153
167
build .missing_base_revision = not self .has_revision (hg_base )
154
168
if build .missing_base_revision :
0 commit comments