comparison mercurial/subrepo.py @ 31099:b44ab288358e

subrepo: run the repo decoders when archiving The decoders were already run by default for the main repo, so this seemed like an oversight. The extdiff extension has been using 'archive' since 68822b7cdd01 to support -S, and a colleague noticed that after diffing, making changes, and closing it, the line endings were wrong for the diff-tool modified files in the subrepository. (Files in the parent repo were correct, with the same .hgeol settings.) The editor (Visual Studio in this case) reloads the file, but doesn't notice the EOL change. It still adds new lines with the original EOL setting, and the file ends up inconsistent. Without this change, the first file `cat`d in the test prints '\r (esc)' EOL, but the second doesn't on Windows or Linux.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 25 Feb 2017 21:13:59 -0500
parents 0fbb3a5c188e
children 96d561c90ad0
comparison
equal deleted inserted replaced
31098:876f08f30ade 31099:b44ab288358e
540 540
541 def files(self): 541 def files(self):
542 """return filename iterator""" 542 """return filename iterator"""
543 raise NotImplementedError 543 raise NotImplementedError
544 544
545 def filedata(self, name): 545 def filedata(self, name, decode):
546 """return file data""" 546 """return file data, optionally passed through repo decoders"""
547 raise NotImplementedError 547 raise NotImplementedError
548 548
549 def fileflags(self, name): 549 def fileflags(self, name):
550 """return file flags""" 550 """return file flags"""
551 return '' 551 return ''
556 556
557 def printfiles(self, ui, m, fm, fmt, subrepos): 557 def printfiles(self, ui, m, fm, fmt, subrepos):
558 """handle the files command for this subrepo""" 558 """handle the files command for this subrepo"""
559 return 1 559 return 1
560 560
561 def archive(self, archiver, prefix, match=None): 561 def archive(self, archiver, prefix, match=None, decode=True):
562 if match is not None: 562 if match is not None:
563 files = [f for f in self.files() if match(f)] 563 files = [f for f in self.files() if match(f)]
564 else: 564 else:
565 files = self.files() 565 files = self.files()
566 total = len(files) 566 total = len(files)
570 for i, name in enumerate(files): 570 for i, name in enumerate(files):
571 flags = self.fileflags(name) 571 flags = self.fileflags(name)
572 mode = 'x' in flags and 0o755 or 0o644 572 mode = 'x' in flags and 0o755 or 0o644
573 symlink = 'l' in flags 573 symlink = 'l' in flags
574 archiver.addfile(prefix + self._path + '/' + name, 574 archiver.addfile(prefix + self._path + '/' + name,
575 mode, symlink, self.filedata(name)) 575 mode, symlink, self.filedata(name, decode))
576 self.ui.progress(_('archiving (%s)') % relpath, i + 1, 576 self.ui.progress(_('archiving (%s)') % relpath, i + 1,
577 unit=_('files'), total=total) 577 unit=_('files'), total=total)
578 self.ui.progress(_('archiving (%s)') % relpath, None) 578 self.ui.progress(_('archiving (%s)') % relpath, None)
579 return total 579 return total
580 580
780 except error.RepoLookupError as inst: 780 except error.RepoLookupError as inst:
781 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n') 781 self.ui.warn(_('warning: error "%s" in subrepository "%s"\n')
782 % (inst, subrelpath(self))) 782 % (inst, subrelpath(self)))
783 783
784 @annotatesubrepoerror 784 @annotatesubrepoerror
785 def archive(self, archiver, prefix, match=None): 785 def archive(self, archiver, prefix, match=None, decode=True):
786 self._get(self._state + ('hg',)) 786 self._get(self._state + ('hg',))
787 total = abstractsubrepo.archive(self, archiver, prefix, match) 787 total = abstractsubrepo.archive(self, archiver, prefix, match)
788 rev = self._state[1] 788 rev = self._state[1]
789 ctx = self._repo[rev] 789 ctx = self._repo[rev]
790 for subpath in ctx.substate: 790 for subpath in ctx.substate:
791 s = subrepo(ctx, subpath, True) 791 s = subrepo(ctx, subpath, True)
792 submatch = matchmod.subdirmatcher(subpath, match) 792 submatch = matchmod.subdirmatcher(subpath, match)
793 total += s.archive(archiver, prefix + self._path + '/', submatch) 793 total += s.archive(archiver, prefix + self._path + '/', submatch,
794 decode)
794 return total 795 return total
795 796
796 @annotatesubrepoerror 797 @annotatesubrepoerror
797 def dirty(self, ignoreupdate=False): 798 def dirty(self, ignoreupdate=False):
798 r = self._state[1] 799 r = self._state[1]
954 def files(self): 955 def files(self):
955 rev = self._state[1] 956 rev = self._state[1]
956 ctx = self._repo[rev] 957 ctx = self._repo[rev]
957 return ctx.manifest().keys() 958 return ctx.manifest().keys()
958 959
959 def filedata(self, name): 960 def filedata(self, name, decode):
960 rev = self._state[1] 961 rev = self._state[1]
961 return self._repo[rev][name].data() 962 data = self._repo[rev][name].data()
963 if decode:
964 data = self._repo.wwritedata(name, data)
965 return data
962 966
963 def fileflags(self, name): 967 def fileflags(self, name):
964 rev = self._state[1] 968 rev = self._state[1]
965 ctx = self._repo[rev] 969 ctx = self._repo[rev]
966 return ctx.flags(name) 970 return ctx.flags(name)
1290 in e.getElementsByTagName('name')[0].childNodes 1294 in e.getElementsByTagName('name')[0].childNodes
1291 if c.nodeType == c.TEXT_NODE) 1295 if c.nodeType == c.TEXT_NODE)
1292 paths.append(name.encode('utf-8')) 1296 paths.append(name.encode('utf-8'))
1293 return paths 1297 return paths
1294 1298
1295 def filedata(self, name): 1299 def filedata(self, name, decode):
1296 return self._svncommand(['cat'], name)[0] 1300 return self._svncommand(['cat'], name)[0]
1297 1301
1298 1302
1299 class gitsubrepo(abstractsubrepo): 1303 class gitsubrepo(abstractsubrepo):
1300 def __init__(self, ctx, path, state, allowcreate): 1304 def __init__(self, ctx, path, state, allowcreate):
1770 if kind == stat.S_IFDIR: 1774 if kind == stat.S_IFDIR:
1771 self.wvfs.rmtree(f) 1775 self.wvfs.rmtree(f)
1772 else: 1776 else:
1773 self.wvfs.unlink(f) 1777 self.wvfs.unlink(f)
1774 1778
1775 def archive(self, archiver, prefix, match=None): 1779 def archive(self, archiver, prefix, match=None, decode=True):
1776 total = 0 1780 total = 0
1777 source, revision = self._state 1781 source, revision = self._state
1778 if not revision: 1782 if not revision:
1779 return total 1783 return total
1780 self._fetch(source, revision) 1784 self._fetch(source, revision)