本文整理汇总了Python中git.Commit类的典型用法代码示例。如果您正苦于以下问题:Python Commit类的具体用法?Python Commit怎么用?Python Commit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Commit类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serialization_unicode_support
def test_serialization_unicode_support(self):
assert Commit.default_encoding.lower() == 'utf-8'
# create a commit with unicode in the message, and the author's name
# Verify its serialization and deserialization
cmt = self.rorepo.commit('0.1.6')
assert isinstance(cmt.message, text_type) # it automatically decodes it as such
assert isinstance(cmt.author.name, text_type) # same here
cmt.message = u"üäêèß"
assert len(cmt.message) == 5
cmt.author.name = u"äüß"
assert len(cmt.author.name) == 3
cstream = BytesIO()
cmt._serialize(cstream)
cstream.seek(0)
assert len(cstream.getvalue())
ncmt = Commit(self.rorepo, cmt.binsha)
ncmt._deserialize(cstream)
assert cmt.author.name == ncmt.author.name
assert cmt.message == ncmt.message
# actually, it can't be printed in a shell as repr wants to have ascii only
# it appears
cmt.author.__repr__()
示例2: test_commit_serialization
def test_commit_serialization(self):
assert_commit_serialization(self.gitrwrepo, self.gitrwrepo.head, True)
rwrepo = self.gitrwrepo
make_object = rwrepo.odb.store
# direct serialization - deserialization can be tested afterwards
# serialization is probably limited on IO
hc = rwrepo.commit(rwrepo.head)
nc = 5000
st = time()
for i in xrange(nc):
cm = Commit(rwrepo, Commit.NULL_BIN_SHA, hc.tree,
hc.author, hc.authored_date, hc.author_tz_offset,
hc.committer, hc.committed_date, hc.committer_tz_offset,
str(i), parents=hc.parents, encoding=hc.encoding)
stream = BytesIO()
cm._serialize(stream)
slen = stream.tell()
stream.seek(0)
cm.binsha = make_object(IStream(Commit.type, slen, stream)).binsha
# END commit creation
elapsed = time() - st
print("Serialized %i commits to loose objects in %f s ( %f commits / s )"
% (nc, elapsed, nc / elapsed), file=sys.stderr)
示例3: assert_commit_serialization
def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
"""traverse all commits in the history of commit identified by commit_id and check
if the serialization works.
:param print_performance_info: if True, we will show how fast we are"""
ns = 0 # num serializations
nds = 0 # num deserializations
st = time.time()
for cm in rwrepo.commit(commit_id).traverse():
nds += 1
# assert that we deserialize commits correctly, hence we get the same
# sha on serialization
stream = BytesIO()
cm._serialize(stream)
ns += 1
streamlen = stream.tell()
stream.seek(0)
istream = rwrepo.odb.store(IStream(Commit.type, streamlen, stream))
assert istream.hexsha == cm.hexsha.encode('ascii')
nc = Commit(rwrepo, Commit.NULL_BIN_SHA, cm.tree,
cm.author, cm.authored_date, cm.author_tz_offset,
cm.committer, cm.committed_date, cm.committer_tz_offset,
cm.message, cm.parents, cm.encoding)
assert nc.parents == cm.parents
stream = BytesIO()
nc._serialize(stream)
ns += 1
streamlen = stream.tell()
stream.seek(0)
# reuse istream
istream.size = streamlen
istream.stream = stream
istream.binsha = None
nc.binsha = rwrepo.odb.store(istream).binsha
# if it worked, we have exactly the same contents !
assert nc.hexsha == cm.hexsha
# END check commits
elapsed = time.time() - st
if print_performance_info:
print("Serialized %i and deserialized %i commits in %f s ( (%f, %f) commits / s"
% (ns, nds, elapsed, ns / elapsed, nds / elapsed), file=sys.stderr)
示例4: test_iteration
def test_iteration(self):
# we can iterate commits
all_commits = Commit.list_items(self.rorepo, self.rorepo.head)
assert all_commits
assert all_commits == list(self.rorepo.iter_commits())
# this includes merge commits
mcomit = self.rorepo.commit('d884adc80c80300b4cc05321494713904ef1df2d')
assert mcomit in all_commits
# we can limit the result to paths
ltd_commits = list(self.rorepo.iter_commits(paths='CHANGES'))
assert ltd_commits and len(ltd_commits) < len(all_commits)
# show commits of multiple paths, resulting in a union of commits
less_ltd_commits = list(Commit.iter_items(self.rorepo, 'master', paths=('CHANGES', 'AUTHORS')))
assert len(ltd_commits) < len(less_ltd_commits)
示例5: test_commit_iteration
def test_commit_iteration(self):
# bound to stream parsing performance
nc = 0
st = time()
for c in Commit.iter_items(self.gitrorepo, self.gitrorepo.head):
nc += 1
self._query_commit_info(c)
# END for each traversed commit
elapsed_time = time() - st
print("Iterated %i Commits in %s [s] ( %f commits/s )"
% (nc, elapsed_time, nc / elapsed_time), file=sys.stderr)
示例6: get_commits_not_in_prs
def get_commits_not_in_prs(start_ref, end_ref):
"""
Return a tuple of commits that exist between start_ref and end_ref,
but were not merged to the end_ref. If everyone is following the
pull request process correctly, this should return an empty tuple.
"""
return tuple(Commit.iter_items(
repo,
"{start}..{end}".format(start=start_ref, end=end_ref),
first_parent=True, no_merges=True,
))
示例7: _do_commit
def _do_commit (self, repo, head, tree_binsha, msg, parent=None):
""" if parent parameter is None, we make it default to be [head.commit]
return new commit's hexsha, on error return None and output error
"""
assert (repo)
assert head is None or isinstance (head, HEAD) or isinstance (head, Head)
assert msg != None
if parent is None:
try:
parent = [head.commit]
except ValueError:
pass
new_commit = Commit.create_from_tree (repo, Tree (repo, tree_binsha), msg, \
parent_commits=parent, head=False) # because the first commit has no parent, parameter head==True likely fails
head.commit = new_commit #modify head's ref to commit
return new_commit
示例8: test_rev_list_bisect_all
def test_rev_list_bisect_all(self):
"""
'git rev-list --bisect-all' returns additional information
in the commit header. This test ensures that we properly parse it.
"""
revs = self.rorepo.git.rev_list('933d23bf95a5bd1624fbcdf328d904e1fa173474',
first_parent=True,
bisect_all=True)
commits = Commit._iter_from_process_or_stream(self.rorepo, StringProcessAdapter(revs.encode('ascii')))
expected_ids = (
'7156cece3c49544abb6bf7a0c218eb36646fad6d',
'1f66cfbbce58b4b552b041707a12d437cc5f400a',
'33ebe7acec14b25c5f84f35a664803fcab2f7781',
'933d23bf95a5bd1624fbcdf328d904e1fa173474'
)
for sha1, commit in zip(expected_ids, commits):
assert_equal(sha1, commit.hexsha)
示例9: get_files_changed_between_commits
def get_files_changed_between_commits(commit_a: Commit, commit_b: Commit)-> (Set[str], Set[str]):
"""Determine what files have been added or modified between commits b and a
Those files should be added to a_files and if they are present in commit b,
added to b_files
:param commit_a:
:param commit_b:
:return: a pair of sets, the first set is the files in commit a
the second set is the files in commit b
":rtype (Set[str], Set[str]):
"""
diffs = commit_b.diff(other=commit_a)
a_files = set() # type: Set[str]
b_files = set() # type: Set[str]
for diff in diffs:
if diff.new_file or (diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob):
a_files.add(diff.a_path)
if not diff.new_file:
b_files.add(diff.b_path)
return a_files, b_files
示例10: create_rpmbuild_content
def create_rpmbuild_content(repo, target, config):
rpm_prefix = config['rpm']['prefix']
for branch in repo.branches:
# We only want environment branches, not manifest branches.
if not branch.name.startswith(manifest_branch_prefix):
manifest_branch_name = manifest_branch_prefix + branch.name
# If there is no equivalent manifest branch, we need to
# skip this environment.
if manifest_branch_name not in repo.branches:
continue
branch.checkout()
labelled_tags = tags_by_label(os.path.join(repo.working_dir,
'labels'))
# Get number of commits to determine the version of the env rpm.
commit_num = len(list(Commit.iter_items(repo, branch.commit)))
# Keep track of the labels which have tags - its those we want.
for label, tag in labelled_tags.items():
create_rpmbuild_for_tag(repo, tag, target, config)
fname = '{}-env-{}-label-{}.spec'.format(rpm_prefix, branch.name, label)
with open(os.path.join(target, 'SPECS', fname), 'w') as fh:
fh.write(generate.render_env(branch.name, label,
repo, config, tag, commit_num))
示例11: test_list
def test_list(self):
# This doesn't work anymore, as we will either attempt getattr with bytes, or compare 20 byte string
# with actual 20 byte bytes. This usage makes no sense anyway
assert isinstance(Commit.list_items(self.rorepo, '0.1.5', max_count=5)[
'5117c9c8a4d3af19a9958677e45cda9269de1541'], Commit)
示例12: newcommit
def newcommit(repo, message, date, name=None, email=None):
"""Creates a commit object with a custom date.
:param repo: Repo object the commit should be part of
:param tree: Tree object
:param message: Commit message. It may be an empty string
if no message is provided.
:param date: Date in seconds, as an Int
:return: Commit object representing the new commit
:note:
Additional information about the committer and Author are taken from
the git configuration
"""
tree = repo.index.write_tree()
try:
parents = [repo.head.commit]
except ValueError:
parents = []
# Committer and Author info
cr = repo.config_reader()
if name == None or email == None:
actor = Actor.committer(cr)
else:
actor = Actor(name, email)
committer = actor
author = actor
# Date
# offset = altzone # 3600*offsethours
offset = 0 # UTC
author_time, author_offset = date, offset
committer_time, committer_offset = date, offset
# assume utf8 encoding
enc_section, enc_option = Commit.conf_encoding.split('.')
conf_encoding = cr.get_value(enc_section,
enc_option,
Commit.default_encoding)
# Create New Commit
new_commit = Commit(repo, Commit.NULL_BIN_SHA, tree,
author, author_time, author_offset,
committer, committer_time, committer_offset,
message, parents, conf_encoding)
stream = StringIO()
new_commit._serialize(stream)
streamlen = stream.tell()
stream.seek(0)
istream = repo.odb.store(IStream(Commit.type, streamlen, stream))
new_commit.binsha = istream.binsha
# Advance HEAD to the new commit automatically.
# need late import here, importing git at the very beginning throws.
import git.refs
try:
repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
except ValueError:
# head is not yet set to the ref our HEAD points to
# Happens on first commit
import git.refs
master = git.refs.Head.create(repo, repo.head.ref,
new_commit, logmsg="commit (initial): %s" % message)
repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)
# END handle empty repositories
return new_commit
示例13: commit
def commit(self, commit, message):
"""Commits files given a commit message and a given commit"""
self.repo.git.commit()
class CommitFile(object):
"""Holds some information about a file in addition to its diff"""
def __init__(self):
self.isUntracked = None
self.isRenamed = None
self.diff = None
self.lineNumbers = None
#self.
def setDiff(self, diff):
""""""
self.diff = diff
if __name__ == "__main__":
x = GitManager('')
print x.grabUntrackedFiles()
print x.grabAllFilesToBeCommited()
commit = Commit.new(x.repo, x.repo.head.ref)
print commit
print commit.author
print commit.committer
print dir(commit.stats)
print commit.stats.files
#print x.createCommitForPartialFiles()
#print commit.diff(None, None)
#print x.repo.commit().diff(None, None)[1].a_blob.path