Merge lp:~amanica/bzr-externals/push into lp:bzr-externals

Proposed by Marius Kruger
Status: Merged
Merged at revision: not available
Proposed branch: lp:~amanica/bzr-externals/push
Merge into: lp:bzr-externals
Diff against target: 99 lines (+47/-11)
2 files modified
__init__.py (+10/-0)
externals.py (+37/-11)
To merge this branch: bzr merge lp:~amanica/bzr-externals/push
Reviewer Review Type Date Requested Status
Eugene Tarasenko Approve
Review via email: mp+20883@code.launchpad.net

Description of the change

this adds rudimentary support for pushing all the externals when the base is pushed.

To post a comment you must log in.
Revision history for this message
Eugene Tarasenko (etarasenko) wrote :

Marius, why you used '--no-strict' options?

Revision history for this message
Marius Kruger (amanica) wrote :

On 9 March 2010 13:13, Eugene Tarasenko <email address hidden> wrote:
> Marius, why you used '--no-strict' options?

for the specific use case I had when I wrote it, I really needed it,
because I wanted to push my code to
another location before I start committing everything.

I don't think no-strict is a bad default, since bzr's default was like
that for a very long time, and people were talking about reverting it
(although I don't think they will).

as I noted in the comment I think a better solution would be to wrap
the main push command so that we can get at all the options for the
initial command. i.e. if the user typed `bzr push --no-strict` we
would also add --no-strict for each external.
But that could potentially interfere with other plugins as was noted
by the recent 'Overriding commands in plugins' thread on the bazaar
mailinglist.

Revision history for this message
Eugene Tarasenko (etarasenko) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2010-03-06 14:37:09 +0000
3+++ __init__.py 2010-03-08 11:56:24 +0000
4@@ -79,6 +79,16 @@
5 lazy_post_pull_hook,
6 'pull/update external branches')
7
8+ def lazy_post_push_hook(result):
9+ from bzrlib.plugins.externals import externals
10+ return externals.post_push_hook(result)
11+
12+ branch.Branch.hooks.install_named_hook(
13+ 'post_push',
14+ lazy_post_push_hook,
15+ 'push external branches')
16+
17+
18 if hasattr(branch.Branch.hooks, "install_named_hook"):
19 install_hooks()
20
21
22=== modified file 'externals.py'
23--- externals.py 2010-02-27 16:25:38 +0000
24+++ externals.py 2010-03-08 11:56:24 +0000
25@@ -100,26 +100,27 @@
26 if is_verbose():
27 cmd += ['-v']
28
29- def branch_iterator(self):
30+ def branch_iterator(self, target_root=None):
31 if self.config is None:
32 # branch not have externals configuration
33 return
34
35 bound = True
36- parent = self.branch.get_bound_location()
37- if not parent:
38- bound = False
39- parent = self.branch.get_parent()
40- if not parent:
41- # support new braches with no parent yet
42- parent = self.branch.base
43+ if not target_root:
44+ target_root = self.branch.get_bound_location()
45+ if not target_root:
46+ bound = False
47+ target_root = self.branch.get_parent()
48+ if not target_root:
49+ # support new braches with no parent yet
50+ target_root = self.branch.base
51
52 for line in self.config:
53 arg = shlex_split_unicode(line) # url directory [revision]
54- location = self._urljoin(parent, arg[0])
55- if parent.startswith('file:///'):
56+ location = self._urljoin(target_root, arg[0])
57+ if target_root.startswith('file:///'):
58 # try to pull externals from the parent for the feature branch
59- path = pathjoin(local_path_from_url(parent), arg[1])
60+ path = pathjoin(local_path_from_url(target_root), arg[1])
61 if isdir(path):
62 location = self._relpath(path)
63 else:
64@@ -166,6 +167,26 @@
65 self._report(cmd)
66 run_bzr(cmd)
67
68+ def push(self, target):
69+ for location, path, revision, bound in self.branch_iterator(target):
70+ if location == path:
71+ # don't push into itself
72+ continue
73+
74+ # XXX: maybe he should rather decorate the push command
75+ # so that we can get the commandline args
76+ # alternatively the plugin infrastructure must provide it to us?!
77+ cmd = ['push', location, '--directory', path, '--no-strict']
78+
79+ # not sure if we want/need this,
80+ # but leaving it here for completeness
81+ if revision is not None:
82+ cmd += ['--revision', revision]
83+
84+ self._adjust_verbosity(cmd)
85+ self._report(cmd)
86+ run_bzr(cmd)
87+
88 def add_to_ignore(self):
89 from bzrlib import IGNORE_FILENAME
90 f = open(pathjoin(self.root, IGNORE_FILENAME), 'a+')
91@@ -206,3 +227,8 @@
92 if externals.read_config():
93 externals.pull()
94 externals.add_to_ignore()
95+
96+def post_push_hook(result):
97+ externals = Externals(result.source_branch, result.new_revid)
98+ if externals.read_config():
99+ externals.push(result.target_branch.base)

Subscribers

People subscribed via source and target branches