Merge lp:~jr/bzr/314314-obsolete-packs into lp:bzr

Proposed by Jonathan Riddell
Status: Superseded
Proposed branch: lp:~jr/bzr/314314-obsolete-packs
Merge into: lp:bzr
Diff against target: 65 lines (+23/-0)
3 files modified
bzrlib/repofmt/pack_repo.py (+9/-0)
bzrlib/tests/blackbox/test_pack.py (+11/-0)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~jr/bzr/314314-obsolete-packs
Reviewer Review Type Date Requested Status
Martin Packman (community) Needs Fixing
John A Meinel Needs Fixing
Jelmer Vernooij (community) Approve
Review via email: mp+79816@code.launchpad.net

This proposal has been superseded by a proposal from 2011-12-11.

Description of the change

* Create obsolete_packs directory when repacking if it does not
  exist. (Jonathan Riddell, #314314)

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

I'm not sure if this is the right place for the test, but I don't have an idea for a better one. Ideally we would want to test this for all formats for which it is relevant (rather than in a blackbox test, which only exercises the default format). That's pretty hard though - we can't use bt.per_repository, as it's an implementation detail.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Either way, this seems reasonable enough for now. We'll have to move this test when the default format changes, but that's bearable.

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/19/2011 3:42 PM, Jonathan Riddell wrote:
> Jonathan Riddell has proposed merging
> lp:~jr/bzr/314314-obsolete-packs into lp:bzr.
>
> Requested reviews: bzr-core (bzr-core) Related bugs: Bug #314314 in
> Bazaar: "bzr does not automatically create 'obsolete_packs' when it
> is missing." https://bugs.launchpad.net/bzr/+bug/314314
>
> For more details, see:
> https://code.launchpad.net/~jr/bzr/314314-obsolete-packs/+merge/79816
>
> * Create obsolete_packs directory when repacking if it does not
> exist. (Jonathan Riddell, #314314)
>

I really doubt this is correct:
@@ -1221,6 +1222,10 @@
         """
         for pack in packs:
             try:
+ os.mkdir("../obsolete_packs/")
+ except OSError:
+ pass
+ try:
                 pack.pack_transport.move(pack.file_name(),
                     '../obsolete_packs/' + pack.file_name())

Given that the following code is using "pack.pack_transport" that
indicates that this is handling Remote objects. I really don't want to
see "obsolete_packs" suddenly show up in my working directory after
doing 'bzr push'.

 review: needsfixing

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6e2qoACgkQJdeBCYSNAAPBdgCcDEEfUEJBp+0Kilbk0vq9Afkq
0wAAn2nnPqtBvgWvGGAbiXKj6qAH3PK5
=qwd8
-----END PGP SIGNATURE-----

review: Needs Fixing
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks John, you're right. Not sure how I missed that.

Revision history for this message
Martin Packman (gz) wrote :

One other concern:

         for pack in packs:
             try:
+ os.mkdir("../obsolete_packs/")
+ except OSError:
+ pass
+ try:
                 pack.pack_transport.move(pack.file_name(),
                     '../obsolete_packs/' + pack.file_name())
             except (errors.PathError, errors.TransportError), e:

Ignoring the transport issue for now, this does for every pack, try to create the directory and ignoring any errors in the process, then move the file. Presumably this doubles the number of (V)FS operations per pack, which still shouldn't be a big number but seems suboptimal given nearly all the time the directory will already exist.

A better approach would be to detect if the move failed because the move-into directory was missing, create it then, and retry the move. However, it may be that we can't reliably do that over all the different transports we support (translating errors into what they actually mean is very hackish), so always trying to create the directory may still be the best way. Doing that once before this loop, rather than for each pack, should be sufficient though.

review: Needs Fixing
Revision history for this message
Martin Packman (gz) wrote :

Moving this to work in progress for now, but will see if I can pick it up and address the review comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/repofmt/pack_repo.py'
2--- bzrlib/repofmt/pack_repo.py 2011-07-25 07:51:35 +0000
3+++ bzrlib/repofmt/pack_repo.py 2011-10-19 13:45:30 +0000
4@@ -16,6 +16,7 @@
5
6 import re
7 import sys
8+import os
9
10 from bzrlib.lazy_import import lazy_import
11 lazy_import(globals(), """
12@@ -1221,6 +1222,10 @@
13 """
14 for pack in packs:
15 try:
16+ os.mkdir("../obsolete_packs/")
17+ except OSError:
18+ pass
19+ try:
20 pack.pack_transport.move(pack.file_name(),
21 '../obsolete_packs/' + pack.file_name())
22 except (errors.PathError, errors.TransportError), e:
23@@ -1491,6 +1496,10 @@
24 were found in obsolete_packs.
25 """
26 found = []
27+ try:
28+ self.transport.mkdir('obsolete_packs')
29+ except errors.FileExists:
30+ pass
31 obsolete_pack_transport = self.transport.clone('obsolete_packs')
32 if preserve is None:
33 preserve = set()
34
35=== modified file 'bzrlib/tests/blackbox/test_pack.py'
36--- bzrlib/tests/blackbox/test_pack.py 2011-05-13 20:44:45 +0000
37+++ bzrlib/tests/blackbox/test_pack.py 2011-10-19 13:45:30 +0000
38@@ -83,3 +83,14 @@
39
40 pack_names = transport.list_dir('repository/obsolete_packs')
41 self.assertTrue(len(pack_names) == 0)
42+
43+ def test_pack_no_obsolete_packs_directory(self):
44+ """Bug #314314, don't fail if obsolete_packs directory does
45+ not exist."""
46+ wt = self.make_branch_and_tree('.')
47+ open('foo', 'w').write('foo')
48+ self.run_bzr(['add'])
49+ self.run_bzr(['commit', '-m', '"commit 1"'])
50+ import os
51+ os.rmdir('.bzr/repository/obsolete_packs/')
52+ self.run_bzr(['pack'])
53
54=== modified file 'doc/en/release-notes/bzr-2.5.txt'
55--- doc/en/release-notes/bzr-2.5.txt 2011-10-19 12:46:41 +0000
56+++ doc/en/release-notes/bzr-2.5.txt 2011-10-19 13:45:30 +0000
57@@ -48,6 +48,9 @@
58 .. Fixes for situations where bzr would previously crash or give incorrect
59 or undesirable results.
60
61+* Create obsolete_packs directory when repacking if it does not
62+ exist. (Jonathan Riddell, #314314)
63+
64 * ``bzr mkdir --quiet`` now does not print a line for every created
65 directory. (Martin von Gagern, #869915)
66