Ejemplo n.º 1
0
    def test_change_non_ascii(self):
        to_add = [
            FileNode('żółwik/zwierzątko', content='ćććć'),
            FileNode(u'żółwik/zwierzątko_uni', content=u'ćććć'),
        ]
        for node in to_add:
            self.imc.add(node)

        tip = self.imc.commit(u'Initial', u'*****@*****.**')

        # Change node's content
        node = FileNode('żółwik/zwierzątko', content='My **changed** content')
        self.imc.change(node)
        self.imc.commit(u'Changed %s' % safe_unicode(node.path),
                        u'*****@*****.**')

        node = FileNode(u'żółwik/zwierzątko_uni',
                        content=u'My **changed** content')
        self.imc.change(node)
        self.imc.commit(u'Changed %s' % safe_unicode(node.path),
                        u'*****@*****.**')

        newtip = self.repo.get_changeset()
        self.assertNotEqual(tip, newtip)
        self.assertNotEqual(tip.id, newtip.id)

        self.assertEqual(
            newtip.get_node('żółwik/zwierzątko').content,
            'My **changed** content')
        self.assertEqual(
            newtip.get_node('żółwik/zwierzątko_uni').content,
            'My **changed** content')
Ejemplo n.º 2
0
    def test_change_non_ascii(self):
        to_add = [
            FileNode('żółwik/zwierzątko', content='ćććć'),
            FileNode(u'żółwik/zwierzątko_uni', content=u'ćććć'),
        ]
        for node in to_add:
            self.imc.add(node)

        tip = self.imc.commit(u'Initial', u'*****@*****.**')

        # Change node's content
        node = FileNode('żółwik/zwierzątko', content='My **changed** content')
        self.imc.change(node)
        self.imc.commit(u'Changed %s' % safe_unicode(node.path),
                        u'*****@*****.**')

        node = FileNode(u'żółwik/zwierzątko_uni', content=u'My **changed** content')
        self.imc.change(node)
        self.imc.commit(u'Changed %s' % safe_unicode(node.path),
                        u'*****@*****.**')

        newtip = self.repo.get_changeset()
        self.assertNotEqual(tip, newtip)
        self.assertNotEqual(tip.id, newtip.id)

        self.assertEqual(newtip.get_node('żółwik/zwierzątko').content,
                         'My **changed** content')
        self.assertEqual(newtip.get_node('żółwik/zwierzątko_uni').content,
                         'My **changed** content')
Ejemplo n.º 3
0
    def branch(self):

        heads = self.repository._heads(reverse=False)

        ref = heads.get(self.raw_id)
        if ref:
            return safe_unicode(ref)
Ejemplo n.º 4
0
    def __init__(self, repository, revision):
        self._stat_modes = {}
        self.repository = repository

        try:
            commit = self.repository._repo.get_object(revision)
            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._author_property = 'author'
        self._date_property = 'commit_time'
        self._date_tz_property = 'commit_timezone'
        self.revision = repository.revisions.index(revision)

        self.message = safe_unicode(commit.message)

        self.nodes = {}
        self._paths = {}
Ejemplo n.º 5
0
 def description(self):
     undefined_description = u'unknown'
     description_path = os.path.join(self.path, '.git', 'description')
     if os.path.isfile(description_path):
         return safe_unicode(open(description_path).read())
     else:
         return undefined_description
Ejemplo n.º 6
0
    def branch(self):

        heads = self.repository._heads(reverse=False)

        ref = heads.get(self.raw_id)
        if ref:
            return safe_unicode(ref)
Ejemplo n.º 7
0
 def description(self):
     undefined_description = u'unknown'
     return safe_unicode(
         self._repo.ui.config('web',
                              'description',
                              undefined_description,
                              untrusted=True))
Ejemplo n.º 8
0
    def _get_bookmarks(self):
        if self._empty:
            return {}

        sortkey = lambda ctx: ctx[0]  # sort by name
        _bookmarks = [(safe_unicode(n), hex(h)) for n, h in self._repo._bookmarks.items()]
        return OrderedDict(sorted(_bookmarks, key=sortkey, reverse=True))
Ejemplo n.º 9
0
    def __init__(self, repository, revision):
        self._stat_modes = {}
        self.repository = repository

        try:
            commit = self.repository._repo.get_object(revision)
            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._committer_property = 'committer'
        self._author_property = 'author'
        self._date_property = 'commit_time'
        self._date_tz_property = 'commit_timezone'
        self.revision = repository.revisions.index(revision)

        self.message = safe_unicode(commit.message)

        self.nodes = {}
        self._paths = {}
