hghooks: refactor code to facilitate more complex conditionals; r?smacleod
This will make the next commit easier to read. While we could retain a
list comprehension in the next commit, we want to avoid constructing
changectx for perf reasons.
MozReview-Commit-ID: FpaxVqbIZsf
--- a/hghooks/mozhghooks/single_head_per_branch.py
+++ b/hghooks/mozhghooks/single_head_per_branch.py
@@ -16,18 +16,26 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
def hook(ui, repo, source=None, **kwargs):
if source in ('pull', 'strip'):
return 0
for branch, heads in repo.branchmap().iteritems():
- # Filter closed branch heads.
- heads = [h for h in heads if not repo[h].closesbranch()]
+ newheads = []
+
+ for node in heads:
+ ctx = repo[node]
- if len(heads) > 1:
+ # Filter closed branch heads.
+ if ctx.closesbranch():
+ continue
+
+ newheads.append(node)
+
+ if len(newheads) > 1:
print "\n\n************************** ERROR ****************************"
print "Multiple heads detected on branch '%s'" % branch
print "Only one head per branch is allowed!"
print "*************************************************************\n\n"
return 1
return 0