Patchwork D7043: phabricator: add the phabchange data structure

login
register
mail settings
Submitter phabricator
Date Oct. 12, 2019, 1:56 a.m.
Message ID <314fd2a47f86cf5a49c4bc67cd55ba6b@localhost.localdomain>
Download mbox | patch
Permalink /patch/42244/
State Not Applicable
Headers show

Comments

phabricator - Oct. 12, 2019, 1:56 a.m.
Closed by commit rHG99ee4afd352f: phabricator: add the phabchange data structure (authored by Kwan).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7043?vs=17074&id=17091

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7043/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7043

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: Kwan, #hg-reviewers, indygreg
Cc: mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -481,6 +481,47 @@ 
     delLines = attr.ib(default=0)  # camelcase-required
 
 
+@attr.s
+class phabchange(object):
+    """Represents a Differential change, owns Differential hunks and owned by a
+    Differential diff.  Each one represents one file in a diff.
+    """
+
+    currentPath = attr.ib(default=None)  # camelcase-required
+    oldPath = attr.ib(default=None)  # camelcase-required
+    awayPaths = attr.ib(default=attr.Factory(list))  # camelcase-required
+    metadata = attr.ib(default=attr.Factory(dict))
+    oldProperties = attr.ib(default=attr.Factory(dict))  # camelcase-required
+    newProperties = attr.ib(default=attr.Factory(dict))  # camelcase-required
+    type = attr.ib(default=DiffChangeType.CHANGE)
+    fileType = attr.ib(default=DiffFileType.TEXT)  # camelcase-required
+    commitHash = attr.ib(default=None)  # camelcase-required
+    addLines = attr.ib(default=0)  # camelcase-required
+    delLines = attr.ib(default=0)  # camelcase-required
+    hunks = attr.ib(default=attr.Factory(list))
+
+    def copynewmetadatatoold(self):
+        for key in list(self.metadata.keys()):
+            newkey = key.replace(b'new:', b'old:')
+            self.metadata[newkey] = self.metadata[key]
+
+    def addoldmode(self, value):
+        self.oldProperties[b'unix:filemode'] = value
+
+    def addnewmode(self, value):
+        self.newProperties[b'unix:filemode'] = value
+
+    def addhunk(self, hunk):
+        if not isinstance(hunk, phabhunk):
+            raise error.Abort(b'phabchange.addhunk only takes phabhunks')
+        self.hunks.append(hunk)
+        # It's useful to include these stats since the Phab web UI shows them,
+        # and uses them to estimate how large a change a Revision is. Also used
+        # in email subjects for the [+++--] bit.
+        self.addLines += hunk.addLines
+        self.delLines += hunk.delLines
+
+
 def creatediff(ctx):
     """create a Differential Diff"""
     repo = ctx.repo()