changeset 4584:fd8dada76730

evolve: warn user for the metadata being lost in public divergence resolution This patch print warnings if some "extras" of a divergent changeset that is possibly important metadata which is being lost during the resolution of public divergence.
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Sat, 09 Mar 2019 19:35:45 +0530
parents 4fcf9a71befc
children d871c8a92dee
files hgext3rd/evolve/evolvecmd.py tests/test-evolve-public-content-divergent-discard.t
diffstat 2 files changed, 113 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/evolvecmd.py	Wed Apr 17 21:16:17 2019 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sat Mar 09 19:35:45 2019 +0530
@@ -615,10 +615,7 @@
         s = publicdiv.status()
         if not (s.added or s.removed or s.deleted or s.modified):
             # warn user if metadata is being lost
-            if otherdiv.description() != publicdiv.description():
-                msg = _('content-divergent changesets differ by descriptions '
-                        'only, discarding %s\n') % str(otherdiv)
-                repo.ui.warn(msg)
+            warnmetadataloss(repo, publicdiv, otherdiv)
             # no changes, create markers to resolve divergence
             obsolete.createmarkers(repo, [(otherdiv, (publicdiv,))],
                                    operation='evolve')
@@ -675,6 +672,45 @@
     finally:
         repo.ui.restoreconfig(emtpycommitallowed)
 
+def warnmetadataloss(repo, local, other):
+    """warn the user for the metadata being lost while resolving
+    public content-divergence"""
+
+    # needtowarn: aspects where we need to warn user
+    needtowarn = ['branch', 'topic', 'close']
+    aspects = set()
+    localextra = local.extra()
+    otherextra = other.extra()
+
+    for asp in needtowarn:
+        otherasp = otherextra.get(asp)
+        localasp = localextra.get(asp)
+        if otherasp and otherasp != localasp:
+            aspects.add(asp)
+
+    if other.description() != local.description():
+        aspects.add('description')
+
+    if aspects:
+        # warn user
+        locstr = str(local)
+        othstr = str(other)
+        if 'close' in aspects:
+            filteredasp = aspects - {'close'}
+            if filteredasp:
+                msg = _('other divergent changeset %s is a closed branch head '
+                        'and differs from local %s by "%s" only,' %
+                        (othstr, locstr, ', '.join(sorted(filteredasp))))
+            else:
+                msg = _('other divergent changeset %s is a closed branch head '
+                        'and has same content as local %s,' % (othstr, locstr))
+        else:
+            msg = _('other divergent changeset %s has same content as local %s'
+                    ' and differs by "%s" only,' %
+                    (othstr, locstr, ', '.join(sorted(aspects))))
+        msg += _(' discarding %s\n' % othstr)
+        repo.ui.warn(msg)
+
 def bypassphase(repo, relation, flag=0, metadata=None, operation='evolve'):
     """function to create a single obsmarker relation even for public csets
     where relation should be a single pair (prec, succ)"""
--- a/tests/test-evolve-public-content-divergent-discard.t	Wed Apr 17 21:16:17 2019 +0530
+++ b/tests/test-evolve-public-content-divergent-discard.t	Sat Mar 09 19:35:45 2019 +0530
@@ -92,7 +92,7 @@
   base: [2] added c
   merging "other" content-divergent changeset '90522bccf499'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  content-divergent changesets differ by descriptions only, discarding 90522bccf499
+  other divergent changeset 90522bccf499 has same content as local f7c1071f1e7c and differs by "description" only, discarding 90522bccf499
   content divergence resolution between f7c1071f1e7c (public) and 90522bccf499 has same content as f7c1071f1e7c, discarding 90522bccf499
 
   $ hg evolve -l
@@ -186,7 +186,7 @@
   updating to "local" side of the conflict: e800202333a4
   merging "other" content-divergent changeset 'ae3429430ef1'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  content-divergent changesets differ by descriptions only, discarding ae3429430ef1
