Show More
@@ -366,16 +366,16 b' class abstractbackend(object):' | |||||
366 | def __init__(self, ui): |
|
366 | def __init__(self, ui): | |
367 | self.ui = ui |
|
367 | self.ui = ui | |
368 |
|
368 | |||
369 |
def |
|
369 | def getfile(self, fname): | |
370 |
"""Return target file |
|
370 | """Return target file data and flags as a (data, (islink, | |
371 | for symlinks. |
|
371 | isexec)) tuple. | |
372 | """ |
|
372 | """ | |
373 | raise NotImplementedError |
|
373 | raise NotImplementedError | |
374 |
|
374 | |||
375 |
def setfile(self, fname, |
|
375 | def setfile(self, fname, data, mode): | |
376 |
"""Write |
|
376 | """Write data to target file fname and set its mode. mode is a | |
377 | tuple, or None if there is no mode information. If lines is None, |
|
377 | (islink, isexec) tuple. If data is None, the file content should | |
378 | the file must exists and its content is left unchanged. |
|
378 | be left unchanged. | |
379 | """ |
|
379 | """ | |
380 | raise NotImplementedError |
|
380 | raise NotImplementedError | |
381 |
|
381 | |||
@@ -408,35 +408,28 b' class fsbackend(abstractbackend):' | |||||
408 | def _join(self, f): |
|
408 | def _join(self, f): | |
409 | return os.path.join(self.opener.base, f) |
|
409 | return os.path.join(self.opener.base, f) | |
410 |
|
410 | |||
411 |
def |
|
411 | def getfile(self, fname): | |
412 |
|
|
412 | path = self._join(fname) | |
413 | return [os.readlink(self._join(fname))] |
|
413 | if os.path.islink(path): | |
414 | fp = self.opener(fname, 'r') |
|
414 | return (os.readlink(path), (True, False)) | |
415 | try: |
|
|||
416 | return list(fp) |
|
|||
417 | finally: |
|
|||
418 | fp.close() |
|
|||
419 |
|
||||
420 | def setfile(self, fname, lines, mode): |
|
|||
421 | if lines is None: |
|
|||
422 | if mode: |
|
|||
423 | util.setflags(self._join(fname), mode[0], mode[1]) |
|
|||
424 | return |
|
|||
425 | if not mode: |
|
|||
426 | # Preserve mode information |
|
|||
427 |
|
|
415 | isexec, islink = False, False | |
428 |
|
|
416 | try: | |
429 |
|
|
417 | isexec = os.lstat(path).st_mode & 0100 != 0 | |
430 |
|
|
418 | islink = os.path.islink(path) | |
431 |
|
|
419 | except OSError, e: | |
432 |
|
|
420 | if e.errno != errno.ENOENT: | |
433 |
|
|
421 | raise | |
434 | else: |
|
422 | return (self.opener.read(fname), (islink, isexec)) | |
|
423 | ||||
|
424 | def setfile(self, fname, data, mode): | |||
435 |
|
|
425 | islink, isexec = mode | |
|
426 | if data is None: | |||
|
427 | util.setflags(self._join(fname), islink, isexec) | |||
|
428 | return | |||
436 | if islink: |
|
429 | if islink: | |
437 |
self.opener.symlink( |
|
430 | self.opener.symlink(data, fname) | |
438 | else: |
|
431 | else: | |
439 |
self.opener(fname, |
|
432 | self.opener.write(fname, data) | |
440 | if isexec: |
|
433 | if isexec: | |
441 | util.setflags(self._join(fname), False, True) |
|
434 | util.setflags(self._join(fname), False, True) | |
442 |
|
435 | |||
@@ -485,8 +478,8 b' class workingbackend(fsbackend):' | |||||
485 | self.changed = set() |
|
478 | self.changed = set() | |
486 | self.copied = [] |
|
479 | self.copied = [] | |
487 |
|
480 | |||
488 |
def setfile(self, fname, |
|
481 | def setfile(self, fname, data, mode): | |
489 |
super(workingbackend, self).setfile(fname, |
|
482 | super(workingbackend, self).setfile(fname, data, mode) | |
490 | self.changed.add(fname) |
|
483 | self.changed.add(fname) | |
491 |
|
484 | |||
492 | def unlink(self, fname): |
|
485 | def unlink(self, fname): | |
@@ -534,7 +527,11 b' class patchfile(object):' | |||||
534 | self.mode = mode |
|
527 | self.mode = mode | |
535 | if not missing: |
|
528 | if not missing: | |
536 | try: |
|
529 | try: | |
537 |
|
|
530 | data, mode = self.backend.getfile(fname) | |
|
531 | if data: | |||
|
532 | self.lines = data.splitlines(True) | |||
|
533 | if self.mode is None: | |||
|
534 | self.mode = mode | |||
538 | if self.lines: |
|
535 | if self.lines: | |
539 | # Normalize line endings |
|
536 | # Normalize line endings | |
540 | if self.lines[0].endswith('\r\n'): |
|
537 | if self.lines[0].endswith('\r\n'): | |
@@ -550,7 +547,8 b' class patchfile(object):' | |||||
550 | self.lines = nlines |
|
547 | self.lines = nlines | |
551 | self.exists = True |
|
548 | self.exists = True | |
552 | except IOError: |
|
549 | except IOError: | |
553 |
|
|
550 | if self.mode is None: | |
|
551 | self.mode = (False, False) | |||
554 | else: |
|
552 | else: | |
555 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) |
|
553 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) | |
556 |
|
554 | |||
@@ -579,7 +577,7 b' class patchfile(object):' | |||||
579 | rawlines.append(l) |
|
577 | rawlines.append(l) | |
580 | lines = rawlines |
|
578 | lines = rawlines | |
581 |
|
579 | |||
582 | self.backend.setfile(fname, lines, mode) |
|
580 | self.backend.setfile(fname, ''.join(lines), mode) | |
583 |
|
581 | |||
584 | def printfile(self, warn): |
|
582 | def printfile(self, warn): | |
585 | if self.fileprinted: |
|
583 | if self.fileprinted: | |
@@ -1250,7 +1248,7 b' def _applydiff(ui, fp, patcher, backend,' | |||||
1250 | if gp.op == 'ADD': |
|
1248 | if gp.op == 'ADD': | |
1251 | # Added files without content have no hunk and |
|
1249 | # Added files without content have no hunk and | |
1252 | # must be created |
|
1250 | # must be created | |
1253 |
data = |
|
1251 | data = '' | |
1254 | backend.setfile(path, data, gp.mode) |
|
1252 | backend.setfile(path, data, gp.mode) | |
1255 | if not first_hunk: |
|
1253 | if not first_hunk: | |
1256 | continue |
|
1254 | continue |
General Comments 0
You need to be logged in to leave comments.
Login now