Example #1
0
    def history(self,
                path=None,
                revision=None,
                branch='master',
                since_revision=None,
                since=None,
                sort=True):
        if revision == self.null_revision:
            return []

        if path is not None:
            path = clean_path(path)

        if since_revision:
            ctime = self.revision(since_revision).commit_time
            if since:
                since = max(ctime, since)
            else:
                since = ctime

        if revision or branch:
            pending = set([self._get_commit(revision, branch).id])
        else:
            pending = set(self._repo.get_refs().values())

        visited = set()
        result = []
        repo = self.repo

        while pending:
            commit_id = pending.pop()
            commit = self.revision(commit_id)

            if commit_id in visited:
                continue
            visited.add(commit_id)

            if since and since > commit.commit_time:
                continue

            if commit_id != since_revision:
                pending.update(commit._commit.parents)

            if path:
                tree = repo[commit._commit.tree]
                found = False
                parents = commit._commit.parents
                for parent in parents:
                    parent_tree = repo[repo[parent].tree]
                    if not is_same_object(repo, tree, parent_tree, path):
                        found = True
                        break
                if not parents and get_by_path(repo, tree, path):
                    found = True
                if not found:
                    continue
            result.append(commit)
        if sort:
            result.sort(key=attrgetter('commit_time'), reverse=True)
        return result
Example #2
0
    def history(self, path=None, revision=None, branch='master', since_revision=None, since=None, sort=True):
        if revision == self.null_revision:
            return []

        if path is not None:
            path = clean_path(path)
        
        if since_revision:
            ctime = self.revision(since_revision).commit_time
            if since:
                since = max(ctime, since)
            else:
                since = ctime
                
        if revision or branch:
            pending = set([self._get_commit(revision, branch).id])
        else:
            pending = set(self._repo.get_refs().values())

        visited = set()
        result = []
        repo = self.repo

        while pending:
            commit_id = pending.pop()
            commit = self.revision(commit_id)
            
            if commit_id in visited:
                continue
            visited.add(commit_id)
            
            if since and since > commit.commit_time:
                continue

            if commit_id != since_revision:
                pending.update(commit._commit.parents)
                
            if path:
                tree = repo[commit._commit.tree]
                found = False
                parents = commit._commit.parents
                for parent in parents:
                    parent_tree = repo[repo[parent].tree]
                    if not is_same_object(repo, tree, parent_tree, path):
                        found = True
                        break
                if not parents and get_by_path(repo, tree, path):
                    found = True
                if not found:
                    continue
            result.append(commit)
        if sort:
            result.sort(key=attrgetter('commit_time'), reverse=True)
        return result
Example #3
0
 def do_read(self, path, revision=None, branch='master'):
     path = clean_path(path)
     repo = self.repo
     if revision == self.null_revision:
         raise FileDoesNotExist(self, "'%s' does not exist at revision null" % path)
     c = self._get_commit(revision, branch)
     obj = get_by_path(repo, repo[c.tree], path)
     if not obj:
         raise FileDoesNotExist(self, "'%s' does not exist" % path)
     if not isinstance(obj, Blob):
         raise FileDoesNotExist(self, "'%s' is not a regular file" % path)
     data = obj.as_pretty_string()
     return data
Example #4
0
 def do_read(self, path, revision=None, branch='master'):
     path = clean_path(path)
     repo = self.repo
     if revision == self.null_revision:
         raise FileDoesNotExist(
             self, "'%s' does not exist at revision null" % path)
     c = self._get_commit(revision, branch)
     obj = get_by_path(repo, repo[c.tree], path)
     if not obj:
         raise FileDoesNotExist(self, "'%s' does not exist" % path)
     if not isinstance(obj, Blob):
         raise FileDoesNotExist(self, "'%s' is not a regular file" % path)
     data = obj.as_pretty_string()
     return data