evolve: consider using three way merge to get the user for div resolution
authorSushil khanchi <sushilkhanchi97@gmail.com>
Sun, 05 May 2019 18:24:59 +0530
changeset 4636 c0e9a3c01c44
parent 4635 ea9ae2d2095a
child 4637 4a22dac48b42
evolve: consider using three way merge to get the user for div resolution This patch adds the logic to merge the users from two divergent csets considering the base (i.e three way merge). The case when all the three are different, we concatenate the two authors of divergent csets.
hgext3rd/evolve/evolvecmd.py
hgext3rd/evolve/utility.py
tests/test-evolve-content-divergent-meta.t
--- a/hgext3rd/evolve/evolvecmd.py	Sun May 05 18:24:50 2019 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sun May 05 18:24:59 2019 +0530
@@ -628,13 +628,14 @@
         desc = mergecommitmessages(ui, base.description(),
                                    divergent.description(),
                                    other.description())
+        user = utility.mergeusers(ui, base, divergent, other)
 
         # new node if any formed as the replacement
         newnode = None
 
         mergehook(repo, base, divergent, other)
 
-        newnode = repo.commit(text=desc, user=other.user())
+        newnode = repo.commit(text=desc, user=user)
         if newnode == divergent.node() or newnode is None:
             # no changes
             new = divergent
--- a/hgext3rd/evolve/utility.py	Sun May 05 18:24:50 2019 +0530
+++ b/hgext3rd/evolve/utility.py	Sun May 05 18:24:59 2019 +0530
@@ -187,3 +187,26 @@
         return None
 
     return revs[intidx - 1]
+
+def mergeusers(ui, base, divergent, other):
+    """ merges the users from two divergent changesets using three-way merge
+    and return the user that will be used as the author of resolved cset"""
+    baseuser = base.user()
+    divuser = divergent.user()
+    othuser = other.user()
+
+    if divuser == othuser:
+        return divuser
+    else:
+        if baseuser == divuser:
+            return othuser
+        elif baseuser == othuser:
+            return divuser
+        else:
+            # all three are different, lets concatenate the two authors
+            # XXX: should we let the user know about concatenation of authors
+            #      by printing some message (or maybe in verbose mode)
+            users = set(divuser.split(', '))
+            users.update(othuser.split(', '))
+            user = ', '.join(sorted(users))
+            return user
--- a/tests/test-evolve-content-divergent-meta.t	Sun May 05 18:24:50 2019 +0530
+++ b/tests/test-evolve-content-divergent-meta.t	Sun May 05 18:24:59 2019 +0530
@@ -151,9 +151,9 @@
   with: [5] updated c
   base: [2] added c
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  working directory is now at 85c4e0b92028
+  working directory is now at 202a770d8c1f
 
   $ hg log -r tip | grep "^user"
-  user:        baruser
+  user:        baruser, foouser
 
   $ cd ..