Ejemplo n.º 10
0
 def name(self):
     """
     Returns name of the node so if its path
     then only last part is returned.
     """
     org = safe_unicode(self.path.rstrip('/').split('/')[-1])
     return u'%s @ %s' % (org, self.changeset.short_id)
Ejemplo n.º 11
0
 def name(self):
     """
     Returns name of the node so if its path
     then only last part is returned.
     """
     org = safe_unicode(self.path.rstrip('/').split('/')[-1])
     return u'%s @ %s' % (org, self.changeset.short_id)
Ejemplo n.º 12
0
 def description(self):
     undefined_description = u'unknown'
     description_path = os.path.join(self.path, '.git', 'description')
     if os.path.isfile(description_path):
         return safe_unicode(open(description_path).read())
     else:
         return undefined_description
Ejemplo n.º 13
0
 def description(self):
     idx_loc = '' if self.bare else '.git'
     undefined_description = u'unknown'
     description_path = os.path.join(self.path, idx_loc, 'description')
     if os.path.isfile(description_path):
         return safe_unicode(open(description_path).read())
     else:
         return undefined_description
Ejemplo n.º 14
0
 def description(self):
     idx_loc = "" if self.bare else ".git"
     undefined_description = u"unknown"
     description_path = os.path.join(self.path, idx_loc, "description")
     if os.path.isfile(description_path):
         return safe_unicode(open(description_path).read())
     else:
         return undefined_description
Ejemplo n.º 15
0
    def content(self):
        """
        Returns lazily content of the FileNode. If possible, would try to
        decode content from UTF-8.
        """
        content = self._get_content()

        if bool(content and '\0' in content):
            return content
        return safe_unicode(content)
Ejemplo n.º 16
0
    def _get_bookmarks(self):
        if self._empty:
            return {}

        sortkey = lambda ctx: ctx[0]  # sort by name
        _bookmarks = [(
            safe_unicode(n),
            hex(h),
        ) for n, h in self._repo._bookmarks.items()]
        return OrderedDict(sorted(_bookmarks, key=sortkey, reverse=True))
Ejemplo n.º 17
0
    def content(self):
        """
        Returns lazily content of the FileNode. If possible, would try to
        decode content from UTF-8.
        """
        content = self._get_content()

        if bool(content and '\0' in content):
            return content
        return safe_unicode(content)
Ejemplo n.º 18
0
    def content(self):
        """
        Returns lazily content of the FileNode. If possible, would try to
        decode content from UTF-8.
        """
        if self.changeset:
            content = self.changeset.get_file_content(self.path)
        else:
            content = self._content

        if bool(content and '\0' in content):
            return content
        return safe_unicode(content)
Ejemplo n.º 19
0
    def __init__(self, repository, revision):
        self._stat_modes = {}
        self.repository = repository
        self.raw_id = revision
        self.revision = repository.revisions.index(revision)

        self.short_id = self.raw_id[:12]
        self.id = self.raw_id
        try:
            commit = self.repository._repo.get_object(self.raw_id)
        except KeyError:
            raise RepositoryError("Cannot get object with id %s" % self.raw_id)
        self._commit = commit
        self._tree_id = commit.tree

        self.message = safe_unicode(commit.message)
        #self.branch = None
        self.tags = []
        self.nodes = {}
        self._paths = {}
Ejemplo n.º 20
0
    def __init__(self, repository, revision):
        self._stat_modes = {}
        self.repository = repository
        self.raw_id = revision
        self.revision = repository.revisions.index(revision)

        self.short_id = self.raw_id[:12]
        self.id = self.raw_id
        try:
            commit = self.repository._repo.get_object(self.raw_id)
        except KeyError:
            raise RepositoryError("Cannot get object with id %s" % self.raw_id)
        self._commit = commit
        self._tree_id = commit.tree

        self.message = safe_unicode(commit.message)
        #self.branch = None
        self.tags = []
        self.nodes = {}
        self._paths = {}
Ejemplo n.º 21
0
    def _get_branches(self, normal=True, closed=False):
        """
        Get's branches for this repository
        Returns only not closed branches by default

        :param closed: return also closed branches for mercurial
        :param normal: return also normal branches
        """

        if self._empty:
            return {}

        def _branchtags(localrepo):
            """
            Patched version of mercurial branchtags to not return the closed
            branches

            :param localrepo: locarepository instance
            """

            bt = {}
            bt_closed = {}
            for bn, heads in localrepo.branchmap().iteritems():
                tip = heads[-1]
                if 'close' in localrepo.changelog.read(tip)[5]:
                    bt_closed[bn] = tip
                else:
                    bt[bn] = tip

            if not normal:
                return bt_closed
            if closed:
                bt.update(bt_closed)
            return bt

        sortkey = lambda ctx: ctx[0]  # sort by name
        _branches = [(safe_unicode(n), hex(h),) for n, h in
                     _branchtags(self._repo).items()]

        return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
