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