comparison hgext/fetch.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
28 command = registrar.command(cmdtable) 28 command = registrar.command(cmdtable)
29 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for 29 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
30 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 30 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
31 # 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
32 # leave the attribute unspecified. 32 # leave the attribute unspecified.
33 testedwith = 'ships-with-hg-core' 33 testedwith = b'ships-with-hg-core'
34 34
35 35
36 @command( 36 @command(
37 'fetch', 37 b'fetch',
38 [ 38 [
39 ( 39 (
40 'r', 40 b'r',
41 'rev', 41 b'rev',
42 [], 42 [],
43 _('a specific revision you would like to pull'), 43 _(b'a specific revision you would like to pull'),
44 _('REV'), 44 _(b'REV'),
45 ), 45 ),
46 ('', 'edit', None, _('invoke editor on commit messages')), 46 (b'', b'edit', None, _(b'invoke editor on commit messages')),
47 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')), 47 (b'', b'force-editor', None, _(b'edit commit message (DEPRECATED)')),
48 ('', 'switch-parent', None, _('switch parents when merging')), 48 (b'', b'switch-parent', None, _(b'switch parents when merging')),
49 ] 49 ]
50 + cmdutil.commitopts 50 + cmdutil.commitopts
51 + cmdutil.commitopts2 51 + cmdutil.commitopts2
52 + cmdutil.remoteopts, 52 + cmdutil.remoteopts,
53 _('hg fetch [SOURCE]'), 53 _(b'hg fetch [SOURCE]'),
54 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT, 54 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
55 ) 55 )
56 def fetch(ui, repo, source='default', **opts): 56 def fetch(ui, repo, source=b'default', **opts):
57 '''pull changes from a remote repository, merge new changes if needed. 57 '''pull changes from a remote repository, merge new changes if needed.
58 58
59 This finds all changes from the repository at the specified path 59 This finds all changes from the repository at the specified path
60 or URL and adds them to the local repository. 60 or URL and adds them to the local repository.
61 61
72 72
73 Returns 0 on success. 73 Returns 0 on success.
74 ''' 74 '''
75 75
76 opts = pycompat.byteskwargs(opts) 76 opts = pycompat.byteskwargs(opts)
77 date = opts.get('date') 77 date = opts.get(b'date')
78 if date: 78 if date:
79 opts['date'] = dateutil.parsedate(date) 79 opts[b'date'] = dateutil.parsedate(date)
80 80
81 parent = repo.dirstate.p1() 81 parent = repo.dirstate.p1()
82 branch = repo.dirstate.branch() 82 branch = repo.dirstate.branch()
83 try: 83 try:
84 branchnode = repo.branchtip(branch) 84 branchnode = repo.branchtip(branch)
85 except error.RepoLookupError: 85 except error.RepoLookupError:
86 branchnode = None 86 branchnode = None
87 if parent != branchnode: 87 if parent != branchnode:
88 raise error.Abort( 88 raise error.Abort(
89 _('working directory not at branch tip'), 89 _(b'working directory not at branch tip'),
90 hint=_("use 'hg update' to check out branch tip"), 90 hint=_(b"use 'hg update' to check out branch tip"),
91 ) 91 )
92 92
93 wlock = lock = None 93 wlock = lock = None
94 try: 94 try:
95 wlock = repo.wlock() 95 wlock = repo.wlock()
100 bheads = repo.branchheads(branch) 100 bheads = repo.branchheads(branch)
101 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]
102 if len(bheads) > 1: 102 if len(bheads) > 1:
103 raise error.Abort( 103 raise error.Abort(
104 _( 104 _(
105 'multiple heads in this branch ' 105 b'multiple heads in this branch '
106 '(use "hg heads ." and "hg merge" to merge)' 106 b'(use "hg heads ." and "hg merge" to merge)'
107 ) 107 )
108 ) 108 )
109 109
110 other = hg.peer(repo, opts, ui.expandpath(source)) 110 other = hg.peer(repo, opts, ui.expandpath(source))
111 ui.status( 111 ui.status(
112 _('pulling from %s\n') % util.hidepassword(ui.expandpath(source)) 112 _(b'pulling from %s\n') % util.hidepassword(ui.expandpath(source))
113 ) 113 )
114 revs = None 114 revs = None
115 if opts['rev']: 115 if opts[b'rev']:
116 try: 116 try:
117 revs = [other.lookup(rev) for rev in opts['rev']] 117 revs = [other.lookup(rev) for rev in opts[b'rev']]
118 except error.CapabilityError: 118 except error.CapabilityError:
119 err = _( 119 err = _(
120 "other repository doesn't support revision lookup, " 120 b"other repository doesn't support revision lookup, "
121 "so a rev cannot be specified." 121 b"so a rev cannot be specified."
122 ) 122 )
123 raise error.Abort(err) 123 raise error.Abort(err)
124 124
125 # Are there any changes at all? 125 # Are there any changes at all?
126 modheads = exchange.pull(repo, other, heads=revs).cgresult 126 modheads = exchange.pull(repo, other, heads=revs).cgresult
144 hg.clean(repo, newparent) 144 hg.clean(repo, newparent)
145 newheads = [n for n in newheads if n != newparent] 145 newheads = [n for n in newheads if n != newparent]
146 if len(newheads) > 1: 146 if len(newheads) > 1:
147 ui.status( 147 ui.status(
148 _( 148 _(
149 'not merging with %d other new branch heads ' 149 b'not merging with %d other new branch heads '
150 '(use "hg heads ." and "hg merge" to merge them)\n' 150 b'(use "hg heads ." and "hg merge" to merge them)\n'
151 ) 151 )
152 % (len(newheads) - 1) 152 % (len(newheads) - 1)
153 ) 153 )
154 return 1 154 return 1
155 155
160 err = False 160 err = False
161 if newheads: 161 if newheads:
162 # By default, we consider the repository we're pulling 162 # By default, we consider the repository we're pulling
163 # *from* as authoritative, so we merge our changes into 163 # *from* as authoritative, so we merge our changes into
164 # theirs. 164 # theirs.
165 if opts['switch_parent']: 165 if opts[b'switch_parent']:
166 firstparent, secondparent = newparent, newheads[0] 166 firstparent, secondparent = newparent, newheads[0]
167 else: 167 else:
168 firstparent, secondparent = newheads[0], newparent 168 firstparent, secondparent = newheads[0], newparent
169 ui.status( 169 ui.status(
170 _('updating to %d:%s\n') 170 _(b'updating to %d:%s\n')
171 % (repo.changelog.rev(firstparent), short(firstparent)) 171 % (repo.changelog.rev(firstparent), short(firstparent))
172 ) 172 )
173 hg.clean(repo, firstparent) 173 hg.clean(repo, firstparent)
174 ui.status( 174 ui.status(
175 _('merging with %d:%s\n') 175 _(b'merging with %d:%s\n')
176 % (repo.changelog.rev(secondparent), short(secondparent)) 176 % (repo.changelog.rev(secondparent), short(secondparent))
177 ) 177 )
178 err = hg.merge(repo, secondparent, remind=False) 178 err = hg.merge(repo, secondparent, remind=False)
179 179
180 if not err: 180 if not err:
181 # we don't translate commit messages 181 # we don't translate commit messages
182 message = cmdutil.logmessage(ui, opts) or ( 182 message = cmdutil.logmessage(ui, opts) or (
183 'Automated merge with %s' % util.removeauth(other.url()) 183 b'Automated merge with %s' % util.removeauth(other.url())
184 ) 184 )
185 editopt = opts.get('edit') or opts.get('force_editor') 185 editopt = opts.get(b'edit') or opts.get(b'force_editor')
186 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch') 186 editor = cmdutil.getcommiteditor(edit=editopt, editform=b'fetch')
187 n = repo.commit(message, opts['user'], opts['date'], editor=editor) 187 n = repo.commit(
188 message, opts[b'user'], opts[b'date'], editor=editor
189 )
188 ui.status( 190 ui.status(
189 _('new changeset %d:%s merges remote changes ' 'with local\n') 191 _(b'new changeset %d:%s merges remote changes ' b'with local\n')
190 % (repo.changelog.rev(n), short(n)) 192 % (repo.changelog.rev(n), short(n))
191 ) 193 )
192 194
193 return err 195 return err
194 196