当前位置: 首页>>代码示例>>Python>>正文


Python Repo.blame方法代码示例

本文整理汇总了Python中git.Repo.blame方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.blame方法的具体用法?Python Repo.blame怎么用?Python Repo.blame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.blame方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_exception

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import blame [as 别名]
    def process_exception(request, exception):
        exception_traceback = sys.exc_traceback

        stack = traceback.extract_tb(exception_traceback)

        repo_dir = settings.EXCEPTION_BLAME['REPO_DIR']
        repo = Repo(repo_dir)

        first_file_project = None
        for stack_file in reversed(stack):
            file_path = stack_file[0]

            if repo.git.ls_files(file_path, {'error-unmatch':True}):
                first_file_project = stack_file
                break

        if first_file_project:
            file_path = first_file_project[0]
            abs_linenumber = first_file_project[1]
            blame = repo.blame(None, file_path)

            # blame returns array with lists [commit, [lines]]
            blame_commit = [commit[0]
                            for commit in blame
                                for _ in commit[1]][abs_linenumber-1]


            author = blame_commit.author.name
            if author == 'Not Committed Yet':
                author = author + ', probably your modifications'
            else:
                author = '{} - {}'.format(author, blame_commit.author.email)

            request.META['BLAMED_DEVELOPER'] = author
开发者ID:gdelfresno,项目名称:django-exception-blame,代码行数:36,代码来源:middleware.py

示例2: GetHistory

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import blame [as 别名]
def GetHistory():
  """Obtain mapping from release version to DEPRECATED.md PRs.

  Returns:
    A dictionary mapping from release version to a set of git commit objects.
  """
  repo = Repo(os.getcwd())
  version = None
  history = defaultdict(set)
  for commit, lines in repo.blame('HEAD', 'DEPRECATED.md'):
    for line in lines:
      sr = re.match('## Version (.*)', line)
      if sr:
        version = sr.group(1)
        continue
      history[version].add(commit)
  return history
开发者ID:iTransCloud,项目名称:envoy,代码行数:19,代码来源:deprecate_version.py

示例3: Repository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import blame [as 别名]

