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


Python pygit2.Repository类代码示例

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


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

示例1: init

def init(req):
	print "args:", req.args, req.args.path
	repo_path = os.path.join(req.args.path,'.git')
	if not os.path.isdir(repo_path):
		raise Abort("no repository found in '%s' (.git not found)!" % (os.path.abspath(req.args.path)))
	repo = Repository(req.args.path)
	print "repo references:", repo.listall_references()
	xxl_path = os.path.join(req.args.path,'.gitxxl')
	if os.path.exists(xxl_path):
		print "reinitializing existing XXL repo"
	else:
		print "initialiling XXL repo"
		os.mkdir(xxl_path)
		
	#install commit hooks
	dst = os.path.join(repo_path,"hooks","pre-commit")
	if not os.path.isfile(dst):
		src = os.path.join(sys.exec_prefix,"dist","hooks","pre-commit")
		print "installing pre-commit hook from:", src
		shutil.copyfile(src, dst)
		perm = os.stat(dst)
		os.chmod(dst,perm.st_mode | stat.S_IXUSR)

	dst = os.path.join(repo_path,"hooks","post-commit")
	if not os.path.isfile(dst):
		src = os.path.join(sys.exec_prefix,"dist","hooks","post-commit")
		print "installing post-commit hook from:", src
		shutil.copyfile(src, dst)
		perm = os.stat(dst)
		os.chmod(dst,perm.st_mode | stat.S_IXUSR)
开发者ID:pgavazzi,项目名称:gitxxl,代码行数:30,代码来源:commands.py

示例2: get_commit_activity

    def get_commit_activity(self, project):
        from datetime import date, timedelta
        from pygit2 import Repository
        from pygit2 import GIT_SORT_TIME
        repo = Repository(project.gitrepo)

        weeks = self.get_weeks()
        for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):
            commit_time = date.fromtimestamp(commit.commit_time)
            commit_week = commit_time - timedelta(days=commit_time.weekday())

            if commit_week not in weeks:
                continue

            weeks[commit_week]['mine'] += 1

        counts = []
        max = 0
        for k in sorted(weeks.iterkeys()):
            counts.append({
                "week":     k.isoformat(),
                "mine":     weeks[k]['mine'],
                "others":   weeks[k]['others'],
            })
        return counts
开发者ID:alexwright,项目名称:cms-projectinfo,代码行数:25,代码来源:cms_plugins.py

示例3: get_bug_commit_ratio_per_file

def get_bug_commit_ratio_per_file(git_folder = ".git/", output_file):
    result = []
    exec_dir = os.getcwd()
    repo = Repository(os.path.join(git_repo, git_folder))

    os.chdir(git_repo)

    for commit in repo.walk(repo.head.target):
        touched_files = get_touched_files(commit)

        for file in touched_files:
            file_data = [f for f in result if f['file_name'] == file]

            if file_data:
                file_data = file_data[0]
                file_data['commit_num'] += 1
                if bug_related:
                    file_data['bug_commit_num'] += 1
            else:
                result.append({'file_name': file,
                               'commit_num': 1,
                               'bug_commit_num': 1 if bug_related else 0})

    os.chdir(exec_dir)

    for entry in result:
        entry['bug_commit_ratio'] = entry['bug_commit_num'] / entry['commit_num']

    with open(output_file, "w", newline='') as output:
        writer = csv.DictWriter(output, csv_header)
        writer.writeheader()
        writer.writerows(result)
开发者ID:an1ket,项目名称:technical-debt-capstone,代码行数:32,代码来源:get_blame_test.py

示例4: extract_commits

def extract_commits(repos_root, output_path):
    # Uncomment code to generate a separate file for each commit.

    try:
        os.makedirs(output_path)
    except FileExistsError as ex:
        pass

    exec_dir = os.getcwd()

    for git_repo in get_immediate_subdirectories(repos_root):
        os.chdir(git_repo)
        repo = Repository(os.path.join(git_repo, git_folder))
        root = etree.Element("commits")

        repo_name = os.path.basename(os.path.normpath(git_repo))

        print("\n> project: " + repo_name + " extraction started")

        for commit in repo.walk(repo.head.target):
            stats = get_commit_stats(commit.id)
            commit_xml = commit_to_xml(commit, stats)
            root.append(commit_xml)

            # print(".", end=" ")
            print("> project: " + repo_name + ", commit " + str(commit.id) + " processed")

        output_xml = xml_to_string(root)

        os.chdir(exec_dir)

        with open(os.path.join(output_path, repo_name + "_" + output_commit_file), "w") as file:
            file.write(output_xml)

        print("\n> project: " + repo_name + " extraction finished")
开发者ID:megakevin,项目名称:research-assistantship-rit,代码行数:35,代码来源:get_commits.py

示例5: commit_new_tickets_to_git

def commit_new_tickets_to_git(queue, repo_path):
    global last_push_ts
    #repo
    repo = Repository(os.path.join(repo_path, '.git'))
    index = repo.index
    author = Signature('yourname', 'youremail')
    while True:
        #write tickets into file
        ticket = queue.get(block=True)
        #filename format is yyyy-mm-dd
        d = datetime.utcnow().date()
        filename = '%s.txt' % d.strftime('%Y-%m-%d')
        f = open(os.path.join(repo_path, filename), 'ab')
        f.write('%s\n' % ticket.toJson())
        f.close()
        #commit
        index.add(filename)
        index.write()
        oid = index.write_tree()
        repo.create_commit('HEAD', author, author, ticket.toJson(), oid, [repo.head.oid])
        #push
        d_ts = datetime.utcnow()
        if last_push_ts is None or d_ts > (last_push_ts + timedelta(seconds = 60)):
            push_to_github(repo_path)
            last_push_ts = datetime.utcnow()
开发者ID:icefreedom,项目名称:tickets_app,代码行数:25,代码来源:backup_tickets.py

示例6: get_new_articles

def get_new_articles():
    blog = PelicanBlog()
    content_dir = blog.get_content_directory()
    repo = Repository(os.path.abspath(os.path.dirname(__file__)))
    diff = repo.revparse_single("HEAD").tree.diff_to_tree()
    existing_articles = set(os.path.relpath(obj.old_file_path, content_dir)
                            for obj in diff
                            if obj.old_file_path.startswith(content_dir))
    all_articles = set(blog.get_posts())
    new_articles = {art for art in all_articles - existing_articles
                    if blog.get_post_lang(art) in (TWITTER_LANGUAGE, "")}
    new_titles = []
    repo.index.read()
    for newart in new_articles:
        title = blog.get_post_title(newart)
        yield Article(title, blog.get_post_url(newart),
                      blog.get_post_authors(newart))
        new_titles.append(title)
        repo.index.add(os.path.join(content_dir, newart))
    blogger = Signature(repo.config["user.name"], repo.config["user.email"])
    repo.create_commit("HEAD", blogger, blogger,
                       "[BLOG] %s" % ", ".join(new_titles),
                       repo.index.write_tree(), [repo.head.peel().oid])
    repo.index.write()
    # TODO(v.markovtsev): implement git push using pygit2
    subprocess.call(("git", "push", "origin", repo.head.shorthand))
开发者ID:ajkxyz,项目名称:veles-blog,代码行数:26,代码来源:tweet.py

