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