Patchwork [3,of,7,mergedriver] mergestate: add a method to return updated/merged/removed counts

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 21, 2015, 1:03 a.m.
Message ID <fa34efec3ea506994c9d.1448067838@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11559/
State Accepted
Commit 09139ccf3085e5a5acf9bb2cd70f66668fe93703
Delegated to: Martin von Zweigbergk
Headers show

Comments

Siddharth Agarwal - Nov. 21, 2015, 1:03 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1448065074 28800
#      Fri Nov 20 16:17:54 2015 -0800
# Node ID fa34efec3ea506994c9de30357f68d09aee0f744
# Parent  2712ae8efb1942f3ac0f1b3b3a67e5fb3a8df9e3
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r fa34efec3ea5
mergestate: add a method to return updated/merged/removed counts

This will not only allow us to remove a bunch of duplicate code in applyupdates
in an upcoming patch, it will also allow the resolve interface to be a lot
simpler: it doesn't need to return the dirstate action to applyupdates.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -490,6 +490,20 @@  class mergestate(object):
         Returns the exit code of the merge."""
         return self._resolve(False, dfile, wctx, labels=labels)[1]
 
+    def counts(self):
+        """return counts for updated, merged and removed files in this
+        session"""
+        updated, merged, removed = 0, 0, 0
+        for r, action in self._results.itervalues():
+            if r is None:
+                updated += 1
+            elif r == 0:
+                if action == 'r':
+                    removed += 1
+                else:
+                    merged += 1
+        return updated, merged, removed
+
 def _checkunknownfile(repo, wctx, mctx, f, f2=None):
     if f2 is None:
         f2 = f