Patchwork [1,of,5] merge: prevent simplemerge from mutating label list

login
register
mail settings
Submitter Durham Goode
Date May 9, 2014, 12:33 a.m.
Message ID <86c73023576a450fd7c6.1399595606@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/4685/
State Accepted
Commit 4aeb7a6029bafb4847bb27604a97d70ea1ee0fde
Headers show

Comments

Durham Goode - May 9, 2014, 12:33 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1399591986 25200
#      Thu May 08 16:33:06 2014 -0700
# Node ID 86c73023576a450fd7c61a22cdb9fb82ad504e4b
# Parent  62a2749895e4151f766a4243fa870b1ddd7386d0
merge: prevent simplemerge from mutating label list

simplemerge was using list.pop() to remove items from the labels list. This
mutated the list and made it unusable by other calls (for instance, it might be
used in both the premerge and actual merge stages).

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -416,11 +416,11 @@ 
     name_a = local
     name_b = other
     labels = opts.get('label', [])
-    if labels:
-        name_a = labels.pop(0)
-    if labels:
-        name_b = labels.pop(0)
-    if labels:
+    if len(labels) > 0:
+        name_a = labels[0]
+    if len(labels) > 1:
+        name_b = labels[1]
+    if len(labels) > 2:
         raise util.Abort(_("can only specify two labels."))
 
     try: