Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

tests/utils: Build graphs of commits with arbitrary attributes.

Change-Id: I6a73e3f08ba8be1887b0a19cf9e1c4d795a1340d

Changeset c567629a8274

Parent a7907599bdef

committed by Jelmer Vernooij

authored by Dave Borowitz

Changes to 2 files · Browse files at c567629a8274 Showing diff from parent a7907599bdef Diff from another changeset...

 
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@@ -68,3 +68,17 @@
  2: [('a', a2, 0100644)]})   self.assertEqual((0100644, a1.id), self.store[c1.tree]['a'])   self.assertEqual((0100644, a2.id), self.store[c2.tree]['a']) + + def test_attrs(self): + c1, c2 = build_commit_graph(self.store, [[1], [2, 1]], + attrs={1: {'message': 'Hooray!'}}) + self.assertEqual('Hooray!', c1.message) + self.assertEqual('Commit 2', c2.message) + + def test_commit_time(self): + c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]], + attrs={1: {'commit_time': 124}, + 2: {'commit_time': 123}}) + self.assertEqual(124, c1.commit_time) + self.assertEqual(123, c2.commit_time) + self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)
 
238
239
240
241
 
242
243
244
 
262
263
264
 
 
265
266
267
268
269
 
 
270
271
272
 
289
290
291
292
293
294
295
296
297
298
 
 
 
 
 
 
 
 
 
 
 
 
299
300
301
 
238
239
240
 
241
242
243
244
 
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 
293
294
295
 
 
 
 
 
 
 
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
@@ -238,7 +238,7 @@
  return expected     -def build_commit_graph(object_store, commit_spec, trees=None): +def build_commit_graph(object_store, commit_spec, trees=None, attrs=None):   """Build a commit graph from a concise specification.     Sample usage: @@ -262,11 +262,15 @@
  trees for commits. The tree spec is an iterable of (path, blob, mode) or   (path, blob) entries; if mode is omitted, it defaults to the normal file   mode (0100644). + :param attrs: A dict of commit number -> (dict of attribute -> value) for + assigning additional values to the commits.   :return: The list of commit objects created.   :raise ValueError: If an undefined commit identifier is listed as a parent.   """   if trees is None:   trees = {} + if attrs is None: + attrs = {}   commit_time = 0   nums = {}   commits = [] @@ -289,13 +293,18 @@
  object_store.add_object(blob)   tree_id = commit_tree(object_store, blobs)   - commit_obj = make_commit( - message=('Commit %i' % commit_num), - parents=parent_ids, - tree=tree_id, - commit_time=commit_time) - - commit_time += 1 + commit_attrs = { + 'message': 'Commit %i' % commit_num, + 'parents': parent_ids, + 'tree': tree_id, + 'commit_time': commit_time, + } + commit_attrs.update(attrs.get(commit_num, {})) + commit_obj = make_commit(**commit_attrs) + + # By default, increment the time by a lot. Out-of-order commits should + # be closer together than this because their main cause is clock skew. + commit_time = commit_attrs['commit_time'] + 100   nums[commit_num] = commit_obj.id   object_store.add_object(commit_obj)   commits.append(commit_obj)