示例7: install_package

    def install_package(self, pkg_name, expression):
        package_cache_path = path.join(APP_CACHE_DIR, pkg_name)

        # Check if the package is cached
        try:
            repo = Repository(package_cache_path)

            # TODO: check lastest version
            # If lastest is cached, advance
            # If no, prompt user
        except KeyError as e:
            repo = clone_repository(APP_REMOTE['url'], package_cache_path)

        # Get suitable version for the expression
        versions = utils.get_versions_cached(repo)
        version = max_satisfy(versions=versions.keys(), expression='')

        package_archive_name = '{0}-{1}.tar'.format(pkg_name, version)
        package_archive_path = path.join(APP_ARCHIVE_DIR, package_archive_name)

        # Create archive file
        # If the file already exists, move forward
        if path.isfile(package_archive_path):
            with tarfile.open(package_archive_path, 'w') as archive:
                repo.write_archive(archive=archive, treeish=versions[version].tree_id)

        # TODO: use strategy
        # Extract archive to package dir
        path_to_package = path.join(USER_PACKAGE_FOLDER, 'user', pkg_name)
        tar = tarfile.open(package_archive_path)
        tar.extractall(path=path_to_package)
        tar.close()
开发者ID:nghiattran,项目名称:pm,代码行数:32,代码来源:default.py

示例8: GitRepositoryTestCase

