hghooks: refactor code to facilitate more complex conditionals; r?smacleod draft
authorGregory Szorc <gps@mozilla.com>
Wed, 14 Dec 2016 15:44:13 -0800
changeset 10055 5514a5068cfe7a9fb917c29c539d509cb81a94d7
parent 10054 f1e5524cb68e2cb765e4d9eb6e70ef58e30d314d
child 10056 7f1af2d417a4c2684cee92d0e8fad15099f09ad0
push id1417
push userbmo:gps@mozilla.com
push dateWed, 14 Dec 2016 23:54:52 +0000
reviewerssmacleod
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
hghooks/mozhghooks/single_head_per_branch.py
--- 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