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


Python Repository.checkout方法代码示例

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


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

示例1: sync_handler

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
def sync_handler(fork_from: str, from_sha: str, repo_name: str,
                 ticket_id: int, pr_url: str):
    output_path = '{}.txt'.format(pr_url.split('/', 3)[3].rsplit('/', 2)[0])
    output_path = os.path.join(WORK_DIR, output_path.replace('/', '_'))
    work_tree = os.path.join(WORK_DIR, fork_from)
    parent_path = os.path.dirname(work_tree)
    if not os.path.exists(parent_path):
        os.makedirs(parent_path)
    if not os.path.exists(work_tree):
        repo = clone_repository(
            '{0}{1}.git'.format(GITHUB_URL, fork_from), work_tree)
    else:
        repo = Repository(work_tree)

    remote_name = repo_name.split('/')[0]
    update_remote(work_tree, repo, repo_name, remote_name)

    if remote_name == 'origin':
        commit = repo.revparse_single(from_sha)
        repo.checkout_tree(commit, strategy=GIT_CHECKOUT_FORCE)
    else:
        ref_name = 'refs/pull/{0}/head'.format(ticket_id)
        try:
            repo.create_reference(ref_name, from_sha)
        except ValueError:
            pass
        ref = repo.lookup_reference(ref_name)
        repo.checkout(ref, strategy=GIT_CHECKOUT_FORCE)
    cwd = os.getcwd()
    os.chdir(work_tree)
    subprocess.call(
        '{} . --output-file={}'.format(FLAKE8_EXECUTABLE, output_path),
        shell=True)
    os.chdir(cwd)
    return output_path
开发者ID:dongweiming,项目名称:gandalf,代码行数:37,代码来源:project.py

示例2: getHist

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
def getHist(repo):
	base = Repository(repo)
	base.checkout('HEAD')
	history = []
	for commit in base.walk(base.head.target, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE):
		history.append(commit)
	
	return history
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:10,代码来源:gitreap.py

示例3: commitInfo

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
def commitInfo(repo, history):
	# GET A REPO ON DISK
	base = Repository(repo)
	base.checkout('HEAD')

	# MOVE THROUGH THE SYSTEM HISTORY FROM NEWEST TO OLDEST COMMIT
	for commit in history:
		print 'Date/Time: ' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(commit.commit_time))
		print 'Comment Hex: ' + commit.hex
		print 'Message: ' + commit.message.rstrip('\n')
		print ''
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:13,代码来源:gitreap.py

示例4: Repo

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
class Repo(object):
	def __init__(self, path="", branch="develop"):
		self.path = path if path else os.getcwd()
		# Retrieve the repo if its already defined
		try:
			self.repo = Repository(self.path)
			# This is a little hacky, but we need a git command interface to do
			# certain things
			self.pygitrepo = git.Repo(self.repo.path)
			self.git = self.pygitrepo.git
			self.currentBranch = self.repo.lookup_branch(self.repo.head.shorthand)
			self._user = self.repo.default_signature
		except KeyError:
			self.repo = None
			self.currentBranch = None
			self._user = None
		# TODO Handle this another way
		self.branch = branch

	@property
	def user(self):
		if not self._user and self.repo:
			self._user = self.repo.default_signature
		return self._user

	def clone(self, repourl):
		self.repo = clone_repository(
			repourl,
			self.path,
			checkout_branch=self.branch
		)

	def checkoutBranch(self, name):
		# TODO check if a branch of this name exists
 		developBranch = self.repo.lookup_branch("develop")
		self.repo.checkout(developBranch)
		self.currentBranch = self.repo.create_branch(
			name,
			self.repo.head.get_object()
		)
		self.repo.checkout(self.currentBranch)

	def merge(self, branch, delete=False, push=False):
		pass

	def release(self):
		# Checkout the release branch
		# Need some way to control versioning
		# Internal versioning
		pass
开发者ID:Munk801,项目名称:blurgit,代码行数:52,代码来源:__init__.py

示例5: clone_repository

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
from pygit2 import clone_repository
from pygit2 import Repository
from pygit2 import GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE, GIT_CHECKOUT_SAFE_CREATE
import os
import sh
import subprocess
import time

repo_url = 'https://github.com/octocat/Spoon-Knife.git'
repo_path = 'spoon-knife'

if not os.path.exists(repo_path):
    repo = clone_repository(repo_url, repo_path)

base = Repository(repo_path + '/.git')
base.checkout('HEAD')

history = []
# Display Commits Newest to Oldest
for commit in base.walk(base.head.target, GIT_SORT_TOPOLOGICAL):
    #print commit.hex
    #print commit.message
    print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(commit.commit_time))
    history.append(commit.hex)

#print '-----------------------------------------------------------'

# Display Commits Oldest to Newest
for commit in base.walk(base.head.target, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE):
    pass
#    print commit.hex
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:33,代码来源:hunks.py

