Patchwork [2,of,3] patch: implement recordhunk.reversehunk

login
register
mail settings
Submitter Jun Wu
Date June 21, 2017, 3:45 a.m.
Message ID <4fddabb1c843b8068063.1498016733@x1c>
Download mbox | patch
Permalink /patch/21573/
State Changes Requested
Headers show

Comments

Jun Wu - June 21, 2017, 3:45 a.m.
# HG changeset patch
# User Jun Wu <quark@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

Patch

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)