8000 Writes predecessor headers in the commits · gitpython-developers/GitPython@42ec41d · GitHub
[go: up one dir, main page]

Skip to content

Commit 42ec41d

Browse files
committed
Writes predecessor headers in the commits
1 parent 8f76463 commit 42ec41d

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

git/objects/commit.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
6666
__slots__ = ("tree",
6767
"author", "authored_date", "author_tz_offset",
6868
"committer", "committed_date", "committer_tz_offset",
69-
"message", "parents", "encoding", "gpgsig")
69+
"message", "parents", "encoding", "gpgsig", "predecessors")
7070
_id_attribute_ = "hexsha"
7171

7272
def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None,
7373
committer=None, committed_date=None, committer_tz_offset=None,
74-
message=None, parents=None, encoding=None, gpgsig=None):
74+
message=None, parents=None, encoding=None, gpgsig=None, predecessors=None):
7575
"""Instantiate a new Commit. All keyword arguments taking None as default will
7676
be implicitly set on first query.
7777
@@ -101,6 +101,9 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
101101
:param parents:
102102
List or tuple of Commit objects which are our parent(s) in the commit
103103
dependency graph
104+
:param predecessors:
105+
List or tuple of Commit objects which this commit replaces after rebasing or amending
106+
rewrite graph
104107
:return: git.Commit
105108
106109
:note:
@@ -132,6 +135,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
132135
self.encoding = encoding
133136
if gpgsig is not None:
134137
self.gpgsig = gpgsig
138+
if predecessors is not None:
139+
self.predecessors = predecessors
135140

136141
@classmethod
137142
def _get_intermediate_items(cls, commit):
@@ -280,7 +285,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
280285

281286
@classmethod
282287
def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, author=None, committer=None,
283-
author_date=None, commit_date=None):
288+
author_date=None, commit_date=None, predecessors=None):
284289
"""Commit the given tree, creating a commit object.
285290
286291
:param repo: Repo object the commit should be part of
@@ -325,6 +330,15 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
325330
# end check parent commit types
326331
# END if parent commits are unset
327332

333+
if predecessors is None:
334+
predecessors=list()
335+
else:
336+
for p in predecessors:
337+
if not isinstance(p, cls):
338+
raise ValueError("Replaced commit '%r' must be of type %s" % (p, cls))
339+
# end check predecessors commit types
340+
# END if predecessors commits are unset
341+
328342
# retrieve all additional information, create a commit object, and
329343
# serialize it
330344
# Generally:
@@ -375,7 +389,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
375389
new_commit = cls(repo, cls.NULL_BIN_SHA, tree,
376390
author, author_time, author_offset,
377391
committer, committer_time, committer_offset,
378-
message, parent_commits, conf_encoding)
392+
message, parent_commits, conf_encoding, predecessors=predecessors)
379393

380394
stream = BytesIO()
381395
new_commit._serialize(stream)
@@ -434,6 +448,9 @@ def _serialize(self, stream):
434448
except AttributeError:
435449
pass
436450 5A0C

451+
for p in self.predecessors:
452+
write(("predecessor %s\n" % p).encode('ascii'))
453+
437454
write(b"\n")
438455

439456
# write plain bytes, be sure its encoded according to our encoding

0 commit comments

Comments
 (0)
0