示例6: init

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
class prototype:
    repo = ""  # Path to a given repository
    name = ""  # Name of a repository
    base = ""  # Repository as defined in pygit2

    # Initialization. Clones the given repository, placing it in the current directory,
    # and changes to the repository directory.
    def init(self, repository):
        self.repo = repository

        # Use regular expressions to match the last instance of a forward slash
        # followed by the name of the repository, which we wish to extract, followed
        # by ".git". 
        m = re.search('/([^/]+).git$', repository)
        if m:
            self.name = m.group(1)

        if not os.path.isdir(self.name):
            os.system('git clone ' + self.repo) # Get the repository from GitHub

        self.base = Repository(self.name)
        self.base.checkout('HEAD')

    # Destruction. Remove the given repository from memory.
    def destroy(self):
        os.system('cd ' + self.name)
        os.system('rm -rf ' + self.name)

    # Get total LOC by given repository. 
    def totalRepoLOC(self):
        loc = countDirLOC(self.name)
        return loc

    # Get total commits by a given repository
    def totalRepoCommits(self):
        commits = 0
        for commit in self.base.walk(self.base.head.target, GIT_SORT_TOPOLOGICAL):
            commits = commits + 1
        return commits

    # Get a list of LOC changed per commit
    def locPerCommit(self):
        loc = []
        oldPath = os.popen('pwd')
        os.chdir(self.name)
        sha1 = 0
        sha2 = 0

        start = 1
        total = self.totalRepoCommits()

        # For each commit within the repository
        for commit in self.base.walk(self.base.head.target, GIT_SORT_TOPOLOGICAL):

            print '\r', start, '/', total,
            start += 1

            # Based on the SHA, use git to show the patch for that commit
            sha1 = sha2
            sha2 = commit.hex
            if sha1 != 0:
                p = os.popen('git diff --shortstat ' + sha1 + ' ' + sha2)
                line = p.readline()

                # line contains "# file changed, # insertions(+), # deletions(-)
                # Use regular expressions to find the number of additions and deletions.
                # Additions are found after ", " and before " insertion". Deletions are
                # found after "(+), " and before " deletion".
                m = re.search(', (.*) insertion', line)
                additions = 0
                deletions = 0
                if m:
                    additions = m.group(1)
                m = re.search('\(\+\), (.*) deletion', line)
                if m:
                    deletions = m.group(1)

                # Get the total and append to array
                modifications = int(additions) + int(deletions)
                loc.append(modifications)

        os.chdir('..')
        return loc


    # Get a list containing the total number of line additions and deletions (including
    # whitespace and comments) contained within each hunk that was changed over t
    def locPerHunk(self):
        loc = []
        history = []

        # Get the hex number for each commit within the repository
        for commit in self.base.walk(self.base.head.target, GIT_SORT_TOPOLOGICAL):
            sha = commit.hex
            history.append(sha)

        # Compare each revision in the history of the repository with the previous rev.
        i = 0
        while i < len(history) - 1:
            t0 = self.base.revparse_single(history[i])
#.........这里部分代码省略.........
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:103,代码来源:prototype.py

示例7: process

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import checkout [as 别名]
def process(repo, history):
	# GET A REPO ON DISK
	base = Repository(repo)
	base.checkout('HEAD')

	file_xsmall = 0
	file_small = 0
	file_medium = 0
	file_large = 0
	file_xlarge = 0
		
	hunk_xsmall = 0
	hunk_small = 0
	hunk_medium = 0
	hunk_large = 0
	hunk_xlarge = 0

	line_xsmall = 0
	line_small = 0
	line_medium = 0
	line_large = 0
	line_xlarge = 0 
	
	i = 0
	while i < len(history) - 1:
		print '\rDiff#: ' + str(i + 1) + ' of ' + str(len(history)-1),

		t0 = base.revparse_single(history[i].hex)
		t1 = base.revparse_single(history[i+1].hex)
		
		try:
			diff = base.diff(t0,t1)
		except ValueError:
			print ''
			print 'Value Error'
			print ''
			i += 1
			continue
		
		files = [p for p in diff]
		
		if len(files) == 1:
			file_xsmall += 1
		if len(files) >= 2 and len(files) <= 4:
			file_small += 1
		if len(files) >= 5 and len(files) <= 7:
			file_medium += 1
		if len(files) >= 8 and len(files) <= 10:
			file_large += 1
		if len(files) >= 11:
			file_xlarge += 1
		
		hunksInCommit = 0
		linesInCommit = 0

		for modfile in files:
			hunksInCommit += len(modfile.hunks)
			for hunk in modfile.hunks:
				for line in hunk.lines:
					if line[0] == '-' or line[0] == '+':
						linesInCommit += 1


		if hunksInCommit <= 1:
			hunk_xsmall += 1
		if hunksInCommit >= 2 and hunksInCommit <= 8:
			hunk_small += 1
		if hunksInCommit >= 9 and hunksInCommit <= 17:
			hunk_medium += 1
		if hunksInCommit >= 18 and hunksInCommit <= 26:
			hunk_large += 1
		if hunksInCommit >= 27:
			hunk_xlarge += 1

		if linesInCommit <= 5:
			line_xsmall += 1
		if linesInCommit >= 6 and linesInCommit <= 46:
			line_small += 1
		if linesInCommit >= 47 and linesInCommit <= 106:
			line_medium += 1
		if linesInCommit >= 107 and linesInCommit <= 166:
			line_large += 1
		if linesInCommit >= 167:
			line_xlarge += 1

		i += 1
	print ''

	ts = time.time()
	st = datetime.datetime.fromtimestamp(ts).strftime('-%Y-%m-%d.%H.%M.%S')
	name = repo.replace('/.git', '') + st + '.txt'
	output = open(name,'w')

	output.write('--------- ' + repo + ' ----------' + '\n')
	output.write('Number of Lines Modified:' + '\n')
	output.write('x-small: ' + str( + line_xsmall) + '\n')
	output.write('small: ' + str(line_small) + '\n')
	output.write('medium: ' + str(line_medium) + '\n')
	output.write('large: ' + str(line_large) + '\n')
	output.write('x-large: ' + str(line_xlarge) + '\n')
#.........这里部分代码省略.........
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:103,代码来源:gitreap.py


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