subrepo: run the repo decoders when archiving
authorMatt Harbison <matt_harbison@yahoo.com>
Sat, 25 Feb 2017 21:13:59 -0500
changeset 31099 b44ab288358e
parent 31098 876f08f30ade
child 31100 8903f67b9ca8
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.
hgext/largefiles/overrides.py
mercurial/archival.py
mercurial/subrepo.py
tests/test-eol.t
--- a/hgext/largefiles/overrides.py	Sat Feb 25 21:44:34 2017 -0500
+++ b/hgext/largefiles/overrides.py	Sat Feb 25 21:13:59 2017 -0500
@@ -993,9 +993,9 @@
 
     archiver.done()
 
-def hgsubrepoarchive(orig, repo, archiver, prefix, match=None):
+def hgsubrepoarchive(orig, repo, archiver, prefix, match=None, decode=True):
     if not repo._repo.lfstatus:
-        return orig(repo, archiver, prefix, match)
+        return orig(repo, archiver, prefix, match, decode)
 
     repo._get(repo._state + ('hg',))
     rev = repo._state[1]
@@ -1010,6 +1010,8 @@
         if match and not match(f):
             return
         data = getdata()
+        if decode:
+            data = repo._repo.wwritedata(name, data)
 
         archiver.addfile(prefix + repo._path + '/' + name, mode, islink, data)
 
@@ -1037,7 +1039,7 @@
         sub = ctx.workingsub(subpath)
         submatch = matchmod.subdirmatcher(subpath, match)
         sub._repo.lfstatus = True
-        sub.archive(archiver, prefix + repo._path + '/', submatch)
+        sub.archive(archiver, prefix + repo._path + '/', submatch, decode)
 
 # If a largefile is modified, the change is not reflected in its
 # standin until a commit. cmdutil.bailifchanged() raises an exception
--- a/mercurial/archival.py	Sat Feb 25 21:44:34 2017 -0500
+++ b/mercurial/archival.py	Sat Feb 25 21:13:59 2017 -0500
@@ -331,7 +331,7 @@
         for subpath in sorted(ctx.substate):
             sub = ctx.workingsub(subpath)
             submatch = matchmod.subdirmatcher(subpath, matchfn)
-            total += sub.archive(archiver, prefix, submatch)
+            total += sub.archive(archiver, prefix, submatch, decode)
 
     if total == 0:
         raise error.Abort(_('no files match the archive pattern'))
--- a/mercurial/subrepo.py	Sat Feb 25 21:44:34 2017 -0500
+++ b/mercurial/subrepo.py	Sat Feb 25 21:13:59 2017 -0500
@@ -542,8 +542,8 @@
         """return filename iterator"""
         raise NotImplementedError
 
-    def filedata(self, name):
-        """return file data"""
+    def filedata(self, name, decode):
+        """return file data, optionally passed through repo decoders"""
         raise NotImplementedError
 
     def fileflags(self, name):
@@ -558,7 +558,7 @@
         """handle the files command for this subrepo"""
         return 1
 
-    def archive(self, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None, decode=True):
         if match is not None:
             files = [f for f in self.files() if match(f)]
         else:
@@ -572,7 +572,7 @@
             mode = 'x' in flags and 0o755 or 0o644
             symlink = 'l' in flags
             archiver.addfile(prefix + self._path + '/' + name,
-                             mode, symlink, self.filedata(name))
+                             mode, symlink, self.filedata(name, decode))
             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
                              unit=_('files'), total=total)
         self.ui.progress(_('archiving (%s)') % relpath, None)
@@ -782,7 +782,7 @@
                           % (inst, subrelpath(self)))
 
     @annotatesubrepoerror
-    def archive(self, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None, decode=True):
         self._get(self._state + ('hg',))
         total = abstractsubrepo.archive(self, archiver, prefix, match)
         rev = self._state[1]
@@ -790,7 +790,8 @@
         for subpath in ctx.substate:
             s = subrepo(ctx, subpath, True)
             submatch = matchmod.subdirmatcher(subpath, match)
-            total += s.archive(archiver, prefix + self._path + '/', submatch)
+            total += s.archive(archiver, prefix + self._path + '/', submatch,
+                               decode)
         return total
 
     @annotatesubrepoerror
@@ -956,9 +957,12 @@
         ctx = self._repo[rev]
         return ctx.manifest().keys()
 
-    def filedata(self, name):
+    def filedata(self, name, decode):
         rev = self._state[1]
-        return self._repo[rev][name].data()
+        data = self._repo[rev][name].data()
+        if decode:
+            data = self._repo.wwritedata(name, data)
+        return data
 
     def fileflags(self, name):
         rev = self._state[1]
@@ -1292,7 +1296,7 @@
             paths.append(name.encode('utf-8'))
         return paths
 
-    def filedata(self, name):
+    def filedata(self, name, decode):
         return self._svncommand(['cat'], name)[0]
 
 
@@ -1772,7 +1776,7 @@
             else:
                 self.wvfs.unlink(f)
 
-    def archive(self, archiver, prefix, match=None):
+    def archive(self, archiver, prefix, match=None, decode=True):
         total = 0
         source, revision = self._state
         if not revision:
--- a/tests/test-eol.t	Sat Feb 25 21:44:34 2017 -0500
+++ b/tests/test-eol.t	Sat Feb 25 21:13:59 2017 -0500
@@ -470,6 +470,22 @@
   > EOF
   $ hg commit -m 'consistent'
 
+  $ hg init subrepo
+  $ hg -R subrepo pull -qu .
+  $ echo "subrepo = subrepo" > .hgsub
+  $ hg ci -Am "add subrepo"
+  adding .hgeol
+  adding .hgsub
+  $ hg archive -S ../archive
+  $ find ../archive/* | sort
+  ../archive/a.txt
+  ../archive/subrepo
+  ../archive/subrepo/a.txt
+  $ cat ../archive/a.txt ../archive/subrepo/a.txt
+  first\r (esc)
+  second\r (esc)
+  first\r (esc)
+  second\r (esc)
 
 Test trailing newline