Commits

Martin Vejnár committed 871bbba

Small fixes to make hgdeps compatible with hg-1.0.

- change contexts are retrived using mercurial.context module.
- repo.lookup may raise LookupError in addition to RepoError
- changectx.parents() behaves differenly with regard to null parents
- added some more debug prints

  • Participants
  • Parent commits 4b11a89

Comments (0)

Files changed (1)

 import mercurial.revlog
 from mercurial.i18n import _
 from mercurial import cmdutil, commands, fancyopts, hg, util, localrepo
+from mercurial import context
+from mercurial.repo import RepoError
 
 def deps(ui, repo, tag = None, **opts):
     '''create and manage versioned repository dependencies
     old_deplist.sort()
     
     if old_deplist != deplist:
-        parents = repo[None].parents()
+        parents = context.workingctx(repo).parents()
         if len(parents) != 1:
             raise util.Abort(_('cannot commit dependencies on a merged working copy'))
         rev = mercurial.node.hex(parents[0].node())
             scmhandler = _get_scm_handler(ui, repo, manifest, alias_name, config.aliases)
             
             if rev is not None:
+                ui.debug("fetching dependency to version: %s\n" % rev)
                 scmhandler.fetch(config.aliases, rev)
+                ui.debug("updating dependency to version: %s\n" % rev)
                 scmhandler.update(rev)
             elif alias_name not in manifest:
                 raise util.Abort(_('unfetched dependency: %s (specify revision to update to)')
     last = {}
     filenodes = []
     for node in heads:
-        c = repo[node]
+        c = context.changectx(repo, node)
         try:
             fnode = c.filenode('.hgdeps')
         except mercurial.revlog.LookupError:
         return config.tag(rev)
     
     if rev is None:
-        parents = repo[None].parents()
+        parents = context.workingctx(repo).parents()
         chctx = parents[0] if len(parents) == 1 else None
     else:
-        chctx = repo[repo.lookup(rev)]
+        chctx = context.changectx(repo, repo.lookup(rev))
     
-    while chctx is not None and chctx.node() != mercurial.node.nullid:
+    while chctx is not None:
         tag = mercurial.node.hex(chctx.node())
         if config.has_tag(tag):
             return config.tag(tag)
         
-        parents = chctx.parents()
+        # Filter out null parents manually,
+        # the behavior of parents() differ between
+        # hg-1.0 and hg-1.2.
+        parents = [parent for parent in chctx.parents()
+            if parent.node() != mercurial.node.nullid]
         chctx = parents[0] if len(parents) == 1 else None
     
     return default
         path = self._make_deppath(dir)
         
         deprepo = localrepo.localrepository(self.ui, path)
-        nodeids = deprepo[None].parents()
+        nodeids = context.workingctx(deprepo).parents()
         return ','.join(mercurial.node.hex(nodeid.node()) for nodeid in nodeids)
     
     def readable_rev(revision):
         deprepo = localrepo.localrepository(self.ui, path, create)
         self.manifest.set(self.alias_name, 'hg', '-', dir)
         
+        need_pull = True
         try:
             deprepo.lookup(rev)
             need_pull = False
-        except mercurial.error.RepoError:
-            need_pull = True
+        except mercurial.revlog.LookupError:
+            pass
+        except RepoError:
+            pass
         
         if need_pull:
-            self.ui.debug(_('fetching changesets for dependency: %s up to: %s')
+            self.ui.debug(_('fetching changesets for dependency: %s up to: %s\n')
                 % (self.alias_name, rev))
             alias = aliases[self.alias_name]
             if alias.scmtype != 'hg':