Mercurial > hg
comparison hgext/fetch.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 5cb8158a61f7 |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
8 '''pull, update and merge in one command (DEPRECATED)''' | 8 '''pull, update and merge in one command (DEPRECATED)''' |
9 | 9 |
10 from __future__ import absolute_import | 10 from __future__ import absolute_import |
11 | 11 |
12 from mercurial.i18n import _ | 12 from mercurial.i18n import _ |
13 from mercurial.node import ( | 13 from mercurial.node import short |
14 short, | |
15 ) | |
16 from mercurial import ( | 14 from mercurial import ( |
17 cmdutil, | 15 cmdutil, |
18 error, | 16 error, |
19 exchange, | 17 exchange, |
20 hg, | 18 hg, |
32 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 30 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
33 # be specifying the version(s) of Mercurial they are tested with, or | 31 # be specifying the version(s) of Mercurial they are tested with, or |
34 # leave the attribute unspecified. | 32 # leave the attribute unspecified. |
35 testedwith = 'ships-with-hg-core' | 33 testedwith = 'ships-with-hg-core' |
36 | 34 |
37 @command('fetch', | 35 |
38 [('r', 'rev', [], | 36 @command( |
39 _('a specific revision you would like to pull'), _('REV')), | 37 'fetch', |
40 ('', 'edit', None, _('invoke editor on commit messages')), | 38 [ |
41 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')), | 39 ( |
42 ('', 'switch-parent', None, _('switch parents when merging')), | 40 'r', |
43 ] + cmdutil.commitopts + cmdutil.commitopts2 + cmdutil.remoteopts, | 41 'rev', |
42 [], | |
43 _('a specific revision you would like to pull'), | |
44 _('REV'), | |
45 ), | |
46 ('', 'edit', None, _('invoke editor on commit messages')), | |
47 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')), | |
48 ('', 'switch-parent', None, _('switch parents when merging')), | |
49 ] | |
50 + cmdutil.commitopts | |
51 + cmdutil.commitopts2 | |
52 + cmdutil.remoteopts, | |
44 _('hg fetch [SOURCE]'), | 53 _('hg fetch [SOURCE]'), |
45 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT) | 54 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, |
55 ) | |
46 def fetch(ui, repo, source='default', **opts): | 56 def fetch(ui, repo, source='default', **opts): |
47 '''pull changes from a remote repository, merge new changes if needed. | 57 '''pull changes from a remote repository, merge new changes if needed. |
48 | 58 |
49 This finds all changes from the repository at the specified path | 59 This finds all changes from the repository at the specified path |
50 or URL and adds them to the local repository. | 60 or URL and adds them to the local repository. |
73 try: | 83 try: |
74 branchnode = repo.branchtip(branch) | 84 branchnode = repo.branchtip(branch) |
75 except error.RepoLookupError: | 85 except error.RepoLookupError: |
76 branchnode = None | 86 branchnode = None |
77 if parent != branchnode: | 87 if parent != branchnode: |
78 raise error.Abort(_('working directory not at branch tip'), | 88 raise error.Abort( |
79 hint=_("use 'hg update' to check out branch tip")) | 89 _('working directory not at branch tip'), |
90 hint=_("use 'hg update' to check out branch tip"), | |
91 ) | |
80 | 92 |
81 wlock = lock = None | 93 wlock = lock = None |
82 try: | 94 try: |
83 wlock = repo.wlock() | 95 wlock = repo.wlock() |
84 lock = repo.lock() | 96 lock = repo.lock() |
86 cmdutil.bailifchanged(repo) | 98 cmdutil.bailifchanged(repo) |
87 | 99 |
88 bheads = repo.branchheads(branch) | 100 bheads = repo.branchheads(branch) |
89 bheads = [head for head in bheads if len(repo[head].children()) == 0] | 101 bheads = [head for head in bheads if len(repo[head].children()) == 0] |
90 if len(bheads) > 1: | 102 if len(bheads) > 1: |
91 raise error.Abort(_('multiple heads in this branch ' | 103 raise error.Abort( |
92 '(use "hg heads ." and "hg merge" to merge)')) | 104 _( |
105 'multiple heads in this branch ' | |
106 '(use "hg heads ." and "hg merge" to merge)' | |
107 ) | |
108 ) | |
93 | 109 |
94 other = hg.peer(repo, opts, ui.expandpath(source)) | 110 other = hg.peer(repo, opts, ui.expandpath(source)) |
95 ui.status(_('pulling from %s\n') % | 111 ui.status( |
96 util.hidepassword(ui.expandpath(source))) | 112 _('pulling from %s\n') % util.hidepassword(ui.expandpath(source)) |
113 ) | |
97 revs = None | 114 revs = None |
98 if opts['rev']: | 115 if opts['rev']: |
99 try: | 116 try: |
100 revs = [other.lookup(rev) for rev in opts['rev']] | 117 revs = [other.lookup(rev) for rev in opts['rev']] |
101 except error.CapabilityError: | 118 except error.CapabilityError: |
102 err = _("other repository doesn't support revision lookup, " | 119 err = _( |
103 "so a rev cannot be specified.") | 120 "other repository doesn't support revision lookup, " |
121 "so a rev cannot be specified." | |
122 ) | |
104 raise error.Abort(err) | 123 raise error.Abort(err) |
105 | 124 |
106 # Are there any changes at all? | 125 # Are there any changes at all? |
107 modheads = exchange.pull(repo, other, heads=revs).cgresult | 126 modheads = exchange.pull(repo, other, heads=revs).cgresult |
108 if modheads == 0: | 127 if modheads == 0: |
123 if newchildren: | 142 if newchildren: |
124 newparent = newchildren[0] | 143 newparent = newchildren[0] |
125 hg.clean(repo, newparent) | 144 hg.clean(repo, newparent) |
126 newheads = [n for n in newheads if n != newparent] | 145 newheads = [n for n in newheads if n != newparent] |
127 if len(newheads) > 1: | 146 if len(newheads) > 1: |
128 ui.status(_('not merging with %d other new branch heads ' | 147 ui.status( |
129 '(use "hg heads ." and "hg merge" to merge them)\n') % | 148 _( |
130 (len(newheads) - 1)) | 149 'not merging with %d other new branch heads ' |
150 '(use "hg heads ." and "hg merge" to merge them)\n' | |
151 ) | |
152 % (len(newheads) - 1) | |
153 ) | |
131 return 1 | 154 return 1 |
132 | 155 |
133 if not newheads: | 156 if not newheads: |
134 return 0 | 157 return 0 |
135 | 158 |
141 # theirs. | 164 # theirs. |
142 if opts['switch_parent']: | 165 if opts['switch_parent']: |
143 firstparent, secondparent = newparent, newheads[0] | 166 firstparent, secondparent = newparent, newheads[0] |
144 else: | 167 else: |
145 firstparent, secondparent = newheads[0], newparent | 168 firstparent, secondparent = newheads[0], newparent |
146 ui.status(_('updating to %d:%s\n') % | 169 ui.status( |
147 (repo.changelog.rev(firstparent), | 170 _('updating to %d:%s\n') |
148 short(firstparent))) | 171 % (repo.changelog.rev(firstparent), short(firstparent)) |
172 ) | |
149 hg.clean(repo, firstparent) | 173 hg.clean(repo, firstparent) |
150 ui.status(_('merging with %d:%s\n') % | 174 ui.status( |
151 (repo.changelog.rev(secondparent), short(secondparent))) | 175 _('merging with %d:%s\n') |
176 % (repo.changelog.rev(secondparent), short(secondparent)) | |
177 ) | |
152 err = hg.merge(repo, secondparent, remind=False) | 178 err = hg.merge(repo, secondparent, remind=False) |
153 | 179 |
154 if not err: | 180 if not err: |
155 # we don't translate commit messages | 181 # we don't translate commit messages |
156 message = (cmdutil.logmessage(ui, opts) or | 182 message = cmdutil.logmessage(ui, opts) or ( |
157 ('Automated merge with %s' % | 183 'Automated merge with %s' % util.removeauth(other.url()) |
158 util.removeauth(other.url()))) | 184 ) |
159 editopt = opts.get('edit') or opts.get('force_editor') | 185 editopt = opts.get('edit') or opts.get('force_editor') |
160 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch') | 186 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch') |
161 n = repo.commit(message, opts['user'], opts['date'], editor=editor) | 187 n = repo.commit(message, opts['user'], opts['date'], editor=editor) |
162 ui.status(_('new changeset %d:%s merges remote changes ' | 188 ui.status( |
163 'with local\n') % (repo.changelog.rev(n), | 189 _('new changeset %d:%s merges remote changes ' 'with local\n') |
164 short(n))) | 190 % (repo.changelog.rev(n), short(n)) |
191 ) | |
165 | 192 |
166 return err | 193 return err |
167 | 194 |
168 finally: | 195 finally: |
169 release(lock, wlock) | 196 release(lock, wlock) |