##// END OF EJS Templates
py3: handle keyword arguments in hgext/fetch.py...
Pulkit Goyal -
r34978:a56bf559 default
parent child Browse files
Show More
@@ -1,165 +1,167 b''
1 1 # fetch.py - pull and merge remote changes
2 2 #
3 3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 '''pull, update and merge in one command (DEPRECATED)'''
9 9
10 10 from __future__ import absolute_import
11 11
12 12 from mercurial.i18n import _
13 13 from mercurial.node import (
14 14 short,
15 15 )
16 16 from mercurial import (
17 17 cmdutil,
18 18 error,
19 19 exchange,
20 20 hg,
21 21 lock,
22 pycompat,
22 23 registrar,
23 24 util,
24 25 )
25 26
26 27 release = lock.release
27 28 cmdtable = {}
28 29 command = registrar.command(cmdtable)
29 30 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
30 31 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
31 32 # be specifying the version(s) of Mercurial they are tested with, or
32 33 # leave the attribute unspecified.
33 34 testedwith = 'ships-with-hg-core'
34 35
35 36 @command('fetch',
36 37 [('r', 'rev', [],
37 38 _('a specific revision you would like to pull'), _('REV')),
38 39 ('', 'edit', None, _('invoke editor on commit messages')),
39 40 ('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
40 41 ('', 'switch-parent', None, _('switch parents when merging')),
41 42 ] + cmdutil.commitopts + cmdutil.commitopts2 + cmdutil.remoteopts,
42 43 _('hg fetch [SOURCE]'))
43 44 def fetch(ui, repo, source='default', **opts):
44 45 '''pull changes from a remote repository, merge new changes if needed.
45 46
46 47 This finds all changes from the repository at the specified path
47 48 or URL and adds them to the local repository.
48 49
49 50 If the pulled changes add a new branch head, the head is
50 51 automatically merged, and the result of the merge is committed.
51 52 Otherwise, the working directory is updated to include the new
52 53 changes.
53 54
54 55 When a merge is needed, the working directory is first updated to
55 56 the newly pulled changes. Local changes are then merged into the
56 57 pulled changes. To switch the merge order, use --switch-parent.
57 58
58 59 See :hg:`help dates` for a list of formats valid for -d/--date.
59 60
60 61 Returns 0 on success.
61 62 '''
62 63
64 opts = pycompat.byteskwargs(opts)
63 65 date = opts.get('date')
64 66 if date:
65 67 opts['date'] = util.parsedate(date)
66 68
67 69 parent, _p2 = repo.dirstate.parents()
68 70 branch = repo.dirstate.branch()
69 71 try:
70 72 branchnode = repo.branchtip(branch)
71 73 except error.RepoLookupError:
72 74 branchnode = None
73 75 if parent != branchnode:
74 76 raise error.Abort(_('working directory not at branch tip'),
75 77 hint=_("use 'hg update' to check out branch tip"))
76 78
77 79 wlock = lock = None
78 80 try:
79 81 wlock = repo.wlock()
80 82 lock = repo.lock()
81 83
82 84 cmdutil.bailifchanged(repo)
83 85
84 86 bheads = repo.branchheads(branch)
85 87 bheads = [head for head in bheads if len(repo[head].children()) == 0]
86 88 if len(bheads) > 1:
87 89 raise error.Abort(_('multiple heads in this branch '
88 90 '(use "hg heads ." and "hg merge" to merge)'))
89 91
90 92 other = hg.peer(repo, opts, ui.expandpath(source))
91 93 ui.status(_('pulling from %s\n') %
92 94 util.hidepassword(ui.expandpath(source)))
93 95 revs = None
94 96 if opts['rev']:
95 97 try:
96 98 revs = [other.lookup(rev) for rev in opts['rev']]
97 99 except error.CapabilityError:
98 100 err = _("other repository doesn't support revision lookup, "
99 101 "so a rev cannot be specified.")
100 102 raise error.Abort(err)
101 103
102 104 # Are there any changes at all?
103 105 modheads = exchange.pull(repo, other, heads=revs).cgresult
104 106 if modheads == 0:
105 107 return 0
106 108
107 109 # Is this a simple fast-forward along the current branch?
108 110 newheads = repo.branchheads(branch)
109 111 newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
110 112 if len(newheads) == 1 and len(newchildren):
111 113 if newchildren[0] != parent:
112 114 return hg.update(repo, newchildren[0])
113 115 else:
114 116 return 0
115 117
116 118 # Are there more than one additional branch heads?
117 119 newchildren = [n for n in newchildren if n != parent]
118 120 newparent = parent
119 121 if newchildren:
120 122 newparent = newchildren[0]
121 123 hg.clean(repo, newparent)
122 124 newheads = [n for n in newheads if n != newparent]
123 125 if len(newheads) > 1:
124 126 ui.status(_('not merging with %d other new branch heads '
125 127 '(use "hg heads ." and "hg merge" to merge them)\n') %
126 128 (len(newheads) - 1))
127 129 return 1
128 130
129 131 if not newheads:
130 132 return 0
131 133
132 134 # Otherwise, let's merge.
133 135 err = False
134 136 if newheads:
135 137 # By default, we consider the repository we're pulling
136 138 # *from* as authoritative, so we merge our changes into
137 139 # theirs.
138 140 if opts['switch_parent']:
139 141 firstparent, secondparent = newparent, newheads[0]
140 142 else:
141 143 firstparent, secondparent = newheads[0], newparent
142 144 ui.status(_('updating to %d:%s\n') %
143 145 (repo.changelog.rev(firstparent),
144 146 short(firstparent)))
145 147 hg.clean(repo, firstparent)
146 148 ui.status(_('merging with %d:%s\n') %
147 149 (repo.changelog.rev(secondparent), short(secondparent)))
148 150 err = hg.merge(repo, secondparent, remind=False)
149 151
150 152 if not err:
151 153 # we don't translate commit messages
152 154 message = (cmdutil.logmessage(ui, opts) or
153 155 ('Automated merge with %s' %
154 156 util.removeauth(other.url())))
155 157 editopt = opts.get('edit') or opts.get('force_editor')
156 158 editor = cmdutil.getcommiteditor(edit=editopt, editform='fetch')
157 159 n = repo.commit(message, opts['user'], opts['date'], editor=editor)
158 160 ui.status(_('new changeset %d:%s merges remote changes '
159 161 'with local\n') % (repo.changelog.rev(n),
160 162 short(n)))
161 163
162 164 return err
163 165
164 166 finally:
165 167 release(lock, wlock)
General Comments 0
You need to be logged in to leave comments. Login now