[PATCH] add file function to open other filelogs

Sune Foldager cryo at cyanite.org
Sun May 8 02:47:14 CDT 2011


I posted this before, I think, but I can't find the mails. Anyway, this is
needed by lwcopy later, to have its filelog open other filelogs (namely the
copy source) when unpacking lwcopy entries. For normal filelogs, this is not
a problem, but bundlerepo uses its own filelogs, which only bundlerepo knows
how to open.

There was some concern over the patches passing down the repo object to the
filelog, and a suggestion that I pass down perhaps just a lambda or similar.
In my oppinion this would not be an improvement, but YMMV.

Also, some people might be concerned about the reference cycle created by
the code. But I need to open those filelogs, so what would YOU do instead? :)


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1304537075 -7200
# Node ID f9bc746f341a5721829da1915c2d13bacb6d5353
# Parent  07f21a18358b4b63027f54cfd0a26eaabb79b343
filelog: add file function to open other filelogs

diff -r 07f21a18358b -r f9bc746f341a mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py   Sat May 07 23:12:40 2011 +0200
+++ b/mercurial/bundlerepo.py   Wed May 04 21:24:35 2011 +0200
@@ -150,10 +150,14 @@
                                linkmapper)

  class bundlefilelog(bundlerevlog, filelog.filelog):
-    def __init__(self, opener, path, bundle, linkmapper):
+    def __init__(self, opener, path, bundle, linkmapper, repo):
          filelog.filelog.__init__(self, opener, path)
          bundlerevlog.__init__(self, opener, self.indexfile, bundle,
                                linkmapper)
+        self._repo = repo
+
+    def _file(self, f):
+        self._repo.file(f)

  class bundlerepository(localrepo.localrepository):
      def __init__(self, ui, path, bundlename):
@@ -244,7 +248,7 @@
          if f in self.bundlefilespos:
              self.bundle.seek(self.bundlefilespos[f])
              return bundlefilelog(self.sopener, f, self.bundle,
-                                 self.changelog.rev)
+                                 self.changelog.rev, self)
          else:
              return filelog.filelog(self.sopener, f)

diff -r 07f21a18358b -r f9bc746f341a mercurial/filelog.py
--- a/mercurial/filelog.py      Sat May 07 23:12:40 2011 +0200
+++ b/mercurial/filelog.py      Wed May 04 21:24:35 2011 +0200
@@ -87,3 +87,6 @@
              return t2 != text

          return True
+
+    def _file(self, f):
+        return filelog(self.opener, f)


More information about the Mercurial-devel mailing list