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