[PATCH 2 of 2] keyword: handle LookupError eg. for hg convert

Christian Ebert blacktrash at gmx.net
Tue Jan 29 18:51:27 CST 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1201654174 -3600
# Node ID cc0782a6a84fe5cbe4a31490a327e9cf61dfd0de
# Parent  6787a1ae7f963d8cdf2e9f980da9f5136ecec805
keyword: handle LookupError eg. for hg convert

Circumvent revlog.LookupError eg. on initial run of "hg convert"
when [keyword] filename patterns are set in a global hgrc
(not recommended).

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -131,10 +131,14 @@
             # kwrepo.wwrite except when overwriting on commit
             if self.ctx is None:
                 self.ctx = self.repo.changectx()
-            fnode = self.ctx.filenode(path)
-            fl = self.repo.file(path)
-            c = context.filectx(self.repo, path, fileid=fnode, filelog=fl)
-            node = c.node()
+            try:
+                fnode = self.ctx.filenode(path)
+                fl = self.repo.file(path)
+                c = context.filectx(self.repo, path, fileid=fnode, filelog=fl)
+                node = c.node()
+            except revlog.LookupError:
+                # eg: convert
+                return subfunc == self.re_kw.sub and data or (data, None)
         elif subfunc == self.re_kw.sub:
             # hg kwcat using kwfilelog.read
             c = context.filectx(self.repo, path, fileid=node)


More information about the Mercurial-devel mailing list