Merge lp:~nmb/bzr/484101-default-format into lp:bzr

Proposed by Neil Martinsen-Burrell
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5481
Proposed branch: lp:~nmb/bzr/484101-default-format
Merge into: lp:bzr
Diff against target: 82 lines (+30/-1)
4 files modified
NEWS (+5/-0)
bzrlib/bzrdir.py (+5/-1)
bzrlib/help_topics/en/configuration.txt (+6/-0)
bzrlib/tests/blackbox/test_init.py (+14/-0)
To merge this branch: bzr merge lp:~nmb/bzr/484101-default-format
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+36952@code.launchpad.net

Commit message

Add a ``default_format`` configuration option.

Description of the change

This branch fixes bug 484101 by creating a "default_format" option that can be set in bazaar.conf. When given a format name, this option makes that format the default for any new branches that are created. Tests are provided for "bzr init" and one particular format.

To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

Neil Martinsen-Burrell пишет:
> This branch fixes bug 484101 by creating a "default_format" option that can be set in bazaar.conf. When given a format name, this option makes that format the default for any new branches that are created. Tests are provided for "bzr init" and one particular format.

God bless you! Thank you for this.

Revision history for this message
Martin Pool (mbp) wrote :

I think ideally it would be able to be configured by location, but this is a huge improvement. Thanks.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

@Neil: Just noticed while landing:

68 + def _restore_config(self):
69 + conf = _mod_config.GlobalConfig.from_string('', save=True)
70 +

77 + self.addCleanup(self._restore_config)

This is exactly how it should be done.
But it's useless :)

Your test class is already using TestCaseWithTransport and is executed in a temporary directory with BZR_HOME pointing there.

So you start with no config file and they will be deleted after the test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-09-27 19:31:45 +0000
3+++ NEWS 2010-09-29 05:49:43 +0000
4@@ -27,8 +27,13 @@
5 hook.
6 (Parth Malwankar, #403687)
7
8+* Provide a configuration option "default_format" that controls the
9+ default format for new branches created with ``bzr init``.
10+ (Neil Martinsen-Burrell, #484101)
11+
12 Bug Fixes
13 *********
14+
15 * Skip tests that needs a bzr source tree when there isn't one. This is
16 needed to succesfully run the test suite for installed versions.
17 (Vincent Ladeuil, #644855).
18
19=== modified file 'bzrlib/bzrdir.py'
20--- bzrlib/bzrdir.py 2010-09-10 09:46:15 +0000
21+++ bzrlib/bzrdir.py 2010-09-29 05:49:43 +0000
22@@ -3345,7 +3345,11 @@
23 help='Same as 2a.')
24
25 # The current format that is made on 'bzr init'.
26-controldir.format_registry.set_default('2a')
27+format_name = config.GlobalConfig().get_user_option('default_format')
28+if format_name is None:
29+ controldir.format_registry.set_default('2a')
30+else:
31+ controldir.format_registry.set_default(format_name)
32
33 # XXX 2010-08-20 JRV: There is still a lot of code relying on
34 # bzrlib.bzrdir.format_registry existing. When BzrDir.create/BzrDir.open/etc
35
36=== modified file 'bzrlib/help_topics/en/configuration.txt'
37--- bzrlib/help_topics/en/configuration.txt 2010-07-06 01:26:59 +0000
38+++ bzrlib/help_topics/en/configuration.txt 2010-09-29 05:49:43 +0000
39@@ -504,6 +504,12 @@
40 whether the format deprecation warning is shown on repositories that are
41 using deprecated formats.
42
43+default_format
44+~~~~~~~~~~~~~~
45+
46+A format name for the default format used when creating branches. See ``bzr
47+help formats`` for possible values.
48+
49
50 Unicode options
51 ---------------
52
53=== modified file 'bzrlib/tests/blackbox/test_init.py'
54--- bzrlib/tests/blackbox/test_init.py 2010-06-11 07:32:12 +0000
55+++ bzrlib/tests/blackbox/test_init.py 2010-09-29 05:49:43 +0000
56@@ -22,6 +22,7 @@
57
58 from bzrlib import (
59 branch as _mod_branch,
60+ config as _mod_config,
61 osutils,
62 urlutils,
63 )
64@@ -163,6 +164,19 @@
65 self.run_bzr('init ../new/tree --create-prefix', working_dir='tree')
66 self.failUnlessExists('new/tree/.bzr')
67
68+ def _restore_config(self):
69+ conf = _mod_config.GlobalConfig.from_string('', save=True)
70+
71+ def test_init_default_format_option(self):
72+ """bzr init should read default format from option default_format"""
73+ conf = _mod_config.GlobalConfig.from_string('''
74+[DEFAULT]
75+default_format = 1.9
76+''', save=True)
77+ self.addCleanup(self._restore_config)
78+ out, err = self.run_bzr_subprocess('init')
79+ self.assertContainsRe(out, '1.9')
80+
81
82 class TestSFTPInit(TestCaseWithSFTPServer):
83