Merge lp:~jelmer/brz-git/fix-thin-packs into lp:brz-git

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 1902
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz-git/fix-thin-packs
Merge into: lp:brz-git
Diff against target: 111 lines (+25/-28)
2 files modified
fetch.py (+16/-1)
transportgit.py (+9/-27)
To merge this branch: bzr merge lp:~jelmer/brz-git/fix-thin-packs
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+342292@code.launchpad.net

Commit message

Fix thin packs.

Description of the change

Fix thin packs.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Rubberstamp! Proposer approves of own proposal.

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
lp:~jelmer/brz-git/fix-thin-packs updated
1902. By Jelmer Vernooij

Fix tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'fetch.py'
2--- fetch.py 2018-03-26 22:28:24 +0000
3+++ fetch.py 2018-03-28 21:16:28 +0000
4@@ -33,10 +33,12 @@
5 ObjectStoreGraphWalker,
6 tree_lookup_path,
7 )
8+from dulwich.protocol import CAPABILITY_THIN_PACK
9 from dulwich.walk import Walker
10 from itertools import (
11 imap,
12 )
13+from io import BytesIO
14 import posixpath
15 import re
16 import stat
17@@ -847,7 +849,20 @@
18 isinstance(self.target, LocalGitRepository)):
19 pb = ui.ui_factory.nested_progress_bar()
20 try:
21- f, commit, abort = self.target._git.object_store.add_pack()
22+ if CAPABILITY_THIN_PACK in self.source.controldir._client._fetch_capabilities:
23+ # TODO(jelmer): Avoid reading entire file into memory and
24+ # only processing it after the whole file has been fetched.
25+ f = BytesIO()
26+
27+ def commit():
28+ if f.tell():
29+ f.seek(0)
30+ self.target._git.object_store.move_in_thin_pack(f)
31+
32+ def abort():
33+ pass
34+ else:
35+ f, commit, abort = self.target._git.object_store.add_pack()
36 try:
37 refs = self.source.controldir.fetch_pack(
38 determine_wants, graphwalker, f.write,
39
40=== modified file 'transportgit.py'
41--- transportgit.py 2018-03-28 02:09:45 +0000
42+++ transportgit.py 2018-03-28 21:16:28 +0000
43@@ -41,7 +41,7 @@
44 Pack,
45 iter_sha1,
46 load_pack_index_file,
47- write_pack_data,
48+ write_pack_objects,
49 write_pack_index_v2,
50 )
51 from dulwich.repo import (
52@@ -649,21 +649,6 @@
53 self._add_known_pack(basename, final_pack)
54 return final_pack
55
56- def add_thin_pack(self):
57- """Add a new thin pack to this object store.
58-
59- Thin packs are packs that contain deltas with parents that exist
60- in a different pack.
61- """
62- from cStringIO import StringIO
63- f = StringIO()
64- def commit():
65- if len(f.getvalue()) > 0:
66- return self.move_in_thin_pack(f)
67- else:
68- return None
69- return f, commit
70-
71 def move_in_thin_pack(self, f):
72 """Move a specific file containing a pack into the pack directory.
73
74@@ -673,29 +658,26 @@
75 :param path: Path to the pack file.
76 """
77 f.seek(0)
78- data = PackData.from_file(self.get_raw, f, len(f.getvalue()))
79- idx = MemoryPackIndex(data.sorted_entries(), data.get_stored_checksum())
80- p = Pack.from_objects(data, idx)
81+ p = Pack('', resolve_ext_ref=self.get_raw)
82+ p._data = PackData.from_file(f, len(f.getvalue()))
83+ p._data.pack = p
84+ p._idx_load = lambda: MemoryPackIndex(p.data.sorted_entries(), p.data.get_stored_checksum())
85
86- pack_sha = idx.objects_sha1()
87+ pack_sha = p.index.objects_sha1()
88
89 datafile = self.pack_transport.open_write_stream(
90 "pack-%s.pack" % pack_sha)
91 try:
92- entries, data_sum = write_pack_data(datafile, p.pack_tuples())
93+ entries, data_sum = write_pack_objects(datafile, p.pack_tuples())
94 finally:
95 datafile.close()
96- entries.sort()
97+ entries = sorted([(k, v[0], v[1]) for (k, v) in entries.items()])
98 idxfile = self.pack_transport.open_write_stream(
99 "pack-%s.idx" % pack_sha)
100 try:
101- write_pack_index_v2(idxfile, data.sorted_entries(), data_sum)
102+ write_pack_index_v2(idxfile, entries, data_sum)
103 finally:
104 idxfile.close()
105- basename = "pack-%s" % pack_sha
106- final_pack = Pack(basename)
107- self._add_known_pack(basename, final_pack)
108- return final_pack
109
110 def add_pack(self):
111 """Add a new pack to this object store.

Subscribers

People subscribed via source and target branches

to all changes: