@@ -66,12 +66,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
66
66
__slots__ = ("tree" ,
67
67
"author" , "authored_date" , "author_tz_offset" ,
68
68
"committer" , "committed_date" , "committer_tz_offset" ,
69
- "message" , "parents" , "encoding" , "gpgsig" )
69
+ "message" , "parents" , "encoding" , "gpgsig" , "predecessors" )
70
70
_id_attribute_ = "hexsha"
71
71
72
72
def __init__ (self , repo , binsha , tree = None , author = None , authored_date = None , author_tz_offset = None ,
73
73
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 ):
75
75
"""Instantiate a new Commit. All keyword arguments taking None as default will
76
76
be implicitly set on first query.
77
77
@@ -101,6 +101,9 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
101
101
:param parents:
102
102
List or tuple of Commit objects which are our parent(s) in the commit
103
103
dependency graph
104
+ :param predecessors:
105
+ List or tuple of Commit objects which this commit replaces after rebasing or amending
106
+ rewrite graph
104
107
:return: git.Commit
105
108
106
109
:note:
@@ -132,6 +135,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut
132
135
self .encoding = encoding
133
136
if gpgsig is not None :
134
137
self .gpgsig = gpgsig
138
+ if predecessors is not None :
139
+ self .predecessors = predecessors
135
140
136
141
@classmethod
137
142
def _get_intermediate_items (cls , commit ):
@@ -280,7 +285,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream):
280
285
281
286
@classmethod
282
287
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 ):
284
289
"""Commit the given tree, creating a commit object.
285
290
286
291
: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,
325
330
# end check parent commit types
326
331
# END if parent commits are unset
327
332
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
+
328
342
# retrieve all additional information, create a commit object, and
329
343
# serialize it
330
344
# Generally:
@@ -375,7 +389,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
375
389
new_commit = cls (repo , cls .NULL_BIN_SHA , tree ,
376
390
author , author_time , author_offset ,
377
391
committer , committer_time , committer_offset ,
378
- message , parent_commits , conf_encoding )
392
+ message , parent_commits , conf_encoding , predecessors = predecessors )
379
393
380
394
stream = BytesIO ()
381
395
new_commit ._serialize (stream )
@@ -434,6 +448,9 @@ def _serialize(self, stream):
434
448
except AttributeError :
435
449
pass
436
450
5A0C
451
+ for p in self .predecessors :
452
+ write (("predecessor %s\n " % p ).encode ('ascii' ))
453
+
437
454
write (b"\n " )
438
455
439
456
# write plain bytes, be sure its encoded according to our encoding
0 commit comments