##// END OF EJS Templates
patch: handle symlinks without symlinkhunk...
Patrick Mezard -
r9585:ea1935e2 default
parent child Browse files
Show More
@@ -292,6 +292,8 b' class patchfile(object):'
292 self.hunks = 0
292 self.hunks = 0
293
293
294 def readlines(self, fname):
294 def readlines(self, fname):
295 if os.path.islink(fname):
296 return [os.readlink(fname)]
295 fp = self.opener(fname, 'r')
297 fp = self.opener(fname, 'r')
296 try:
298 try:
297 return list(linereader(fp, self.eol is not None))
299 return list(linereader(fp, self.eol is not None))
@@ -405,7 +407,7 b' class patchfile(object):'
405 self.rej.append(h)
407 self.rej.append(h)
406 return -1
408 return -1
407
409
408 if isinstance(h, githunk):
410 if isinstance(h, binhunk):
409 if h.rmfile():
411 if h.rmfile():
410 self.unlink(self.fname)
412 self.unlink(self.fname)
411 else:
413 else:
@@ -696,12 +698,12 b' class hunk(object):'
696 def new(self, fuzz=0, toponly=False):
698 def new(self, fuzz=0, toponly=False):
697 return self.fuzzit(self.b, fuzz, toponly)
699 return self.fuzzit(self.b, fuzz, toponly)
698
700
699 class githunk(object):
701 class binhunk:
700 """A git hunk"""
702 'A binary patch file. Only understands literals so far.'
701 def __init__(self, gitpatch):
703 def __init__(self, gitpatch):
702 self.gitpatch = gitpatch
704 self.gitpatch = gitpatch
703 self.text = None
705 self.text = None
704 self.hunk = []
706 self.hunk = ['GIT binary patch\n']
705
707
706 def createfile(self):
708 def createfile(self):
707 return self.gitpatch.op in ('ADD', 'RENAME', 'COPY')
709 return self.gitpatch.op in ('ADD', 'RENAME', 'COPY')
@@ -715,12 +717,6 b' class githunk(object):'
715 def new(self):
717 def new(self):
716 return [self.text]
718 return [self.text]
717
719
718 class binhunk(githunk):
719 'A binary patch file. Only understands literals so far.'
720 def __init__(self, gitpatch):
721 super(binhunk, self).__init__(gitpatch)
722 self.hunk = ['GIT binary patch\n']
723
724 def extract(self, lr):
720 def extract(self, lr):
725 line = lr.readline()
721 line = lr.readline()
726 self.hunk.append(line)
722 self.hunk.append(line)
@@ -748,18 +744,6 b' class binhunk(githunk):'
748 len(text), size)
744 len(text), size)
749 self.text = text
745 self.text = text
750
746
751 class symlinkhunk(githunk):
752 """A git symlink hunk"""
753 def __init__(self, gitpatch, hunk):
754 super(symlinkhunk, self).__init__(gitpatch)
755 self.hunk = hunk
756
757 def complete(self):
758 return True
759
760 def fix_newline(self):
761 return
762
763 def parsefilename(str):
747 def parsefilename(str):
764 # --- filename \t|space stuff
748 # --- filename \t|space stuff
765 s = str[4:].rstrip('\r\n')
749 s = str[4:].rstrip('\r\n')
@@ -897,10 +881,6 b' def iterhunks(ui, fp, sourcefile=None, t'
897 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
881 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
898 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
882 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
899 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)
883 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)
900 if remove:
901 gpatch = changed.get(afile[2:])
902 if gpatch and gpatch.mode[0]:
903 current_hunk = symlinkhunk(gpatch, current_hunk)
904 except PatchError, err:
884 except PatchError, err:
905 ui.debug(err)
885 ui.debug(err)
906 current_hunk = None
886 current_hunk = None
@@ -1,9 +1,11 b''
1 a -> a not a symlink
1 a -> a not a symlink
2 % test replacing a file with a symlink
2 a -> b
3 a -> b
3 now at: base.patch
4 now at: base.patch
4 applying symlink.patch
5 applying symlink.patch
5 now at: symlink.patch
6 now at: symlink.patch
6 a -> b
7 a -> b
8 % test symlink removal
7 now at: symlink.patch
9 now at: symlink.patch
8 applying removesl.patch
10 applying removesl.patch
9 now at: removesl.patch
11 now at: removesl.patch
General Comments 0
You need to be logged in to leave comments. Login now