Commits

Marcin Kuzminski  committed bc7ff25

Added submodule support to mercurial changeset
- added bookmarks attribute to changeset
- added diff attribute to changeset

  • Participants
  • Parent commits 9b3f256

Comments (0)

Files changed (1)

File vcs/backends/hg/changeset.py

 from vcs.conf import settings
 from vcs.exceptions import  ChangesetDoesNotExistError, \
     ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
-from vcs.nodes import AddedFileNodesGenerator, ChangedFileNodesGenerator, \
-    DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode
+from vcs.nodes import AddedFileNodesGenerator, \
+    ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, \
+    RemovedFileNodesGenerator, RootNode, SubModuleNode
 
 from vcs.utils import safe_str, safe_unicode, date_fromtimestamp
 from vcs.utils.lazy import LazyProperty
 from vcs.utils.paths import get_dirs_for_path
-
-from ...utils.hgcompat import archival, hex
+from vcs.utils.hgcompat import archival, hex
 
 
 class MercurialChangeset(BaseChangeset):
         return  safe_unicode(self._ctx.branch())
 
     @LazyProperty
+    def bookmarks(self):
+        return map(safe_unicode, self._ctx.bookmarks())
+
+    @LazyProperty
     def message(self):
         return safe_unicode(self._ctx.description())
 
 
         return _prev(self, branch)
 
+    def diff(self, ignore_whitespace=True, context=3):
+        return ''.join(self._ctx.diff(git=True,
+                                      ignore_whitespace=ignore_whitespace,
+                                      context=context))
+
     def _fix_path(self, path):
         """
         Paths are stored without trailing slash so we need to get rid off it if
                 " %r" % (self.revision, path))
         return self._ctx.filectx(path)
 
+    def _extract_submodules(self):
+        """
+        returns a dictionary with submodule information from substate file
+        of hg repository
+        """
+        return self._ctx.substate
+
     def get_file_mode(self, path):
         """
         Returns stat mode of the file at the given ``path``.
         """
         Returns last commit of the file at the given ``path``.
         """
-        fctx = self._get_filectx(path)
-        changeset = self.repository.get_changeset(fctx.linkrev())
-        return changeset
+        node = self.get_node(path)
+        return node.history[0]
 
     def get_file_history(self, path):
         """
         archival.archive(self.repository._repo, stream, self.raw_id,
                          kind, prefix=prefix, subrepos=subrepos)
 
-        #stream.close()
-
         if stream.closed and hasattr(stream, 'name'):
             stream = open(stream.name, 'rb')
         elif hasattr(stream, 'mode') and 'r' not in stream.mode:
             raise ChangesetError("Directory does not exist for revision %r at "
                 " %r" % (self.revision, path))
         path = self._fix_path(path)
+
         filenodes = [FileNode(f, changeset=self) for f in self._file_paths
             if os.path.dirname(f) == path]
         dirs = path == '' and '' or [d for d in self._dir_paths
             if d and posixpath.dirname(d) == path]
         dirnodes = [DirNode(d, changeset=self) for d in dirs
             if os.path.dirname(d) == path]
+
+        als = self.repository.alias
+        for k, vals in self._extract_submodules().iteritems():
+            #vals = url,rev,type
+            loc = vals[0]
+            cs = vals[1]
+            dirnodes.append(SubModuleNode(k, url=loc, changeset=cs,
+                                          alias=als))
         nodes = dirnodes + filenodes
         # cache nodes
         for node in nodes:
             self.nodes[node.path] = node
         nodes.sort()
+
         return nodes
 
     def get_node(self, path):