#.........这里部分代码省略.........

        :param files:
        :param extensions: a list of file extensions to return commits for
        :param ignore_dir: a list of directory names to ignore
        :param ignore_globs: a list of globs to ignore (if none falls back to extensions and ignore_dir)
        :return: dict
        """

        if ignore_globs is not None:
            out = {}
            for key in files.keys():
                if sum([1 if fnmatch.fnmatch(key, local_glob) else 0 for local_glob in ignore_globs]) == 0:
                    out[key] = files[key]

            return out
        else:
            warnings.warn('Warning, extensions and ignore_dir will be deprecated in v2.0.0, please use ignore_globs instead')
            if extensions is None:
                return files

            if ignore_dir is None:
                ignore_dir = []
            else:
                ignore_dir = [str(x).replace('/', '').replace('\\', '') + os.sep for x in ignore_dir]

            out = {}
            for key in files.keys():
                if key.split('.')[-1] in extensions:
                    if sum([1 if x in key else 0 for x in ignore_dir]) == 0:
                        out[key] = files[key]

            return out

    def blame(self, extensions=None, ignore_dir=None, rev='HEAD', committer=True, by='repository'):
        """
        Returns the blame from the current HEAD of the repository as a DataFrame.  The DataFrame is grouped by committer
        name, so it will be the sum of all contributions to the repository by each committer. As with the commit history
        method, extensions and ignore_dirs parameters can be passed to exclude certain directories, or focus on certain
        file extensions. The DataFrame will have the columns:

         * committer
         * loc

        :param extensions: (optional, default=None) a list of file extensions to return commits for
        :param ignore_dir: (optional, default=None) a list of directory names to ignore
        :param rev: (optional, default=HEAD) the specific revision to blame
        :param committer: (optional, defualt=True) true if committer should be reported, false if author
        :param by: (optional, default=repository) whether to group by repository or by file
        :return: DataFrame
        """

        if ignore_dir is None:
            ignore_dir = []

        blames = []
        file_names = [x for x in self.repo.git.log(pretty='format:', name_only=True, diff_filter='A').split('\n') if x.strip() != '']
        for file in file_names:
            if sum([1 if x in file else 0 for x in ignore_dir]) == 0:
                if extensions is not None:
                    if file.split('.')[-1] not in extensions:
                        continue
                try:
                    blames.append([x + [str(file).replace(self.git_dir + '/', '')] for x in self.repo.blame(rev, str(file).replace(self.git_dir + '/', ''))])
                except GitCommandError:
                    pass
开发者ID:rvisio,项目名称:git-pandas,代码行数:69,代码来源:repository.py

示例4: GitRepository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import blame [as 别名]

#.........这里部分代码省略.........
            return ref

        try:
            return GitRepository(repository).commit(ref).hexsha
        except:
            return None

    def _traverse_tree(self, path):
        rev, path = (path + "/").split("/", 1)
        tree = self.repo.tree(rev)
        if path == "":
            return (x for x in [tree])
        return tree.traverse(predicate=lambda i, d: i.path == path[:-1])

    def blob(self, path):
        try:
            gen = self._traverse_tree(path)
            return GitRepository.GitBlob(gen.next())
        except BadObject:
            raise RepositoryError("Repository '%s' has no tree '%s'" % (self.path, path))
        except StopIteration:
            raise RepositoryError("Repository '%s' has no tree '%s'" % (self.path, path))

    def tree(self, path):
        try:
            gen = self._traverse_tree(path)
            return GitRepository.GitTree(gen.next())
        except BadObject:
            raise RepositoryError("Repository '%s' has no tree '%s'" % (self.path, path))
        except StopIteration:
            raise RepositoryError("Repository '%s' has no tree '%s'" % (self.path, path))

    def last_activities(self, treeish, count=4, skip=0):
        return (GitRepository.GitCommit(c) for c in self.repo.iter_commits(treeish, max_count=count, skip=skip))

    def commit(self, rev):
        try:
            return GitRepository.GitCommit(self.repo.commit(rev))
        except BadObject:
            raise RepositoryError("Repository '%s' has no branch '%s'" % (self.path, rev))

    def submodules(self, base, tree):
        # let us parse .gitmodules ourselves. the implementation
        # of GitPython does not allow to iterate submodules of
        # a specific path nor of a specific revision!!

        try:
            result = []
            path = tree + "/.gitmodules"
            data = self.blob(path).data.split("\n")

            previous = -1
            for n in xrange(0, len(data)):
                line = data[n]
                if line.startswith("[submodule"):
                    if not previous == -1:
                        result.append(GitRepository.GitSubmodule(data[previous:n]))
                    previous = n

            if not previous == -1:
                result.append(GitRepository.GitSubmodule(data[previous:len(data)]))

            return sorted([x for x in result if x.path_base == base], key=lambda x: x.path_name)
        except RepositoryError:
            pass

        return []

    def history(self, path):
        breadcrumbs = path.split("/")
        return (
            GitRepository.GitCommit(c) for c in
                self.repo.iter_commits(breadcrumbs[0], "/".join(breadcrumbs[1:]))
        )

    def blame(self, path):
        breadcrumbs = path.split("/")
        return ((GitRepository.GitCommit(c), b) for c, b in
            self.repo.blame(breadcrumbs[0], "/".join(breadcrumbs[1:]))
        )

    def commit_count(self, start):
        try:
            commit = self.repo.commit(start)
            return commit.count()
        except BadObject:
            raise RepositoryError("Repository '%s' has no branch '%s'" % (self.path, start))

    def archive(self, treeish):
       try:
            from tempfile import TemporaryFile
            with TemporaryFile(mode='w+b') as fp:
                self.repo.archive(fp, treeish)
                fp.flush()
                fp.seek(0)
                data = fp.read()

            return data
       except GitCommandError:
            raise RepositoryError("Repository '%s' has no tree '%s'" % (self.path, treeish))
开发者ID:mensi,项目名称:pyggi,代码行数:104,代码来源:gitr.py


注:本文中的git.Repo.blame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。