[PATCH 1 of 6] convert: add converter_source.getrevid(), hg source implementation

Patrick Mezard pmezard at gmail.com
Tue Jan 1 17:03:11 CST 2008


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1199227752 -3600
# Node ID ffda8917bd5720caa2fe75efa14b55202130cc09
# Parent  7eb1146b72ec22e3c8da091544401550fac0b946
convert: add converter_source.getrevid(), hg source implementation

Sources being the only one able to understand user supplied revisions made
generic code hard to write.

diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -88,6 +88,12 @@ class converter_source(object):
         """Return the tags as a dictionary of name: revision"""
         raise NotImplementedError()
 
+    def getrevid(self, rev):
+        """Return the normalized revision identifier for the specified
+        revision sample.
+        """
+        raise NotImplementedError()
+
     def recode(self, s, encoding=None):
         if not encoding:
             encoding = self.encoding or 'utf-8'
diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py
--- a/hgext/convert/filemap.py
+++ b/hgext/convert/filemap.py
@@ -345,3 +345,6 @@ class filemap_source(converter_source):
 
     def gettags(self):
         return self.base.gettags()
+
+    def getrevid(self, rev):
+        return self.base.getrevid(rev)
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -258,6 +258,12 @@ class mercurial_source(converter_source)
         tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
         return dict([(name, hex(node)) for name, node in tags])
 
+    def getrevid(self, rev):
+        node = self.repo.lookup(rev)
+        if not node:
+            raise util.Abort(_("%r is not a valid hash, revision number or tag"))
+        return hex(node)
+
     def getchangedfiles(self, rev, i):
         ctx = self.changectx(rev)
         i = i or 0


More information about the Mercurial-devel mailing list