+  other divergent changeset ae3429430ef1 has same content as local e800202333a4 and differs by "description" only, discarding ae3429430ef1
   content divergence resolution between e800202333a4 (public) and ae3429430ef1 has same content as e800202333a4, discarding ae3429430ef1
 
   $ hg evolve -l
@@ -293,7 +293,7 @@
   continue: hg evolve --continue
 
   $ hg evolve --continue
-  content-divergent changesets differ by descriptions only, discarding 229da2719b19
+  other divergent changeset 229da2719b19 has same content as local f7c1071f1e7c and differs by "description" only, discarding 229da2719b19
   working directory is now at f7c1071f1e7c
 
   $ hg evolve -l
@@ -400,7 +400,7 @@
   updating to "local" side of the conflict: e800202333a4
   merging "other" content-divergent changeset 'bc309da55b88'
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  content-divergent changesets differ by descriptions only, discarding bc309da55b88
+  other divergent changeset bc309da55b88 has same content as local e800202333a4 and differs by "description" only, discarding bc309da55b88
   working directory is now at e800202333a4
 
   $ hg evolve -l
@@ -505,7 +505,7 @@
   continue: hg evolve --continue
 
   $ hg evolve --continue
-  content-divergent changesets differ by descriptions only, discarding a5bbf2042450
+  other divergent changeset a5bbf2042450 has same content as local e800202333a4 and differs by "description" only, discarding a5bbf2042450
   working directory is now at e800202333a4
 
   $ hg evolve -l
@@ -623,7 +623,7 @@
   continue: hg evolve --continue
 
   $ hg evolve --continue
-  content-divergent changesets differ by descriptions only, discarding 09054d1f3c97
+  other divergent changeset 09054d1f3c97 has same content as local e800202333a4 and differs by "description" only, discarding 09054d1f3c97
   working directory is now at e800202333a4
 
   $ hg evolve -l
@@ -637,3 +637,70 @@
   summary:     added d
   
   $ cd ..
+
+Testing that we warn the user for the metadata being lost in divergence resolution:
+-----------------------------------------------------------------------------------
+
+  $ hg init pubdiv7
+  $ cd pubdiv7
+  $ for ch in a b c d; do
+  >   echo $ch > $ch;
+  >   hg ci -Am "added "$ch;
+  > done;
+  adding a
+  adding b
+  adding c
+  adding d
+
+  $ echo dada > d
+  $ hg amend
+  $ hg up -r "desc('added c')"
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch feature
+  marked working directory as branch feature
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo dada > d
+  $ hg ci -Am "added d"
+  adding d
+  $ hg prune -r "min(desc('added d'))" -s . --hidden
+  1 changesets pruned
+  2 new content-divergent changesets
+
+(publish one side)
+  $ hg phase --public
+  $ hg up -r "draft()"
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+(make other divergent a closed branch head)
+  $ hg ci --amend -m "closing feature branch" --close-branch
+
+  $ hg glog
+  @  6:af442315d198 closing feature branch
+  |   draft content-divergent
+  |
+  | o  5:497d0d2b90ba added d
+  |/    public
+  |
+  o  2:155349b645be added c
+  |   public
+  |
+  o  1:5f6d8a4bf34a added b
+  |   public
+  |
+  o  0:9092f1db7931 added a
+      public
+  
+
+Run automatic evolution:
+
+  $ hg evolve --content-divergent
+  merge:[5] added d
+  with: [6] closing feature branch
+  base: [3] added d
+  updating to "local" side of the conflict: 497d0d2b90ba
+  merging "other" content-divergent changeset 'af442315d198'
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  other divergent changeset af442315d198 is a closed branch head and differs from local 497d0d2b90ba by "branch, description" only, discarding af442315d198
+  content divergence resolution between 497d0d2b90ba (public) and af442315d198 has same content as 497d0d2b90ba, discarding af442315d198
+  working directory is now at 497d0d2b90ba
+