Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 14384:9d59c596eb9e
patch: construct and parse binary hunks at the same time
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Thu, 19 May 2011 22:44:01 +0200 |
parents | 1bd52cb12a55 |
children | 7709cc983025 |
comparison
equal
deleted
inserted
replaced
14383:1bd52cb12a55 | 14384:9d59c596eb9e |
---|---|
958 def new(self, fuzz=0, toponly=False): | 958 def new(self, fuzz=0, toponly=False): |
959 return self.fuzzit(self.b, fuzz, toponly) | 959 return self.fuzzit(self.b, fuzz, toponly) |
960 | 960 |
961 class binhunk: | 961 class binhunk: |
962 'A binary patch file. Only understands literals so far.' | 962 'A binary patch file. Only understands literals so far.' |
963 def __init__(self, gitpatch): | 963 def __init__(self, gitpatch, lr): |
964 self.gitpatch = gitpatch | 964 self.gitpatch = gitpatch |
965 self.text = None | 965 self.text = None |
966 self.hunk = ['GIT binary patch\n'] | 966 self.hunk = ['GIT binary patch\n'] |
967 self._read(lr) | |
967 | 968 |
968 def createfile(self): | 969 def createfile(self): |
969 return self.gitpatch.op == 'ADD' | 970 return self.gitpatch.op == 'ADD' |
970 | 971 |
971 def rmfile(self): | 972 def rmfile(self): |
975 return self.text is not None | 976 return self.text is not None |
976 | 977 |
977 def new(self): | 978 def new(self): |
978 return [self.text] | 979 return [self.text] |
979 | 980 |
980 def extract(self, lr): | 981 def _read(self, lr): |
981 line = lr.readline() | 982 line = lr.readline() |
982 self.hunk.append(line) | 983 self.hunk.append(line) |
983 while line and not line.startswith('literal '): | 984 while line and not line.startswith('literal '): |
984 line = lr.readline() | 985 line = lr.readline() |
985 self.hunk.append(line) | 986 self.hunk.append(line) |
1133 (not context and x[0] == '@') | 1134 (not context and x[0] == '@') |
1134 or (context is not False and x.startswith('***************')) | 1135 or (context is not False and x.startswith('***************')) |
1135 or x.startswith('GIT binary patch')): | 1136 or x.startswith('GIT binary patch')): |
1136 gp = changed.get(bfile) | 1137 gp = changed.get(bfile) |
1137 if x.startswith('GIT binary patch'): | 1138 if x.startswith('GIT binary patch'): |
1138 h = binhunk(gp) | 1139 h = binhunk(gp, lr) |
1139 h.extract(lr) | |
1140 afile = 'a/' + afile | 1140 afile = 'a/' + afile |
1141 bfile = 'b/' + bfile | 1141 bfile = 'b/' + bfile |
1142 else: | 1142 else: |
1143 if context is None and x.startswith('***************'): | 1143 if context is None and x.startswith('***************'): |
1144 context = True | 1144 context = True |