Changeset - 03a770980b55
[Not reviewed]
beta
0 8 0
Marcin Kuzminski - 13 years ago 2012-07-04 11:42:16
marcin@python-works.com
Synced vcs with upstream
8 files changed with 15 insertions and 9 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/vcs/__init__.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
"""
 
    vcs
 
    ~~~
 

	
 
    Various version Control System (vcs) management abstraction layer for
 
    Python.
 

	
 
    :created_on: Apr 8, 2010
 
    :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
 
"""
 

	
 
VERSION = (0, 2, 3, 'dev')
 
VERSION = (0, 3, 0, 'dev')
 

	
 
__version__ = '.'.join((str(each) for each in VERSION[:4]))
 

	
 
__all__ = [
 
    'get_version', 'get_repo', 'get_backend',
 
    'VCSError', 'RepositoryError', 'ChangesetError']
 

	
 
import sys
 
from rhodecode.lib.vcs.backends import get_repo, get_backend
 
from rhodecode.lib.vcs.exceptions import VCSError, RepositoryError, ChangesetError
 

	
 

	
rhodecode/lib/vcs/backends/git/changeset.py
Show inline comments
 
@@ -6,39 +6,38 @@ from rhodecode.lib.vcs.conf import setti
 
from rhodecode.lib.vcs.exceptions import RepositoryError
 
from rhodecode.lib.vcs.exceptions import ChangesetError
 
from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
 
from rhodecode.lib.vcs.exceptions import VCSError
 
from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
 
from rhodecode.lib.vcs.exceptions import ImproperArchiveTypeError
 
from rhodecode.lib.vcs.backends.base import BaseChangeset
 
from rhodecode.lib.vcs.nodes import FileNode, DirNode, NodeKind, RootNode, \
 
    RemovedFileNode, SubModuleNode
 
from rhodecode.lib.vcs.utils import safe_unicode
 
from rhodecode.lib.vcs.utils import date_fromtimestamp
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 
from dulwich.objects import Commit, Tag
 

	
 

	
 
class GitChangeset(BaseChangeset):
 
    """
 
    Represents state of the repository at single revision.
 
    """
 

	
 
    def __init__(self, repository, revision):
 
        self._stat_modes = {}
 
        self.repository = repository
 

	
 
        try:
 
            commit = self.repository._repo.get_object(revision)
 
            if isinstance(commit, Tag):
 
            if isinstance(commit, objects.Tag):
 
                revision = commit.object[1]
 
                commit = self.repository._repo.get_object(commit.object[1])
 
        except KeyError:
 
            raise RepositoryError("Cannot get object with id %s" % revision)
 
        self.raw_id = revision
 
        self.id = self.raw_id
 
        self.short_id = self.raw_id[:12]
 
        self._commit = commit
 

	
 
        self._tree_id = commit.tree
 
        self._commiter_property = 'committer'
 
        self._date_property = 'commit_time'
rhodecode/lib/vcs/backends/hg/changeset.py
Show inline comments
 
@@ -3,26 +3,25 @@ import posixpath
 

	
 
from rhodecode.lib.vcs.backends.base import BaseChangeset
 
from rhodecode.lib.vcs.conf import settings
 
from rhodecode.lib.vcs.exceptions import  ChangesetDoesNotExistError, \
 
    ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
 
from rhodecode.lib.vcs.nodes import AddedFileNodesGenerator, \
 
    ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, \
 
    RemovedFileNodesGenerator, RootNode, SubModuleNode
 

	
 
from rhodecode.lib.vcs.utils import safe_str, safe_unicode, date_fromtimestamp
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 
from rhodecode.lib.vcs.utils.paths import get_dirs_for_path
 

	
 
from ...utils.hgcompat import archival, hex
 
from rhodecode.lib.vcs.utils.hgcompat import archival, hex
 

	
 

	
 
class MercurialChangeset(BaseChangeset):
 
    """
 
    Represents state of the repository at the single revision.
 
    """
 

	
 
    def __init__(self, repository, revision):
 
        self.repository = repository
 
        self.raw_id = revision
 
        self._ctx = repository._repo[revision]
 
        self.revision = self._ctx._rev
rhodecode/lib/vcs/backends/hg/inmemory.py
Show inline comments
 
import datetime
 
import errno
 

	
 
from rhodecode.lib.vcs.backends.base import BaseInMemoryChangeset
 
from rhodecode.lib.vcs.exceptions import RepositoryError
 

	
 
from ...utils.hgcompat import memfilectx, memctx, hex, tolocal
 
from rhodecode.lib.vcs.utils.hgcompat import memfilectx, memctx, hex, tolocal
 

	
 

	
 
