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

Deal with thin packs appropriately.

Changeset 14711851a193

Parent ececb785a296

by Jelmer Vernooij

Changes to 3 files · Browse files at 14711851a193 Showing diff from parent ececb785a296 Diff from another changeset...

 
18
19
20
 
21
22
23
 
27
28
29
 
30
31
32
 
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
 
95
96
97
98
 
99
100
101
102
 
 
 
 
 
 
 
 
 
 
 
 
 
103
104
105
 
18
19
20
21
22
23
24
 
28
29
30
31
32
33
34
 
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
114
115
116
 
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@@ -18,6 +18,7 @@
   from objects import (   ShaFile, + hex_to_sha,   )  import os, tempfile  from pack import ( @@ -27,6 +28,7 @@
  PackData,   )  import tempfile +import urllib2  PACKDIR = 'pack'    class ObjectStore(object): @@ -86,6 +88,23 @@
  type, uncomp = self.get_raw(sha)   return ShaFile.from_raw_string(type, uncomp)   + def move_in_thin_pack(self, path): + """Move a specific file containing a pack into the pack directory. + + :note: The file should be on the same file system as the + packs directory. + + :param path: Path to the pack file. + """ + p = PackData(path) + temppath = os.path.join(self.pack_dir(), sha_to_hex(urllib2.randombytes(20))+".temppack") + write_pack(temppath, p.iterobjects(self.get_raw), len(p)) + pack_sha = PackIndex(temppath+".idx").objects_sha1() + os.rename(temppath+".pack", + os.path.join(self.pack_dir(), "pack-%s.pack" % pack_sha)) + os.rename(temppath+".idx", + os.path.join(self.pack_dir(), "pack-%s.idx" % pack_sha)) +   def move_in_pack(self, path):   """Move a specific file containing a pack into the pack directory.   @@ -95,11 +114,24 @@
  :param path: Path to the pack file.   """   p = PackData(path) - entries = p.sorted_entries(self.get_raw) + entries = p.sorted_entries()   basename = os.path.join(self.pack_dir(),   "pack-%s" % iter_sha1(entry[0] for entry in entries))   write_pack_index_v2(basename+".idx", entries, p.calculate_checksum())   os.rename(path, basename + ".pack") + + def add_thin_pack(self): + """Add a new thin pack to this object store. + + Thin packs are packs that contain deltas with parents that exist + in a different pack. + """ + fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack") + f = os.fdopen(fd, 'w') + def commit(): + if os.path.getsize(path) > 0: + self.move_in_thin_pack(path) + return f, commit     def add_pack(self):   """Add a new pack to this object store.
Change 1 of 2 Show Entire File dulwich/​pack.py Stacked
 
848
849
850
851
852
853
854
855
 
864
865
866
867
 
 
 
 
868
869
870
871
872
 
 
 
873
874
875
 
848
849
850
 
 
851
852
853
 
862
863
864
 
865
866
867
868
869
870
871
 
 
872
873
874
875
876
877
@@ -848,8 +848,6 @@
  return (self.idx.object_index(sha1) is not None)     def get_raw(self, sha1, resolve_ref=None): - if resolve_ref is None: - resolve_ref = self.get_raw   offset = self.idx.object_index(sha1)   if offset is None:   raise KeyError(sha1) @@ -864,12 +862,16 @@
  type, uncomp = self.get_raw(sha1)   return ShaFile.from_raw_string(type, uncomp)   - def iterobjects(self): + def iterobjects(self, get_raw=None): + if get_raw is None: + def get_raw(x): + raise KeyError(x)   for offset, type, obj in self.data.iterobjects():   assert isinstance(offset, int)   yield ShaFile.from_raw_string( - *resolve_object(offset, type, obj, self.get_raw, - self.data.get_object_at)) + *resolve_object(offset, type, obj, + get_raw, + self.data.get_object_at))      def load_packs(path):
Change 1 of 1 Show Entire File dulwich/​server.py Stacked
 
63
64
65
66
 
67
68
69
 
63
64
65
 
66
67
68
69
@@ -63,7 +63,7 @@
  self.get_refs = self.repo.get_refs     def apply_pack(self, refs, read): - fd, commit = self.repo.object_store.add_pack() + fd, commit = self.repo.object_store.add_thin_pack()   fd.write(read())   fd.close()   commit()