Patchwork D7050: phabricator: add addadded function

login
register
mail settings
Submitter phabricator
Date Oct. 11, 2019, 5:55 p.m.
Message ID <5a1430db0d8b659c0be829f1a5fc5a8e@localhost.localdomain>
Download mbox | patch
Permalink /patch/42233/
State Not Applicable
Headers show

Comments

phabricator - Oct. 11, 2019, 5:55 p.m.
Kwan added a comment.
Kwan updated this revision to Diff 17081.


  Fix some test-check-code issues, and one test-check-pyflakes unused local.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7050?vs=17056&id=17081

BRANCH
  default

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

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

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




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

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -722,6 +722,71 @@ 
         pdiff.addchange(pchange)
 
 
+def addadded(pdiff, ctx, added, removed):
+    """add file adds to the phabdiff, both new files and copies/moves"""
+    # Keep track of files that've been recorded as moved/copied, so if there are
+    # additional copies we can mark them (moves get removed from removed)
+    copiedchanges = {}
+    movedchanges = {}
+    for fname in added:
+        fctx = ctx[fname]
+        pchange = phabchange(currentPath=fname)
+
+        filemode = gitmode[ctx[fname].flags()]
+        renamed = fctx.renamed()
+
+        if renamed:
+            originalfname = renamed[0]
+            originalmode = gitmode[ctx.p1()[originalfname].flags()]
+            pchange.oldPath = originalfname
+
+            if originalfname in removed:
+                origpchange = phabchange(
+                    currentPath=originalfname,
+                    oldPath=originalfname,
+                    type=DiffChangeType.MOVE_AWAY,
+                    awayPaths=[fname],
+                )
+                movedchanges[originalfname] = origpchange
+                removed.remove(originalfname)
+                pchange.type = DiffChangeType.MOVE_HERE
+            elif originalfname in movedchanges:
+                movedchanges[originalfname].type = DiffChangeType.MULTICOPY
+                movedchanges[originalfname].awayPaths.append(fname)
+                pchange.type = DiffChangeType.COPY_HERE
+            else:  # pure copy
+                if originalfname not in copiedchanges:
+                    origpchange = phabchange(
+                        currentPath=originalfname, type=DiffChangeType.COPY_AWAY
+                    )
+                    copiedchanges[originalfname] = origpchange
+                else:
+                    origpchange = copiedchanges[originalfname]
+                origpchange.awayPaths.append(fname)
+                pchange.type = DiffChangeType.COPY_HERE
+
+            if filemode != originalmode:
+                pchange.addoldmode(originalmode)
+                pchange.addnewmode(filemode)
+        else:  # Brand-new file
+            pchange.addnewmode(gitmode[fctx.flags()])
+            pchange.type = DiffChangeType.ADD
+
+        if fctx.isbinary():
+            makebinary(pchange, fctx)
+            if renamed:
+                addoldbinary(pchange, fctx, originalfname)
+        else:
+            maketext(pchange, ctx, fname)
+
+        pdiff.addchange(pchange)
+
+    for _path, copiedchange in copiedchanges.items():
+        pdiff.addchange(copiedchange)
+    for _path, movedchange in movedchanges.items():
+        pdiff.addchange(movedchange)
+
+
 def creatediff(ctx):
     """create a Differential Diff"""
     repo = ctx.repo()