class MercurialInMemoryChangeset(BaseInMemoryChangeset):
 

	
 
    def commit(self, message, author, parents=None, branch=None, date=None,
 
            **kwargs):
 
        """
 
        Performs in-memory commit (doesn't check workdir in any way) and
 
        returns newly created ``Changeset``. Updates repository's
 
        ``revisions``.
 

	
 
        :param message: message of the commit
rhodecode/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -9,25 +9,25 @@ from .workdir import MercurialWorkdir
 
from .changeset import MercurialChangeset
 
from .inmemory import MercurialInMemoryChangeset
 

	
 
from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError, \
 
    ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, \
 
    VCSError, TagAlreadyExistError, TagDoesNotExistError
 
from rhodecode.lib.vcs.utils import author_email, author_name, date_fromtimestamp, \
 
    makedate, safe_unicode
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 
from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict
 
from rhodecode.lib.vcs.utils.paths import abspath
 

	
 
from ...utils.hgcompat import ui, nullid, match, patch, diffopts, clone, \
 
from rhodecode.lib.vcs.utils.hgcompat import ui, nullid, match, patch, diffopts, clone, \
 
    get_contact, pull, localrepository, RepoLookupError, Abort, RepoError, hex
 

	
 

	
 
class MercurialRepository(BaseRepository):
 
    """
 
    Mercurial repository backend
 
    """
 
    DEFAULT_BRANCH_NAME = 'default'
 
    scm = 'hg'
 

	
 
    def __init__(self, repo_path, create=False, baseui=None, src_url=None,
 
                 update_after_clone=False):
rhodecode/lib/vcs/backends/hg/workdir.py
Show inline comments
 
from rhodecode.lib.vcs.backends.base import BaseWorkdir
 
from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError
 

	
 
from ...utils.hgcompat import hg_merge
 
from rhodecode.lib.vcs.utils.hgcompat import hg_merge
 

	
 

	
 
class MercurialWorkdir(BaseWorkdir):
 

	
 
    def get_branch(self):
 
        return self.repository._repo.dirstate.branch()
 

	
 
    def get_changeset(self):
 
        return self.repository.get_changeset()
 

	
 
    def checkout_branch(self, branch=None):
 
        if branch is None:
rhodecode/lib/vcs/nodes.py
Show inline comments
 
@@ -7,25 +7,25 @@
 

	
 
    :created_on: Apr 8, 2010
 
    :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
 
"""
 
import os
 
import stat
 
import posixpath
 
import mimetypes
 

	
 
from pygments import lexers
 

	
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 
from rhodecode.lib.vcs.utils import safe_unicode, safe_str
 
from rhodecode.lib.vcs.utils import safe_unicode
 
from rhodecode.lib.vcs.exceptions import NodeError
 
from rhodecode.lib.vcs.exceptions import RemovedFileNodeError
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 

	
 

	
 
class NodeKind:
 
    SUBMODULE = -1
 
    DIR = 1
 
    FILE = 2
 

	
 

	
 
class NodeState:
rhodecode/tests/vcs/test_changesets.py
Show inline comments
 
@@ -110,24 +110,32 @@ class ChangesetsWithCommitsTestCaseixin(
 
            branch='docs',
 
        )
 
        self.imc.add(vcs.nodes.FileNode('newfile', content=''))
 
        self.imc.commit(
 
            message=u'Back in default branch',
 
            author=u'joe',
 
            parents=[tip],
 
        )
 
        default_branch_changesets = self.repo.get_changesets(
 
            branch_name=self.repo.DEFAULT_BRANCH_NAME)
 
        self.assertNotIn(doc_changeset, default_branch_changesets)
 

	
 
    def test_get_changeset_by_branch(self):
 
        for branch, sha in self.repo.branches.iteritems():
 
            self.assertEqual(sha, self.repo.get_changeset(branch).raw_id)
 

	
 
    def test_get_changeset_by_tag(self):
 
        for tag, sha in self.repo.tags.iteritems():
 
            self.assertEqual(sha, self.repo.get_changeset(tag).raw_id)
 

	
 

	
 
class ChangesetsTestCaseMixin(BackendTestMixin):
 
    recreate_repo_per_test = False
 

	
 
    @classmethod
 
    def _get_commits(cls):
 
        start_date = datetime.datetime(2010, 1, 1, 20)
 
        for x in xrange(5):
 
            yield {
 
                'message': u'Commit %d' % x,
 
                'author': u'Joe Doe <joe.doe@example.com>',
 
                'date': start_date + datetime.timedelta(hours=12 * x),
0 comments (0 inline, 0 general)