[PATCH 2 of 3] patch: implement recordhunk.reversehunk

Jun Wu quark at fb.com
Tue Jun 20 23:45:33 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1498014668 25200
#      Tue Jun 20 20:11:08 2017 -0700
# Node ID 4fddabb1c843b8068063c98cabbb55b3b9276d64
# Parent  9b1db75aec5d7c6b6900c1afadddd9fa3e0cbe91
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 4fddabb1c843
patch: implement recordhunk.reversehunk

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -960,4 +960,10 @@ class recordhunk(object):
         return add, rem
 
+    def reversehunk(self):
+        m = {'+': '-', '-': '+'}
+        hunk = ['%s%s' % (m[l[0]], l[1:]) for l in self.hunk]
+        return recordhunk(self.header, self.toline, self.fromline, self.proc,
+                          self.before, hunk, self.after)
+
     def write(self, fp):
         delta = len(self.before) + len(self.after)


More information about the Mercurial-devel mailing list