[PATCH 1 of 9 RFC] normfn: convert filenames at reading/writing changelog metadata from/into storage

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri May 25 10:00:50 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1337957587 -32400
# Node ID 7488bcab8351aaaa0e8fbc4e98911fea225e8b38
# Parent  2ac08d8b21aa7b6e0a062afed5a3f357ccef67f9
normfn: convert filenames at reading/writing changelog metadata from/into storage

with this patch, changelog metadata contains:

  - filenames normalized in "global style" (= "fnfromlocal()"-ed),
    in storage layer

  - filenames normalized in "local style" (= "fnfromlocal()"-ed),
    in memory layer

On MacOS environment, each functions are expected to work:

  - as same as "normalize('NFC')" for "fnfromlocal()", and
  - as same as "normalize('NFD')" for "fntolocal()"

these are enabled, only when normfn extension is enabled and
normalization style is configured as NFC.

diff -r 2ac08d8b21aa -r 7488bcab8351 mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/bundlerepo.py	Fri May 25 23:53:07 2012 +0900
@@ -145,8 +145,8 @@
         raise NotImplementedError
 
 class bundlechangelog(bundlerevlog, changelog.changelog):
-    def __init__(self, opener, bundle):
-        changelog.changelog.__init__(self, opener)
+    def __init__(self, opener, bundle, fntolocal=None, fnfromlocal=None):
+        changelog.changelog.__init__(self, opener, fntolocal, fnfromlocal)
         linkmapper = lambda x: x
         bundlerevlog.__init__(self, opener, self.indexfile, bundle,
                               linkmapper)
@@ -212,7 +212,9 @@
     def changelog(self):
         # consume the header if it exists
         self.bundle.changelogheader()
-        c = bundlechangelog(self.sopener, self.bundle)
+        fntolocal = getattr(self, 'fntolocal', None)
+        fnfromlocal = getattr(self, 'fnfromlocal', None)
+        c = bundlechangelog(self.sopener, self.bundle, fntolocal, fnfromlocal)
         self.manstart = self.bundle.tell()
         return c
 
diff -r 2ac08d8b21aa -r 7488bcab8351 mercurial/changelog.py
--- a/mercurial/changelog.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/changelog.py	Fri May 25 23:53:07 2012 +0900
@@ -111,13 +111,15 @@
     return o
 
 class changelog(revlog.revlog):
-    def __init__(self, opener):
+    def __init__(self, opener, fntolocal=None, fnfromlocal=None):
         revlog.revlog.__init__(self, opener, "00changelog.i")
         if self._initempty:
             # changelogs don't benefit from generaldelta
             self.version &= ~revlog.REVLOGGENERALDELTA
             self._generaldelta = False
         self._realopener = opener
+        self._fntolocal = fntolocal
+        self._fnfromlocal = fnfromlocal
         self._delayed = False
         self._divert = False
         # hiddenrevs: revs that should be hidden by command and tools
@@ -215,6 +217,8 @@
             extra = decodeextra(tdata[2])
 
         files = l[3:]
+        if self._fntolocal:
+            files = [self._fntolocal(f) for f in files]
         return (manifest, user, (time, timezone), files, desc, extra)
 
     def add(self, manifest, files, desc, transaction, p1, p2,
@@ -251,6 +255,8 @@
         if extra:
             extra = encodeextra(extra)
             parseddate = "%s %s" % (parseddate, extra)
+        if self._fnfromlocal:
+            files = [self._fnfromlocal(f) for f in files]
         l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
         text = "\n".join(l)
         return self.addrevision(text, transaction, len(self), p1, p2)
diff -r 2ac08d8b21aa -r 7488bcab8351 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/localrepo.py	Fri May 25 23:53:07 2012 +0900
@@ -194,7 +194,9 @@
 
     @storecache('00changelog.i')
     def changelog(self):
-        c = changelog.changelog(self.sopener)
+        fntolocal = getattr(self, 'fntolocal', None)
+        fnfromlocal = getattr(self, 'fnfromlocal', None)
+        c = changelog.changelog(self.sopener, fntolocal, fnfromlocal)
         if 'HG_PENDING' in os.environ:
             p = os.environ['HG_PENDING']
             if p.startswith(self.root):


More information about the Mercurial-devel mailing list