From patchwork Fri Oct 11 17:55:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7049: phabricator: add addremoved and addmodified functions From: phabricator X-Patchwork-Id: 42232 Message-Id: <61cc5a08f8e29ce93700d7f5b07219fb@localhost.localdomain> To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Fri, 11 Oct 2019 17:55:13 +0000 Kwan added a comment. Kwan updated this revision to Diff 17080. 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/D7049?vs=17055&id=17080 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7049/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7049 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS To: Kwan, #hg-reviewers Cc: mercurial-devel diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -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()