本文整理汇总了Python中pygit2.Repository.listall_branches方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.listall_branches方法的具体用法?Python Repository.listall_branches怎么用?Python Repository.listall_branches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygit2.Repository
的用法示例。
在下文中一共展示了Repository.listall_branches方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import listall_branches [as 别名]
def __init__(self):
pubsub = PubSub()
events_dispatcher = EventsDispatcher(pubsub)
display = self.display_surface()
repo = Repository(config["repo_path"])
branches = repo.listall_branches()
drawer = Drawer(repo, branches, display, pubsub)
pubsub.sub("on_program_exit", self.exit_program)
self.main_loop = MainLoop(display, drawer, events_dispatcher)
self.init_screen()
示例2: GitStorage
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import listall_branches [as 别名]
#.........这里部分代码省略.........
return self._get_obj(path, Blob).data
def listdir(self, path):
if path:
tree = self._get_obj(path, Tree)
else:
if self._commit is None:
return []
tree = self._commit.tree
return [entry.name for entry in tree]
def format(self, **kw):
# XXX backwards compatibility??
return kw
def log(self, start, count, branch=None, shortlog=False):
"""
start and branch are literally the same thing.
"""
def _log(iterator):
for pos, commit in iterator:
if pos == count:
raise StopIteration
yield {
'author': commit.committer.name,
'email': self._commit.committer.email,
'date': self.strftime(committer_dt(commit.committer)),
'node': commit.hex,
'rev': commit.hex,
'desc': commit.message
}
if start is None:
# assumption.
start = 'HEAD'
try:
self.repo.revparse_single(start)
except KeyError:
return []
try:
rev = self.repo.revparse_single(start).hex
except KeyError:
raise RevisionNotFoundError('revision %s not found' % start)
iterator = enumerate(self.repo.walk(rev, GIT_SORT_TIME))
return list(_log(iterator))
def pathinfo(self, path):
obj = self._get_obj(path)
if isinstance(obj, Blob):
return self.format(**{
'type': 'file',
'basename': self.basename(path),
'size': obj.size,
'date': self.strftime(committer_dt(self._commit.committer)),
})
elif isinstance(obj, dict):
# special cases are represented as dict.
if obj[''] == '_subrepo':
return self.format(**{
'type': 'subrepo',
'date': '',
'size': 0,
'basename': self.basename(path),
# extra field.
'obj': obj,
})
elif obj[''] == '_empty_root':
return self.format(**{
'type': 'folder',
'date': '',
'size': 0,
'basename': self.basename(path),
})
# Assume this is a Tree.
return self.format(**{
'basename': self.basename(path),
'size': 0,
'type': 'folder',
'date': '',
})
def branches(self):
return tuple(
(b, self.repo.lookup_branch(b).target.hex)
for b in self.repo.listall_branches()
)
def tags(self):
return tuple(
(b[10:], self.repo.lookup_reference(b).target.hex)
for b in self.repo.listall_references()
if b.startswith('refs/tags')
)
示例3: len
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import listall_branches [as 别名]
c.execute(sql, {"repo_name": repo_name})
result = c.fetchall()
if len(result) > 0:
# The unique id # for the repo in the database
repo_id = result[0][0]
else:
# The repo isn't in the database yet, so we add it
sql = 'INSERT INTO repo (repo_id, name) VALUES (NULL, :repo_name)'
c.execute(sql, {"repo_name": repo_name})
conn.commit()
# Retrieve the repo_id value generated by the database for the above insert
repo_id = c.lastrowid
# Loop around for each branch, adding their commits to the database
for branch_name in repo.listall_branches(GIT_BRANCH_REMOTE):
# Starting with the oldest commit in the branch, add its commits to the database
branch = repo.lookup_reference('refs/remotes/' + branch_name)
for commit in repo.walk(branch.target, GIT_SORT_TIME | GIT_SORT_REVERSE):
# If requested, display the commit info for debugging purposes
if debug == 1:
print "commit {0}".format(commit.hex)
print "Author: {0} <{1}>".format(unicode(commit.author.name).encode("utf-8"), commit.author.email)
print datetime.utcfromtimestamp(commit.commit_time).strftime('Date: %a %b %d %H:%M:%S %Y +0000\n')
print " {0}".format(unicode(commit.message).encode("utf-8"))
# Check if the commit already exists in the database. Don't add it if its already there
sql = 'SELECT commit_id, hash FROM commits WHERE repo = :repo AND hash = :hash'
c.execute(sql, {"repo": repo_id, "hash": commit.hex})
示例4: show_status
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import listall_branches [as 别名]
def show_status(srcdir, packages, projects, other_git, ws_state, show_up_to_date=True, cache=None):
def create_upstream_status(repo, head_branch, master_branch, master_remote_branch, tracking_branch):
status = []
if not repo.head_is_detached and not has_pending_merge(repo):
if tracking_branch is not None:
if master_remote_branch is not None:
if tracking_branch.remote_name != master_remote_branch.remote_name:
status.append("@[email protected]{rf}remote '%s'" % tracking_branch.remote_name)
if need_push(repo, head_branch):
status.append("@[email protected]{yf}needs push")
elif need_pull(repo, head_branch):
status.append("@[email protected]{cf}needs pull")
elif not is_up_to_date(repo, head_branch):
status.append("@[email protected]{yf}needs pull -M")
else:
if head_branch:
status.append("@!on branch '%s'" % repo.head.shorthand)
else:
status.append("empty branch")
if master_remote_branch is None:
status.append("@[email protected]{rf}no remote")
elif master_branch is None:
status.append("@[email protected]{rf}untracked remote")
if is_up_to_date(repo, master_branch) or need_push(repo, master_branch):
if need_pull(repo, head_branch, master_branch):
status.append("@[email protected]{cf}needs pull -L")
else:
if not is_ancestor(repo, master_branch, head_branch):
status.append("@[email protected]{yf}needs merge --from-master")
if not is_up_to_date(repo, head_branch, master_branch):
status.append("@[email protected]{yf}needs merge --to-master")
if master_branch is not None and master_remote_branch is not None and (tracking_branch is None or tracking_branch.name != master_remote_branch.name):
if need_push(repo, master_branch):
status.append("@[email protected]{yf}%s needs push" % master_branch.shorthand)
elif need_pull(repo, master_branch):
status.append("@[email protected]{cf}%s needs pull" % master_branch.shorthand)
elif not is_up_to_date(repo, master_branch):
status.append("@[email protected]{yf}%s needs merge" % master_branch.shorthand)
return status
def create_local_status(repo, upstream_status, is_dirty):
status = []
if repo.head_is_detached:
status.append("@[email protected]{rf}detached HEAD")
return status
if has_pending_merge(repo):
if repo.index.conflicts:
status.append("@[email protected]{rf}merge conflicts")
else:
status.append("@[email protected]{yf}merged, needs commit")
return status
if is_dirty:
status.append("@[email protected]{yf}needs commit")
status += upstream_status
if not status:
if not show_up_to_date:
return None
status.append("@[email protected]{gf}up-to-date")
return status
table = TableView("Package", "Path", "Status")
found_packages = set()
for project in projects:
repo = Repository(os.path.join(srcdir, project.workspace_path, ".git"))
dirty_files = [a for a, b in iteritems(repo.status()) if b != GIT_STATUS_IGNORED and b != GIT_STATUS_CURRENT]
head_branch = get_head_branch(repo)
tracking_branch = head_branch.upstream if head_branch else None
master_remote = get_origin(repo, project)
if master_remote is not None:
master_remote_branch = repo.lookup_branch("%s/%s" % (master_remote.name, project.master_branch), GIT_BRANCH_REMOTE)
master_branch = None
if master_remote_branch is not None:
for name in repo.listall_branches(GIT_BRANCH_LOCAL):
b = repo.lookup_branch(name, GIT_BRANCH_LOCAL)
if b.upstream and b.upstream.branch_name == master_remote_branch.branch_name:
master_branch = b
break
else:
master_remote_branch = None
master_branch = None
ws_packages = find_catkin_packages(srcdir, project.workspace_path, cache=cache)
found_packages |= set(ws_packages.keys())
upstream_status = create_upstream_status(repo, head_branch, master_branch, master_remote_branch, tracking_branch)
for name, pkg_list in iteritems(ws_packages):
if name not in packages:
continue
for pkg in pkg_list:
is_dirty = False
local_path = os.path.relpath(pkg.workspace_path, project.workspace_path)
if dirty_files and local_path == ".":
is_dirty = True
else:
for fpath in dirty_files:
if path_has_prefix(fpath, local_path):
is_dirty = True
break
status = create_local_status(repo, upstream_status, is_dirty)
if status is not None:
head, tail = os.path.split(pkg.workspace_path)
#.........这里部分代码省略.........
示例5: GitRepo
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import listall_branches [as 别名]
class GitRepo(object):
''' git repo class '''
def __init__(self, path):
try:
self.__repo = Repository(path)
except Exception as e:
self.__repo = None
print(e)
def get_info(self):
if not self.__repo:
return None
signature = self.__repo.default_signature
result = {
'path': self.__repo.path,
'workdir': self.__repo.workdir,
'bare': self.__repo.is_bare,
'empty': self.__repo.is_empty,
'name': signature.name,
'email': signature.email,
'time': signature.time,
'offset': signature.offset,
}
return result
def get_all_references(self):
return self.__repo.listall_references()
def get_reference(self, name):
if not self.__repo:
return None
ref = None
try:
ref = self.__repo.lookup_reference(name)
except Exception as e:
print(e)
return ref
def get_all_branches(self, branch_type=None):
if not self.__repo:
return None
if branch_type:
return self.__repo.listall_branches(branch_type)
r = self.__repo.listall_branches(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE)
return r
def get_branch(self, name, branch_type=GIT_BRANCH_LOCAL):
if not self.__repo:
return None
return self.__repo.lookup_branch(name, branch_type)
def check_branch(self, name, branch_type=None):
if not branch_type:
if '/' in name:
branch_type = GIT_BRANCH_REMOTE
else:
branch_type = GIT_BRANCH_LOCAL
try:
result = self.get_branch(name, branch_type)
return result
except Exception as e:
print(e)
return False
def get_current_commit(self):
if not self.__repo:
return None
commit = self.__repo.revparse_single('HEAD')
return self.get_commit(commit)
def get_commit_by_branch(self, branch):
if not self.__repo:
return None
query = 'refs/'
if hasattr(branch, 'remote_name'):
query += 'remotes/'
else:
query += 'heads/'
query += branch.branch_name
try:
ref = self.get_reference(query)
commit = ref.target
return self.get_commit(commit)
except Exception as e:
print(e)
return None
def get_commit_by_tag(self, tag):
if self.__repo is None:
return None
if tag:
commit = tag.get_object()
return self.get_commit(commit)
return None
def get_commit(self, oid_or_commit):
''' return a commit w/ json '''
if not self.__repo or not oid_or_commit:
#.........这里部分代码省略.........