changeset 43190:c19b327017b9

phabricator: add addremoved and addmodified functions These are relatively simple so add them together. As the name indicates, these add phabchange objects for removed and modified files to the phabdiff. Differential Revision: https://phab.mercurial-scm.org/D7049
author Ian Moody <moz-ian@perix.co.uk>
date Sun, 06 Oct 2019 16:57:26 +0100
parents 9f802243a42e
children 5ed1abd0ea26
files hgext/phabricator.py
diffstat 1 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Sun Oct 06 15:37:13 2019 +0100
+++ b/hgext/phabricator.py	Sun Oct 06 16:57:26 2019 +0100
@@ -684,6 +684,44 @@
             pchange.fileType = DiffFileType.IMAGE
 
 
+# Copied from mercurial/patch.py
+gitmode = {b'l': b'120000', b'x': b'100755', b'': b'100644'}
+
+
+def addremoved(pdiff, ctx, removed):
+    """add removed files to the phabdiff. Shouldn't include moves"""
+    for fname in removed:
+        pchange = phabchange(
+            currentPath=fname, oldPath=fname, type=DiffChangeType.DELETE
+        )
+        pchange.addoldmode(gitmode[ctx.p1()[fname].flags()])
+        fctx = ctx.p1()[fname]
+        if not fctx.isbinary():
+            maketext(pchange, ctx, fname)
+
+        pdiff.addchange(pchange)
+
+
+def addmodified(pdiff, ctx, modified):
+    """add modified files to the phabdiff"""
+    for fname in modified:
+        fctx = ctx[fname]
+        pchange = phabchange(currentPath=fname, oldPath=fname)
+        filemode = gitmode[ctx[fname].flags()]
+        originalmode = gitmode[ctx.p1()[fname].flags()]
+        if filemode != originalmode:
+            pchange.addoldmode(originalmode)
+            pchange.addnewmode(filemode)
+
+        if fctx.isbinary():
+            makebinary(pchange, fctx)
+            addoldbinary(pchange, fctx, fname)
+        else:
+            maketext(pchange, ctx, fname)
+
+        pdiff.addchange(pchange)
+
+
 def creatediff(ctx):
     """create a Differential Diff"""
     repo = ctx.repo()