annotate mercurial_all_paths.py @ 77:772d75b1a030

Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 20 Aug 2017 16:24:22 -0700
parents 03cc0603800e
children 02b85549369b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
1 # -*- coding: utf-8 -*-
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
2 #
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 # allpaths.py - execute commands on multiple paths
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 #
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 # the GNU General Public License version 2 or any later version.
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 '''execute commands on multiple paths'''
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
77
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
10 import os
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
11 import sys
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 import mercurial.util
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 import mercurial.commands
7
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
14 import mercurial.cmdutil
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 from mercurial.i18n import _
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
17
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
18 def import_meu():
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
19 """Importing mercurial_extension_utils so it can be found also outside
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
20 Python PATH (support for TortoiseHG/Win and similar setups)"""
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
21 try:
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
22 import mercurial_extension_utils
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
23 except ImportError:
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
24 my_dir = os.path.dirname(__file__)
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
25 sys.path.extend([
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
26 # In the same dir (manual or site-packages after pip)
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
27 my_dir,
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
28 # Developer clone
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
29 os.path.join(os.path.dirname(my_dir), "extension_utils"),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
30 # Side clone
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
31 os.path.join(os.path.dirname(my_dir), "mercurial-extension_utils"),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
32 ])
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
33 try:
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
34 import mercurial_extension_utils
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
35 except ImportError:
77
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
36 return None
76
03cc0603800e Fix incorrect call for `Abort`, and add error message when MEU is outdated.
Ludovic Chabant <ludovic@chabant.com>
parents: 73
diff changeset
37
03cc0603800e Fix incorrect call for `Abort`, and add error message when MEU is outdated.
Ludovic Chabant <ludovic@chabant.com>
parents: 73
diff changeset
38 if not hasattr(mercurial_extension_utils, 'command'):
03cc0603800e Fix incorrect call for `Abort`, and add error message when MEU is outdated.
Ludovic Chabant <ludovic@chabant.com>
parents: 73
diff changeset
39 raise mercurial.util.Abort(_("""Your mercurial_extension_utils is outdated.
03cc0603800e Fix incorrect call for `Abort`, and add error message when MEU is outdated.
Ludovic Chabant <ludovic@chabant.com>
parents: 73
diff changeset
40 See Installation chapter in https://bitbucket.org/Mekk/mercurial-dynamic_username/ for details."""))
03cc0603800e Fix incorrect call for `Abort`, and add error message when MEU is outdated.
Ludovic Chabant <ludovic@chabant.com>
parents: 73
diff changeset
41
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
42 return mercurial_extension_utils
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
43
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
44 meu = import_meu()
77
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
45 if meu:
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
46 command_decorator = meu.command
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
47 else:
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
48 command_decorator = mercurial.cmdutil.command
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
49
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
50
34
7500a4ecb935 Preliminary steps towards tests (tox.ini, would-be testedwith decl)
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 31
diff changeset
51 # pylint:disable=invalid-name,broad-except,line-too-long
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
53 def _find_all_paths(ui, skip_ignored=False, sort_by_priority=False):
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
54 """
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
55 Finds all paths defined for repo
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
56 :return: list of pairs (alias, path)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
57 """
48
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
58 paths = ui.configitems("paths")
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
59 if not paths:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
60 raise mercurial.util.Abort(_('No paths defined for repository'))
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
61
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
62 if skip_ignored:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
63 ignored = ui.configlist("all_paths", "ignore")
48
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
64 if ignored:
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
65 paths = [(alias, path) for alias, path in paths if alias not in ignored]
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
66 if not paths:
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
67 raise mercurial.util.Abort(_('All paths defined for this repository are ignored'))
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
68
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
69 if sort_by_priority:
48
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
70 prior = ui.configlist("all_paths", "prioritize")
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
71 if prior:
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
72 prior_val = {}
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
73 for idx, item in enumerate(prior):
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
74 prior_val[item] = idx
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
75 higher = len(prior)
00995da9c204 Implemented priorities, fixed bugs in ignoring, both should work.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 47
diff changeset
76 paths.sort(key = lambda it: prior_val.get(it[0], higher))
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
77
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
78 return paths
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
79
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
80 def _find_paths(ui, group=None):
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
81 """
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
82 Finds and returns all paths defined in given group, or all paths
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
83 (sans config) if group is not specified.
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
84
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
85 :param ui: repository ui
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
86 :param group: group name or None for all paths
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
87 :return: list of pairs (alias, path)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
88 """
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
89 if not group:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
90 return _find_all_paths(ui, skip_ignored=True, sort_by_priority=True)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
91
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
92 # „Modern” syntax
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
93 grp_def = ui.configlist("all_paths", "group." + group)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
94 if grp_def:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
95 all_paths = dict(_find_all_paths(ui))
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
96 paths = []
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
97 for item in grp_def:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
98 if item in all_paths:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
99 paths.append((item, all_paths[item]))
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
100 if not paths:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
101 raise mercurial.util.Abort(_('None of the paths from group %s is defined in this repository') % group)
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
102
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
103 return paths
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
104
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
105 # „Legacy” syntax, used also for all paths
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
106 paths = ui.configitems(group)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
107 if not paths:
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
108 raise mercurial.util.Abort(_('No paths defined in section %s') % group)
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
109 return paths
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
110
8
eced61373a74 Added pullall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 7
diff changeset
111
44
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
112 def _iter_over_paths(command, ui, repo, add_sep, **opts):
8
eced61373a74 Added pullall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 7
diff changeset
113 """execute given command on multiple paths"""
6
b1d440f1027a (internal) Changed the way in which extension options are separated:
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 1
diff changeset
114 # Extract our options and filter them out
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
115 group = opts.pop('group', None)
6
b1d440f1027a (internal) Changed the way in which extension options are separated:
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 1
diff changeset
116 ignore_errors = opts.pop('ignore_errors', None)
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 # Get the paths to push to.
47
916b05f73b53 preliminary impl of groups
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 45
diff changeset
119 paths = _find_paths(ui, group)
0
6f92e4c814d1 Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120
12
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
121 # Used to avoid handling duplicate paths twice
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
122 handled = {}
44
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
123 # Used to add extra newline between items
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
124 sep = ''
12
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
125
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
126 # Act!
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
127 for alias, path in paths:
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
128 if path in handled:
45
237dd8c4fe78 Finalized separators
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 44
diff changeset
129 ui.status(sep + _("Skipping %s as path %s was already handled\n") % (alias, handled[path]))
237dd8c4fe78 Finalized separators
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 44
diff changeset
130 sep = '\n'
12
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
131 else:
44
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
132 ui.status(sep)
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
133 sep = '\n' if add_sep else ''
12
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
134 handled[path] = alias
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
135 try:
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
136 command(ui, repo, path, **opts)
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
137 except Exception as e:
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
138 if not ignore_errors:
bed42905e871 Avoiding doing pull or push twice in case some path has more than one
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 11
diff changeset
139 raise
31
9d595bda6f2f Fixed buggy information printed on errors:
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 13
diff changeset
140 ui.warn(_('error handling %s: %s\n') % (alias, e))
44
2d6c7e0c1b2f Added newline between successive items output
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 41
diff changeset
141 sep = '\n'
8
eced61373a74 Added pullall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 7
diff changeset
142
eced61373a74 Added pullall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 7
diff changeset
143
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
144 EXT_OPTS = [
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
145 ('g', 'group', '', _('use a named group instead of all paths')),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
146 ('', 'ignore-errors', None, _('continue execution despite errors')),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
147 ]
9
dac7580bfff2 Added incomingall and outgoingall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 8
diff changeset
148
dac7580bfff2 Added incomingall and outgoingall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 8
diff changeset
149
7
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
150 def _original_options(cmdname):
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
151 """Gets list of given command options as specified in Mercurial core"""
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
152 _, spec = mercurial.cmdutil.findcmd(cmdname, mercurial.commands.table)
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
153 return spec[1]
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
154
1ea915867337 Standard push options are imported from mercurial, not copied here.
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 6
diff changeset
155
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
156 cmdtable = {}
77
772d75b1a030 Fallback to normal Mercurial API if `mercurial_extension_utils` isn't found.
Ludovic Chabant <ludovic@chabant.com>
parents: 76
diff changeset
157 command = command_decorator(cmdtable)
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
158
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
159
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
160 @command("pushall",
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
161 EXT_OPTS + _original_options('push'),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
162 _('[-g GROUP] [--ignore-errors] <push options>'))
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
163 def pushall(ui, repo, **opts):
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
164 """execute push on multiple paths"""
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
165 _iter_over_paths(mercurial.commands.push, ui, repo, True, **opts)
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
166
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
167
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
168 @command("pullall",
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
169 EXT_OPTS + _original_options('pull'),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
170 _('[-g GROUP] [--ignore-errors] <pull options>'))
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
171 def pullall(ui, repo, **opts):
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
172 """execute pull on multiple paths"""
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
173 _iter_over_paths(mercurial.commands.pull, ui, repo, True, **opts)
9
dac7580bfff2 Added incomingall and outgoingall
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 8
diff changeset
174
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
175
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
176 @command("incomingall",
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
177 EXT_OPTS + _original_options('incoming'),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
178 _('[--group GROUP] [--ignore-errors] <incoming options>'))
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
179 def incomingall(ui, repo, **opts):
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
180 """execute incoming on multiple paths"""
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
181 _iter_over_paths(mercurial.commands.incoming, ui, repo, False, **opts)
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
182
34
7500a4ecb935 Preliminary steps towards tests (tox.ini, would-be testedwith decl)
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 31
diff changeset
183
73
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
184 @command("outgoingall",
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
185 EXT_OPTS + _original_options('outgoing'),
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
186 _('[--group GROUP] [--ignore-errors] <outgoing options>'))
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
187 def outgoingall(ui, repo, **opts):
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
188 """execute outgoing on multiple paths"""
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
189 _iter_over_paths(mercurial.commands.outgoing, ui, repo, False, **opts)
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
190
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
191
d262139732f7 Fixed to work against mercurial >= 4.1 (which requires using @command
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 57
diff changeset
192 testedwith = '2.7 2.9 3.0 3.3 3.6 3.7 3.8 4.0 4.1 4.2'
34
7500a4ecb935 Preliminary steps towards tests (tox.ini, would-be testedwith decl)
Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
parents: 31
diff changeset
193 buglink = 'https://bitbucket.org/Mekk/mercurial-all_paths/issues'