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

walk: Add option to limit the number of commits returned.

Change-Id: Ice14da3a020d62d1f9d959de7d0e1e795bd5c376

Changeset 4406d2347758

Parent 16838115fc46

committed by Jelmer Vernooij

authored by Dave Borowitz

Changes to 2 files · Browse files at 4406d2347758 Showing diff from parent 16838115fc46 Diff from another changeset...

 
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@@ -75,3 +75,16 @@
  def test_reverse(self):   c1, c2, c3 = self.make_linear_commits(3)   self.assertWalkYields([c1, c2, c3], [c3.id], reverse=True) + + def test_max_commits(self): + c1, c2, c3 = self.make_linear_commits(3) + self.assertWalkYields([c3, c2, c1], [c3.id], max_commits=3) + self.assertWalkYields([c3, c2], [c3.id], max_commits=2) + self.assertWalkYields([c3], [c3.id], max_commits=1) + + def test_reverse_after_max_commits(self): + c1, c2, c3 = self.make_linear_commits(3) + self.assertWalkYields([c1, c2, c3], [c3.id], max_commits=3, + reverse=True) + self.assertWalkYields([c2, c3], [c3.id], max_commits=2, reverse=True) + self.assertWalkYields([c3], [c3.id], max_commits=1, reverse=True)
Change 1 of 4 Show Entire File dulwich/​walk.py Stacked
 
32
33
34
35
 
36
37
38
 
44
45
46
 
 
47
48
49
 
51
52
53
 
54
55
56
 
88
89
90
 
 
 
91
92
93
 
32
33
34
 
35
36
37
38
 
44
45
46
47
48
49
50
51
 
53
54
55
56
57
58
59
 
91
92
93
94
95
96
97
98
99
@@ -32,7 +32,7 @@
  """     def __init__(self, store, include, exclude=None, order=ORDER_DATE, - reverse=False): + reverse=False, max_commits=None):   """Constructor.     :param store: ObjectStore instance for looking up objects. @@ -44,6 +44,8 @@
  other than ORDER_DATE may result in O(n) memory usage.   :param reverse: If True, reverse the order of output, requiring O(n)   memory. + :param max_commits: The maximum number of commits to yield, or None for + no limit.   """   self._store = store   @@ -51,6 +53,7 @@
  raise ValueError('Unknown walk order %s' % order)   self._order = order   self._reverse = reverse + self._max_commits = max_commits     exclude = exclude or []   self._excluded = set(exclude) @@ -88,6 +91,9 @@
  return None     def _next(self): + limit = self._max_commits + if limit is not None and len(self._done) >= limit: + return None   return self._pop()     def __iter__(self):