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

Add more docstrings.

Changeset 2e9ea87d7178

Parent b706e4d30405

by Jelmer Vernooij

Changes to 2 files · Browse files at 2e9ea87d7178 Showing diff from parent b706e4d30405 Diff from another changeset...

 
41
42
43
44
45
46
47
 
169
170
171
172
 
173
 
 
 
 
 
 
 
174
175
176
 
41
42
43
 
44
45
46
 
168
169
170
 
171
172
173
174
175
176
177
178
179
180
181
182
@@ -41,7 +41,6 @@
  Pack,   PackData,   iter_sha1, - load_packs,   load_pack_index,   write_pack,   write_pack_data, @@ -169,8 +168,15 @@
  def packs(self):   """List with pack objects."""   if self._pack_cache is None: - self._pack_cache = list(load_packs(self.pack_dir)) + self._pack_cache = list(self._load_packs())   return self._pack_cache + + def _load_packs(self): + if not os.path.exists(self.pack_dir): + return + for name in os.listdir(self.pack_dir): + if name.startswith("pack-") and name.endswith(".pack"): + yield Pack(os.path.join(self.pack_dir, name[:-len(".pack")]))     def _add_known_pack(self, path):   """Add a newly appeared pack to the cache by path.
Change 1 of 8 Show Entire File dulwich/​pack.py Stacked
 
68
69
70
 
 
 
 
 
71
72
73
 
75
76
77
78
 
 
 
 
 
 
 
 
79
80
81
 
91
92
93
94
 
 
 
 
 
 
 
 
95
96
97
 
123
124
125
 
 
 
 
126
127
128
 
371
372
373
374
375
376
377
378
379
380
 
472
473
474
475
 
476
477
478
 
636
637
638
 
639
640
641
 
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
 
68
69
70
71
72
73
74
75
76
77
78
 
80
81
82
 
83
84
85
86
87
88
89
90
91
92
93
 
103
104
105
 
106
107
108
109
110
111
112
113
114
115
116
 
142
143
144
145
146
147
148
149
150
151
 
394
395
396
 
 
 
 
397
398
399
 
491
492
493
 
494
495
496
497
 
655
656
657
658
659
660
661
 
1117
1118
1119
 
 
 
 
 
 
 
 
1120
1121
1122
@@ -68,6 +68,11 @@
     def take_msb_bytes(map, offset): + """Read bytes marked with most significant bit. + + :param map: The buffer. + :param offset: Offset in the buffer at which to start reading. + """   ret = []   while len(ret) == 0 or ret[-1] & 0x80:   ret.append(ord(map[offset])) @@ -75,7 +80,14 @@
  return ret     -def read_zlib_chunks(data, offset, dec_size): +def read_zlib_chunks(data, offset): + """Read chunks of zlib data from a buffer. + + :param data: Buffer to read from + :param offset: Offset at which to start reading + :return: Tuple with list of chunks and length of + compressed data length + """   obj = zlib.decompressobj()   ret = []   fed = 0 @@ -91,7 +103,14 @@
     def read_zlib(data, offset, dec_size): - ret, comp_len = read_zlib_chunks(data, offset, dec_size) + """Read zlib-compressed data from a buffer. + + :param data: Buffer + :param offset: Offset in the buffer at which to read + :param dec_size: Size of the decompressed buffer + :return: Uncompressed buffer and compressed buffer length. + """ + ret, comp_len = read_zlib_chunks(data, offset)   x = "".join(ret)   assert len(x) == dec_size   return x, comp_len @@ -123,6 +142,10 @@
     def load_pack_index(filename): + """Load an index file by path. + + :param filename: Path to the index file + """   f = open(filename, 'rb')   if f.read(4) == '\377tOc':   version = struct.unpack(">L", f.read(4))[0] @@ -371,10 +394,6 @@
  assert version in (2, 3), "Version was %d" % version   (num_objects,) = unpack_from(">L", header, 8)   return (version, num_objects) - - -def read_pack_tail(f): - return (f.read(20),)      def unpack_object(map, offset=0): @@ -472,7 +491,7 @@
  def _read_header(self):   (version, self._num_objects) = read_pack_header(self._file)   self._file.seek(self._size-20) - (self._stored_checksum,) = read_pack_tail(self._file) + self._stored_checksum = self._file.read(20)     def __len__(self):   """Returns the number of objects in this pack.""" @@ -636,6 +655,7 @@
  return self._stored_checksum     def check(self): + """Check the consistency of this pack."""   return (self.calculate_checksum() == self.get_stored_checksum())     def get_object_at(self, offset): @@ -1097,14 +1117,6 @@
  *self.data.resolve_object(offset, type, obj, get_raw))     -def load_packs(path): - if not os.path.exists(path): - return - for name in os.listdir(path): - if name.startswith("pack-") and name.endswith(".pack"): - yield Pack(os.path.join(path, name[:-len(".pack")])) - -  try:   from dulwich._pack import apply_delta, bisect_find_sha  except ImportError: