Merge lp:~a1s/bzr-externals/breezy into lp:bzr-externals
- breezy
- Merge into trunk
Proposed by
Aleksandr Smyshliaev
Status: | Needs review |
---|---|
Proposed branch: | lp:~a1s/bzr-externals/breezy |
Merge into: | lp:bzr-externals |
Diff against target: |
660 lines (+282/-279) 4 files modified
__init__.py (+9/-9) commands.py (+16/-18) externals.py (+254/-249) setup.py (+3/-3) |
To merge this branch: | bzr merge lp:~a1s/bzr-externals/breezy |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Eugene Tarasenko | Pending | ||
Review via email: mp+435589@code.launchpad.net |
Commit message
Update for Breezy and Python3
Description of the change
- Change imports from bzrlib to breezy
- Use Python3 text file operations to read and write bzrmeta files
- Fix reading externals configuration from an InventoryTree
- Use command "brz ignore" instead of writing to IGNORE_FILENAME (Breezy doesn't export IGNORE_FILENAME)
To post a comment you must log in.
Unmerged revisions
- 59. By Aleksandr Smyshliaev
-
Fix adding external working tree to the ignore list
- 58. By Aleksandr Smyshliaev
-
Fix reading externals config from a revision tree: the argument for get_file_text() must be a path, not file id
- 57. By Aleksandr Smyshliaev
-
Normalize line endings
- 56. By Aleksandr Smyshliaev
-
fix import paths in the commands module
- 55. By Aleksandr Smyshliaev
-
use Python3 text mode for file operations
- 54. By Aleksandr Smyshliaev
-
Change imports from bzrlib to breezy
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 2012-03-15 02:32:58 +0000 | |||
3 | +++ __init__.py 2023-01-11 14:30:26 +0000 | |||
4 | @@ -56,15 +56,15 @@ | |||
5 | 56 | url directory [revisionspec] | 56 | url directory [revisionspec] |
6 | 57 | """ | 57 | """ |
7 | 58 | 58 | ||
9 | 59 | from bzrlib.lazy_import import lazy_import | 59 | from breezy.lazy_import import lazy_import |
10 | 60 | lazy_import(globals(), """ | 60 | lazy_import(globals(), """ |
13 | 61 | from bzrlib.plugins.externals import externals as lazy_externals | 61 | from breezy.plugins.externals import externals as lazy_externals |
14 | 62 | from bzrlib.plugins.externals import commands as lazy_commands | 62 | from breezy.plugins.externals import commands as lazy_commands |
15 | 63 | """) | 63 | """) |
16 | 64 | 64 | ||
20 | 65 | from bzrlib.branch import Branch | 65 | from breezy.branch import Branch |
21 | 66 | from bzrlib.mutabletree import MutableTree | 66 | from breezy.mutabletree import MutableTree |
22 | 67 | from bzrlib.commands import Command, plugin_cmds | 67 | from breezy.commands import Command, plugin_cmds |
23 | 68 | 68 | ||
24 | 69 | plugin_name = 'externals' | 69 | plugin_name = 'externals' |
25 | 70 | version_info = (1, 3, 4, 'dev', 2) | 70 | version_info = (1, 3, 4, 'dev', 2) |
26 | @@ -115,7 +115,7 @@ | |||
27 | 115 | install_hooks() | 115 | install_hooks() |
28 | 116 | 116 | ||
29 | 117 | def register_commands(): | 117 | def register_commands(): |
31 | 118 | module = 'bzrlib.plugins.externals.commands' | 118 | module = 'breezy.plugins.externals.commands' |
32 | 119 | plugin_cmds.register_lazy('cmd_externals_add', | 119 | plugin_cmds.register_lazy('cmd_externals_add', |
33 | 120 | ['eadd'], module) | 120 | ['eadd'], module) |
34 | 121 | plugin_cmds.register_lazy('cmd_externals_command', | 121 | plugin_cmds.register_lazy('cmd_externals_command', |
35 | @@ -135,9 +135,9 @@ | |||
36 | 135 | def new_finished(self): | 135 | def new_finished(self): |
37 | 136 | old_finished(self) | 136 | old_finished(self) |
38 | 137 | # clear line | 137 | # clear line |
40 | 138 | from bzrlib.ui import ui_factory | 138 | from breezy.ui import ui_factory |
41 | 139 | ui_factory.clear_term() | 139 | ui_factory.clear_term() |
42 | 140 | 140 | ||
44 | 141 | from bzrlib.progress import ProgressTask | 141 | from breezy.progress import ProgressTask |
45 | 142 | old_finished = ProgressTask.finished | 142 | old_finished = ProgressTask.finished |
46 | 143 | ProgressTask.finished = new_finished | 143 | ProgressTask.finished = new_finished |
47 | 144 | 144 | ||
48 | === modified file 'commands.py' | |||
49 | --- commands.py 2012-03-15 02:32:58 +0000 | |||
50 | +++ commands.py 2023-01-11 14:30:26 +0000 | |||
51 | @@ -16,14 +16,14 @@ | |||
52 | 16 | 16 | ||
53 | 17 | import os.path | 17 | import os.path |
54 | 18 | 18 | ||
61 | 19 | from bzrlib.osutils import getcwd, get_user_encoding, isdir, isfile, pathjoin, relpath | 19 | from breezy.osutils import getcwd, get_user_encoding, isdir, isfile, pathjoin, relpath |
62 | 20 | from bzrlib.commands import Command, run_bzr_catch_user_errors | 20 | from breezy.commands import Command, run_bzr_catch_user_errors |
63 | 21 | from bzrlib.option import Option | 21 | from breezy.option import Option |
64 | 22 | from bzrlib.trace import is_quiet, note | 22 | from breezy.trace import is_quiet, note |
65 | 23 | from bzrlib.bzrdir import BzrDir | 23 | from breezy.bzr.bzrdir import BzrDir |
66 | 24 | from bzrlib.workingtree import WorkingTree | 24 | from breezy.workingtree import WorkingTree |
67 | 25 | 25 | ||
69 | 26 | import externals | 26 | from . import externals |
70 | 27 | 27 | ||
71 | 28 | _main_cwd = getcwd() | 28 | _main_cwd = getcwd() |
72 | 29 | _main_base = None | 29 | _main_base = None |
73 | @@ -92,12 +92,10 @@ | |||
74 | 92 | self._add_to_file(root, externals.SNAPSHOT_PATH, line) | 92 | self._add_to_file(root, externals.SNAPSHOT_PATH, line) |
75 | 93 | 93 | ||
76 | 94 | # add ignore mask | 94 | # add ignore mask |
79 | 95 | from bzrlib import IGNORE_FILENAME | 95 | run_bzr_catch_user_errors(['ignore', './' + to_location]) |
78 | 96 | self._add_to_file(root, IGNORE_FILENAME, './' + to_location) | ||
80 | 97 | 96 | ||
81 | 98 | # add config files to repository | 97 | # add config files to repository |
82 | 99 | cmd = ['add', | 98 | cmd = ['add', |
83 | 100 | '.bzrignore', | ||
84 | 101 | '.bzrmeta/externals', | 99 | '.bzrmeta/externals', |
85 | 102 | '.bzrmeta/externals-snapshot'] | 100 | '.bzrmeta/externals-snapshot'] |
86 | 103 | run_bzr_catch_user_errors(cmd) | 101 | run_bzr_catch_user_errors(cmd) |
87 | @@ -112,7 +110,7 @@ | |||
88 | 112 | content = '' | 110 | content = '' |
89 | 113 | path = pathjoin(root, file_name) | 111 | path = pathjoin(root, file_name) |
90 | 114 | if isfile(path): | 112 | if isfile(path): |
92 | 115 | f = open(path, 'rU') | 113 | f = open(path, 'rt', encoding='utf-8') |
93 | 116 | try: | 114 | try: |
94 | 117 | content = f.read() | 115 | content = f.read() |
95 | 118 | finally: | 116 | finally: |
96 | @@ -121,8 +119,8 @@ | |||
97 | 121 | # add at end of file the char '\n' if needed | 119 | # add at end of file the char '\n' if needed |
98 | 122 | content += '\n' | 120 | content += '\n' |
99 | 123 | 121 | ||
102 | 124 | content += line.encode('utf-8') + '\n' | 122 | content += line + '\n' |
103 | 125 | f = open(path, 'w') | 123 | f = open(path, 'wt', encoding='utf-8') |
104 | 126 | try: | 124 | try: |
105 | 127 | f.write(content) | 125 | f.write(content) |
106 | 128 | finally: | 126 | finally: |
107 | @@ -210,10 +208,10 @@ | |||
108 | 210 | def _substitute_in_commandlist(self, command_list, rel_path): | 208 | def _substitute_in_commandlist(self, command_list, rel_path): |
109 | 211 | return [x.replace('{relpath}', rel_path) for x in command_list] | 209 | return [x.replace('{relpath}', rel_path) for x in command_list] |
110 | 212 | 210 | ||
112 | 213 | import bzrlib.builtins | 211 | import breezy.builtins |
113 | 214 | 212 | ||
116 | 215 | class cmd_branch(bzrlib.builtins.cmd_branch): | 213 | class cmd_branch(breezy.builtins.cmd_branch): |
117 | 216 | __doc__ = bzrlib.builtins.cmd_branch.__doc__ | 214 | __doc__ = breezy.builtins.cmd_branch.__doc__ |
118 | 217 | 215 | ||
119 | 218 | def plugin_name(self): | 216 | def plugin_name(self): |
120 | 219 | return None | 217 | return None |
121 | @@ -222,8 +220,8 @@ | |||
122 | 222 | externals.command_kwargs = kwargs | 220 | externals.command_kwargs = kwargs |
123 | 223 | super(cmd_branch, self).run(**kwargs) | 221 | super(cmd_branch, self).run(**kwargs) |
124 | 224 | 222 | ||
127 | 225 | class cmd_checkout(bzrlib.builtins.cmd_checkout): | 223 | class cmd_checkout(breezy.builtins.cmd_checkout): |
128 | 226 | __doc__ = bzrlib.builtins.cmd_checkout.__doc__ | 224 | __doc__ = breezy.builtins.cmd_checkout.__doc__ |
129 | 227 | 225 | ||
130 | 228 | def plugin_name(self): | 226 | def plugin_name(self): |
131 | 229 | return None | 227 | return None |
132 | 230 | 228 | ||
133 | === modified file 'externals.py' | |||
134 | --- externals.py 2012-01-20 00:19:27 +0000 | |||
135 | +++ externals.py 2023-01-11 14:30:26 +0000 | |||
136 | @@ -1,249 +1,254 @@ | |||
386 | 1 | # Copyright (C) 2009 Eugene Tarasenko, Alexander Belchenko | 1 | # Copyright (C) 2009 Eugene Tarasenko, Alexander Belchenko |
387 | 2 | # | 2 | # |
388 | 3 | # This program is free software; you can redistribute it and/or modify | 3 | # This program is free software; you can redistribute it and/or modify |
389 | 4 | # it under the terms of the GNU General Public License as published by | 4 | # it under the terms of the GNU General Public License as published by |
390 | 5 | # the Free Software Foundation; either version 2 of the License, or | 5 | # the Free Software Foundation; either version 2 of the License, or |
391 | 6 | # (at your option) any later version. | 6 | # (at your option) any later version. |
392 | 7 | # | 7 | # |
393 | 8 | # This program is distributed in the hope that it will be useful, | 8 | # This program is distributed in the hope that it will be useful, |
394 | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
395 | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
396 | 11 | # GNU General Public License for more details. | 11 | # GNU General Public License for more details. |
397 | 12 | # | 12 | # |
398 | 13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
399 | 14 | # along with this program; if not, write to the Free Software | 14 | # along with this program; if not, write to the Free Software |
400 | 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
401 | 16 | 16 | ||
402 | 17 | import os | 17 | import os |
403 | 18 | 18 | ||
404 | 19 | from bzrlib.urlutils import join, local_path_from_url | 19 | from breezy.urlutils import join, local_path_from_url |
405 | 20 | from bzrlib.osutils import check_legal_path, getcwd, get_user_encoding, isdir, isfile, pathjoin, relpath | 20 | from breezy.osutils import check_legal_path, getcwd, get_user_encoding, isdir, isfile, pathjoin, relpath |
406 | 21 | from bzrlib.commands import run_bzr_catch_user_errors | 21 | from breezy.commands import run_bzr_catch_user_errors |
407 | 22 | from bzrlib.cmdline import split | 22 | from breezy.cmdline import split |
408 | 23 | from bzrlib.trace import is_quiet, is_verbose, note, warning | 23 | from breezy.trace import is_quiet, is_verbose, note, warning |
409 | 24 | 24 | ||
410 | 25 | CONFIG_PATH = '.bzrmeta/externals' | 25 | CONFIG_PATH = '.bzrmeta/externals' |
411 | 26 | SNAPSHOT_PATH = '.bzrmeta/externals-snapshot' | 26 | SNAPSHOT_PATH = '.bzrmeta/externals-snapshot' |
412 | 27 | 27 | ||
413 | 28 | disable_hooks = False # for prevent double running external command | 28 | disable_hooks = False # for prevent double running external command |
414 | 29 | command_kwargs = None # each new command changed value | 29 | command_kwargs = None # each new command changed value |
415 | 30 | 30 | ||
416 | 31 | class Externals: | 31 | class Externals: |
417 | 32 | 32 | ||
418 | 33 | def __init__(self, branch, revid, root=None): | 33 | def __init__(self, branch, revid, root=None): |
419 | 34 | self.branch = branch | 34 | self.branch = branch |
420 | 35 | self.revid = revid | 35 | self.revid = revid |
421 | 36 | if root is not None: | 36 | if root is not None: |
422 | 37 | self.root = root | 37 | self.root = root |
423 | 38 | else: | 38 | else: |
424 | 39 | self.root = local_path_from_url(branch.base) | 39 | self.root = local_path_from_url(branch.base) |
425 | 40 | self.cwd = getcwd() | 40 | self.cwd = getcwd() |
426 | 41 | self.config = [] | 41 | self.config = [] |
427 | 42 | self.bound = True | 42 | self.bound = True |
428 | 43 | self.use_snapshot = command_kwargs and 'revision' in command_kwargs | 43 | self.use_snapshot = command_kwargs and 'revision' in command_kwargs |
429 | 44 | 44 | ||
430 | 45 | def _set_config(self, text): | 45 | def _set_config(self, text): |
431 | 46 | lines = text.splitlines() | 46 | lines = text.splitlines() |
432 | 47 | for line in lines: | 47 | for line in lines: |
433 | 48 | if len(line.strip()) > 0 and not line.startswith('#'): | 48 | if len(line.strip()) > 0 and not line.startswith('#'): |
434 | 49 | # function cmdline.split does not support windows path separator '\' | 49 | # function cmdline.split does not support windows path separator '\' |
435 | 50 | line = line.decode('utf-8').replace('\\', '/') | 50 | line = line.replace('\\', '/') |
436 | 51 | arg = split(line) | 51 | arg = split(line) |
437 | 52 | if arg not in self.config: | 52 | if arg not in self.config: |
438 | 53 | self.config.append(arg) | 53 | self.config.append(arg) |
439 | 54 | 54 | ||
440 | 55 | def read_config(self): | 55 | def read_config(self): |
441 | 56 | path = pathjoin(self.root, CONFIG_PATH) | 56 | path = pathjoin(self.root, CONFIG_PATH) |
442 | 57 | if self.use_snapshot or not isfile(path): | 57 | if self.use_snapshot or not isfile(path): |
443 | 58 | # config file not exist in directory | 58 | # config file not exist in directory |
444 | 59 | return False | 59 | return False |
445 | 60 | f = open(path, 'rU') | 60 | f = open(path, 'rt', encoding='utf-8') |
446 | 61 | try: | 61 | try: |
447 | 62 | self._set_config(f.read()) | 62 | self._set_config(f.read()) |
448 | 63 | finally: | 63 | finally: |
449 | 64 | f.close() | 64 | f.close() |
450 | 65 | return len(self.config) > 0 | 65 | return len(self.config) > 0 |
451 | 66 | 66 | ||
452 | 67 | def read_config_from_repository(self): | 67 | def read_config_from_repository(self): |
453 | 68 | rev_tree = self.branch.repository.revision_tree(self.revid) | 68 | rev_tree = self.branch.repository.revision_tree(self.revid) |
454 | 69 | if self.use_snapshot: | 69 | if self.use_snapshot: |
455 | 70 | file_id = rev_tree.path2id(SNAPSHOT_PATH) | 70 | if rev_tree.is_versioned(SNAPSHOT_PATH): |
456 | 71 | if not file_id: | 71 | cfg_path = SHAPSHOT_PATH |
457 | 72 | file_id = rev_tree.path2id(CONFIG_PATH) | 72 | else: |
458 | 73 | if file_id: | 73 | cfg_path = CONFIG_PATH |
459 | 74 | warning('warning: for this revision there is no snapshot of external branches!') | 74 | if rev_tree.is_versioned(cfg_path): |
460 | 75 | else: | 75 | warning('warning: for this revision there is no snapshot of external branches!') |
461 | 76 | file_id = rev_tree.path2id(CONFIG_PATH) | 76 | else: |
462 | 77 | if not file_id: | 77 | cfg_path = None |
463 | 78 | # there is no config or snapshot files in repository | 78 | else: |
464 | 79 | return False | 79 | cfg_path = CONFIG_PATH |
465 | 80 | rev_tree.lock_read() | 80 | if not rev_tree.is_versioned(cfg_path): |
466 | 81 | try: | 81 | cfg_path = None |
467 | 82 | text = rev_tree.get_file_text(file_id) | 82 | if not cfg_path: |
468 | 83 | self._set_config(text) | 83 | # there is no config or snapshot files in repository |
469 | 84 | finally: | 84 | return False |
470 | 85 | rev_tree.unlock() | 85 | rev_tree.lock_read() |
471 | 86 | return len(self.config) > 0 | 86 | try: |
472 | 87 | 87 | text = rev_tree.get_file_text(cfg_path) | |
473 | 88 | def _relpath(self, path): | 88 | self._set_config(text.decode('utf-8')) |
474 | 89 | try: | 89 | finally: |
475 | 90 | return relpath(self.cwd, path) | 90 | rev_tree.unlock() |
476 | 91 | except: | 91 | return len(self.config) > 0 |
477 | 92 | pass | 92 | |
478 | 93 | return path | 93 | def _relpath(self, path): |
479 | 94 | 94 | try: | |
480 | 95 | @staticmethod | 95 | return relpath(self.cwd, path) |
481 | 96 | def _relurljoin(base, relative): | 96 | except: |
482 | 97 | if relative.startswith('//'): | 97 | pass |
483 | 98 | # urlutils.join not supports relative urls start with '//' | 98 | return path |
484 | 99 | scheme = base.partition('://') | 99 | |
485 | 100 | return scheme[0] + ':' + relative | 100 | @staticmethod |
486 | 101 | else: | 101 | def _relurljoin(base, relative): |
487 | 102 | return join(base, relative) | 102 | if relative.startswith('//'): |
488 | 103 | 103 | # urlutils.join not supports relative urls start with '//' | |
489 | 104 | @staticmethod | 104 | scheme = base.partition('://') |
490 | 105 | def _report(cmd): | 105 | return scheme[0] + ':' + relative |
491 | 106 | if not is_quiet(): | 106 | else: |
492 | 107 | note('External ' + ' '.join(cmd)) | 107 | return join(base, relative) |
493 | 108 | 108 | ||
494 | 109 | @staticmethod | 109 | @staticmethod |
495 | 110 | def adjust_verbosity(cmd): | 110 | def _report(cmd): |
496 | 111 | if is_quiet(): | 111 | if not is_quiet(): |
497 | 112 | cmd += ['-q'] | 112 | note('External ' + ' '.join(cmd)) |
498 | 113 | if is_verbose(): | 113 | |
499 | 114 | cmd += ['-v'] | 114 | @staticmethod |
500 | 115 | 115 | def adjust_verbosity(cmd): | |
501 | 116 | def branch_iterator(self, target_root=None): | 116 | if is_quiet(): |
502 | 117 | if len(self.config) == 0: | 117 | cmd += ['-q'] |
503 | 118 | # branch not have externals configuration | 118 | if is_verbose(): |
504 | 119 | return | 119 | cmd += ['-v'] |
505 | 120 | 120 | ||
506 | 121 | self.bound = True | 121 | def branch_iterator(self, target_root=None): |
507 | 122 | if not target_root: | 122 | if len(self.config) == 0: |
508 | 123 | target_root = self.branch.get_bound_location() | 123 | # branch not have externals configuration |
509 | 124 | if not target_root: | 124 | return |
510 | 125 | self.bound = False | 125 | |
511 | 126 | target_root = self.branch.get_parent() | 126 | self.bound = True |
512 | 127 | if not target_root: | 127 | if not target_root: |
513 | 128 | # support new braches with no parent yet | 128 | target_root = self.branch.get_bound_location() |
514 | 129 | target_root = self.branch.base | 129 | if not target_root: |
515 | 130 | 130 | self.bound = False | |
516 | 131 | for arg in self.config: # url directory [revisionspec] | 131 | target_root = self.branch.get_parent() |
517 | 132 | location = self._relurljoin(target_root, arg[0]) | 132 | if not target_root: |
518 | 133 | if target_root.startswith('file:///'): | 133 | # support new braches with no parent yet |
519 | 134 | # try to pull externals from the parent for the feature branch | 134 | target_root = self.branch.base |
520 | 135 | path = pathjoin(local_path_from_url(target_root), arg[1]) | 135 | |
521 | 136 | if isdir(path): | 136 | for arg in self.config: # url directory [revisionspec] |
522 | 137 | location = self._relpath(path) | 137 | location = self._relurljoin(target_root, arg[0]) |
523 | 138 | else: | 138 | if target_root.startswith('file:///'): |
524 | 139 | # parent is local master branch | 139 | # try to pull externals from the parent for the feature branch |
525 | 140 | if location.startswith('file:///'): | 140 | path = pathjoin(local_path_from_url(target_root), arg[1]) |
526 | 141 | location = self._relpath(local_path_from_url(location)) | 141 | if isdir(path): |
527 | 142 | 142 | location = self._relpath(path) | |
528 | 143 | check_legal_path(arg[1]) | 143 | else: |
529 | 144 | rel_path = self._relpath(pathjoin(self.root, arg[1])) | 144 | # parent is local master branch |
530 | 145 | 145 | if location.startswith('file:///'): | |
531 | 146 | revision = None | 146 | location = self._relpath(local_path_from_url(location)) |
532 | 147 | if len(arg) > 2: | 147 | |
533 | 148 | revision = arg[2] | 148 | check_legal_path(arg[1]) |
534 | 149 | yield location, rel_path, revision | 149 | rel_path = self._relpath(pathjoin(self.root, arg[1])) |
535 | 150 | 150 | ||
536 | 151 | def pull(self): | 151 | revision = None |
537 | 152 | if disable_hooks: | 152 | if len(arg) > 2: |
538 | 153 | return | 153 | revision = arg[2] |
539 | 154 | 154 | yield location, rel_path, revision | |
540 | 155 | # need use merged config from repository and working tree | 155 | |
541 | 156 | # because new added external branch from repository or working tree | 156 | def pull(self): |
542 | 157 | # need pull/update for correct snapshot | 157 | if disable_hooks: |
543 | 158 | self.read_config() | 158 | return |
544 | 159 | self.read_config_from_repository() | 159 | |
545 | 160 | if len(self.config) == 0: | 160 | # need use merged config from repository and working tree |
546 | 161 | return | 161 | # because new added external branch from repository or working tree |
547 | 162 | 162 | # need pull/update for correct snapshot | |
548 | 163 | for location, path, revision in self.branch_iterator(): | 163 | self.read_config() |
549 | 164 | if location == path: | 164 | self.read_config_from_repository() |
550 | 165 | # not create feature branch for directory above the root | 165 | if len(self.config) == 0: |
551 | 166 | continue | 166 | return |
552 | 167 | 167 | ||
553 | 168 | # select what do it | 168 | for location, path, revision in self.branch_iterator(): |
554 | 169 | if isdir(pathjoin(path, '.bzr')) or isdir(pathjoin(path, '.svn')): | 169 | if location == path: |
555 | 170 | if self.bound: | 170 | # not create feature branch for directory above the root |
556 | 171 | cmd = ['update', path] | 171 | continue |
557 | 172 | else: | 172 | |
558 | 173 | cmd = ['pull', location, '--directory', path] | 173 | # select what do it |
559 | 174 | else: | 174 | if isdir(pathjoin(path, '.bzr')) or isdir(pathjoin(path, '.svn')): |
560 | 175 | if self.bound: | 175 | if self.bound: |
561 | 176 | cmd = ['checkout', location, path] | 176 | cmd = ['update', path] |
562 | 177 | else: | 177 | else: |
563 | 178 | cmd = ['branch', location, path] | 178 | cmd = ['pull', location, '--directory', path] |
564 | 179 | 179 | else: | |
565 | 180 | # command branch don't create recursive directory | 180 | if self.bound: |
566 | 181 | dirs = path.rpartition('/') | 181 | cmd = ['checkout', location, path] |
567 | 182 | if dirs[0] != '' and not isdir(dirs[0]): | 182 | else: |
568 | 183 | os.makedirs(dirs[0].encode(get_user_encoding())) | 183 | cmd = ['branch', location, path] |
569 | 184 | 184 | ||
570 | 185 | # if use revision options but not for 'update' | 185 | # command branch don't create recursive directory |
571 | 186 | if revision is not None and cmd[0] != 'update': | 186 | dirs = path.rpartition('/') |
572 | 187 | cmd += ['--revision', revision] | 187 | if dirs[0] != '' and not isdir(dirs[0]): |
573 | 188 | 188 | os.makedirs(dirs[0].encode(get_user_encoding())) | |
574 | 189 | self.adjust_verbosity(cmd) | 189 | |
575 | 190 | self._report(cmd) | 190 | # if use revision options but not for 'update' |
576 | 191 | run_bzr_catch_user_errors(cmd) | 191 | if revision is not None and cmd[0] != 'update': |
577 | 192 | 192 | cmd += ['--revision', revision] | |
578 | 193 | def push(self, target): | 193 | |
579 | 194 | if disable_hooks or not self.read_config(): | 194 | self.adjust_verbosity(cmd) |
580 | 195 | return | 195 | self._report(cmd) |
581 | 196 | 196 | run_bzr_catch_user_errors(cmd) | |
582 | 197 | for location, path, revision in self.branch_iterator(target): | 197 | |
583 | 198 | if location == path: | 198 | def push(self, target): |
584 | 199 | # don't push into itself | 199 | if disable_hooks or not self.read_config(): |
585 | 200 | continue | 200 | return |
586 | 201 | 201 | ||
587 | 202 | # XXX: maybe he should rather decorate the push command | 202 | for location, path, revision in self.branch_iterator(target): |
588 | 203 | # so that we can get the commandline args | 203 | if location == path: |
589 | 204 | # alternatively the plugin infrastructure must provide it to us?! | 204 | # don't push into itself |
590 | 205 | cmd = ['push', location, '--directory', path, '--no-strict'] | 205 | continue |
591 | 206 | 206 | ||
592 | 207 | if revision is not None: | 207 | # XXX: maybe he should rather decorate the push command |
593 | 208 | # not push if use revision | 208 | # so that we can get the commandline args |
594 | 209 | continue | 209 | # alternatively the plugin infrastructure must provide it to us?! |
595 | 210 | 210 | cmd = ['push', location, '--directory', path, '--no-strict'] | |
596 | 211 | self.adjust_verbosity(cmd) | 211 | |
597 | 212 | self._report(cmd) | 212 | if revision is not None: |
598 | 213 | run_bzr_catch_user_errors(cmd) | 213 | # not push if use revision |
599 | 214 | 214 | continue | |
600 | 215 | @staticmethod | 215 | |
601 | 216 | def _quoted_if_need(text): | 216 | self.adjust_verbosity(cmd) |
602 | 217 | if text.find(' ') != -1: | 217 | self._report(cmd) |
603 | 218 | text = '"' + text + '"' | 218 | run_bzr_catch_user_errors(cmd) |
604 | 219 | return text | 219 | |
605 | 220 | 220 | @staticmethod | |
606 | 221 | def commit(self, mutable_tree): | 221 | def _quoted_if_need(text): |
607 | 222 | # BUG: not run recursively if in above branch not have changes | 222 | if text.find(' ') != -1: |
608 | 223 | if disable_hooks or not self.read_config(): | 223 | text = '"' + text + '"' |
609 | 224 | return | 224 | return text |
610 | 225 | 225 | ||
611 | 226 | from bzrlib.workingtree import WorkingTree | 226 | def commit(self, mutable_tree): |
612 | 227 | snapshot = [] | 227 | # BUG: not run recursively if in above branch not have changes |
613 | 228 | for arg in self.config: # url directory [revisionspec] | 228 | if disable_hooks or not self.read_config(): |
614 | 229 | wt = WorkingTree.open(pathjoin(self.root, arg[1])) | 229 | return |
615 | 230 | if wt.has_changes(wt.basis_tree()): | 230 | |
616 | 231 | cmd = ['ci'] | 231 | from breezy.workingtree import WorkingTree |
617 | 232 | os.chdir(wt.basedir) | 232 | snapshot = [] |
618 | 233 | try: | 233 | for arg in self.config: # url directory [revisionspec] |
619 | 234 | run_bzr_catch_user_errors(cmd) | 234 | wt = WorkingTree.open(pathjoin(self.root, arg[1])) |
620 | 235 | finally: | 235 | if wt.has_changes(wt.basis_tree()): |
621 | 236 | os.chdir(self.cwd) | 236 | cmd = ['ci'] |
622 | 237 | 237 | os.chdir(wt.basedir) | |
623 | 238 | if len(arg) < 3: | 238 | try: |
624 | 239 | arg.append('') | 239 | run_bzr_catch_user_errors(cmd) |
625 | 240 | arg[2] = 'revid:' + wt.last_revision() | 240 | finally: |
626 | 241 | arg[1] = self._quoted_if_need(arg[1]) | 241 | os.chdir(self.cwd) |
627 | 242 | snapshot.append(' '.join(arg).encode('utf-8')) | 242 | |
628 | 243 | 243 | if len(arg) < 3: | |
629 | 244 | path = pathjoin(self.root, SNAPSHOT_PATH) | 244 | arg.append('') |
630 | 245 | f = open(path, 'w') | 245 | arg[2] = 'revid:' + wt.last_revision() |
631 | 246 | try: | 246 | arg[1] = self._quoted_if_need(arg[1]) |
632 | 247 | f.write('\n'.join(snapshot)) | 247 | snapshot.append(' '.join(arg)) |
633 | 248 | finally: | 248 | |
634 | 249 | f.close() | 249 | path = pathjoin(self.root, SNAPSHOT_PATH) |
635 | 250 | f = open(path, 'wt', encoding='utf-8') | ||
636 | 251 | try: | ||
637 | 252 | f.write('\n'.join(snapshot)) | ||
638 | 253 | finally: | ||
639 | 254 | f.close() | ||
640 | 250 | 255 | ||
641 | === modified file 'setup.py' | |||
642 | --- setup.py 2010-03-18 12:25:55 +0000 | |||
643 | +++ setup.py 2023-01-11 14:30:26 +0000 | |||
644 | @@ -22,7 +22,7 @@ | |||
645 | 22 | bzr_plugin_name = __init__.plugin_name | 22 | bzr_plugin_name = __init__.plugin_name |
646 | 23 | bzr_commands = ['externals-add', 'externals-command'] | 23 | bzr_commands = ['externals-add', 'externals-command'] |
647 | 24 | bzr_plugin_version = __init__.version_info | 24 | bzr_plugin_version = __init__.version_info |
649 | 25 | bzr_minimum_version = (1, 4, 0) | 25 | bzr_minimum_version = (3, 0, 0) |
650 | 26 | bzr_maximum_version = None | 26 | bzr_maximum_version = None |
651 | 27 | 27 | ||
652 | 28 | if __name__ == '__main__': | 28 | if __name__ == '__main__': |
653 | @@ -34,5 +34,5 @@ | |||
654 | 34 | author_email="eugene.tarasenko@gmail.com", | 34 | author_email="eugene.tarasenko@gmail.com", |
655 | 35 | license="GNU GPL v2", | 35 | license="GNU GPL v2", |
656 | 36 | url="https://launchpad.net/bzr-externals", | 36 | url="https://launchpad.net/bzr-externals", |
659 | 37 | packages=['bzrlib.plugins.externals', ], | 37 | packages=['breezy.plugins.externals', ], |
660 | 38 | package_dir={'bzrlib.plugins.externals': '.'}) | 38 | package_dir={'breezy.plugins.externals': '.'}) |