Ejemplo n.º 22
0
    def _get_branches(self, closed=False):
        """
        Get's branches for this repository
        Returns only not closed branches by default

        :param closed: return also closed branches for mercurial
        """

        if self._empty:
            return {}

        def _branchtags(localrepo):
            """
            Patched version of mercurial branchtags to not return the closed
            branches

            :param localrepo: locarepository instance
            """

            bt = {}
            bt_closed = {}
            for bn, heads in localrepo.branchmap().iteritems():
                tip = heads[-1]
                if 'close' in localrepo.changelog.read(tip)[5]:
                    bt_closed[bn] = tip
                else:
                    bt[bn] = tip

            if closed:
                bt.update(bt_closed)
            return bt

        sortkey = lambda ctx: ctx[0]  # sort by name
        _branches = [(
            safe_unicode(n),
            hex(h),
        ) for n, h in _branchtags(self._repo).items()]

        return OrderedDict(sorted(_branches, key=sortkey, reverse=False))
Ejemplo n.º 23
0
 def message(self):
     return safe_unicode(self._ctx.description())
Ejemplo n.º 24
0
 def branch(self):
     return  safe_unicode(self._ctx.branch())
Ejemplo n.º 25
0
 def description(self):
     undefined_description = u"unknown"
     return safe_unicode(self._repo.ui.config("web", "description", undefined_description, untrusted=True))
Ejemplo n.º 26
0
 def committer(self):
     return safe_unicode(getattr(self._commit, self._committer_property))
Ejemplo n.º 27
0
 def message(self):
     return safe_unicode(self._commit.message)
Ejemplo n.º 28
0
 def name(self):
     """
     Returns name of the node so if its path
     then only last part is returned.
     """
     return safe_unicode(self.path.rstrip('/').split('/')[-1])
Ejemplo n.º 29
0
 def contact(self):
     undefined_contact = u'Unknown'
     return safe_unicode(get_contact(self._repo.ui.config)
                         or undefined_contact)
Ejemplo n.º 30
0
 def name(self):
     """
     Returns name of the node so if its path
     then only last part is returned.
     """
     return safe_unicode(self.path.rstrip('/').split('/')[-1])
Ejemplo n.º 31
0
 def committer(self):
     return safe_unicode(self.author)
Ejemplo n.º 32
0
 def message(self):
     return safe_unicode(self._commit.message)
Ejemplo n.º 33
0
 def line_decoder(l):
     if l.startswith('+') and not l.startswith('+++'):
         self.adds += 1
     elif l.startswith('-') and not l.startswith('---'):
         self.removes += 1
     return safe_unicode(l)
Ejemplo n.º 34
0
 def committer(self):
     return safe_unicode(self.author)
Ejemplo n.º 35
0
 def commiter(self):
     return safe_unicode(self.auhtor)
Ejemplo n.º 36
0
 def author(self):
     return safe_unicode(getattr(self._commit, self._author_property))
Ejemplo n.º 37
0
 def author(self):
     return safe_unicode(self._ctx.user())
Ejemplo n.º 38
0
 def description(self):
     undefined_description = u'unknown'
     return safe_unicode(self._repo.ui.config('web', 'description',
                                undefined_description, untrusted=True))
Ejemplo n.º 39
0
 def author(self):
     return safe_unicode(getattr(self._commit, self._author_property))
Ejemplo n.º 40
0
 def unicode_path(self):
     return safe_unicode(self.path)
Ejemplo n.º 41
0
 def author(self):
     return safe_unicode(self._commit.committer)
Ejemplo n.º 42
0
 def contact(self):
     undefined_contact = u'Unknown'
     return safe_unicode(
         get_contact(self._repo.ui.config) or undefined_contact)
Ejemplo n.º 43
0
 def author(self):
     return safe_unicode(self._commit.committer)
Ejemplo n.º 44
0
 def commiter(self):
     return safe_unicode(getattr(self._commit, self._commiter_property))
Ejemplo n.º 45
0
 def unicode_path(self):
     return safe_unicode(self.path)