[PATCH 3 of 3] imported patch replaceclass-eol.patch

Bryan O'Sullivan bos at serpentine.com
Tue Nov 20 16:55:45 CST 2012


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1353452138 28800
# Node ID 59df062cc80377e4fc35bc69b7f6d379c89e12c9
# Parent  5e900b16c15eae6113a9e3de6684f6da42784d52
imported patch replaceclass-eol.patch

diff --git a/hgext/eol.py b/hgext/eol.py
--- a/hgext/eol.py
+++ b/hgext/eol.py
@@ -91,7 +91,7 @@ used.
 """
 
 from mercurial.i18n import _
-from mercurial import util, config, extensions, match, error
+from mercurial import util, config, extensions, match, error, localrepo
 import re, os
 
 testedwith = 'internal'
@@ -270,6 +270,72 @@ def extsetup(ui):
     except KeyError:
         pass
 
+ at extensions.replaceclass(localrepo, 'localrepository')
+class eolrepo(localrepo.localrepository):
+
+    def loadeol(self, nodes):
+        eol = parseeol(self.ui, self, nodes)
+        if eol is None:
+            return None
+        eol.copytoui(self.ui)
+        return eol.match
+
+    def _hgcleardirstate(self):
+        self._eolfile = self.loadeol([None, 'tip'])
+        if not self._eolfile:
+            self._eolfile = util.never
+            return
+
+        try:
+            cachemtime = os.path.getmtime(self.join("eol.cache"))
+        except OSError:
+            cachemtime = 0
+
+        try:
+            eolmtime = os.path.getmtime(self.wjoin(".hgeol"))
+        except OSError:
+            eolmtime = 0
+
+        if eolmtime > cachemtime:
+            self.ui.debug("eol: detected change in .hgeol\n")
+            wlock = None
+            try:
+                wlock = self.wlock()
+                for f in self.dirstate:
+                    if self.dirstate[f] == 'n':
+                        # all normal files need to be looked at
+                        # again since the new .hgeol file might no
+                        # longer match a file it matched before
+                        self.dirstate.normallookup(f)
+                # Create or touch the cache to update mtime
+                self.opener("eol.cache", "w").close()
+                wlock.release()
+            except error.LockUnavailable:
+                # If we cannot lock the repository and clear the
+                # dirstate, then a commit might not see all files
+                # as modified. But if we cannot lock the
+                # repository, then we can also not make a commit,
+                # so ignore the error.
+                pass
+
+    def commitctx(self, ctx, error=False):
+        for f in sorted(ctx.added() + ctx.modified()):
+            if not self._eolfile(f):
+                continue
+            try:
+                data = ctx[f].data()
+            except IOError:
+                continue
+            if util.binary(data):
+                # We should not abort here, since the user should
+                # be able to say "** = native" to automatically
+                # have all non-binary files taken care of.
+                continue
+            if inconsistenteol(data):
+                raise util.Abort(_("inconsistent newline style "
+                                   "in %s\n" % f))
+        return super(eolrepo, self).commitctx(ctx, error)
+
 
 def reposetup(ui, repo):
     uisetup(repo.ui)
@@ -280,70 +346,4 @@ def reposetup(ui, repo):
         repo.adddatafilter(name, fn)
 
     ui.setconfig('patch', 'eol', 'auto')
-
-    class eolrepo(repo.__class__):
-
-        def loadeol(self, nodes):
-            eol = parseeol(self.ui, self, nodes)
-            if eol is None:
-                return None
-            eol.copytoui(self.ui)
-            return eol.match
-
-        def _hgcleardirstate(self):
-            self._eolfile = self.loadeol([None, 'tip'])
-            if not self._eolfile:
-                self._eolfile = util.never
-                return
-
-            try:
-                cachemtime = os.path.getmtime(self.join("eol.cache"))
-            except OSError:
-                cachemtime = 0
-
-            try:
-                eolmtime = os.path.getmtime(self.wjoin(".hgeol"))
-            except OSError:
-                eolmtime = 0
-
-            if eolmtime > cachemtime:
-                self.ui.debug("eol: detected change in .hgeol\n")
-                wlock = None
-                try:
-                    wlock = self.wlock()
-                    for f in self.dirstate:
-                        if self.dirstate[f] == 'n':
-                            # all normal files need to be looked at
-                            # again since the new .hgeol file might no
-                            # longer match a file it matched before
-                            self.dirstate.normallookup(f)
-                    # Create or touch the cache to update mtime
-                    self.opener("eol.cache", "w").close()
-                    wlock.release()
-                except error.LockUnavailable:
-                    # If we cannot lock the repository and clear the
-                    # dirstate, then a commit might not see all files
-                    # as modified. But if we cannot lock the
-                    # repository, then we can also not make a commit,
-                    # so ignore the error.
-                    pass
-
-        def commitctx(self, ctx, error=False):
-            for f in sorted(ctx.added() + ctx.modified()):
-                if not self._eolfile(f):
-                    continue
-                try:
-                    data = ctx[f].data()
-                except IOError:
-                    continue
-                if util.binary(data):
-                    # We should not abort here, since the user should
-                    # be able to say "** = native" to automatically
-                    # have all non-binary files taken care of.
-                    continue
-                if inconsistenteol(data):
-                    raise util.Abort(_("inconsistent newline style "
-                                       "in %s\n" % f))
-            return super(eolrepo, self).commitctx(ctx, error)
-    repo.__class__ = eolrepo
     repo._hgcleardirstate()


More information about the Mercurial-devel mailing list