Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

Refactor GraphWalker.

Changeset 23240f0f5ecc

Parent 264b631fe2ef

by Jelmer Vernooij

Changes to 4 files · Browse files at 23240f0f5ecc Showing diff from parent 264b631fe2ef Diff from another changeset...

Change 1 of 4 Show Entire File bin/​dulwich Stacked
 
31
32
33
34
35
36
37
 
41
42
43
44
 
45
46
47
 
143
144
145
146
147
148
149
 
164
165
166
167
 
168
169
170
 
31
32
33
 
34
35
36
 
40
41
42
 
43
44
45
46
 
142
143
144
 
145
146
147
 
162
163
164
 
165
166
167
168
@@ -31,7 +31,6 @@
     def cmd_fetch_pack(args): - from dulwich.client import SimpleFetchGraphWalker   from dulwich.repo import Repo   opts, args = getopt(args, "", ["all"])   opts = dict(opts) @@ -41,7 +40,7 @@
  else:   determine_wants = lambda x: [y for y in args if not y in r.object_store]   r = Repo(".") - graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents) + graphwalker = r.get_graph_walker()   f, commit = r.object_store.add_pack()   try:   client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write) @@ -143,7 +142,6 @@
     def cmd_clone(args): - from dulwich.client import SimpleFetchGraphWalker   from dulwich.repo import Repo   import os   import sys @@ -164,7 +162,7 @@
  os.mkdir(path)   Repo.init(path)   r = Repo(path) - graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents) + graphwalker = r.get_graph_walker()   f, commit = r.object_store.add_pack()   client.fetch_pack(host_path, r.object_store.determine_wants_all,   graphwalker, f.write, sys.stdout.write)
Change 1 of 1 Show Entire File dulwich/​client.py Stacked
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
@@ -42,38 +42,6 @@
 def _fileno_can_read(fileno):   """Check if a file descriptor is readable."""   return len(select.select([fileno], [], [], 0)[0]) > 0 - - -class SimpleFetchGraphWalker(object): - """Graph walker that finds out what commits are missing.""" - - def __init__(self, local_heads, get_parents): - """Create a new SimpleFetchGraphWalker instance. - - :param local_heads: SHA1s that should be retrieved - :param get_parents: Function for finding the parents of a SHA1. - """ - self.heads = set(local_heads) - self.get_parents = get_parents - self.parents = {} - - def ack(self, sha): - """Ack that a particular revision and its ancestors are present in the target.""" - if sha in self.heads: - self.heads.remove(sha) - if sha in self.parents: - for p in self.parents[sha]: - self.ack(p) - - def next(self): - """Iterate over revisions that might be missing in the target.""" - if self.heads: - ret = self.heads.pop() - ps = self.get_parents(ret) - self.parents[ret] = ps - self.heads.update(ps) - return ret - return None      CAPABILITIES = ["multi_ack", "side-band-64k", "ofs-delta"]
 
111
112
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
115
116
 
476
477
478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
@@ -111,6 +111,22 @@
  """   return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None)   + def get_commit_parents(self, sha): + """Retrieve the parents of a commit. + + :param sha: SHA1 of the commit + :return: List of parent SHA1s + """ + return self[sha].parents + + def get_graph_walker(self, heads): + """Obtain a graph walker for this object store. + + :param heads: Local heads to start search with + :return: GraphWalker object + """ + return ObjectStoreGraphWalker(heads, self.get_commit_parents) +    class DiskObjectStore(BaseObjectStore):   """Git-style object store that exists on disk.""" @@ -476,3 +492,38 @@
  self.sha_done.add(sha)   self.progress("counting objects: %d\r" % len(self.sha_done))   return (sha, name) + + +class ObjectStoreGraphWalker(object): + """Graph walker that finds out what commits are missing from an object store.""" + + def __init__(self, local_heads, get_parents): + """Create a new instance. + + :param local_heads: Heads to start search with + :param get_parents: Function for finding the parents of a SHA1. + """ + self.heads = set(local_heads) + self.get_parents = get_parents + self.parents = {} + + def ack(self, sha): + """Ack that a particular revision and its ancestors are present in the source.""" + if sha in self.heads: + self.heads.remove(sha) + if sha in self.parents: + for p in self.parents[sha]: + self.ack(p) + + def next(self): + """Iterate over ancestors of heads in the target.""" + if self.heads: + ret = self.heads.pop() + ps = self.get_parents(ret) + self.parents[ret] = ps + self.heads.update(ps) + return ret + return None + + +
Change 1 of 2 Show Entire File dulwich/​repo.py Stacked
 
156
157
158
 
 
 
 
 
159
160
161
 
292
293
294
295
 
296
297
298
 
156
157
158
159
160
161
162
163
164
165
166
 
297
298
299
 
300
301
302
303
@@ -156,6 +156,11 @@
  return self.object_store.iter_shas(   self.find_missing_objects(determine_wants, graph_walker, progress))   + def get_graph_walker(self, heads=None): + if heads is None: + heads = self.heads().values() + return self.object_store.get_graph_walker(heads) +   def object_dir(self):   """Return path of the object directory."""   return os.path.join(self.controldir(), OBJECTDIR) @@ -292,7 +297,7 @@
  return self.object_store[sha]     def get_parents(self, sha): - return self.commit(sha).parents + return self.object_store.get_commit_parents(sha)     def commit(self, sha):   return self._get_object(sha, Commit)