class GitRepositoryTestCase(unittest.TestCase):

    def setUp(self):
        self.repo_path = mkdtemp()
        init_repository(self.repo_path, False)
        self.repo = Repository(self.repo_path)

    def tearDown(self):
        try:
            rmtree(self.repo_path)
        except:
            pass

    def test_create_repo(self):
        repo_path = mkdtemp()
        try:
            GitRepository.create_repo(repo_path)
            for f in [os.path.join('content', 'attachments', 'mercurial.png'),
                      os.path.join('content', 'post', 'example-post.rst'),
                      os.path.join('content', 'post', 'lorem-ipsum.rst'),
                      os.path.join('content', 'about.rst'),
                      os.path.join('static', 'screen.css'),
                      os.path.join('templates', 'base.html'),
                      os.path.join('templates', 'posts.html'),
                      os.path.join('templates', 'post_list.html'),
                      'config.yaml', '.gitignore', '.git']:
                self.assertTrue(os.path.exists(os.path.join(repo_path, f)),
                                'Not found: %s' % f)
        finally:
            rmtree(repo_path)

    def test_get_changectx_rev_default(self):
        git_repo = GitRepository(self.repo_path)
        with codecs.open(os.path.join(self.repo_path, 'foo.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('foo')
        sign = Signature('foo', '[email protected]')
        tree = self.repo.TreeBuilder().write()
        self.repo.index.add('foo.rst')
        self.repo.create_commit('refs/heads/master', sign, sign, 'foo', tree,
                                [])
        self.assertTrue(isinstance(git_repo.get_changectx(REVISION_DEFAULT),
                                   ChangeCtxDefault),
                        'changectx object is not an instance of '
                        'ChangeCtxDefault')

    def test_get_changectx_rev_working_dir(self):
        git_repo = GitRepository(self.repo_path)
        with codecs.open(os.path.join(self.repo_path, 'foo.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('foo')
        sign = Signature('foo', '[email protected]')
        tree = self.repo.TreeBuilder().write()
        self.repo.index.add('foo.rst')
        self.repo.create_commit('refs/heads/master', sign, sign, 'foo', tree,
                                [])
        self.assertTrue(
            isinstance(git_repo.get_changectx(REVISION_WORKING_DIR),
                       ChangeCtxWorkingDir),
            'changectx object is not an instance of ChangeCtxWorkingDir')
开发者ID:foyslei,项目名称:blohg,代码行数:60,代码来源:__init__.py

示例9: Repo

class Repo(object):
  def __init__(self,path,username,password):
    self.repo = Repository(path)
    self.username = username
    self.password = password
    self.path=path

  def commit(self,file,refspec,email,author_username,message):
    self.repo.index.add(file)
    index = self.repo.index
    index.write()
    tree = self.repo.index.write_tree()
    author = Signature(author_username,email)
    self.repo.create_commit(refspec,
        author,
        author,message,tree, [self.repo.head.get_object().hex] )

  def commit_fallback(self,message):
    return subprocess.check_output(["git","commit","-m",message],cwd=self.path)

  def push(self,refspec):
    credentials = UserPass(self.username,self.password)
    remoteCall = RemoteCallbacks(credentials)
    remo = self.repo.remotes["origin"]
    remo.push(refspec,remoteCall)
开发者ID:girishramnani,项目名称:python_programs_linux,代码行数:25,代码来源:pygit.py

示例10: getHist

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,代码行数:8,代码来源:gitreap.py

示例11: get_blame_test

def get_blame_test():
    git_repo = "/Users/aniketp/Workspace/Capstone/Source/eclipse/eclipse.platform.runtime"
    sample_file = "bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/JobManager.java"
    exec_dir = os.getcwd()
    repo = Repository(os.path.join(git_repo, git_folder))
    os.chdir(git_repo)
    
    blameObj = repo.blame(sample_file, min_line=1, max_line=20)
开发者ID:an1ket,项目名称:technical-debt-capstone,代码行数:8,代码来源:get_blame_test.py

示例12: get_and_update_repo_cache

def get_and_update_repo_cache(repo_path):
    cache_filename = '%s-stats.cache' % repo_path
    if os.path.exists(cache_filename):
        with open(cache_filename) as f:
            data = load(f)
    else:
        data = {
            'author_to_month_to_additions': defaultdict(defaultdict_int),
            'author_to_month_to_deletions': defaultdict(defaultdict_int),
            'author_to_month_to_commits': defaultdict(defaultdict_int),
            'day_to_count': defaultdict(defaultdict_int),
            'latest_sha': None,
        }

    repo = Repository(repo_path)

    count = 0
    for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
        count += 1
        if commit.type == GIT_OBJ_COMMIT:
            if data['latest_sha'] == commit.hex:
                break
        
            if not commit.message.lower().startswith('merge'):
                try:
                    d = repo.diff('%s^' % commit.hex, commit)
                except KeyError:
                    # First commit!
                    break
                patches = list(d)
                additions = sum([p.additions for p in patches])
                deletions = sum([p.deletions for p in patches])

                author = author_aliases.get(commit.author.email, commit.author.email)

                day = date.fromtimestamp(commit.commit_time)
                data['day_to_count']['Lines'][day] += additions
                data['day_to_count']['Lines'][day] -= deletions

                if additions > 1000 and deletions < 5 and commit.hex not in whitelist_commits:
                    if commit.hex not in blacklist_commits:
                        print 'WARNING: ignored %s looks like an embedding of a lib (message: %s)' % (commit.hex, commit.message)
                    continue
                if (additions > 3000 or deletions > 3000) and commit.hex not in whitelist_commits:
                    if commit.hex not in blacklist_commits and additions != deletions:  # Guess that if additions == deletions it's a big rename of files
                        print 'WARNING: ignored %s because it is bigger than 3k lines. Put this commit in the whitelist or the blacklist (message: %s)' % (commit.hex, commit.message)
                    continue
                month = date(day.year, day.month, 1)
                data['author_to_month_to_additions'][author][month] += additions
                data['author_to_month_to_deletions'][author][month] += deletions
                data['author_to_month_to_commits'][author][month] += 1
                if data['latest_sha'] is None:
                    data['latest_sha'] = commit.hex

    with open(cache_filename, 'w') as f:
        dump(data, f)

    return data
开发者ID:ismaproco,项目名称:git-stats2,代码行数:58,代码来源:git_stats2.py

示例13: gets

    def gets(cls, path, max_count=100, order=GIT_SORT_TIME):
        """gets commits from a git repository.

        :param path: The normalized path to the git repository.
        :param max_count: max count of commits.
        :param order: order commits list."""
        repo = Repository(path)
        return [cls(c.hex, [p.hex for p in c.parents])
                for c in islice(repo.walk(repo.head.target, order),
                                max_count)]
开发者ID:HiWong,项目名称:commits-graph,代码行数:10,代码来源:commit.py

示例14: sync_handler

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,代码行数:35,代码来源:project.py

示例15: commitInfo

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,代码行数:11,代码来源:gitreap.py


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