Dulwich.io dulwich / 58df749
Honor shallows when pushing from a shallow clone. Fixes: #794 Jelmer Vernooij 25 days ago
4 changed file(s) with 51 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
44
55 * Fix pushing of new branches from porcelain.push.
66 (Jelmer Vernooij, #788)
7
8 * Honor shallows when pushing from a shallow clone.
9 (Jelmer Vernooij, #794)
710
811 0.20.5 2020-06-22
912
9898 c2s = commit_ids[1:]
9999 if c1 in c2s:
100100 return [c1]
101 return _find_lcas(repo.get_parents, c1, c2s)
101 parents_provider = repo.parents_provider()
102 return _find_lcas(parents_provider.get_parents, c1, c2s)
102103
103104
104105 def find_octopus_base(repo, commit_ids):
115116 return []
116117 if len(commit_ids) <= 2:
117118 return find_merge_base(repo, commit_ids)
119 parents_provider = repo.parents_provider()
118120 lcas = [commit_ids[0]]
119121 others = commit_ids[1:]
120122 for cmt in others:
121123 next_lcas = []
122124 for ca in lcas:
123 res = _find_lcas(repo.get_parents, cmt, [ca])
125 res = _find_lcas(parents_provider.get_parents, cmt, [ca])
124126 next_lcas.extend(res)
125127 lcas = next_lcas[:]
126128 return lcas
138140 return True
139141
140142 # Algorithm: Find the common ancestor
141 lcas = _find_lcas(repo.get_parents, c1, [c2])
143 parents_provider = repo.parents_provider()
144 lcas = _find_lcas(parents_provider.get_parents, c1, [c2])
142145 return lcas == [c1]
296296 # Could implement other platform specific filesytem hiding here
297297
298298
299 class ParentsProvider(object):
300
301 def __init__(self, store, grafts={}, shallows=[]):
302 self.store = store
303 self.grafts = grafts
304 self.shallows = set(shallows)
305
306 def get_parents(self, commit_id, commit=None):
307 try:
308 return self.grafts[commit_id]
309 except KeyError:
310 pass
311 if commit_id in self.shallows:
312 return []
313 if commit is None:
314 commit = self.store[commit_id]
315 return commit.parents
316
317
299318 class BaseRepo(object):
300319 """Base class for a git repository.
301320
486505 # commits aren't missing.
487506 haves = []
488507
508 parents_provider = ParentsProvider(
509 self.object_store, shallows=shallows)
510
489511 def get_parents(commit):
490 if commit.id in shallows:
491 return []
492 return self.get_parents(commit.id, commit)
512 return parents_provider.get_parents(commit.id, commit)
493513
494514 return self.object_store.iter_shas(
495515 self.object_store.find_missing_objects(
524544 heads = [
525545 sha for sha in self.refs.as_dict(b'refs/heads').values()
526546 if sha in self.object_store]
547 parents_provider = ParentsProvider(self.object_store)
527548 return ObjectStoreGraphWalker(
528 heads, self.get_parents, shallow=self.get_shallow())
549 heads, parents_provider.get_parents, shallow=self.get_shallow())
529550
530551 def get_refs(self) -> Dict[bytes, bytes]:
531552 """Get dictionary with all refs.
566587 """
567588 return self.object_store[sha]
568589
590 def parents_provider(self):
591 return ParentsProvider(
592 self.object_store, grafts=self._graftpoints,
593 shallows=self.get_shallow())
594
569595 def get_parents(self, sha: bytes, commit: Commit = None) -> List[bytes]:
570596 """Retrieve the parents of a specific commit.
571597
577603 commit: Optional commit matching the sha
578604 Returns: List of parents
579605 """
580 try:
581 return self._graftpoints[sha]
582 except KeyError:
583 if commit is None:
584 commit = self[sha]
585 return commit.parents
606 return self.parents_provider().get_parents(sha, commit)
586607
587608 def get_config(self):
588609 """Retrieve the config object.
250250 def test_get_peeled_not_tag(self):
251251 r = self.open_repo('a.git')
252252 self.assertEqual(r.get_peeled(b'HEAD'), r.head())
253
254 def test_get_parents(self):
255 r = self.open_repo('a.git')
256 self.assertEqual(
257 [b'2a72d929692c41d8554c07f6301757ba18a65d91'],
258 r.get_parents(b'a90fa2d900a17e99b433217e988c4eb4a2e9a097'))
259 r.update_shallow(
260 [b'a90fa2d900a17e99b433217e988c4eb4a2e9a097'],
261 None)
262 self.assertEqual(
263 [], r.get_parents(b'a90fa2d900a17e99b433217e988c4eb4a2e9a097'))
253264
254265 def test_get_walker(self):
255266 r = self.open_repo('a.git')