Show More
@@ -1,5725 +1,5716 b'' | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.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 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import difflib |
|
10 | import difflib | |
11 | import errno |
|
11 | import errno | |
12 | import os |
|
12 | import os | |
13 | import re |
|
13 | import re | |
14 | import sys |
|
14 | import sys | |
15 |
|
15 | |||
16 | from .i18n import _ |
|
16 | from .i18n import _ | |
17 | from .node import ( |
|
17 | from .node import ( | |
18 | hex, |
|
18 | hex, | |
19 | nullid, |
|
19 | nullid, | |
20 | nullrev, |
|
20 | nullrev, | |
21 | short, |
|
21 | short, | |
22 | ) |
|
22 | ) | |
23 | from . import ( |
|
23 | from . import ( | |
24 | archival, |
|
24 | archival, | |
25 | bookmarks, |
|
25 | bookmarks, | |
26 | bundle2, |
|
26 | bundle2, | |
27 | changegroup, |
|
27 | changegroup, | |
28 | cmdutil, |
|
28 | cmdutil, | |
29 | copies, |
|
29 | copies, | |
30 | debugcommands as debugcommandsmod, |
|
30 | debugcommands as debugcommandsmod, | |
31 | destutil, |
|
31 | destutil, | |
32 | dirstateguard, |
|
32 | dirstateguard, | |
33 | discovery, |
|
33 | discovery, | |
34 | encoding, |
|
34 | encoding, | |
35 | error, |
|
35 | error, | |
36 | exchange, |
|
36 | exchange, | |
37 | extensions, |
|
37 | extensions, | |
38 | formatter, |
|
38 | formatter, | |
39 | graphmod, |
|
39 | graphmod, | |
40 | hbisect, |
|
40 | hbisect, | |
41 | help, |
|
41 | help, | |
42 | hg, |
|
42 | hg, | |
43 | lock as lockmod, |
|
|||
44 | logcmdutil, |
|
43 | logcmdutil, | |
45 | merge as mergemod, |
|
44 | merge as mergemod, | |
46 | obsolete, |
|
45 | obsolete, | |
47 | obsutil, |
|
46 | obsutil, | |
48 | patch, |
|
47 | patch, | |
49 | phases, |
|
48 | phases, | |
50 | pycompat, |
|
49 | pycompat, | |
51 | rcutil, |
|
50 | rcutil, | |
52 | registrar, |
|
51 | registrar, | |
53 | revsetlang, |
|
52 | revsetlang, | |
54 | rewriteutil, |
|
53 | rewriteutil, | |
55 | scmutil, |
|
54 | scmutil, | |
56 | server, |
|
55 | server, | |
57 | state as statemod, |
|
56 | state as statemod, | |
58 | streamclone, |
|
57 | streamclone, | |
59 | tags as tagsmod, |
|
58 | tags as tagsmod, | |
60 | templatekw, |
|
59 | templatekw, | |
61 | ui as uimod, |
|
60 | ui as uimod, | |
62 | util, |
|
61 | util, | |
63 | wireprotoserver, |
|
62 | wireprotoserver, | |
64 | ) |
|
63 | ) | |
65 | from .utils import ( |
|
64 | from .utils import ( | |
66 | dateutil, |
|
65 | dateutil, | |
67 | stringutil, |
|
66 | stringutil, | |
68 | ) |
|
67 | ) | |
69 |
|
68 | |||
70 | release = lockmod.release |
|
|||
71 |
|
||||
72 | table = {} |
|
69 | table = {} | |
73 | table.update(debugcommandsmod.command._table) |
|
70 | table.update(debugcommandsmod.command._table) | |
74 |
|
71 | |||
75 | command = registrar.command(table) |
|
72 | command = registrar.command(table) | |
76 | INTENT_READONLY = registrar.INTENT_READONLY |
|
73 | INTENT_READONLY = registrar.INTENT_READONLY | |
77 |
|
74 | |||
78 | # common command options |
|
75 | # common command options | |
79 |
|
76 | |||
80 | globalopts = [ |
|
77 | globalopts = [ | |
81 | ('R', 'repository', '', |
|
78 | ('R', 'repository', '', | |
82 | _('repository root directory or name of overlay bundle file'), |
|
79 | _('repository root directory or name of overlay bundle file'), | |
83 | _('REPO')), |
|
80 | _('REPO')), | |
84 | ('', 'cwd', '', |
|
81 | ('', 'cwd', '', | |
85 | _('change working directory'), _('DIR')), |
|
82 | _('change working directory'), _('DIR')), | |
86 | ('y', 'noninteractive', None, |
|
83 | ('y', 'noninteractive', None, | |
87 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
84 | _('do not prompt, automatically pick the first choice for all prompts')), | |
88 | ('q', 'quiet', None, _('suppress output')), |
|
85 | ('q', 'quiet', None, _('suppress output')), | |
89 | ('v', 'verbose', None, _('enable additional output')), |
|
86 | ('v', 'verbose', None, _('enable additional output')), | |
90 | ('', 'color', '', |
|
87 | ('', 'color', '', | |
91 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords |
|
88 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords | |
92 | # and should not be translated |
|
89 | # and should not be translated | |
93 | _("when to colorize (boolean, always, auto, never, or debug)"), |
|
90 | _("when to colorize (boolean, always, auto, never, or debug)"), | |
94 | _('TYPE')), |
|
91 | _('TYPE')), | |
95 | ('', 'config', [], |
|
92 | ('', 'config', [], | |
96 | _('set/override config option (use \'section.name=value\')'), |
|
93 | _('set/override config option (use \'section.name=value\')'), | |
97 | _('CONFIG')), |
|
94 | _('CONFIG')), | |
98 | ('', 'debug', None, _('enable debugging output')), |
|
95 | ('', 'debug', None, _('enable debugging output')), | |
99 | ('', 'debugger', None, _('start debugger')), |
|
96 | ('', 'debugger', None, _('start debugger')), | |
100 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
97 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), | |
101 | _('ENCODE')), |
|
98 | _('ENCODE')), | |
102 | ('', 'encodingmode', encoding.encodingmode, |
|
99 | ('', 'encodingmode', encoding.encodingmode, | |
103 | _('set the charset encoding mode'), _('MODE')), |
|
100 | _('set the charset encoding mode'), _('MODE')), | |
104 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
101 | ('', 'traceback', None, _('always print a traceback on exception')), | |
105 | ('', 'time', None, _('time how long the command takes')), |
|
102 | ('', 'time', None, _('time how long the command takes')), | |
106 | ('', 'profile', None, _('print command execution profile')), |
|
103 | ('', 'profile', None, _('print command execution profile')), | |
107 | ('', 'version', None, _('output version information and exit')), |
|
104 | ('', 'version', None, _('output version information and exit')), | |
108 | ('h', 'help', None, _('display help and exit')), |
|
105 | ('h', 'help', None, _('display help and exit')), | |
109 | ('', 'hidden', False, _('consider hidden changesets')), |
|
106 | ('', 'hidden', False, _('consider hidden changesets')), | |
110 | ('', 'pager', 'auto', |
|
107 | ('', 'pager', 'auto', | |
111 | _("when to paginate (boolean, always, auto, or never)"), _('TYPE')), |
|
108 | _("when to paginate (boolean, always, auto, or never)"), _('TYPE')), | |
112 | ] |
|
109 | ] | |
113 |
|
110 | |||
114 | dryrunopts = cmdutil.dryrunopts |
|
111 | dryrunopts = cmdutil.dryrunopts | |
115 | remoteopts = cmdutil.remoteopts |
|
112 | remoteopts = cmdutil.remoteopts | |
116 | walkopts = cmdutil.walkopts |
|
113 | walkopts = cmdutil.walkopts | |
117 | commitopts = cmdutil.commitopts |
|
114 | commitopts = cmdutil.commitopts | |
118 | commitopts2 = cmdutil.commitopts2 |
|
115 | commitopts2 = cmdutil.commitopts2 | |
119 | formatteropts = cmdutil.formatteropts |
|
116 | formatteropts = cmdutil.formatteropts | |
120 | templateopts = cmdutil.templateopts |
|
117 | templateopts = cmdutil.templateopts | |
121 | logopts = cmdutil.logopts |
|
118 | logopts = cmdutil.logopts | |
122 | diffopts = cmdutil.diffopts |
|
119 | diffopts = cmdutil.diffopts | |
123 | diffwsopts = cmdutil.diffwsopts |
|
120 | diffwsopts = cmdutil.diffwsopts | |
124 | diffopts2 = cmdutil.diffopts2 |
|
121 | diffopts2 = cmdutil.diffopts2 | |
125 | mergetoolopts = cmdutil.mergetoolopts |
|
122 | mergetoolopts = cmdutil.mergetoolopts | |
126 | similarityopts = cmdutil.similarityopts |
|
123 | similarityopts = cmdutil.similarityopts | |
127 | subrepoopts = cmdutil.subrepoopts |
|
124 | subrepoopts = cmdutil.subrepoopts | |
128 | debugrevlogopts = cmdutil.debugrevlogopts |
|
125 | debugrevlogopts = cmdutil.debugrevlogopts | |
129 |
|
126 | |||
130 | # Commands start here, listed alphabetically |
|
127 | # Commands start here, listed alphabetically | |
131 |
|
128 | |||
132 | @command('^add', |
|
129 | @command('^add', | |
133 | walkopts + subrepoopts + dryrunopts, |
|
130 | walkopts + subrepoopts + dryrunopts, | |
134 | _('[OPTION]... [FILE]...'), |
|
131 | _('[OPTION]... [FILE]...'), | |
135 | inferrepo=True) |
|
132 | inferrepo=True) | |
136 | def add(ui, repo, *pats, **opts): |
|
133 | def add(ui, repo, *pats, **opts): | |
137 | """add the specified files on the next commit |
|
134 | """add the specified files on the next commit | |
138 |
|
135 | |||
139 | Schedule files to be version controlled and added to the |
|
136 | Schedule files to be version controlled and added to the | |
140 | repository. |
|
137 | repository. | |
141 |
|
138 | |||
142 | The files will be added to the repository at the next commit. To |
|
139 | The files will be added to the repository at the next commit. To | |
143 | undo an add before that, see :hg:`forget`. |
|
140 | undo an add before that, see :hg:`forget`. | |
144 |
|
141 | |||
145 | If no names are given, add all files to the repository (except |
|
142 | If no names are given, add all files to the repository (except | |
146 | files matching ``.hgignore``). |
|
143 | files matching ``.hgignore``). | |
147 |
|
144 | |||
148 | .. container:: verbose |
|
145 | .. container:: verbose | |
149 |
|
146 | |||
150 | Examples: |
|
147 | Examples: | |
151 |
|
148 | |||
152 | - New (unknown) files are added |
|
149 | - New (unknown) files are added | |
153 | automatically by :hg:`add`:: |
|
150 | automatically by :hg:`add`:: | |
154 |
|
151 | |||
155 | $ ls |
|
152 | $ ls | |
156 | foo.c |
|
153 | foo.c | |
157 | $ hg status |
|
154 | $ hg status | |
158 | ? foo.c |
|
155 | ? foo.c | |
159 | $ hg add |
|
156 | $ hg add | |
160 | adding foo.c |
|
157 | adding foo.c | |
161 | $ hg status |
|
158 | $ hg status | |
162 | A foo.c |
|
159 | A foo.c | |
163 |
|
160 | |||
164 | - Specific files to be added can be specified:: |
|
161 | - Specific files to be added can be specified:: | |
165 |
|
162 | |||
166 | $ ls |
|
163 | $ ls | |
167 | bar.c foo.c |
|
164 | bar.c foo.c | |
168 | $ hg status |
|
165 | $ hg status | |
169 | ? bar.c |
|
166 | ? bar.c | |
170 | ? foo.c |
|
167 | ? foo.c | |
171 | $ hg add bar.c |
|
168 | $ hg add bar.c | |
172 | $ hg status |
|
169 | $ hg status | |
173 | A bar.c |
|
170 | A bar.c | |
174 | ? foo.c |
|
171 | ? foo.c | |
175 |
|
172 | |||
176 | Returns 0 if all files are successfully added. |
|
173 | Returns 0 if all files are successfully added. | |
177 | """ |
|
174 | """ | |
178 |
|
175 | |||
179 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) |
|
176 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) | |
180 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) |
|
177 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) | |
181 | return rejected and 1 or 0 |
|
178 | return rejected and 1 or 0 | |
182 |
|
179 | |||
183 | @command('addremove', |
|
180 | @command('addremove', | |
184 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
181 | similarityopts + subrepoopts + walkopts + dryrunopts, | |
185 | _('[OPTION]... [FILE]...'), |
|
182 | _('[OPTION]... [FILE]...'), | |
186 | inferrepo=True) |
|
183 | inferrepo=True) | |
187 | def addremove(ui, repo, *pats, **opts): |
|
184 | def addremove(ui, repo, *pats, **opts): | |
188 | """add all new files, delete all missing files |
|
185 | """add all new files, delete all missing files | |
189 |
|
186 | |||
190 | Add all new files and remove all missing files from the |
|
187 | Add all new files and remove all missing files from the | |
191 | repository. |
|
188 | repository. | |
192 |
|
189 | |||
193 | Unless names are given, new files are ignored if they match any of |
|
190 | Unless names are given, new files are ignored if they match any of | |
194 | the patterns in ``.hgignore``. As with add, these changes take |
|
191 | the patterns in ``.hgignore``. As with add, these changes take | |
195 | effect at the next commit. |
|
192 | effect at the next commit. | |
196 |
|
193 | |||
197 | Use the -s/--similarity option to detect renamed files. This |
|
194 | Use the -s/--similarity option to detect renamed files. This | |
198 | option takes a percentage between 0 (disabled) and 100 (files must |
|
195 | option takes a percentage between 0 (disabled) and 100 (files must | |
199 | be identical) as its parameter. With a parameter greater than 0, |
|
196 | be identical) as its parameter. With a parameter greater than 0, | |
200 | this compares every removed file with every added file and records |
|
197 | this compares every removed file with every added file and records | |
201 | those similar enough as renames. Detecting renamed files this way |
|
198 | those similar enough as renames. Detecting renamed files this way | |
202 | can be expensive. After using this option, :hg:`status -C` can be |
|
199 | can be expensive. After using this option, :hg:`status -C` can be | |
203 | used to check which files were identified as moved or renamed. If |
|
200 | used to check which files were identified as moved or renamed. If | |
204 | not specified, -s/--similarity defaults to 100 and only renames of |
|
201 | not specified, -s/--similarity defaults to 100 and only renames of | |
205 | identical files are detected. |
|
202 | identical files are detected. | |
206 |
|
203 | |||
207 | .. container:: verbose |
|
204 | .. container:: verbose | |
208 |
|
205 | |||
209 | Examples: |
|
206 | Examples: | |
210 |
|
207 | |||
211 | - A number of files (bar.c and foo.c) are new, |
|
208 | - A number of files (bar.c and foo.c) are new, | |
212 | while foobar.c has been removed (without using :hg:`remove`) |
|
209 | while foobar.c has been removed (without using :hg:`remove`) | |
213 | from the repository:: |
|
210 | from the repository:: | |
214 |
|
211 | |||
215 | $ ls |
|
212 | $ ls | |
216 | bar.c foo.c |
|
213 | bar.c foo.c | |
217 | $ hg status |
|
214 | $ hg status | |
218 | ! foobar.c |
|
215 | ! foobar.c | |
219 | ? bar.c |
|
216 | ? bar.c | |
220 | ? foo.c |
|
217 | ? foo.c | |
221 | $ hg addremove |
|
218 | $ hg addremove | |
222 | adding bar.c |
|
219 | adding bar.c | |
223 | adding foo.c |
|
220 | adding foo.c | |
224 | removing foobar.c |
|
221 | removing foobar.c | |
225 | $ hg status |
|
222 | $ hg status | |
226 | A bar.c |
|
223 | A bar.c | |
227 | A foo.c |
|
224 | A foo.c | |
228 | R foobar.c |
|
225 | R foobar.c | |
229 |
|
226 | |||
230 | - A file foobar.c was moved to foo.c without using :hg:`rename`. |
|
227 | - A file foobar.c was moved to foo.c without using :hg:`rename`. | |
231 | Afterwards, it was edited slightly:: |
|
228 | Afterwards, it was edited slightly:: | |
232 |
|
229 | |||
233 | $ ls |
|
230 | $ ls | |
234 | foo.c |
|
231 | foo.c | |
235 | $ hg status |
|
232 | $ hg status | |
236 | ! foobar.c |
|
233 | ! foobar.c | |
237 | ? foo.c |
|
234 | ? foo.c | |
238 | $ hg addremove --similarity 90 |
|
235 | $ hg addremove --similarity 90 | |
239 | removing foobar.c |
|
236 | removing foobar.c | |
240 | adding foo.c |
|
237 | adding foo.c | |
241 | recording removal of foobar.c as rename to foo.c (94% similar) |
|
238 | recording removal of foobar.c as rename to foo.c (94% similar) | |
242 | $ hg status -C |
|
239 | $ hg status -C | |
243 | A foo.c |
|
240 | A foo.c | |
244 | foobar.c |
|
241 | foobar.c | |
245 | R foobar.c |
|
242 | R foobar.c | |
246 |
|
243 | |||
247 | Returns 0 if all files are successfully added. |
|
244 | Returns 0 if all files are successfully added. | |
248 | """ |
|
245 | """ | |
249 | opts = pycompat.byteskwargs(opts) |
|
246 | opts = pycompat.byteskwargs(opts) | |
250 | if not opts.get('similarity'): |
|
247 | if not opts.get('similarity'): | |
251 | opts['similarity'] = '100' |
|
248 | opts['similarity'] = '100' | |
252 | matcher = scmutil.match(repo[None], pats, opts) |
|
249 | matcher = scmutil.match(repo[None], pats, opts) | |
253 | return scmutil.addremove(repo, matcher, "", opts) |
|
250 | return scmutil.addremove(repo, matcher, "", opts) | |
254 |
|
251 | |||
255 | @command('^annotate|blame', |
|
252 | @command('^annotate|blame', | |
256 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
253 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), | |
257 | ('', 'follow', None, |
|
254 | ('', 'follow', None, | |
258 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
255 | _('follow copies/renames and list the filename (DEPRECATED)')), | |
259 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
256 | ('', 'no-follow', None, _("don't follow copies and renames")), | |
260 | ('a', 'text', None, _('treat all files as text')), |
|
257 | ('a', 'text', None, _('treat all files as text')), | |
261 | ('u', 'user', None, _('list the author (long with -v)')), |
|
258 | ('u', 'user', None, _('list the author (long with -v)')), | |
262 | ('f', 'file', None, _('list the filename')), |
|
259 | ('f', 'file', None, _('list the filename')), | |
263 | ('d', 'date', None, _('list the date (short with -q)')), |
|
260 | ('d', 'date', None, _('list the date (short with -q)')), | |
264 | ('n', 'number', None, _('list the revision number (default)')), |
|
261 | ('n', 'number', None, _('list the revision number (default)')), | |
265 | ('c', 'changeset', None, _('list the changeset')), |
|
262 | ('c', 'changeset', None, _('list the changeset')), | |
266 | ('l', 'line-number', None, _('show line number at the first appearance')), |
|
263 | ('l', 'line-number', None, _('show line number at the first appearance')), | |
267 | ('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')), |
|
264 | ('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')), | |
268 | ] + diffwsopts + walkopts + formatteropts, |
|
265 | ] + diffwsopts + walkopts + formatteropts, | |
269 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
266 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), | |
270 | inferrepo=True) |
|
267 | inferrepo=True) | |
271 | def annotate(ui, repo, *pats, **opts): |
|
268 | def annotate(ui, repo, *pats, **opts): | |
272 | """show changeset information by line for each file |
|
269 | """show changeset information by line for each file | |
273 |
|
270 | |||
274 | List changes in files, showing the revision id responsible for |
|
271 | List changes in files, showing the revision id responsible for | |
275 | each line. |
|
272 | each line. | |
276 |
|
273 | |||
277 | This command is useful for discovering when a change was made and |
|
274 | This command is useful for discovering when a change was made and | |
278 | by whom. |
|
275 | by whom. | |
279 |
|
276 | |||
280 | If you include --file, --user, or --date, the revision number is |
|
277 | If you include --file, --user, or --date, the revision number is | |
281 | suppressed unless you also include --number. |
|
278 | suppressed unless you also include --number. | |
282 |
|
279 | |||
283 | Without the -a/--text option, annotate will avoid processing files |
|
280 | Without the -a/--text option, annotate will avoid processing files | |
284 | it detects as binary. With -a, annotate will annotate the file |
|
281 | it detects as binary. With -a, annotate will annotate the file | |
285 | anyway, although the results will probably be neither useful |
|
282 | anyway, although the results will probably be neither useful | |
286 | nor desirable. |
|
283 | nor desirable. | |
287 |
|
284 | |||
288 | Returns 0 on success. |
|
285 | Returns 0 on success. | |
289 | """ |
|
286 | """ | |
290 | opts = pycompat.byteskwargs(opts) |
|
287 | opts = pycompat.byteskwargs(opts) | |
291 | if not pats: |
|
288 | if not pats: | |
292 | raise error.Abort(_('at least one filename or pattern is required')) |
|
289 | raise error.Abort(_('at least one filename or pattern is required')) | |
293 |
|
290 | |||
294 | if opts.get('follow'): |
|
291 | if opts.get('follow'): | |
295 | # --follow is deprecated and now just an alias for -f/--file |
|
292 | # --follow is deprecated and now just an alias for -f/--file | |
296 | # to mimic the behavior of Mercurial before version 1.5 |
|
293 | # to mimic the behavior of Mercurial before version 1.5 | |
297 | opts['file'] = True |
|
294 | opts['file'] = True | |
298 |
|
295 | |||
299 | rev = opts.get('rev') |
|
296 | rev = opts.get('rev') | |
300 | if rev: |
|
297 | if rev: | |
301 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
298 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
302 | ctx = scmutil.revsingle(repo, rev) |
|
299 | ctx = scmutil.revsingle(repo, rev) | |
303 |
|
300 | |||
304 | rootfm = ui.formatter('annotate', opts) |
|
301 | rootfm = ui.formatter('annotate', opts) | |
305 | if ui.quiet: |
|
302 | if ui.quiet: | |
306 | datefunc = dateutil.shortdate |
|
303 | datefunc = dateutil.shortdate | |
307 | else: |
|
304 | else: | |
308 | datefunc = dateutil.datestr |
|
305 | datefunc = dateutil.datestr | |
309 | if ctx.rev() is None: |
|
306 | if ctx.rev() is None: | |
310 | def hexfn(node): |
|
307 | def hexfn(node): | |
311 | if node is None: |
|
308 | if node is None: | |
312 | return None |
|
309 | return None | |
313 | else: |
|
310 | else: | |
314 | return rootfm.hexfunc(node) |
|
311 | return rootfm.hexfunc(node) | |
315 | if opts.get('changeset'): |
|
312 | if opts.get('changeset'): | |
316 | # omit "+" suffix which is appended to node hex |
|
313 | # omit "+" suffix which is appended to node hex | |
317 | def formatrev(rev): |
|
314 | def formatrev(rev): | |
318 | if rev is None: |
|
315 | if rev is None: | |
319 | return '%d' % ctx.p1().rev() |
|
316 | return '%d' % ctx.p1().rev() | |
320 | else: |
|
317 | else: | |
321 | return '%d' % rev |
|
318 | return '%d' % rev | |
322 | else: |
|
319 | else: | |
323 | def formatrev(rev): |
|
320 | def formatrev(rev): | |
324 | if rev is None: |
|
321 | if rev is None: | |
325 | return '%d+' % ctx.p1().rev() |
|
322 | return '%d+' % ctx.p1().rev() | |
326 | else: |
|
323 | else: | |
327 | return '%d ' % rev |
|
324 | return '%d ' % rev | |
328 | def formathex(hex): |
|
325 | def formathex(hex): | |
329 | if hex is None: |
|
326 | if hex is None: | |
330 | return '%s+' % rootfm.hexfunc(ctx.p1().node()) |
|
327 | return '%s+' % rootfm.hexfunc(ctx.p1().node()) | |
331 | else: |
|
328 | else: | |
332 | return '%s ' % hex |
|
329 | return '%s ' % hex | |
333 | else: |
|
330 | else: | |
334 | hexfn = rootfm.hexfunc |
|
331 | hexfn = rootfm.hexfunc | |
335 | formatrev = formathex = pycompat.bytestr |
|
332 | formatrev = formathex = pycompat.bytestr | |
336 |
|
333 | |||
337 | opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), |
|
334 | opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), | |
338 | ('rev', ' ', lambda x: x.fctx.rev(), formatrev), |
|
335 | ('rev', ' ', lambda x: x.fctx.rev(), formatrev), | |
339 | ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex), |
|
336 | ('node', ' ', lambda x: hexfn(x.fctx.node()), formathex), | |
340 | ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), |
|
337 | ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), | |
341 | ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr), |
|
338 | ('file', ' ', lambda x: x.fctx.path(), pycompat.bytestr), | |
342 | ('line_number', ':', lambda x: x.lineno, pycompat.bytestr), |
|
339 | ('line_number', ':', lambda x: x.lineno, pycompat.bytestr), | |
343 | ] |
|
340 | ] | |
344 | opnamemap = {'rev': 'number', 'node': 'changeset'} |
|
341 | opnamemap = {'rev': 'number', 'node': 'changeset'} | |
345 |
|
342 | |||
346 | if (not opts.get('user') and not opts.get('changeset') |
|
343 | if (not opts.get('user') and not opts.get('changeset') | |
347 | and not opts.get('date') and not opts.get('file')): |
|
344 | and not opts.get('date') and not opts.get('file')): | |
348 | opts['number'] = True |
|
345 | opts['number'] = True | |
349 |
|
346 | |||
350 | linenumber = opts.get('line_number') is not None |
|
347 | linenumber = opts.get('line_number') is not None | |
351 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
348 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): | |
352 | raise error.Abort(_('at least one of -n/-c is required for -l')) |
|
349 | raise error.Abort(_('at least one of -n/-c is required for -l')) | |
353 |
|
350 | |||
354 | ui.pager('annotate') |
|
351 | ui.pager('annotate') | |
355 |
|
352 | |||
356 | if rootfm.isplain(): |
|
353 | if rootfm.isplain(): | |
357 | def makefunc(get, fmt): |
|
354 | def makefunc(get, fmt): | |
358 | return lambda x: fmt(get(x)) |
|
355 | return lambda x: fmt(get(x)) | |
359 | else: |
|
356 | else: | |
360 | def makefunc(get, fmt): |
|
357 | def makefunc(get, fmt): | |
361 | return get |
|
358 | return get | |
362 | datahint = rootfm.datahint() |
|
359 | datahint = rootfm.datahint() | |
363 | funcmap = [(makefunc(get, fmt), sep) for fn, sep, get, fmt in opmap |
|
360 | funcmap = [(makefunc(get, fmt), sep) for fn, sep, get, fmt in opmap | |
364 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint] |
|
361 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint] | |
365 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
362 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column | |
366 | fields = ' '.join(fn for fn, sep, get, fmt in opmap |
|
363 | fields = ' '.join(fn for fn, sep, get, fmt in opmap | |
367 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint) |
|
364 | if opts.get(opnamemap.get(fn, fn)) or fn in datahint) | |
368 |
|
365 | |||
369 | def bad(x, y): |
|
366 | def bad(x, y): | |
370 | raise error.Abort("%s: %s" % (x, y)) |
|
367 | raise error.Abort("%s: %s" % (x, y)) | |
371 |
|
368 | |||
372 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
369 | m = scmutil.match(ctx, pats, opts, badfn=bad) | |
373 |
|
370 | |||
374 | follow = not opts.get('no_follow') |
|
371 | follow = not opts.get('no_follow') | |
375 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', |
|
372 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', | |
376 | whitespace=True) |
|
373 | whitespace=True) | |
377 | skiprevs = opts.get('skip') |
|
374 | skiprevs = opts.get('skip') | |
378 | if skiprevs: |
|
375 | if skiprevs: | |
379 | skiprevs = scmutil.revrange(repo, skiprevs) |
|
376 | skiprevs = scmutil.revrange(repo, skiprevs) | |
380 |
|
377 | |||
381 | for abs in ctx.walk(m): |
|
378 | for abs in ctx.walk(m): | |
382 | fctx = ctx[abs] |
|
379 | fctx = ctx[abs] | |
383 | rootfm.startitem() |
|
380 | rootfm.startitem() | |
384 | rootfm.data(abspath=abs, path=m.rel(abs)) |
|
381 | rootfm.data(abspath=abs, path=m.rel(abs)) | |
385 | if not opts.get('text') and fctx.isbinary(): |
|
382 | if not opts.get('text') and fctx.isbinary(): | |
386 | rootfm.plain(_("%s: binary file\n") |
|
383 | rootfm.plain(_("%s: binary file\n") | |
387 | % ((pats and m.rel(abs)) or abs)) |
|
384 | % ((pats and m.rel(abs)) or abs)) | |
388 | continue |
|
385 | continue | |
389 |
|
386 | |||
390 | fm = rootfm.nested('lines', tmpl='{rev}: {line}') |
|
387 | fm = rootfm.nested('lines', tmpl='{rev}: {line}') | |
391 | lines = fctx.annotate(follow=follow, skiprevs=skiprevs, |
|
388 | lines = fctx.annotate(follow=follow, skiprevs=skiprevs, | |
392 | diffopts=diffopts) |
|
389 | diffopts=diffopts) | |
393 | if not lines: |
|
390 | if not lines: | |
394 | fm.end() |
|
391 | fm.end() | |
395 | continue |
|
392 | continue | |
396 | formats = [] |
|
393 | formats = [] | |
397 | pieces = [] |
|
394 | pieces = [] | |
398 |
|
395 | |||
399 | for f, sep in funcmap: |
|
396 | for f, sep in funcmap: | |
400 | l = [f(n) for n in lines] |
|
397 | l = [f(n) for n in lines] | |
401 | if fm.isplain(): |
|
398 | if fm.isplain(): | |
402 | sizes = [encoding.colwidth(x) for x in l] |
|
399 | sizes = [encoding.colwidth(x) for x in l] | |
403 | ml = max(sizes) |
|
400 | ml = max(sizes) | |
404 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
|
401 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) | |
405 | else: |
|
402 | else: | |
406 | formats.append(['%s' for x in l]) |
|
403 | formats.append(['%s' for x in l]) | |
407 | pieces.append(l) |
|
404 | pieces.append(l) | |
408 |
|
405 | |||
409 | for f, p, n in zip(zip(*formats), zip(*pieces), lines): |
|
406 | for f, p, n in zip(zip(*formats), zip(*pieces), lines): | |
410 | fm.startitem() |
|
407 | fm.startitem() | |
411 | fm.context(fctx=n.fctx) |
|
408 | fm.context(fctx=n.fctx) | |
412 | fm.write(fields, "".join(f), *p) |
|
409 | fm.write(fields, "".join(f), *p) | |
413 | if n.skip: |
|
410 | if n.skip: | |
414 | fmt = "* %s" |
|
411 | fmt = "* %s" | |
415 | else: |
|
412 | else: | |
416 | fmt = ": %s" |
|
413 | fmt = ": %s" | |
417 | fm.write('line', fmt, n.text) |
|
414 | fm.write('line', fmt, n.text) | |
418 |
|
415 | |||
419 | if not lines[-1].text.endswith('\n'): |
|
416 | if not lines[-1].text.endswith('\n'): | |
420 | fm.plain('\n') |
|
417 | fm.plain('\n') | |
421 | fm.end() |
|
418 | fm.end() | |
422 |
|
419 | |||
423 | rootfm.end() |
|
420 | rootfm.end() | |
424 |
|
421 | |||
425 | @command('archive', |
|
422 | @command('archive', | |
426 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
423 | [('', 'no-decode', None, _('do not pass files through decoders')), | |
427 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
424 | ('p', 'prefix', '', _('directory prefix for files in archive'), | |
428 | _('PREFIX')), |
|
425 | _('PREFIX')), | |
429 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
426 | ('r', 'rev', '', _('revision to distribute'), _('REV')), | |
430 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
427 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), | |
431 | ] + subrepoopts + walkopts, |
|
428 | ] + subrepoopts + walkopts, | |
432 | _('[OPTION]... DEST')) |
|
429 | _('[OPTION]... DEST')) | |
433 | def archive(ui, repo, dest, **opts): |
|
430 | def archive(ui, repo, dest, **opts): | |
434 | '''create an unversioned archive of a repository revision |
|
431 | '''create an unversioned archive of a repository revision | |
435 |
|
432 | |||
436 | By default, the revision used is the parent of the working |
|
433 | By default, the revision used is the parent of the working | |
437 | directory; use -r/--rev to specify a different revision. |
|
434 | directory; use -r/--rev to specify a different revision. | |
438 |
|
435 | |||
439 | The archive type is automatically detected based on file |
|
436 | The archive type is automatically detected based on file | |
440 | extension (to override, use -t/--type). |
|
437 | extension (to override, use -t/--type). | |
441 |
|
438 | |||
442 | .. container:: verbose |
|
439 | .. container:: verbose | |
443 |
|
440 | |||
444 | Examples: |
|
441 | Examples: | |
445 |
|
442 | |||
446 | - create a zip file containing the 1.0 release:: |
|
443 | - create a zip file containing the 1.0 release:: | |
447 |
|
444 | |||
448 | hg archive -r 1.0 project-1.0.zip |
|
445 | hg archive -r 1.0 project-1.0.zip | |
449 |
|
446 | |||
450 | - create a tarball excluding .hg files:: |
|
447 | - create a tarball excluding .hg files:: | |
451 |
|
448 | |||
452 | hg archive project.tar.gz -X ".hg*" |
|
449 | hg archive project.tar.gz -X ".hg*" | |
453 |
|
450 | |||
454 | Valid types are: |
|
451 | Valid types are: | |
455 |
|
452 | |||
456 | :``files``: a directory full of files (default) |
|
453 | :``files``: a directory full of files (default) | |
457 | :``tar``: tar archive, uncompressed |
|
454 | :``tar``: tar archive, uncompressed | |
458 | :``tbz2``: tar archive, compressed using bzip2 |
|
455 | :``tbz2``: tar archive, compressed using bzip2 | |
459 | :``tgz``: tar archive, compressed using gzip |
|
456 | :``tgz``: tar archive, compressed using gzip | |
460 | :``uzip``: zip archive, uncompressed |
|
457 | :``uzip``: zip archive, uncompressed | |
461 | :``zip``: zip archive, compressed using deflate |
|
458 | :``zip``: zip archive, compressed using deflate | |
462 |
|
459 | |||
463 | The exact name of the destination archive or directory is given |
|
460 | The exact name of the destination archive or directory is given | |
464 | using a format string; see :hg:`help export` for details. |
|
461 | using a format string; see :hg:`help export` for details. | |
465 |
|
462 | |||
466 | Each member added to an archive file has a directory prefix |
|
463 | Each member added to an archive file has a directory prefix | |
467 | prepended. Use -p/--prefix to specify a format string for the |
|
464 | prepended. Use -p/--prefix to specify a format string for the | |
468 | prefix. The default is the basename of the archive, with suffixes |
|
465 | prefix. The default is the basename of the archive, with suffixes | |
469 | removed. |
|
466 | removed. | |
470 |
|
467 | |||
471 | Returns 0 on success. |
|
468 | Returns 0 on success. | |
472 | ''' |
|
469 | ''' | |
473 |
|
470 | |||
474 | opts = pycompat.byteskwargs(opts) |
|
471 | opts = pycompat.byteskwargs(opts) | |
475 | rev = opts.get('rev') |
|
472 | rev = opts.get('rev') | |
476 | if rev: |
|
473 | if rev: | |
477 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
474 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
478 | ctx = scmutil.revsingle(repo, rev) |
|
475 | ctx = scmutil.revsingle(repo, rev) | |
479 | if not ctx: |
|
476 | if not ctx: | |
480 | raise error.Abort(_('no working directory: please specify a revision')) |
|
477 | raise error.Abort(_('no working directory: please specify a revision')) | |
481 | node = ctx.node() |
|
478 | node = ctx.node() | |
482 | dest = cmdutil.makefilename(ctx, dest) |
|
479 | dest = cmdutil.makefilename(ctx, dest) | |
483 | if os.path.realpath(dest) == repo.root: |
|
480 | if os.path.realpath(dest) == repo.root: | |
484 | raise error.Abort(_('repository root cannot be destination')) |
|
481 | raise error.Abort(_('repository root cannot be destination')) | |
485 |
|
482 | |||
486 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
483 | kind = opts.get('type') or archival.guesskind(dest) or 'files' | |
487 | prefix = opts.get('prefix') |
|
484 | prefix = opts.get('prefix') | |
488 |
|
485 | |||
489 | if dest == '-': |
|
486 | if dest == '-': | |
490 | if kind == 'files': |
|
487 | if kind == 'files': | |
491 | raise error.Abort(_('cannot archive plain files to stdout')) |
|
488 | raise error.Abort(_('cannot archive plain files to stdout')) | |
492 | dest = cmdutil.makefileobj(ctx, dest) |
|
489 | dest = cmdutil.makefileobj(ctx, dest) | |
493 | if not prefix: |
|
490 | if not prefix: | |
494 | prefix = os.path.basename(repo.root) + '-%h' |
|
491 | prefix = os.path.basename(repo.root) + '-%h' | |
495 |
|
492 | |||
496 | prefix = cmdutil.makefilename(ctx, prefix) |
|
493 | prefix = cmdutil.makefilename(ctx, prefix) | |
497 | match = scmutil.match(ctx, [], opts) |
|
494 | match = scmutil.match(ctx, [], opts) | |
498 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
495 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | |
499 | match, prefix, subrepos=opts.get('subrepos')) |
|
496 | match, prefix, subrepos=opts.get('subrepos')) | |
500 |
|
497 | |||
501 | @command('backout', |
|
498 | @command('backout', | |
502 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
499 | [('', 'merge', None, _('merge with old dirstate parent after backout')), | |
503 | ('', 'commit', None, |
|
500 | ('', 'commit', None, | |
504 | _('commit if no conflicts were encountered (DEPRECATED)')), |
|
501 | _('commit if no conflicts were encountered (DEPRECATED)')), | |
505 | ('', 'no-commit', None, _('do not commit')), |
|
502 | ('', 'no-commit', None, _('do not commit')), | |
506 | ('', 'parent', '', |
|
503 | ('', 'parent', '', | |
507 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
504 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), | |
508 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
505 | ('r', 'rev', '', _('revision to backout'), _('REV')), | |
509 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
506 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
510 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
507 | ] + mergetoolopts + walkopts + commitopts + commitopts2, | |
511 | _('[OPTION]... [-r] REV')) |
|
508 | _('[OPTION]... [-r] REV')) | |
512 | def backout(ui, repo, node=None, rev=None, **opts): |
|
509 | def backout(ui, repo, node=None, rev=None, **opts): | |
513 | '''reverse effect of earlier changeset |
|
510 | '''reverse effect of earlier changeset | |
514 |
|
511 | |||
515 | Prepare a new changeset with the effect of REV undone in the |
|
512 | Prepare a new changeset with the effect of REV undone in the | |
516 | current working directory. If no conflicts were encountered, |
|
513 | current working directory. If no conflicts were encountered, | |
517 | it will be committed immediately. |
|
514 | it will be committed immediately. | |
518 |
|
515 | |||
519 | If REV is the parent of the working directory, then this new changeset |
|
516 | If REV is the parent of the working directory, then this new changeset | |
520 | is committed automatically (unless --no-commit is specified). |
|
517 | is committed automatically (unless --no-commit is specified). | |
521 |
|
518 | |||
522 | .. note:: |
|
519 | .. note:: | |
523 |
|
520 | |||
524 | :hg:`backout` cannot be used to fix either an unwanted or |
|
521 | :hg:`backout` cannot be used to fix either an unwanted or | |
525 | incorrect merge. |
|
522 | incorrect merge. | |
526 |
|
523 | |||
527 | .. container:: verbose |
|
524 | .. container:: verbose | |
528 |
|
525 | |||
529 | Examples: |
|
526 | Examples: | |
530 |
|
527 | |||
531 | - Reverse the effect of the parent of the working directory. |
|
528 | - Reverse the effect of the parent of the working directory. | |
532 | This backout will be committed immediately:: |
|
529 | This backout will be committed immediately:: | |
533 |
|
530 | |||
534 | hg backout -r . |
|
531 | hg backout -r . | |
535 |
|
532 | |||
536 | - Reverse the effect of previous bad revision 23:: |
|
533 | - Reverse the effect of previous bad revision 23:: | |
537 |
|
534 | |||
538 | hg backout -r 23 |
|
535 | hg backout -r 23 | |
539 |
|
536 | |||
540 | - Reverse the effect of previous bad revision 23 and |
|
537 | - Reverse the effect of previous bad revision 23 and | |
541 | leave changes uncommitted:: |
|
538 | leave changes uncommitted:: | |
542 |
|
539 | |||
543 | hg backout -r 23 --no-commit |
|
540 | hg backout -r 23 --no-commit | |
544 | hg commit -m "Backout revision 23" |
|
541 | hg commit -m "Backout revision 23" | |
545 |
|
542 | |||
546 | By default, the pending changeset will have one parent, |
|
543 | By default, the pending changeset will have one parent, | |
547 | maintaining a linear history. With --merge, the pending |
|
544 | maintaining a linear history. With --merge, the pending | |
548 | changeset will instead have two parents: the old parent of the |
|
545 | changeset will instead have two parents: the old parent of the | |
549 | working directory and a new child of REV that simply undoes REV. |
|
546 | working directory and a new child of REV that simply undoes REV. | |
550 |
|
547 | |||
551 | Before version 1.7, the behavior without --merge was equivalent |
|
548 | Before version 1.7, the behavior without --merge was equivalent | |
552 | to specifying --merge followed by :hg:`update --clean .` to |
|
549 | to specifying --merge followed by :hg:`update --clean .` to | |
553 | cancel the merge and leave the child of REV as a head to be |
|
550 | cancel the merge and leave the child of REV as a head to be | |
554 | merged separately. |
|
551 | merged separately. | |
555 |
|
552 | |||
556 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
553 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
557 |
|
554 | |||
558 | See :hg:`help revert` for a way to restore files to the state |
|
555 | See :hg:`help revert` for a way to restore files to the state | |
559 | of another revision. |
|
556 | of another revision. | |
560 |
|
557 | |||
561 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
558 | Returns 0 on success, 1 if nothing to backout or there are unresolved | |
562 | files. |
|
559 | files. | |
563 | ''' |
|
560 | ''' | |
564 | with repo.wlock(), repo.lock(): |
|
561 | with repo.wlock(), repo.lock(): | |
565 | return _dobackout(ui, repo, node, rev, **opts) |
|
562 | return _dobackout(ui, repo, node, rev, **opts) | |
566 |
|
563 | |||
567 | def _dobackout(ui, repo, node=None, rev=None, **opts): |
|
564 | def _dobackout(ui, repo, node=None, rev=None, **opts): | |
568 | opts = pycompat.byteskwargs(opts) |
|
565 | opts = pycompat.byteskwargs(opts) | |
569 | if opts.get('commit') and opts.get('no_commit'): |
|
566 | if opts.get('commit') and opts.get('no_commit'): | |
570 | raise error.Abort(_("cannot use --commit with --no-commit")) |
|
567 | raise error.Abort(_("cannot use --commit with --no-commit")) | |
571 | if opts.get('merge') and opts.get('no_commit'): |
|
568 | if opts.get('merge') and opts.get('no_commit'): | |
572 | raise error.Abort(_("cannot use --merge with --no-commit")) |
|
569 | raise error.Abort(_("cannot use --merge with --no-commit")) | |
573 |
|
570 | |||
574 | if rev and node: |
|
571 | if rev and node: | |
575 | raise error.Abort(_("please specify just one revision")) |
|
572 | raise error.Abort(_("please specify just one revision")) | |
576 |
|
573 | |||
577 | if not rev: |
|
574 | if not rev: | |
578 | rev = node |
|
575 | rev = node | |
579 |
|
576 | |||
580 | if not rev: |
|
577 | if not rev: | |
581 | raise error.Abort(_("please specify a revision to backout")) |
|
578 | raise error.Abort(_("please specify a revision to backout")) | |
582 |
|
579 | |||
583 | date = opts.get('date') |
|
580 | date = opts.get('date') | |
584 | if date: |
|
581 | if date: | |
585 | opts['date'] = dateutil.parsedate(date) |
|
582 | opts['date'] = dateutil.parsedate(date) | |
586 |
|
583 | |||
587 | cmdutil.checkunfinished(repo) |
|
584 | cmdutil.checkunfinished(repo) | |
588 | cmdutil.bailifchanged(repo) |
|
585 | cmdutil.bailifchanged(repo) | |
589 | node = scmutil.revsingle(repo, rev).node() |
|
586 | node = scmutil.revsingle(repo, rev).node() | |
590 |
|
587 | |||
591 | op1, op2 = repo.dirstate.parents() |
|
588 | op1, op2 = repo.dirstate.parents() | |
592 | if not repo.changelog.isancestor(node, op1): |
|
589 | if not repo.changelog.isancestor(node, op1): | |
593 | raise error.Abort(_('cannot backout change that is not an ancestor')) |
|
590 | raise error.Abort(_('cannot backout change that is not an ancestor')) | |
594 |
|
591 | |||
595 | p1, p2 = repo.changelog.parents(node) |
|
592 | p1, p2 = repo.changelog.parents(node) | |
596 | if p1 == nullid: |
|
593 | if p1 == nullid: | |
597 | raise error.Abort(_('cannot backout a change with no parents')) |
|
594 | raise error.Abort(_('cannot backout a change with no parents')) | |
598 | if p2 != nullid: |
|
595 | if p2 != nullid: | |
599 | if not opts.get('parent'): |
|
596 | if not opts.get('parent'): | |
600 | raise error.Abort(_('cannot backout a merge changeset')) |
|
597 | raise error.Abort(_('cannot backout a merge changeset')) | |
601 | p = repo.lookup(opts['parent']) |
|
598 | p = repo.lookup(opts['parent']) | |
602 | if p not in (p1, p2): |
|
599 | if p not in (p1, p2): | |
603 | raise error.Abort(_('%s is not a parent of %s') % |
|
600 | raise error.Abort(_('%s is not a parent of %s') % | |
604 | (short(p), short(node))) |
|
601 | (short(p), short(node))) | |
605 | parent = p |
|
602 | parent = p | |
606 | else: |
|
603 | else: | |
607 | if opts.get('parent'): |
|
604 | if opts.get('parent'): | |
608 | raise error.Abort(_('cannot use --parent on non-merge changeset')) |
|
605 | raise error.Abort(_('cannot use --parent on non-merge changeset')) | |
609 | parent = p1 |
|
606 | parent = p1 | |
610 |
|
607 | |||
611 | # the backout should appear on the same branch |
|
608 | # the backout should appear on the same branch | |
612 | branch = repo.dirstate.branch() |
|
609 | branch = repo.dirstate.branch() | |
613 | bheads = repo.branchheads(branch) |
|
610 | bheads = repo.branchheads(branch) | |
614 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
611 | rctx = scmutil.revsingle(repo, hex(parent)) | |
615 | if not opts.get('merge') and op1 != node: |
|
612 | if not opts.get('merge') and op1 != node: | |
616 | with dirstateguard.dirstateguard(repo, 'backout'): |
|
613 | with dirstateguard.dirstateguard(repo, 'backout'): | |
617 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
614 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
618 | with ui.configoverride(overrides, 'backout'): |
|
615 | with ui.configoverride(overrides, 'backout'): | |
619 | stats = mergemod.update(repo, parent, True, True, node, False) |
|
616 | stats = mergemod.update(repo, parent, True, True, node, False) | |
620 | repo.setparents(op1, op2) |
|
617 | repo.setparents(op1, op2) | |
621 | hg._showstats(repo, stats) |
|
618 | hg._showstats(repo, stats) | |
622 | if stats.unresolvedcount: |
|
619 | if stats.unresolvedcount: | |
623 | repo.ui.status(_("use 'hg resolve' to retry unresolved " |
|
620 | repo.ui.status(_("use 'hg resolve' to retry unresolved " | |
624 | "file merges\n")) |
|
621 | "file merges\n")) | |
625 | return 1 |
|
622 | return 1 | |
626 | else: |
|
623 | else: | |
627 | hg.clean(repo, node, show_stats=False) |
|
624 | hg.clean(repo, node, show_stats=False) | |
628 | repo.dirstate.setbranch(branch) |
|
625 | repo.dirstate.setbranch(branch) | |
629 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) |
|
626 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) | |
630 |
|
627 | |||
631 | if opts.get('no_commit'): |
|
628 | if opts.get('no_commit'): | |
632 | msg = _("changeset %s backed out, " |
|
629 | msg = _("changeset %s backed out, " | |
633 | "don't forget to commit.\n") |
|
630 | "don't forget to commit.\n") | |
634 | ui.status(msg % short(node)) |
|
631 | ui.status(msg % short(node)) | |
635 | return 0 |
|
632 | return 0 | |
636 |
|
633 | |||
637 | def commitfunc(ui, repo, message, match, opts): |
|
634 | def commitfunc(ui, repo, message, match, opts): | |
638 | editform = 'backout' |
|
635 | editform = 'backout' | |
639 | e = cmdutil.getcommiteditor(editform=editform, |
|
636 | e = cmdutil.getcommiteditor(editform=editform, | |
640 | **pycompat.strkwargs(opts)) |
|
637 | **pycompat.strkwargs(opts)) | |
641 | if not message: |
|
638 | if not message: | |
642 | # we don't translate commit messages |
|
639 | # we don't translate commit messages | |
643 | message = "Backed out changeset %s" % short(node) |
|
640 | message = "Backed out changeset %s" % short(node) | |
644 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
641 | e = cmdutil.getcommiteditor(edit=True, editform=editform) | |
645 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
642 | return repo.commit(message, opts.get('user'), opts.get('date'), | |
646 | match, editor=e) |
|
643 | match, editor=e) | |
647 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
644 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) | |
648 | if not newnode: |
|
645 | if not newnode: | |
649 | ui.status(_("nothing changed\n")) |
|
646 | ui.status(_("nothing changed\n")) | |
650 | return 1 |
|
647 | return 1 | |
651 | cmdutil.commitstatus(repo, newnode, branch, bheads) |
|
648 | cmdutil.commitstatus(repo, newnode, branch, bheads) | |
652 |
|
649 | |||
653 | def nice(node): |
|
650 | def nice(node): | |
654 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
651 | return '%d:%s' % (repo.changelog.rev(node), short(node)) | |
655 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
652 | ui.status(_('changeset %s backs out changeset %s\n') % | |
656 | (nice(repo.changelog.tip()), nice(node))) |
|
653 | (nice(repo.changelog.tip()), nice(node))) | |
657 | if opts.get('merge') and op1 != node: |
|
654 | if opts.get('merge') and op1 != node: | |
658 | hg.clean(repo, op1, show_stats=False) |
|
655 | hg.clean(repo, op1, show_stats=False) | |
659 | ui.status(_('merging with changeset %s\n') |
|
656 | ui.status(_('merging with changeset %s\n') | |
660 | % nice(repo.changelog.tip())) |
|
657 | % nice(repo.changelog.tip())) | |
661 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
658 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
662 | with ui.configoverride(overrides, 'backout'): |
|
659 | with ui.configoverride(overrides, 'backout'): | |
663 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
660 | return hg.merge(repo, hex(repo.changelog.tip())) | |
664 | return 0 |
|
661 | return 0 | |
665 |
|
662 | |||
666 | @command('bisect', |
|
663 | @command('bisect', | |
667 | [('r', 'reset', False, _('reset bisect state')), |
|
664 | [('r', 'reset', False, _('reset bisect state')), | |
668 | ('g', 'good', False, _('mark changeset good')), |
|
665 | ('g', 'good', False, _('mark changeset good')), | |
669 | ('b', 'bad', False, _('mark changeset bad')), |
|
666 | ('b', 'bad', False, _('mark changeset bad')), | |
670 | ('s', 'skip', False, _('skip testing changeset')), |
|
667 | ('s', 'skip', False, _('skip testing changeset')), | |
671 | ('e', 'extend', False, _('extend the bisect range')), |
|
668 | ('e', 'extend', False, _('extend the bisect range')), | |
672 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
669 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), | |
673 | ('U', 'noupdate', False, _('do not update to target'))], |
|
670 | ('U', 'noupdate', False, _('do not update to target'))], | |
674 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
671 | _("[-gbsr] [-U] [-c CMD] [REV]")) | |
675 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
672 | def bisect(ui, repo, rev=None, extra=None, command=None, | |
676 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
673 | reset=None, good=None, bad=None, skip=None, extend=None, | |
677 | noupdate=None): |
|
674 | noupdate=None): | |
678 | """subdivision search of changesets |
|
675 | """subdivision search of changesets | |
679 |
|
676 | |||
680 | This command helps to find changesets which introduce problems. To |
|
677 | This command helps to find changesets which introduce problems. To | |
681 | use, mark the earliest changeset you know exhibits the problem as |
|
678 | use, mark the earliest changeset you know exhibits the problem as | |
682 | bad, then mark the latest changeset which is free from the problem |
|
679 | bad, then mark the latest changeset which is free from the problem | |
683 | as good. Bisect will update your working directory to a revision |
|
680 | as good. Bisect will update your working directory to a revision | |
684 | for testing (unless the -U/--noupdate option is specified). Once |
|
681 | for testing (unless the -U/--noupdate option is specified). Once | |
685 | you have performed tests, mark the working directory as good or |
|
682 | you have performed tests, mark the working directory as good or | |
686 | bad, and bisect will either update to another candidate changeset |
|
683 | bad, and bisect will either update to another candidate changeset | |
687 | or announce that it has found the bad revision. |
|
684 | or announce that it has found the bad revision. | |
688 |
|
685 | |||
689 | As a shortcut, you can also use the revision argument to mark a |
|
686 | As a shortcut, you can also use the revision argument to mark a | |
690 | revision as good or bad without checking it out first. |
|
687 | revision as good or bad without checking it out first. | |
691 |
|
688 | |||
692 | If you supply a command, it will be used for automatic bisection. |
|
689 | If you supply a command, it will be used for automatic bisection. | |
693 | The environment variable HG_NODE will contain the ID of the |
|
690 | The environment variable HG_NODE will contain the ID of the | |
694 | changeset being tested. The exit status of the command will be |
|
691 | changeset being tested. The exit status of the command will be | |
695 | used to mark revisions as good or bad: status 0 means good, 125 |
|
692 | used to mark revisions as good or bad: status 0 means good, 125 | |
696 | means to skip the revision, 127 (command not found) will abort the |
|
693 | means to skip the revision, 127 (command not found) will abort the | |
697 | bisection, and any other non-zero exit status means the revision |
|
694 | bisection, and any other non-zero exit status means the revision | |
698 | is bad. |
|
695 | is bad. | |
699 |
|
696 | |||
700 | .. container:: verbose |
|
697 | .. container:: verbose | |
701 |
|
698 | |||
702 | Some examples: |
|
699 | Some examples: | |
703 |
|
700 | |||
704 | - start a bisection with known bad revision 34, and good revision 12:: |
|
701 | - start a bisection with known bad revision 34, and good revision 12:: | |
705 |
|
702 | |||
706 | hg bisect --bad 34 |
|
703 | hg bisect --bad 34 | |
707 | hg bisect --good 12 |
|
704 | hg bisect --good 12 | |
708 |
|
705 | |||
709 | - advance the current bisection by marking current revision as good or |
|
706 | - advance the current bisection by marking current revision as good or | |
710 | bad:: |
|
707 | bad:: | |
711 |
|
708 | |||
712 | hg bisect --good |
|
709 | hg bisect --good | |
713 | hg bisect --bad |
|
710 | hg bisect --bad | |
714 |
|
711 | |||
715 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
712 | - mark the current revision, or a known revision, to be skipped (e.g. if | |
716 | that revision is not usable because of another issue):: |
|
713 | that revision is not usable because of another issue):: | |
717 |
|
714 | |||
718 | hg bisect --skip |
|
715 | hg bisect --skip | |
719 | hg bisect --skip 23 |
|
716 | hg bisect --skip 23 | |
720 |
|
717 | |||
721 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
718 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: | |
722 |
|
719 | |||
723 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
720 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" | |
724 |
|
721 | |||
725 | - forget the current bisection:: |
|
722 | - forget the current bisection:: | |
726 |
|
723 | |||
727 | hg bisect --reset |
|
724 | hg bisect --reset | |
728 |
|
725 | |||
729 | - use 'make && make tests' to automatically find the first broken |
|
726 | - use 'make && make tests' to automatically find the first broken | |
730 | revision:: |
|
727 | revision:: | |
731 |
|
728 | |||
732 | hg bisect --reset |
|
729 | hg bisect --reset | |
733 | hg bisect --bad 34 |
|
730 | hg bisect --bad 34 | |
734 | hg bisect --good 12 |
|
731 | hg bisect --good 12 | |
735 | hg bisect --command "make && make tests" |
|
732 | hg bisect --command "make && make tests" | |
736 |
|
733 | |||
737 | - see all changesets whose states are already known in the current |
|
734 | - see all changesets whose states are already known in the current | |
738 | bisection:: |
|
735 | bisection:: | |
739 |
|
736 | |||
740 | hg log -r "bisect(pruned)" |
|
737 | hg log -r "bisect(pruned)" | |
741 |
|
738 | |||
742 | - see the changeset currently being bisected (especially useful |
|
739 | - see the changeset currently being bisected (especially useful | |
743 | if running with -U/--noupdate):: |
|
740 | if running with -U/--noupdate):: | |
744 |
|
741 | |||
745 | hg log -r "bisect(current)" |
|
742 | hg log -r "bisect(current)" | |
746 |
|
743 | |||
747 | - see all changesets that took part in the current bisection:: |
|
744 | - see all changesets that took part in the current bisection:: | |
748 |
|
745 | |||
749 | hg log -r "bisect(range)" |
|
746 | hg log -r "bisect(range)" | |
750 |
|
747 | |||
751 | - you can even get a nice graph:: |
|
748 | - you can even get a nice graph:: | |
752 |
|
749 | |||
753 | hg log --graph -r "bisect(range)" |
|
750 | hg log --graph -r "bisect(range)" | |
754 |
|
751 | |||
755 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. |
|
752 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. | |
756 |
|
753 | |||
757 | Returns 0 on success. |
|
754 | Returns 0 on success. | |
758 | """ |
|
755 | """ | |
759 | # backward compatibility |
|
756 | # backward compatibility | |
760 | if rev in "good bad reset init".split(): |
|
757 | if rev in "good bad reset init".split(): | |
761 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
758 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) | |
762 | cmd, rev, extra = rev, extra, None |
|
759 | cmd, rev, extra = rev, extra, None | |
763 | if cmd == "good": |
|
760 | if cmd == "good": | |
764 | good = True |
|
761 | good = True | |
765 | elif cmd == "bad": |
|
762 | elif cmd == "bad": | |
766 | bad = True |
|
763 | bad = True | |
767 | else: |
|
764 | else: | |
768 | reset = True |
|
765 | reset = True | |
769 | elif extra: |
|
766 | elif extra: | |
770 | raise error.Abort(_('incompatible arguments')) |
|
767 | raise error.Abort(_('incompatible arguments')) | |
771 |
|
768 | |||
772 | incompatibles = { |
|
769 | incompatibles = { | |
773 | '--bad': bad, |
|
770 | '--bad': bad, | |
774 | '--command': bool(command), |
|
771 | '--command': bool(command), | |
775 | '--extend': extend, |
|
772 | '--extend': extend, | |
776 | '--good': good, |
|
773 | '--good': good, | |
777 | '--reset': reset, |
|
774 | '--reset': reset, | |
778 | '--skip': skip, |
|
775 | '--skip': skip, | |
779 | } |
|
776 | } | |
780 |
|
777 | |||
781 | enabled = [x for x in incompatibles if incompatibles[x]] |
|
778 | enabled = [x for x in incompatibles if incompatibles[x]] | |
782 |
|
779 | |||
783 | if len(enabled) > 1: |
|
780 | if len(enabled) > 1: | |
784 | raise error.Abort(_('%s and %s are incompatible') % |
|
781 | raise error.Abort(_('%s and %s are incompatible') % | |
785 | tuple(sorted(enabled)[0:2])) |
|
782 | tuple(sorted(enabled)[0:2])) | |
786 |
|
783 | |||
787 | if reset: |
|
784 | if reset: | |
788 | hbisect.resetstate(repo) |
|
785 | hbisect.resetstate(repo) | |
789 | return |
|
786 | return | |
790 |
|
787 | |||
791 | state = hbisect.load_state(repo) |
|
788 | state = hbisect.load_state(repo) | |
792 |
|
789 | |||
793 | # update state |
|
790 | # update state | |
794 | if good or bad or skip: |
|
791 | if good or bad or skip: | |
795 | if rev: |
|
792 | if rev: | |
796 | nodes = [repo[i].node() for i in scmutil.revrange(repo, [rev])] |
|
793 | nodes = [repo[i].node() for i in scmutil.revrange(repo, [rev])] | |
797 | else: |
|
794 | else: | |
798 | nodes = [repo.lookup('.')] |
|
795 | nodes = [repo.lookup('.')] | |
799 | if good: |
|
796 | if good: | |
800 | state['good'] += nodes |
|
797 | state['good'] += nodes | |
801 | elif bad: |
|
798 | elif bad: | |
802 | state['bad'] += nodes |
|
799 | state['bad'] += nodes | |
803 | elif skip: |
|
800 | elif skip: | |
804 | state['skip'] += nodes |
|
801 | state['skip'] += nodes | |
805 | hbisect.save_state(repo, state) |
|
802 | hbisect.save_state(repo, state) | |
806 | if not (state['good'] and state['bad']): |
|
803 | if not (state['good'] and state['bad']): | |
807 | return |
|
804 | return | |
808 |
|
805 | |||
809 | def mayupdate(repo, node, show_stats=True): |
|
806 | def mayupdate(repo, node, show_stats=True): | |
810 | """common used update sequence""" |
|
807 | """common used update sequence""" | |
811 | if noupdate: |
|
808 | if noupdate: | |
812 | return |
|
809 | return | |
813 | cmdutil.checkunfinished(repo) |
|
810 | cmdutil.checkunfinished(repo) | |
814 | cmdutil.bailifchanged(repo) |
|
811 | cmdutil.bailifchanged(repo) | |
815 | return hg.clean(repo, node, show_stats=show_stats) |
|
812 | return hg.clean(repo, node, show_stats=show_stats) | |
816 |
|
813 | |||
817 | displayer = logcmdutil.changesetdisplayer(ui, repo, {}) |
|
814 | displayer = logcmdutil.changesetdisplayer(ui, repo, {}) | |
818 |
|
815 | |||
819 | if command: |
|
816 | if command: | |
820 | changesets = 1 |
|
817 | changesets = 1 | |
821 | if noupdate: |
|
818 | if noupdate: | |
822 | try: |
|
819 | try: | |
823 | node = state['current'][0] |
|
820 | node = state['current'][0] | |
824 | except LookupError: |
|
821 | except LookupError: | |
825 | raise error.Abort(_('current bisect revision is unknown - ' |
|
822 | raise error.Abort(_('current bisect revision is unknown - ' | |
826 | 'start a new bisect to fix')) |
|
823 | 'start a new bisect to fix')) | |
827 | else: |
|
824 | else: | |
828 | node, p2 = repo.dirstate.parents() |
|
825 | node, p2 = repo.dirstate.parents() | |
829 | if p2 != nullid: |
|
826 | if p2 != nullid: | |
830 | raise error.Abort(_('current bisect revision is a merge')) |
|
827 | raise error.Abort(_('current bisect revision is a merge')) | |
831 | if rev: |
|
828 | if rev: | |
832 | node = repo[scmutil.revsingle(repo, rev, node)].node() |
|
829 | node = repo[scmutil.revsingle(repo, rev, node)].node() | |
833 | try: |
|
830 | try: | |
834 | while changesets: |
|
831 | while changesets: | |
835 | # update state |
|
832 | # update state | |
836 | state['current'] = [node] |
|
833 | state['current'] = [node] | |
837 | hbisect.save_state(repo, state) |
|
834 | hbisect.save_state(repo, state) | |
838 | status = ui.system(command, environ={'HG_NODE': hex(node)}, |
|
835 | status = ui.system(command, environ={'HG_NODE': hex(node)}, | |
839 | blockedtag='bisect_check') |
|
836 | blockedtag='bisect_check') | |
840 | if status == 125: |
|
837 | if status == 125: | |
841 | transition = "skip" |
|
838 | transition = "skip" | |
842 | elif status == 0: |
|
839 | elif status == 0: | |
843 | transition = "good" |
|
840 | transition = "good" | |
844 | # status < 0 means process was killed |
|
841 | # status < 0 means process was killed | |
845 | elif status == 127: |
|
842 | elif status == 127: | |
846 | raise error.Abort(_("failed to execute %s") % command) |
|
843 | raise error.Abort(_("failed to execute %s") % command) | |
847 | elif status < 0: |
|
844 | elif status < 0: | |
848 | raise error.Abort(_("%s killed") % command) |
|
845 | raise error.Abort(_("%s killed") % command) | |
849 | else: |
|
846 | else: | |
850 | transition = "bad" |
|
847 | transition = "bad" | |
851 | state[transition].append(node) |
|
848 | state[transition].append(node) | |
852 | ctx = repo[node] |
|
849 | ctx = repo[node] | |
853 | ui.status(_('changeset %d:%s: %s\n') % (ctx.rev(), ctx, |
|
850 | ui.status(_('changeset %d:%s: %s\n') % (ctx.rev(), ctx, | |
854 | transition)) |
|
851 | transition)) | |
855 | hbisect.checkstate(state) |
|
852 | hbisect.checkstate(state) | |
856 | # bisect |
|
853 | # bisect | |
857 | nodes, changesets, bgood = hbisect.bisect(repo, state) |
|
854 | nodes, changesets, bgood = hbisect.bisect(repo, state) | |
858 | # update to next check |
|
855 | # update to next check | |
859 | node = nodes[0] |
|
856 | node = nodes[0] | |
860 | mayupdate(repo, node, show_stats=False) |
|
857 | mayupdate(repo, node, show_stats=False) | |
861 | finally: |
|
858 | finally: | |
862 | state['current'] = [node] |
|
859 | state['current'] = [node] | |
863 | hbisect.save_state(repo, state) |
|
860 | hbisect.save_state(repo, state) | |
864 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) |
|
861 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) | |
865 | return |
|
862 | return | |
866 |
|
863 | |||
867 | hbisect.checkstate(state) |
|
864 | hbisect.checkstate(state) | |
868 |
|
865 | |||
869 | # actually bisect |
|
866 | # actually bisect | |
870 | nodes, changesets, good = hbisect.bisect(repo, state) |
|
867 | nodes, changesets, good = hbisect.bisect(repo, state) | |
871 | if extend: |
|
868 | if extend: | |
872 | if not changesets: |
|
869 | if not changesets: | |
873 | extendnode = hbisect.extendrange(repo, state, nodes, good) |
|
870 | extendnode = hbisect.extendrange(repo, state, nodes, good) | |
874 | if extendnode is not None: |
|
871 | if extendnode is not None: | |
875 | ui.write(_("Extending search to changeset %d:%s\n") |
|
872 | ui.write(_("Extending search to changeset %d:%s\n") | |
876 | % (extendnode.rev(), extendnode)) |
|
873 | % (extendnode.rev(), extendnode)) | |
877 | state['current'] = [extendnode.node()] |
|
874 | state['current'] = [extendnode.node()] | |
878 | hbisect.save_state(repo, state) |
|
875 | hbisect.save_state(repo, state) | |
879 | return mayupdate(repo, extendnode.node()) |
|
876 | return mayupdate(repo, extendnode.node()) | |
880 | raise error.Abort(_("nothing to extend")) |
|
877 | raise error.Abort(_("nothing to extend")) | |
881 |
|
878 | |||
882 | if changesets == 0: |
|
879 | if changesets == 0: | |
883 | hbisect.printresult(ui, repo, state, displayer, nodes, good) |
|
880 | hbisect.printresult(ui, repo, state, displayer, nodes, good) | |
884 | else: |
|
881 | else: | |
885 | assert len(nodes) == 1 # only a single node can be tested next |
|
882 | assert len(nodes) == 1 # only a single node can be tested next | |
886 | node = nodes[0] |
|
883 | node = nodes[0] | |
887 | # compute the approximate number of remaining tests |
|
884 | # compute the approximate number of remaining tests | |
888 | tests, size = 0, 2 |
|
885 | tests, size = 0, 2 | |
889 | while size <= changesets: |
|
886 | while size <= changesets: | |
890 | tests, size = tests + 1, size * 2 |
|
887 | tests, size = tests + 1, size * 2 | |
891 | rev = repo.changelog.rev(node) |
|
888 | rev = repo.changelog.rev(node) | |
892 | ui.write(_("Testing changeset %d:%s " |
|
889 | ui.write(_("Testing changeset %d:%s " | |
893 | "(%d changesets remaining, ~%d tests)\n") |
|
890 | "(%d changesets remaining, ~%d tests)\n") | |
894 | % (rev, short(node), changesets, tests)) |
|
891 | % (rev, short(node), changesets, tests)) | |
895 | state['current'] = [node] |
|
892 | state['current'] = [node] | |
896 | hbisect.save_state(repo, state) |
|
893 | hbisect.save_state(repo, state) | |
897 | return mayupdate(repo, node) |
|
894 | return mayupdate(repo, node) | |
898 |
|
895 | |||
899 | @command('bookmarks|bookmark', |
|
896 | @command('bookmarks|bookmark', | |
900 | [('f', 'force', False, _('force')), |
|
897 | [('f', 'force', False, _('force')), | |
901 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), |
|
898 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), | |
902 | ('d', 'delete', False, _('delete a given bookmark')), |
|
899 | ('d', 'delete', False, _('delete a given bookmark')), | |
903 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
|
900 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), | |
904 | ('i', 'inactive', False, _('mark a bookmark inactive')), |
|
901 | ('i', 'inactive', False, _('mark a bookmark inactive')), | |
905 | ] + formatteropts, |
|
902 | ] + formatteropts, | |
906 | _('hg bookmarks [OPTIONS]... [NAME]...')) |
|
903 | _('hg bookmarks [OPTIONS]... [NAME]...')) | |
907 | def bookmark(ui, repo, *names, **opts): |
|
904 | def bookmark(ui, repo, *names, **opts): | |
908 | '''create a new bookmark or list existing bookmarks |
|
905 | '''create a new bookmark or list existing bookmarks | |
909 |
|
906 | |||
910 | Bookmarks are labels on changesets to help track lines of development. |
|
907 | Bookmarks are labels on changesets to help track lines of development. | |
911 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
908 | Bookmarks are unversioned and can be moved, renamed and deleted. | |
912 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
909 | Deleting or moving a bookmark has no effect on the associated changesets. | |
913 |
|
910 | |||
914 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
911 | Creating or updating to a bookmark causes it to be marked as 'active'. | |
915 | The active bookmark is indicated with a '*'. |
|
912 | The active bookmark is indicated with a '*'. | |
916 | When a commit is made, the active bookmark will advance to the new commit. |
|
913 | When a commit is made, the active bookmark will advance to the new commit. | |
917 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
914 | A plain :hg:`update` will also advance an active bookmark, if possible. | |
918 | Updating away from a bookmark will cause it to be deactivated. |
|
915 | Updating away from a bookmark will cause it to be deactivated. | |
919 |
|
916 | |||
920 | Bookmarks can be pushed and pulled between repositories (see |
|
917 | Bookmarks can be pushed and pulled between repositories (see | |
921 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
918 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has | |
922 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
919 | diverged, a new 'divergent bookmark' of the form 'name@path' will | |
923 | be created. Using :hg:`merge` will resolve the divergence. |
|
920 | be created. Using :hg:`merge` will resolve the divergence. | |
924 |
|
921 | |||
925 | Specifying bookmark as '.' to -m or -d options is equivalent to specifying |
|
922 | Specifying bookmark as '.' to -m or -d options is equivalent to specifying | |
926 | the active bookmark's name. |
|
923 | the active bookmark's name. | |
927 |
|
924 | |||
928 | A bookmark named '@' has the special property that :hg:`clone` will |
|
925 | A bookmark named '@' has the special property that :hg:`clone` will | |
929 | check it out by default if it exists. |
|
926 | check it out by default if it exists. | |
930 |
|
927 | |||
931 | .. container:: verbose |
|
928 | .. container:: verbose | |
932 |
|
929 | |||
933 | Examples: |
|
930 | Examples: | |
934 |
|
931 | |||
935 | - create an active bookmark for a new line of development:: |
|
932 | - create an active bookmark for a new line of development:: | |
936 |
|
933 | |||
937 | hg book new-feature |
|
934 | hg book new-feature | |
938 |
|
935 | |||
939 | - create an inactive bookmark as a place marker:: |
|
936 | - create an inactive bookmark as a place marker:: | |
940 |
|
937 | |||
941 | hg book -i reviewed |
|
938 | hg book -i reviewed | |
942 |
|
939 | |||
943 | - create an inactive bookmark on another changeset:: |
|
940 | - create an inactive bookmark on another changeset:: | |
944 |
|
941 | |||
945 | hg book -r .^ tested |
|
942 | hg book -r .^ tested | |
946 |
|
943 | |||
947 | - rename bookmark turkey to dinner:: |
|
944 | - rename bookmark turkey to dinner:: | |
948 |
|
945 | |||
949 | hg book -m turkey dinner |
|
946 | hg book -m turkey dinner | |
950 |
|
947 | |||
951 | - move the '@' bookmark from another branch:: |
|
948 | - move the '@' bookmark from another branch:: | |
952 |
|
949 | |||
953 | hg book -f @ |
|
950 | hg book -f @ | |
954 | ''' |
|
951 | ''' | |
955 | force = opts.get(r'force') |
|
952 | force = opts.get(r'force') | |
956 | rev = opts.get(r'rev') |
|
953 | rev = opts.get(r'rev') | |
957 | delete = opts.get(r'delete') |
|
954 | delete = opts.get(r'delete') | |
958 | rename = opts.get(r'rename') |
|
955 | rename = opts.get(r'rename') | |
959 | inactive = opts.get(r'inactive') |
|
956 | inactive = opts.get(r'inactive') | |
960 |
|
957 | |||
961 | if delete and rename: |
|
958 | if delete and rename: | |
962 | raise error.Abort(_("--delete and --rename are incompatible")) |
|
959 | raise error.Abort(_("--delete and --rename are incompatible")) | |
963 | if delete and rev: |
|
960 | if delete and rev: | |
964 | raise error.Abort(_("--rev is incompatible with --delete")) |
|
961 | raise error.Abort(_("--rev is incompatible with --delete")) | |
965 | if rename and rev: |
|
962 | if rename and rev: | |
966 | raise error.Abort(_("--rev is incompatible with --rename")) |
|
963 | raise error.Abort(_("--rev is incompatible with --rename")) | |
967 | if not names and (delete or rev): |
|
964 | if not names and (delete or rev): | |
968 | raise error.Abort(_("bookmark name required")) |
|
965 | raise error.Abort(_("bookmark name required")) | |
969 |
|
966 | |||
970 | if delete or rename or names or inactive: |
|
967 | if delete or rename or names or inactive: | |
971 | with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: |
|
968 | with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: | |
972 | if delete: |
|
969 | if delete: | |
973 | names = pycompat.maplist(repo._bookmarks.expandname, names) |
|
970 | names = pycompat.maplist(repo._bookmarks.expandname, names) | |
974 | bookmarks.delete(repo, tr, names) |
|
971 | bookmarks.delete(repo, tr, names) | |
975 | elif rename: |
|
972 | elif rename: | |
976 | if not names: |
|
973 | if not names: | |
977 | raise error.Abort(_("new bookmark name required")) |
|
974 | raise error.Abort(_("new bookmark name required")) | |
978 | elif len(names) > 1: |
|
975 | elif len(names) > 1: | |
979 | raise error.Abort(_("only one new bookmark name allowed")) |
|
976 | raise error.Abort(_("only one new bookmark name allowed")) | |
980 | rename = repo._bookmarks.expandname(rename) |
|
977 | rename = repo._bookmarks.expandname(rename) | |
981 | bookmarks.rename(repo, tr, rename, names[0], force, inactive) |
|
978 | bookmarks.rename(repo, tr, rename, names[0], force, inactive) | |
982 | elif names: |
|
979 | elif names: | |
983 | bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) |
|
980 | bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) | |
984 | elif inactive: |
|
981 | elif inactive: | |
985 | if len(repo._bookmarks) == 0: |
|
982 | if len(repo._bookmarks) == 0: | |
986 | ui.status(_("no bookmarks set\n")) |
|
983 | ui.status(_("no bookmarks set\n")) | |
987 | elif not repo._activebookmark: |
|
984 | elif not repo._activebookmark: | |
988 | ui.status(_("no active bookmark\n")) |
|
985 | ui.status(_("no active bookmark\n")) | |
989 | else: |
|
986 | else: | |
990 | bookmarks.deactivate(repo) |
|
987 | bookmarks.deactivate(repo) | |
991 | else: # show bookmarks |
|
988 | else: # show bookmarks | |
992 | bookmarks.printbookmarks(ui, repo, **opts) |
|
989 | bookmarks.printbookmarks(ui, repo, **opts) | |
993 |
|
990 | |||
994 | @command('branch', |
|
991 | @command('branch', | |
995 | [('f', 'force', None, |
|
992 | [('f', 'force', None, | |
996 | _('set branch name even if it shadows an existing branch')), |
|
993 | _('set branch name even if it shadows an existing branch')), | |
997 | ('C', 'clean', None, _('reset branch name to parent branch name')), |
|
994 | ('C', 'clean', None, _('reset branch name to parent branch name')), | |
998 | ('r', 'rev', [], _('change branches of the given revs (EXPERIMENTAL)')), |
|
995 | ('r', 'rev', [], _('change branches of the given revs (EXPERIMENTAL)')), | |
999 | ], |
|
996 | ], | |
1000 | _('[-fC] [NAME]')) |
|
997 | _('[-fC] [NAME]')) | |
1001 | def branch(ui, repo, label=None, **opts): |
|
998 | def branch(ui, repo, label=None, **opts): | |
1002 | """set or show the current branch name |
|
999 | """set or show the current branch name | |
1003 |
|
1000 | |||
1004 | .. note:: |
|
1001 | .. note:: | |
1005 |
|
1002 | |||
1006 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
1003 | Branch names are permanent and global. Use :hg:`bookmark` to create a | |
1007 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1004 | light-weight bookmark instead. See :hg:`help glossary` for more | |
1008 | information about named branches and bookmarks. |
|
1005 | information about named branches and bookmarks. | |
1009 |
|
1006 | |||
1010 | With no argument, show the current branch name. With one argument, |
|
1007 | With no argument, show the current branch name. With one argument, | |
1011 | set the working directory branch name (the branch will not exist |
|
1008 | set the working directory branch name (the branch will not exist | |
1012 | in the repository until the next commit). Standard practice |
|
1009 | in the repository until the next commit). Standard practice | |
1013 | recommends that primary development take place on the 'default' |
|
1010 | recommends that primary development take place on the 'default' | |
1014 | branch. |
|
1011 | branch. | |
1015 |
|
1012 | |||
1016 | Unless -f/--force is specified, branch will not let you set a |
|
1013 | Unless -f/--force is specified, branch will not let you set a | |
1017 | branch name that already exists. |
|
1014 | branch name that already exists. | |
1018 |
|
1015 | |||
1019 | Use -C/--clean to reset the working directory branch to that of |
|
1016 | Use -C/--clean to reset the working directory branch to that of | |
1020 | the parent of the working directory, negating a previous branch |
|
1017 | the parent of the working directory, negating a previous branch | |
1021 | change. |
|
1018 | change. | |
1022 |
|
1019 | |||
1023 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1020 | Use the command :hg:`update` to switch to an existing branch. Use | |
1024 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1021 | :hg:`commit --close-branch` to mark this branch head as closed. | |
1025 | When all heads of a branch are closed, the branch will be |
|
1022 | When all heads of a branch are closed, the branch will be | |
1026 | considered closed. |
|
1023 | considered closed. | |
1027 |
|
1024 | |||
1028 | Returns 0 on success. |
|
1025 | Returns 0 on success. | |
1029 | """ |
|
1026 | """ | |
1030 | opts = pycompat.byteskwargs(opts) |
|
1027 | opts = pycompat.byteskwargs(opts) | |
1031 | revs = opts.get('rev') |
|
1028 | revs = opts.get('rev') | |
1032 | if label: |
|
1029 | if label: | |
1033 | label = label.strip() |
|
1030 | label = label.strip() | |
1034 |
|
1031 | |||
1035 | if not opts.get('clean') and not label: |
|
1032 | if not opts.get('clean') and not label: | |
1036 | if revs: |
|
1033 | if revs: | |
1037 | raise error.Abort(_("no branch name specified for the revisions")) |
|
1034 | raise error.Abort(_("no branch name specified for the revisions")) | |
1038 | ui.write("%s\n" % repo.dirstate.branch()) |
|
1035 | ui.write("%s\n" % repo.dirstate.branch()) | |
1039 | return |
|
1036 | return | |
1040 |
|
1037 | |||
1041 | with repo.wlock(): |
|
1038 | with repo.wlock(): | |
1042 | if opts.get('clean'): |
|
1039 | if opts.get('clean'): | |
1043 | label = repo[None].p1().branch() |
|
1040 | label = repo[None].p1().branch() | |
1044 | repo.dirstate.setbranch(label) |
|
1041 | repo.dirstate.setbranch(label) | |
1045 | ui.status(_('reset working directory to branch %s\n') % label) |
|
1042 | ui.status(_('reset working directory to branch %s\n') % label) | |
1046 | elif label: |
|
1043 | elif label: | |
1047 |
|
1044 | |||
1048 | scmutil.checknewlabel(repo, label, 'branch') |
|
1045 | scmutil.checknewlabel(repo, label, 'branch') | |
1049 | if revs: |
|
1046 | if revs: | |
1050 | return cmdutil.changebranch(ui, repo, revs, label) |
|
1047 | return cmdutil.changebranch(ui, repo, revs, label) | |
1051 |
|
1048 | |||
1052 | if not opts.get('force') and label in repo.branchmap(): |
|
1049 | if not opts.get('force') and label in repo.branchmap(): | |
1053 | if label not in [p.branch() for p in repo[None].parents()]: |
|
1050 | if label not in [p.branch() for p in repo[None].parents()]: | |
1054 | raise error.Abort(_('a branch of the same name already' |
|
1051 | raise error.Abort(_('a branch of the same name already' | |
1055 | ' exists'), |
|
1052 | ' exists'), | |
1056 | # i18n: "it" refers to an existing branch |
|
1053 | # i18n: "it" refers to an existing branch | |
1057 | hint=_("use 'hg update' to switch to it")) |
|
1054 | hint=_("use 'hg update' to switch to it")) | |
1058 |
|
1055 | |||
1059 | repo.dirstate.setbranch(label) |
|
1056 | repo.dirstate.setbranch(label) | |
1060 | ui.status(_('marked working directory as branch %s\n') % label) |
|
1057 | ui.status(_('marked working directory as branch %s\n') % label) | |
1061 |
|
1058 | |||
1062 | # find any open named branches aside from default |
|
1059 | # find any open named branches aside from default | |
1063 | others = [n for n, h, t, c in repo.branchmap().iterbranches() |
|
1060 | others = [n for n, h, t, c in repo.branchmap().iterbranches() | |
1064 | if n != "default" and not c] |
|
1061 | if n != "default" and not c] | |
1065 | if not others: |
|
1062 | if not others: | |
1066 | ui.status(_('(branches are permanent and global, ' |
|
1063 | ui.status(_('(branches are permanent and global, ' | |
1067 | 'did you want a bookmark?)\n')) |
|
1064 | 'did you want a bookmark?)\n')) | |
1068 |
|
1065 | |||
1069 | @command('branches', |
|
1066 | @command('branches', | |
1070 | [('a', 'active', False, |
|
1067 | [('a', 'active', False, | |
1071 | _('show only branches that have unmerged heads (DEPRECATED)')), |
|
1068 | _('show only branches that have unmerged heads (DEPRECATED)')), | |
1072 | ('c', 'closed', False, _('show normal and closed branches')), |
|
1069 | ('c', 'closed', False, _('show normal and closed branches')), | |
1073 | ] + formatteropts, |
|
1070 | ] + formatteropts, | |
1074 | _('[-c]'), |
|
1071 | _('[-c]'), | |
1075 | intents={INTENT_READONLY}) |
|
1072 | intents={INTENT_READONLY}) | |
1076 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1073 | def branches(ui, repo, active=False, closed=False, **opts): | |
1077 | """list repository named branches |
|
1074 | """list repository named branches | |
1078 |
|
1075 | |||
1079 | List the repository's named branches, indicating which ones are |
|
1076 | List the repository's named branches, indicating which ones are | |
1080 | inactive. If -c/--closed is specified, also list branches which have |
|
1077 | inactive. If -c/--closed is specified, also list branches which have | |
1081 | been marked closed (see :hg:`commit --close-branch`). |
|
1078 | been marked closed (see :hg:`commit --close-branch`). | |
1082 |
|
1079 | |||
1083 | Use the command :hg:`update` to switch to an existing branch. |
|
1080 | Use the command :hg:`update` to switch to an existing branch. | |
1084 |
|
1081 | |||
1085 | Returns 0. |
|
1082 | Returns 0. | |
1086 | """ |
|
1083 | """ | |
1087 |
|
1084 | |||
1088 | opts = pycompat.byteskwargs(opts) |
|
1085 | opts = pycompat.byteskwargs(opts) | |
1089 | ui.pager('branches') |
|
1086 | ui.pager('branches') | |
1090 | fm = ui.formatter('branches', opts) |
|
1087 | fm = ui.formatter('branches', opts) | |
1091 | hexfunc = fm.hexfunc |
|
1088 | hexfunc = fm.hexfunc | |
1092 |
|
1089 | |||
1093 | allheads = set(repo.heads()) |
|
1090 | allheads = set(repo.heads()) | |
1094 | branches = [] |
|
1091 | branches = [] | |
1095 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1092 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): | |
1096 | isactive = False |
|
1093 | isactive = False | |
1097 | if not isclosed: |
|
1094 | if not isclosed: | |
1098 | openheads = set(repo.branchmap().iteropen(heads)) |
|
1095 | openheads = set(repo.branchmap().iteropen(heads)) | |
1099 | isactive = bool(openheads & allheads) |
|
1096 | isactive = bool(openheads & allheads) | |
1100 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1097 | branches.append((tag, repo[tip], isactive, not isclosed)) | |
1101 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), |
|
1098 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), | |
1102 | reverse=True) |
|
1099 | reverse=True) | |
1103 |
|
1100 | |||
1104 | for tag, ctx, isactive, isopen in branches: |
|
1101 | for tag, ctx, isactive, isopen in branches: | |
1105 | if active and not isactive: |
|
1102 | if active and not isactive: | |
1106 | continue |
|
1103 | continue | |
1107 | if isactive: |
|
1104 | if isactive: | |
1108 | label = 'branches.active' |
|
1105 | label = 'branches.active' | |
1109 | notice = '' |
|
1106 | notice = '' | |
1110 | elif not isopen: |
|
1107 | elif not isopen: | |
1111 | if not closed: |
|
1108 | if not closed: | |
1112 | continue |
|
1109 | continue | |
1113 | label = 'branches.closed' |
|
1110 | label = 'branches.closed' | |
1114 | notice = _(' (closed)') |
|
1111 | notice = _(' (closed)') | |
1115 | else: |
|
1112 | else: | |
1116 | label = 'branches.inactive' |
|
1113 | label = 'branches.inactive' | |
1117 | notice = _(' (inactive)') |
|
1114 | notice = _(' (inactive)') | |
1118 | current = (tag == repo.dirstate.branch()) |
|
1115 | current = (tag == repo.dirstate.branch()) | |
1119 | if current: |
|
1116 | if current: | |
1120 | label = 'branches.current' |
|
1117 | label = 'branches.current' | |
1121 |
|
1118 | |||
1122 | fm.startitem() |
|
1119 | fm.startitem() | |
1123 | fm.write('branch', '%s', tag, label=label) |
|
1120 | fm.write('branch', '%s', tag, label=label) | |
1124 | rev = ctx.rev() |
|
1121 | rev = ctx.rev() | |
1125 | padsize = max(31 - len("%d" % rev) - encoding.colwidth(tag), 0) |
|
1122 | padsize = max(31 - len("%d" % rev) - encoding.colwidth(tag), 0) | |
1126 | fmt = ' ' * padsize + ' %d:%s' |
|
1123 | fmt = ' ' * padsize + ' %d:%s' | |
1127 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), |
|
1124 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), | |
1128 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1125 | label='log.changeset changeset.%s' % ctx.phasestr()) | |
1129 | fm.context(ctx=ctx) |
|
1126 | fm.context(ctx=ctx) | |
1130 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1127 | fm.data(active=isactive, closed=not isopen, current=current) | |
1131 | if not ui.quiet: |
|
1128 | if not ui.quiet: | |
1132 | fm.plain(notice) |
|
1129 | fm.plain(notice) | |
1133 | fm.plain('\n') |
|
1130 | fm.plain('\n') | |
1134 | fm.end() |
|
1131 | fm.end() | |
1135 |
|
1132 | |||
1136 | @command('bundle', |
|
1133 | @command('bundle', | |
1137 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
1134 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
1138 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
1135 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), | |
1139 | _('REV')), |
|
1136 | _('REV')), | |
1140 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
1137 | ('b', 'branch', [], _('a specific branch you would like to bundle'), | |
1141 | _('BRANCH')), |
|
1138 | _('BRANCH')), | |
1142 | ('', 'base', [], |
|
1139 | ('', 'base', [], | |
1143 | _('a base changeset assumed to be available at the destination'), |
|
1140 | _('a base changeset assumed to be available at the destination'), | |
1144 | _('REV')), |
|
1141 | _('REV')), | |
1145 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
1142 | ('a', 'all', None, _('bundle all changesets in the repository')), | |
1146 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
1143 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), | |
1147 | ] + remoteopts, |
|
1144 | ] + remoteopts, | |
1148 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
1145 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) | |
1149 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1146 | def bundle(ui, repo, fname, dest=None, **opts): | |
1150 | """create a bundle file |
|
1147 | """create a bundle file | |
1151 |
|
1148 | |||
1152 | Generate a bundle file containing data to be transferred to another |
|
1149 | Generate a bundle file containing data to be transferred to another | |
1153 | repository. |
|
1150 | repository. | |
1154 |
|
1151 | |||
1155 | To create a bundle containing all changesets, use -a/--all |
|
1152 | To create a bundle containing all changesets, use -a/--all | |
1156 | (or --base null). Otherwise, hg assumes the destination will have |
|
1153 | (or --base null). Otherwise, hg assumes the destination will have | |
1157 | all the nodes you specify with --base parameters. Otherwise, hg |
|
1154 | all the nodes you specify with --base parameters. Otherwise, hg | |
1158 | will assume the repository has all the nodes in destination, or |
|
1155 | will assume the repository has all the nodes in destination, or | |
1159 | default-push/default if no destination is specified, where destination |
|
1156 | default-push/default if no destination is specified, where destination | |
1160 | is the repository you provide through DEST option. |
|
1157 | is the repository you provide through DEST option. | |
1161 |
|
1158 | |||
1162 | You can change bundle format with the -t/--type option. See |
|
1159 | You can change bundle format with the -t/--type option. See | |
1163 | :hg:`help bundlespec` for documentation on this format. By default, |
|
1160 | :hg:`help bundlespec` for documentation on this format. By default, | |
1164 | the most appropriate format is used and compression defaults to |
|
1161 | the most appropriate format is used and compression defaults to | |
1165 | bzip2. |
|
1162 | bzip2. | |
1166 |
|
1163 | |||
1167 | The bundle file can then be transferred using conventional means |
|
1164 | The bundle file can then be transferred using conventional means | |
1168 | and applied to another repository with the unbundle or pull |
|
1165 | and applied to another repository with the unbundle or pull | |
1169 | command. This is useful when direct push and pull are not |
|
1166 | command. This is useful when direct push and pull are not | |
1170 | available or when exporting an entire repository is undesirable. |
|
1167 | available or when exporting an entire repository is undesirable. | |
1171 |
|
1168 | |||
1172 | Applying bundles preserves all changeset contents including |
|
1169 | Applying bundles preserves all changeset contents including | |
1173 | permissions, copy/rename information, and revision history. |
|
1170 | permissions, copy/rename information, and revision history. | |
1174 |
|
1171 | |||
1175 | Returns 0 on success, 1 if no changes found. |
|
1172 | Returns 0 on success, 1 if no changes found. | |
1176 | """ |
|
1173 | """ | |
1177 | opts = pycompat.byteskwargs(opts) |
|
1174 | opts = pycompat.byteskwargs(opts) | |
1178 | revs = None |
|
1175 | revs = None | |
1179 | if 'rev' in opts: |
|
1176 | if 'rev' in opts: | |
1180 | revstrings = opts['rev'] |
|
1177 | revstrings = opts['rev'] | |
1181 | revs = scmutil.revrange(repo, revstrings) |
|
1178 | revs = scmutil.revrange(repo, revstrings) | |
1182 | if revstrings and not revs: |
|
1179 | if revstrings and not revs: | |
1183 | raise error.Abort(_('no commits to bundle')) |
|
1180 | raise error.Abort(_('no commits to bundle')) | |
1184 |
|
1181 | |||
1185 | bundletype = opts.get('type', 'bzip2').lower() |
|
1182 | bundletype = opts.get('type', 'bzip2').lower() | |
1186 | try: |
|
1183 | try: | |
1187 | bundlespec = exchange.parsebundlespec(repo, bundletype, strict=False) |
|
1184 | bundlespec = exchange.parsebundlespec(repo, bundletype, strict=False) | |
1188 | except error.UnsupportedBundleSpecification as e: |
|
1185 | except error.UnsupportedBundleSpecification as e: | |
1189 | raise error.Abort(pycompat.bytestr(e), |
|
1186 | raise error.Abort(pycompat.bytestr(e), | |
1190 | hint=_("see 'hg help bundlespec' for supported " |
|
1187 | hint=_("see 'hg help bundlespec' for supported " | |
1191 | "values for --type")) |
|
1188 | "values for --type")) | |
1192 | cgversion = bundlespec.contentopts["cg.version"] |
|
1189 | cgversion = bundlespec.contentopts["cg.version"] | |
1193 |
|
1190 | |||
1194 | # Packed bundles are a pseudo bundle format for now. |
|
1191 | # Packed bundles are a pseudo bundle format for now. | |
1195 | if cgversion == 's1': |
|
1192 | if cgversion == 's1': | |
1196 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), |
|
1193 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), | |
1197 | hint=_("use 'hg debugcreatestreamclonebundle'")) |
|
1194 | hint=_("use 'hg debugcreatestreamclonebundle'")) | |
1198 |
|
1195 | |||
1199 | if opts.get('all'): |
|
1196 | if opts.get('all'): | |
1200 | if dest: |
|
1197 | if dest: | |
1201 | raise error.Abort(_("--all is incompatible with specifying " |
|
1198 | raise error.Abort(_("--all is incompatible with specifying " | |
1202 | "a destination")) |
|
1199 | "a destination")) | |
1203 | if opts.get('base'): |
|
1200 | if opts.get('base'): | |
1204 | ui.warn(_("ignoring --base because --all was specified\n")) |
|
1201 | ui.warn(_("ignoring --base because --all was specified\n")) | |
1205 | base = ['null'] |
|
1202 | base = ['null'] | |
1206 | else: |
|
1203 | else: | |
1207 | base = scmutil.revrange(repo, opts.get('base')) |
|
1204 | base = scmutil.revrange(repo, opts.get('base')) | |
1208 | if cgversion not in changegroup.supportedoutgoingversions(repo): |
|
1205 | if cgversion not in changegroup.supportedoutgoingversions(repo): | |
1209 | raise error.Abort(_("repository does not support bundle version %s") % |
|
1206 | raise error.Abort(_("repository does not support bundle version %s") % | |
1210 | cgversion) |
|
1207 | cgversion) | |
1211 |
|
1208 | |||
1212 | if base: |
|
1209 | if base: | |
1213 | if dest: |
|
1210 | if dest: | |
1214 | raise error.Abort(_("--base is incompatible with specifying " |
|
1211 | raise error.Abort(_("--base is incompatible with specifying " | |
1215 | "a destination")) |
|
1212 | "a destination")) | |
1216 | common = [repo[rev].node() for rev in base] |
|
1213 | common = [repo[rev].node() for rev in base] | |
1217 | heads = [repo[r].node() for r in revs] if revs else None |
|
1214 | heads = [repo[r].node() for r in revs] if revs else None | |
1218 | outgoing = discovery.outgoing(repo, common, heads) |
|
1215 | outgoing = discovery.outgoing(repo, common, heads) | |
1219 | else: |
|
1216 | else: | |
1220 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1217 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
1221 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1218 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
1222 | other = hg.peer(repo, opts, dest) |
|
1219 | other = hg.peer(repo, opts, dest) | |
1223 | revs = [repo[r].hex() for r in revs] |
|
1220 | revs = [repo[r].hex() for r in revs] | |
1224 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1221 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) | |
1225 | heads = revs and map(repo.lookup, revs) or revs |
|
1222 | heads = revs and map(repo.lookup, revs) or revs | |
1226 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1223 | outgoing = discovery.findcommonoutgoing(repo, other, | |
1227 | onlyheads=heads, |
|
1224 | onlyheads=heads, | |
1228 | force=opts.get('force'), |
|
1225 | force=opts.get('force'), | |
1229 | portable=True) |
|
1226 | portable=True) | |
1230 |
|
1227 | |||
1231 | if not outgoing.missing: |
|
1228 | if not outgoing.missing: | |
1232 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) |
|
1229 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) | |
1233 | return 1 |
|
1230 | return 1 | |
1234 |
|
1231 | |||
1235 | if cgversion == '01': #bundle1 |
|
1232 | if cgversion == '01': #bundle1 | |
1236 | bversion = 'HG10' + bundlespec.wirecompression |
|
1233 | bversion = 'HG10' + bundlespec.wirecompression | |
1237 | bcompression = None |
|
1234 | bcompression = None | |
1238 | elif cgversion in ('02', '03'): |
|
1235 | elif cgversion in ('02', '03'): | |
1239 | bversion = 'HG20' |
|
1236 | bversion = 'HG20' | |
1240 | bcompression = bundlespec.wirecompression |
|
1237 | bcompression = bundlespec.wirecompression | |
1241 | else: |
|
1238 | else: | |
1242 | raise error.ProgrammingError( |
|
1239 | raise error.ProgrammingError( | |
1243 | 'bundle: unexpected changegroup version %s' % cgversion) |
|
1240 | 'bundle: unexpected changegroup version %s' % cgversion) | |
1244 |
|
1241 | |||
1245 | # TODO compression options should be derived from bundlespec parsing. |
|
1242 | # TODO compression options should be derived from bundlespec parsing. | |
1246 | # This is a temporary hack to allow adjusting bundle compression |
|
1243 | # This is a temporary hack to allow adjusting bundle compression | |
1247 | # level without a) formalizing the bundlespec changes to declare it |
|
1244 | # level without a) formalizing the bundlespec changes to declare it | |
1248 | # b) introducing a command flag. |
|
1245 | # b) introducing a command flag. | |
1249 | compopts = {} |
|
1246 | compopts = {} | |
1250 | complevel = ui.configint('experimental', |
|
1247 | complevel = ui.configint('experimental', | |
1251 | 'bundlecomplevel.' + bundlespec.compression) |
|
1248 | 'bundlecomplevel.' + bundlespec.compression) | |
1252 | if complevel is None: |
|
1249 | if complevel is None: | |
1253 | complevel = ui.configint('experimental', 'bundlecomplevel') |
|
1250 | complevel = ui.configint('experimental', 'bundlecomplevel') | |
1254 | if complevel is not None: |
|
1251 | if complevel is not None: | |
1255 | compopts['level'] = complevel |
|
1252 | compopts['level'] = complevel | |
1256 |
|
1253 | |||
1257 | # Allow overriding the bundling of obsmarker in phases through |
|
1254 | # Allow overriding the bundling of obsmarker in phases through | |
1258 | # configuration while we don't have a bundle version that include them |
|
1255 | # configuration while we don't have a bundle version that include them | |
1259 | if repo.ui.configbool('experimental', 'evolution.bundle-obsmarker'): |
|
1256 | if repo.ui.configbool('experimental', 'evolution.bundle-obsmarker'): | |
1260 | bundlespec.contentopts['obsolescence'] = True |
|
1257 | bundlespec.contentopts['obsolescence'] = True | |
1261 | if repo.ui.configbool('experimental', 'bundle-phases'): |
|
1258 | if repo.ui.configbool('experimental', 'bundle-phases'): | |
1262 | bundlespec.contentopts['phases'] = True |
|
1259 | bundlespec.contentopts['phases'] = True | |
1263 |
|
1260 | |||
1264 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, |
|
1261 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, | |
1265 | bundlespec.contentopts, compression=bcompression, |
|
1262 | bundlespec.contentopts, compression=bcompression, | |
1266 | compopts=compopts) |
|
1263 | compopts=compopts) | |
1267 |
|
1264 | |||
1268 | @command('cat', |
|
1265 | @command('cat', | |
1269 | [('o', 'output', '', |
|
1266 | [('o', 'output', '', | |
1270 | _('print output to file with formatted name'), _('FORMAT')), |
|
1267 | _('print output to file with formatted name'), _('FORMAT')), | |
1271 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1268 | ('r', 'rev', '', _('print the given revision'), _('REV')), | |
1272 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1269 | ('', 'decode', None, _('apply any matching decode filter')), | |
1273 | ] + walkopts + formatteropts, |
|
1270 | ] + walkopts + formatteropts, | |
1274 | _('[OPTION]... FILE...'), |
|
1271 | _('[OPTION]... FILE...'), | |
1275 | inferrepo=True, |
|
1272 | inferrepo=True, | |
1276 | intents={INTENT_READONLY}) |
|
1273 | intents={INTENT_READONLY}) | |
1277 | def cat(ui, repo, file1, *pats, **opts): |
|
1274 | def cat(ui, repo, file1, *pats, **opts): | |
1278 | """output the current or given revision of files |
|
1275 | """output the current or given revision of files | |
1279 |
|
1276 | |||
1280 | Print the specified files as they were at the given revision. If |
|
1277 | Print the specified files as they were at the given revision. If | |
1281 | no revision is given, the parent of the working directory is used. |
|
1278 | no revision is given, the parent of the working directory is used. | |
1282 |
|
1279 | |||
1283 | Output may be to a file, in which case the name of the file is |
|
1280 | Output may be to a file, in which case the name of the file is | |
1284 | given using a template string. See :hg:`help templates`. In addition |
|
1281 | given using a template string. See :hg:`help templates`. In addition | |
1285 | to the common template keywords, the following formatting rules are |
|
1282 | to the common template keywords, the following formatting rules are | |
1286 | supported: |
|
1283 | supported: | |
1287 |
|
1284 | |||
1288 | :``%%``: literal "%" character |
|
1285 | :``%%``: literal "%" character | |
1289 | :``%s``: basename of file being printed |
|
1286 | :``%s``: basename of file being printed | |
1290 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1287 | :``%d``: dirname of file being printed, or '.' if in repository root | |
1291 | :``%p``: root-relative path name of file being printed |
|
1288 | :``%p``: root-relative path name of file being printed | |
1292 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1289 | :``%H``: changeset hash (40 hexadecimal digits) | |
1293 | :``%R``: changeset revision number |
|
1290 | :``%R``: changeset revision number | |
1294 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1291 | :``%h``: short-form changeset hash (12 hexadecimal digits) | |
1295 | :``%r``: zero-padded changeset revision number |
|
1292 | :``%r``: zero-padded changeset revision number | |
1296 | :``%b``: basename of the exporting repository |
|
1293 | :``%b``: basename of the exporting repository | |
1297 | :``\\``: literal "\\" character |
|
1294 | :``\\``: literal "\\" character | |
1298 |
|
1295 | |||
1299 | Returns 0 on success. |
|
1296 | Returns 0 on success. | |
1300 | """ |
|
1297 | """ | |
1301 | opts = pycompat.byteskwargs(opts) |
|
1298 | opts = pycompat.byteskwargs(opts) | |
1302 | rev = opts.get('rev') |
|
1299 | rev = opts.get('rev') | |
1303 | if rev: |
|
1300 | if rev: | |
1304 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
1301 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
1305 | ctx = scmutil.revsingle(repo, rev) |
|
1302 | ctx = scmutil.revsingle(repo, rev) | |
1306 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1303 | m = scmutil.match(ctx, (file1,) + pats, opts) | |
1307 | fntemplate = opts.pop('output', '') |
|
1304 | fntemplate = opts.pop('output', '') | |
1308 | if cmdutil.isstdiofilename(fntemplate): |
|
1305 | if cmdutil.isstdiofilename(fntemplate): | |
1309 | fntemplate = '' |
|
1306 | fntemplate = '' | |
1310 |
|
1307 | |||
1311 | if fntemplate: |
|
1308 | if fntemplate: | |
1312 | fm = formatter.nullformatter(ui, 'cat', opts) |
|
1309 | fm = formatter.nullformatter(ui, 'cat', opts) | |
1313 | else: |
|
1310 | else: | |
1314 | ui.pager('cat') |
|
1311 | ui.pager('cat') | |
1315 | fm = ui.formatter('cat', opts) |
|
1312 | fm = ui.formatter('cat', opts) | |
1316 | with fm: |
|
1313 | with fm: | |
1317 | return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', |
|
1314 | return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', | |
1318 | **pycompat.strkwargs(opts)) |
|
1315 | **pycompat.strkwargs(opts)) | |
1319 |
|
1316 | |||
1320 | @command('^clone', |
|
1317 | @command('^clone', | |
1321 | [('U', 'noupdate', None, _('the clone will include an empty working ' |
|
1318 | [('U', 'noupdate', None, _('the clone will include an empty working ' | |
1322 | 'directory (only a repository)')), |
|
1319 | 'directory (only a repository)')), | |
1323 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), |
|
1320 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), | |
1324 | _('REV')), |
|
1321 | _('REV')), | |
1325 | ('r', 'rev', [], _('do not clone everything, but include this changeset' |
|
1322 | ('r', 'rev', [], _('do not clone everything, but include this changeset' | |
1326 | ' and its ancestors'), _('REV')), |
|
1323 | ' and its ancestors'), _('REV')), | |
1327 | ('b', 'branch', [], _('do not clone everything, but include this branch\'s' |
|
1324 | ('b', 'branch', [], _('do not clone everything, but include this branch\'s' | |
1328 | ' changesets and their ancestors'), _('BRANCH')), |
|
1325 | ' changesets and their ancestors'), _('BRANCH')), | |
1329 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1326 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
1330 | ('', 'uncompressed', None, |
|
1327 | ('', 'uncompressed', None, | |
1331 | _('an alias to --stream (DEPRECATED)')), |
|
1328 | _('an alias to --stream (DEPRECATED)')), | |
1332 | ('', 'stream', None, |
|
1329 | ('', 'stream', None, | |
1333 | _('clone with minimal data processing')), |
|
1330 | _('clone with minimal data processing')), | |
1334 | ] + remoteopts, |
|
1331 | ] + remoteopts, | |
1335 | _('[OPTION]... SOURCE [DEST]'), |
|
1332 | _('[OPTION]... SOURCE [DEST]'), | |
1336 | norepo=True) |
|
1333 | norepo=True) | |
1337 | def clone(ui, source, dest=None, **opts): |
|
1334 | def clone(ui, source, dest=None, **opts): | |
1338 | """make a copy of an existing repository |
|
1335 | """make a copy of an existing repository | |
1339 |
|
1336 | |||
1340 | Create a copy of an existing repository in a new directory. |
|
1337 | Create a copy of an existing repository in a new directory. | |
1341 |
|
1338 | |||
1342 | If no destination directory name is specified, it defaults to the |
|
1339 | If no destination directory name is specified, it defaults to the | |
1343 | basename of the source. |
|
1340 | basename of the source. | |
1344 |
|
1341 | |||
1345 | The location of the source is added to the new repository's |
|
1342 | The location of the source is added to the new repository's | |
1346 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1343 | ``.hg/hgrc`` file, as the default to be used for future pulls. | |
1347 |
|
1344 | |||
1348 | Only local paths and ``ssh://`` URLs are supported as |
|
1345 | Only local paths and ``ssh://`` URLs are supported as | |
1349 | destinations. For ``ssh://`` destinations, no working directory or |
|
1346 | destinations. For ``ssh://`` destinations, no working directory or | |
1350 | ``.hg/hgrc`` will be created on the remote side. |
|
1347 | ``.hg/hgrc`` will be created on the remote side. | |
1351 |
|
1348 | |||
1352 | If the source repository has a bookmark called '@' set, that |
|
1349 | If the source repository has a bookmark called '@' set, that | |
1353 | revision will be checked out in the new repository by default. |
|
1350 | revision will be checked out in the new repository by default. | |
1354 |
|
1351 | |||
1355 | To check out a particular version, use -u/--update, or |
|
1352 | To check out a particular version, use -u/--update, or | |
1356 | -U/--noupdate to create a clone with no working directory. |
|
1353 | -U/--noupdate to create a clone with no working directory. | |
1357 |
|
1354 | |||
1358 | To pull only a subset of changesets, specify one or more revisions |
|
1355 | To pull only a subset of changesets, specify one or more revisions | |
1359 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1356 | identifiers with -r/--rev or branches with -b/--branch. The | |
1360 | resulting clone will contain only the specified changesets and |
|
1357 | resulting clone will contain only the specified changesets and | |
1361 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1358 | their ancestors. These options (or 'clone src#rev dest') imply | |
1362 | --pull, even for local source repositories. |
|
1359 | --pull, even for local source repositories. | |
1363 |
|
1360 | |||
1364 | In normal clone mode, the remote normalizes repository data into a common |
|
1361 | In normal clone mode, the remote normalizes repository data into a common | |
1365 | exchange format and the receiving end translates this data into its local |
|
1362 | exchange format and the receiving end translates this data into its local | |
1366 | storage format. --stream activates a different clone mode that essentially |
|
1363 | storage format. --stream activates a different clone mode that essentially | |
1367 | copies repository files from the remote with minimal data processing. This |
|
1364 | copies repository files from the remote with minimal data processing. This | |
1368 | significantly reduces the CPU cost of a clone both remotely and locally. |
|
1365 | significantly reduces the CPU cost of a clone both remotely and locally. | |
1369 | However, it often increases the transferred data size by 30-40%. This can |
|
1366 | However, it often increases the transferred data size by 30-40%. This can | |
1370 | result in substantially faster clones where I/O throughput is plentiful, |
|
1367 | result in substantially faster clones where I/O throughput is plentiful, | |
1371 | especially for larger repositories. A side-effect of --stream clones is |
|
1368 | especially for larger repositories. A side-effect of --stream clones is | |
1372 | that storage settings and requirements on the remote are applied locally: |
|
1369 | that storage settings and requirements on the remote are applied locally: | |
1373 | a modern client may inherit legacy or inefficient storage used by the |
|
1370 | a modern client may inherit legacy or inefficient storage used by the | |
1374 | remote or a legacy Mercurial client may not be able to clone from a |
|
1371 | remote or a legacy Mercurial client may not be able to clone from a | |
1375 | modern Mercurial remote. |
|
1372 | modern Mercurial remote. | |
1376 |
|
1373 | |||
1377 | .. note:: |
|
1374 | .. note:: | |
1378 |
|
1375 | |||
1379 | Specifying a tag will include the tagged changeset but not the |
|
1376 | Specifying a tag will include the tagged changeset but not the | |
1380 | changeset containing the tag. |
|
1377 | changeset containing the tag. | |
1381 |
|
1378 | |||
1382 | .. container:: verbose |
|
1379 | .. container:: verbose | |
1383 |
|
1380 | |||
1384 | For efficiency, hardlinks are used for cloning whenever the |
|
1381 | For efficiency, hardlinks are used for cloning whenever the | |
1385 | source and destination are on the same filesystem (note this |
|
1382 | source and destination are on the same filesystem (note this | |
1386 | applies only to the repository data, not to the working |
|
1383 | applies only to the repository data, not to the working | |
1387 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1384 | directory). Some filesystems, such as AFS, implement hardlinking | |
1388 | incorrectly, but do not report errors. In these cases, use the |
|
1385 | incorrectly, but do not report errors. In these cases, use the | |
1389 | --pull option to avoid hardlinking. |
|
1386 | --pull option to avoid hardlinking. | |
1390 |
|
1387 | |||
1391 | Mercurial will update the working directory to the first applicable |
|
1388 | Mercurial will update the working directory to the first applicable | |
1392 | revision from this list: |
|
1389 | revision from this list: | |
1393 |
|
1390 | |||
1394 | a) null if -U or the source repository has no changesets |
|
1391 | a) null if -U or the source repository has no changesets | |
1395 | b) if -u . and the source repository is local, the first parent of |
|
1392 | b) if -u . and the source repository is local, the first parent of | |
1396 | the source repository's working directory |
|
1393 | the source repository's working directory | |
1397 | c) the changeset specified with -u (if a branch name, this means the |
|
1394 | c) the changeset specified with -u (if a branch name, this means the | |
1398 | latest head of that branch) |
|
1395 | latest head of that branch) | |
1399 | d) the changeset specified with -r |
|
1396 | d) the changeset specified with -r | |
1400 | e) the tipmost head specified with -b |
|
1397 | e) the tipmost head specified with -b | |
1401 | f) the tipmost head specified with the url#branch source syntax |
|
1398 | f) the tipmost head specified with the url#branch source syntax | |
1402 | g) the revision marked with the '@' bookmark, if present |
|
1399 | g) the revision marked with the '@' bookmark, if present | |
1403 | h) the tipmost head of the default branch |
|
1400 | h) the tipmost head of the default branch | |
1404 | i) tip |
|
1401 | i) tip | |
1405 |
|
1402 | |||
1406 | When cloning from servers that support it, Mercurial may fetch |
|
1403 | When cloning from servers that support it, Mercurial may fetch | |
1407 | pre-generated data from a server-advertised URL or inline from the |
|
1404 | pre-generated data from a server-advertised URL or inline from the | |
1408 | same stream. When this is done, hooks operating on incoming changesets |
|
1405 | same stream. When this is done, hooks operating on incoming changesets | |
1409 | and changegroups may fire more than once, once for each pre-generated |
|
1406 | and changegroups may fire more than once, once for each pre-generated | |
1410 | bundle and as well as for any additional remaining data. In addition, |
|
1407 | bundle and as well as for any additional remaining data. In addition, | |
1411 | if an error occurs, the repository may be rolled back to a partial |
|
1408 | if an error occurs, the repository may be rolled back to a partial | |
1412 | clone. This behavior may change in future releases. |
|
1409 | clone. This behavior may change in future releases. | |
1413 | See :hg:`help -e clonebundles` for more. |
|
1410 | See :hg:`help -e clonebundles` for more. | |
1414 |
|
1411 | |||
1415 | Examples: |
|
1412 | Examples: | |
1416 |
|
1413 | |||
1417 | - clone a remote repository to a new directory named hg/:: |
|
1414 | - clone a remote repository to a new directory named hg/:: | |
1418 |
|
1415 | |||
1419 | hg clone https://www.mercurial-scm.org/repo/hg/ |
|
1416 | hg clone https://www.mercurial-scm.org/repo/hg/ | |
1420 |
|
1417 | |||
1421 | - create a lightweight local clone:: |
|
1418 | - create a lightweight local clone:: | |
1422 |
|
1419 | |||
1423 | hg clone project/ project-feature/ |
|
1420 | hg clone project/ project-feature/ | |
1424 |
|
1421 | |||
1425 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1422 | - clone from an absolute path on an ssh server (note double-slash):: | |
1426 |
|
1423 | |||
1427 | hg clone ssh://user@server//home/projects/alpha/ |
|
1424 | hg clone ssh://user@server//home/projects/alpha/ | |
1428 |
|
1425 | |||
1429 | - do a streaming clone while checking out a specified version:: |
|
1426 | - do a streaming clone while checking out a specified version:: | |
1430 |
|
1427 | |||
1431 | hg clone --stream http://server/repo -u 1.5 |
|
1428 | hg clone --stream http://server/repo -u 1.5 | |
1432 |
|
1429 | |||
1433 | - create a repository without changesets after a particular revision:: |
|
1430 | - create a repository without changesets after a particular revision:: | |
1434 |
|
1431 | |||
1435 | hg clone -r 04e544 experimental/ good/ |
|
1432 | hg clone -r 04e544 experimental/ good/ | |
1436 |
|
1433 | |||
1437 | - clone (and track) a particular named branch:: |
|
1434 | - clone (and track) a particular named branch:: | |
1438 |
|
1435 | |||
1439 | hg clone https://www.mercurial-scm.org/repo/hg/#stable |
|
1436 | hg clone https://www.mercurial-scm.org/repo/hg/#stable | |
1440 |
|
1437 | |||
1441 | See :hg:`help urls` for details on specifying URLs. |
|
1438 | See :hg:`help urls` for details on specifying URLs. | |
1442 |
|
1439 | |||
1443 | Returns 0 on success. |
|
1440 | Returns 0 on success. | |
1444 | """ |
|
1441 | """ | |
1445 | opts = pycompat.byteskwargs(opts) |
|
1442 | opts = pycompat.byteskwargs(opts) | |
1446 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1443 | if opts.get('noupdate') and opts.get('updaterev'): | |
1447 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1444 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) | |
1448 |
|
1445 | |||
1449 | r = hg.clone(ui, opts, source, dest, |
|
1446 | r = hg.clone(ui, opts, source, dest, | |
1450 | pull=opts.get('pull'), |
|
1447 | pull=opts.get('pull'), | |
1451 | stream=opts.get('stream') or opts.get('uncompressed'), |
|
1448 | stream=opts.get('stream') or opts.get('uncompressed'), | |
1452 | revs=opts.get('rev'), |
|
1449 | revs=opts.get('rev'), | |
1453 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1450 | update=opts.get('updaterev') or not opts.get('noupdate'), | |
1454 | branch=opts.get('branch'), |
|
1451 | branch=opts.get('branch'), | |
1455 | shareopts=opts.get('shareopts')) |
|
1452 | shareopts=opts.get('shareopts')) | |
1456 |
|
1453 | |||
1457 | return r is None |
|
1454 | return r is None | |
1458 |
|
1455 | |||
1459 | @command('^commit|ci', |
|
1456 | @command('^commit|ci', | |
1460 | [('A', 'addremove', None, |
|
1457 | [('A', 'addremove', None, | |
1461 | _('mark new/missing files as added/removed before committing')), |
|
1458 | _('mark new/missing files as added/removed before committing')), | |
1462 | ('', 'close-branch', None, |
|
1459 | ('', 'close-branch', None, | |
1463 | _('mark a branch head as closed')), |
|
1460 | _('mark a branch head as closed')), | |
1464 | ('', 'amend', None, _('amend the parent of the working directory')), |
|
1461 | ('', 'amend', None, _('amend the parent of the working directory')), | |
1465 | ('s', 'secret', None, _('use the secret phase for committing')), |
|
1462 | ('s', 'secret', None, _('use the secret phase for committing')), | |
1466 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
1463 | ('e', 'edit', None, _('invoke editor on commit messages')), | |
1467 | ('i', 'interactive', None, _('use interactive mode')), |
|
1464 | ('i', 'interactive', None, _('use interactive mode')), | |
1468 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1465 | ] + walkopts + commitopts + commitopts2 + subrepoopts, | |
1469 | _('[OPTION]... [FILE]...'), |
|
1466 | _('[OPTION]... [FILE]...'), | |
1470 | inferrepo=True) |
|
1467 | inferrepo=True) | |
1471 | def commit(ui, repo, *pats, **opts): |
|
1468 | def commit(ui, repo, *pats, **opts): | |
1472 | """commit the specified files or all outstanding changes |
|
1469 | """commit the specified files or all outstanding changes | |
1473 |
|
1470 | |||
1474 | Commit changes to the given files into the repository. Unlike a |
|
1471 | Commit changes to the given files into the repository. Unlike a | |
1475 | centralized SCM, this operation is a local operation. See |
|
1472 | centralized SCM, this operation is a local operation. See | |
1476 | :hg:`push` for a way to actively distribute your changes. |
|
1473 | :hg:`push` for a way to actively distribute your changes. | |
1477 |
|
1474 | |||
1478 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1475 | If a list of files is omitted, all changes reported by :hg:`status` | |
1479 | will be committed. |
|
1476 | will be committed. | |
1480 |
|
1477 | |||
1481 | If you are committing the result of a merge, do not provide any |
|
1478 | If you are committing the result of a merge, do not provide any | |
1482 | filenames or -I/-X filters. |
|
1479 | filenames or -I/-X filters. | |
1483 |
|
1480 | |||
1484 | If no commit message is specified, Mercurial starts your |
|
1481 | If no commit message is specified, Mercurial starts your | |
1485 | configured editor where you can enter a message. In case your |
|
1482 | configured editor where you can enter a message. In case your | |
1486 | commit fails, you will find a backup of your message in |
|
1483 | commit fails, you will find a backup of your message in | |
1487 | ``.hg/last-message.txt``. |
|
1484 | ``.hg/last-message.txt``. | |
1488 |
|
1485 | |||
1489 | The --close-branch flag can be used to mark the current branch |
|
1486 | The --close-branch flag can be used to mark the current branch | |
1490 | head closed. When all heads of a branch are closed, the branch |
|
1487 | head closed. When all heads of a branch are closed, the branch | |
1491 | will be considered closed and no longer listed. |
|
1488 | will be considered closed and no longer listed. | |
1492 |
|
1489 | |||
1493 | The --amend flag can be used to amend the parent of the |
|
1490 | The --amend flag can be used to amend the parent of the | |
1494 | working directory with a new commit that contains the changes |
|
1491 | working directory with a new commit that contains the changes | |
1495 | in the parent in addition to those currently reported by :hg:`status`, |
|
1492 | in the parent in addition to those currently reported by :hg:`status`, | |
1496 | if there are any. The old commit is stored in a backup bundle in |
|
1493 | if there are any. The old commit is stored in a backup bundle in | |
1497 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1494 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` | |
1498 | on how to restore it). |
|
1495 | on how to restore it). | |
1499 |
|
1496 | |||
1500 | Message, user and date are taken from the amended commit unless |
|
1497 | Message, user and date are taken from the amended commit unless | |
1501 | specified. When a message isn't specified on the command line, |
|
1498 | specified. When a message isn't specified on the command line, | |
1502 | the editor will open with the message of the amended commit. |
|
1499 | the editor will open with the message of the amended commit. | |
1503 |
|
1500 | |||
1504 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1501 | It is not possible to amend public changesets (see :hg:`help phases`) | |
1505 | or changesets that have children. |
|
1502 | or changesets that have children. | |
1506 |
|
1503 | |||
1507 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1504 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
1508 |
|
1505 | |||
1509 | Returns 0 on success, 1 if nothing changed. |
|
1506 | Returns 0 on success, 1 if nothing changed. | |
1510 |
|
1507 | |||
1511 | .. container:: verbose |
|
1508 | .. container:: verbose | |
1512 |
|
1509 | |||
1513 | Examples: |
|
1510 | Examples: | |
1514 |
|
1511 | |||
1515 | - commit all files ending in .py:: |
|
1512 | - commit all files ending in .py:: | |
1516 |
|
1513 | |||
1517 | hg commit --include "set:**.py" |
|
1514 | hg commit --include "set:**.py" | |
1518 |
|
1515 | |||
1519 | - commit all non-binary files:: |
|
1516 | - commit all non-binary files:: | |
1520 |
|
1517 | |||
1521 | hg commit --exclude "set:binary()" |
|
1518 | hg commit --exclude "set:binary()" | |
1522 |
|
1519 | |||
1523 | - amend the current commit and set the date to now:: |
|
1520 | - amend the current commit and set the date to now:: | |
1524 |
|
1521 | |||
1525 | hg commit --amend --date now |
|
1522 | hg commit --amend --date now | |
1526 | """ |
|
1523 | """ | |
1527 | with repo.wlock(), repo.lock(): |
|
1524 | with repo.wlock(), repo.lock(): | |
1528 | return _docommit(ui, repo, *pats, **opts) |
|
1525 | return _docommit(ui, repo, *pats, **opts) | |
1529 |
|
1526 | |||
1530 | def _docommit(ui, repo, *pats, **opts): |
|
1527 | def _docommit(ui, repo, *pats, **opts): | |
1531 | if opts.get(r'interactive'): |
|
1528 | if opts.get(r'interactive'): | |
1532 | opts.pop(r'interactive') |
|
1529 | opts.pop(r'interactive') | |
1533 | ret = cmdutil.dorecord(ui, repo, commit, None, False, |
|
1530 | ret = cmdutil.dorecord(ui, repo, commit, None, False, | |
1534 | cmdutil.recordfilter, *pats, |
|
1531 | cmdutil.recordfilter, *pats, | |
1535 | **opts) |
|
1532 | **opts) | |
1536 | # ret can be 0 (no changes to record) or the value returned by |
|
1533 | # ret can be 0 (no changes to record) or the value returned by | |
1537 | # commit(), 1 if nothing changed or None on success. |
|
1534 | # commit(), 1 if nothing changed or None on success. | |
1538 | return 1 if ret == 0 else ret |
|
1535 | return 1 if ret == 0 else ret | |
1539 |
|
1536 | |||
1540 | opts = pycompat.byteskwargs(opts) |
|
1537 | opts = pycompat.byteskwargs(opts) | |
1541 | if opts.get('subrepos'): |
|
1538 | if opts.get('subrepos'): | |
1542 | if opts.get('amend'): |
|
1539 | if opts.get('amend'): | |
1543 | raise error.Abort(_('cannot amend with --subrepos')) |
|
1540 | raise error.Abort(_('cannot amend with --subrepos')) | |
1544 | # Let --subrepos on the command line override config setting. |
|
1541 | # Let --subrepos on the command line override config setting. | |
1545 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') |
|
1542 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') | |
1546 |
|
1543 | |||
1547 | cmdutil.checkunfinished(repo, commit=True) |
|
1544 | cmdutil.checkunfinished(repo, commit=True) | |
1548 |
|
1545 | |||
1549 | branch = repo[None].branch() |
|
1546 | branch = repo[None].branch() | |
1550 | bheads = repo.branchheads(branch) |
|
1547 | bheads = repo.branchheads(branch) | |
1551 |
|
1548 | |||
1552 | extra = {} |
|
1549 | extra = {} | |
1553 | if opts.get('close_branch'): |
|
1550 | if opts.get('close_branch'): | |
1554 | extra['close'] = '1' |
|
1551 | extra['close'] = '1' | |
1555 |
|
1552 | |||
1556 | if not bheads: |
|
1553 | if not bheads: | |
1557 | raise error.Abort(_('can only close branch heads')) |
|
1554 | raise error.Abort(_('can only close branch heads')) | |
1558 | elif opts.get('amend'): |
|
1555 | elif opts.get('amend'): | |
1559 | if repo[None].parents()[0].p1().branch() != branch and \ |
|
1556 | if repo[None].parents()[0].p1().branch() != branch and \ | |
1560 | repo[None].parents()[0].p2().branch() != branch: |
|
1557 | repo[None].parents()[0].p2().branch() != branch: | |
1561 | raise error.Abort(_('can only close branch heads')) |
|
1558 | raise error.Abort(_('can only close branch heads')) | |
1562 |
|
1559 | |||
1563 | if opts.get('amend'): |
|
1560 | if opts.get('amend'): | |
1564 | if ui.configbool('ui', 'commitsubrepos'): |
|
1561 | if ui.configbool('ui', 'commitsubrepos'): | |
1565 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) |
|
1562 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) | |
1566 |
|
1563 | |||
1567 | old = repo['.'] |
|
1564 | old = repo['.'] | |
1568 | rewriteutil.precheck(repo, [old.rev()], 'amend') |
|
1565 | rewriteutil.precheck(repo, [old.rev()], 'amend') | |
1569 |
|
1566 | |||
1570 | # Currently histedit gets confused if an amend happens while histedit |
|
1567 | # Currently histedit gets confused if an amend happens while histedit | |
1571 | # is in progress. Since we have a checkunfinished command, we are |
|
1568 | # is in progress. Since we have a checkunfinished command, we are | |
1572 | # temporarily honoring it. |
|
1569 | # temporarily honoring it. | |
1573 | # |
|
1570 | # | |
1574 | # Note: eventually this guard will be removed. Please do not expect |
|
1571 | # Note: eventually this guard will be removed. Please do not expect | |
1575 | # this behavior to remain. |
|
1572 | # this behavior to remain. | |
1576 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
1573 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): | |
1577 | cmdutil.checkunfinished(repo) |
|
1574 | cmdutil.checkunfinished(repo) | |
1578 |
|
1575 | |||
1579 | node = cmdutil.amend(ui, repo, old, extra, pats, opts) |
|
1576 | node = cmdutil.amend(ui, repo, old, extra, pats, opts) | |
1580 | if node == old.node(): |
|
1577 | if node == old.node(): | |
1581 | ui.status(_("nothing changed\n")) |
|
1578 | ui.status(_("nothing changed\n")) | |
1582 | return 1 |
|
1579 | return 1 | |
1583 | else: |
|
1580 | else: | |
1584 | def commitfunc(ui, repo, message, match, opts): |
|
1581 | def commitfunc(ui, repo, message, match, opts): | |
1585 | overrides = {} |
|
1582 | overrides = {} | |
1586 | if opts.get('secret'): |
|
1583 | if opts.get('secret'): | |
1587 | overrides[('phases', 'new-commit')] = 'secret' |
|
1584 | overrides[('phases', 'new-commit')] = 'secret' | |
1588 |
|
1585 | |||
1589 | baseui = repo.baseui |
|
1586 | baseui = repo.baseui | |
1590 | with baseui.configoverride(overrides, 'commit'): |
|
1587 | with baseui.configoverride(overrides, 'commit'): | |
1591 | with ui.configoverride(overrides, 'commit'): |
|
1588 | with ui.configoverride(overrides, 'commit'): | |
1592 | editform = cmdutil.mergeeditform(repo[None], |
|
1589 | editform = cmdutil.mergeeditform(repo[None], | |
1593 | 'commit.normal') |
|
1590 | 'commit.normal') | |
1594 | editor = cmdutil.getcommiteditor( |
|
1591 | editor = cmdutil.getcommiteditor( | |
1595 | editform=editform, **pycompat.strkwargs(opts)) |
|
1592 | editform=editform, **pycompat.strkwargs(opts)) | |
1596 | return repo.commit(message, |
|
1593 | return repo.commit(message, | |
1597 | opts.get('user'), |
|
1594 | opts.get('user'), | |
1598 | opts.get('date'), |
|
1595 | opts.get('date'), | |
1599 | match, |
|
1596 | match, | |
1600 | editor=editor, |
|
1597 | editor=editor, | |
1601 | extra=extra) |
|
1598 | extra=extra) | |
1602 |
|
1599 | |||
1603 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1600 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | |
1604 |
|
1601 | |||
1605 | if not node: |
|
1602 | if not node: | |
1606 | stat = cmdutil.postcommitstatus(repo, pats, opts) |
|
1603 | stat = cmdutil.postcommitstatus(repo, pats, opts) | |
1607 | if stat[3]: |
|
1604 | if stat[3]: | |
1608 | ui.status(_("nothing changed (%d missing files, see " |
|
1605 | ui.status(_("nothing changed (%d missing files, see " | |
1609 | "'hg status')\n") % len(stat[3])) |
|
1606 | "'hg status')\n") % len(stat[3])) | |
1610 | else: |
|
1607 | else: | |
1611 | ui.status(_("nothing changed\n")) |
|
1608 | ui.status(_("nothing changed\n")) | |
1612 | return 1 |
|
1609 | return 1 | |
1613 |
|
1610 | |||
1614 | cmdutil.commitstatus(repo, node, branch, bheads, opts) |
|
1611 | cmdutil.commitstatus(repo, node, branch, bheads, opts) | |
1615 |
|
1612 | |||
1616 | @command('config|showconfig|debugconfig', |
|
1613 | @command('config|showconfig|debugconfig', | |
1617 | [('u', 'untrusted', None, _('show untrusted configuration options')), |
|
1614 | [('u', 'untrusted', None, _('show untrusted configuration options')), | |
1618 | ('e', 'edit', None, _('edit user config')), |
|
1615 | ('e', 'edit', None, _('edit user config')), | |
1619 | ('l', 'local', None, _('edit repository config')), |
|
1616 | ('l', 'local', None, _('edit repository config')), | |
1620 | ('g', 'global', None, _('edit global config'))] + formatteropts, |
|
1617 | ('g', 'global', None, _('edit global config'))] + formatteropts, | |
1621 | _('[-u] [NAME]...'), |
|
1618 | _('[-u] [NAME]...'), | |
1622 | optionalrepo=True, |
|
1619 | optionalrepo=True, | |
1623 | intents={INTENT_READONLY}) |
|
1620 | intents={INTENT_READONLY}) | |
1624 | def config(ui, repo, *values, **opts): |
|
1621 | def config(ui, repo, *values, **opts): | |
1625 | """show combined config settings from all hgrc files |
|
1622 | """show combined config settings from all hgrc files | |
1626 |
|
1623 | |||
1627 | With no arguments, print names and values of all config items. |
|
1624 | With no arguments, print names and values of all config items. | |
1628 |
|
1625 | |||
1629 | With one argument of the form section.name, print just the value |
|
1626 | With one argument of the form section.name, print just the value | |
1630 | of that config item. |
|
1627 | of that config item. | |
1631 |
|
1628 | |||
1632 | With multiple arguments, print names and values of all config |
|
1629 | With multiple arguments, print names and values of all config | |
1633 | items with matching section names or section.names. |
|
1630 | items with matching section names or section.names. | |
1634 |
|
1631 | |||
1635 | With --edit, start an editor on the user-level config file. With |
|
1632 | With --edit, start an editor on the user-level config file. With | |
1636 | --global, edit the system-wide config file. With --local, edit the |
|
1633 | --global, edit the system-wide config file. With --local, edit the | |
1637 | repository-level config file. |
|
1634 | repository-level config file. | |
1638 |
|
1635 | |||
1639 | With --debug, the source (filename and line number) is printed |
|
1636 | With --debug, the source (filename and line number) is printed | |
1640 | for each config item. |
|
1637 | for each config item. | |
1641 |
|
1638 | |||
1642 | See :hg:`help config` for more information about config files. |
|
1639 | See :hg:`help config` for more information about config files. | |
1643 |
|
1640 | |||
1644 | Returns 0 on success, 1 if NAME does not exist. |
|
1641 | Returns 0 on success, 1 if NAME does not exist. | |
1645 |
|
1642 | |||
1646 | """ |
|
1643 | """ | |
1647 |
|
1644 | |||
1648 | opts = pycompat.byteskwargs(opts) |
|
1645 | opts = pycompat.byteskwargs(opts) | |
1649 | if opts.get('edit') or opts.get('local') or opts.get('global'): |
|
1646 | if opts.get('edit') or opts.get('local') or opts.get('global'): | |
1650 | if opts.get('local') and opts.get('global'): |
|
1647 | if opts.get('local') and opts.get('global'): | |
1651 | raise error.Abort(_("can't use --local and --global together")) |
|
1648 | raise error.Abort(_("can't use --local and --global together")) | |
1652 |
|
1649 | |||
1653 | if opts.get('local'): |
|
1650 | if opts.get('local'): | |
1654 | if not repo: |
|
1651 | if not repo: | |
1655 | raise error.Abort(_("can't use --local outside a repository")) |
|
1652 | raise error.Abort(_("can't use --local outside a repository")) | |
1656 | paths = [repo.vfs.join('hgrc')] |
|
1653 | paths = [repo.vfs.join('hgrc')] | |
1657 | elif opts.get('global'): |
|
1654 | elif opts.get('global'): | |
1658 | paths = rcutil.systemrcpath() |
|
1655 | paths = rcutil.systemrcpath() | |
1659 | else: |
|
1656 | else: | |
1660 | paths = rcutil.userrcpath() |
|
1657 | paths = rcutil.userrcpath() | |
1661 |
|
1658 | |||
1662 | for f in paths: |
|
1659 | for f in paths: | |
1663 | if os.path.exists(f): |
|
1660 | if os.path.exists(f): | |
1664 | break |
|
1661 | break | |
1665 | else: |
|
1662 | else: | |
1666 | if opts.get('global'): |
|
1663 | if opts.get('global'): | |
1667 | samplehgrc = uimod.samplehgrcs['global'] |
|
1664 | samplehgrc = uimod.samplehgrcs['global'] | |
1668 | elif opts.get('local'): |
|
1665 | elif opts.get('local'): | |
1669 | samplehgrc = uimod.samplehgrcs['local'] |
|
1666 | samplehgrc = uimod.samplehgrcs['local'] | |
1670 | else: |
|
1667 | else: | |
1671 | samplehgrc = uimod.samplehgrcs['user'] |
|
1668 | samplehgrc = uimod.samplehgrcs['user'] | |
1672 |
|
1669 | |||
1673 | f = paths[0] |
|
1670 | f = paths[0] | |
1674 | fp = open(f, "wb") |
|
1671 | fp = open(f, "wb") | |
1675 | fp.write(util.tonativeeol(samplehgrc)) |
|
1672 | fp.write(util.tonativeeol(samplehgrc)) | |
1676 | fp.close() |
|
1673 | fp.close() | |
1677 |
|
1674 | |||
1678 | editor = ui.geteditor() |
|
1675 | editor = ui.geteditor() | |
1679 | ui.system("%s \"%s\"" % (editor, f), |
|
1676 | ui.system("%s \"%s\"" % (editor, f), | |
1680 | onerr=error.Abort, errprefix=_("edit failed"), |
|
1677 | onerr=error.Abort, errprefix=_("edit failed"), | |
1681 | blockedtag='config_edit') |
|
1678 | blockedtag='config_edit') | |
1682 | return |
|
1679 | return | |
1683 | ui.pager('config') |
|
1680 | ui.pager('config') | |
1684 | fm = ui.formatter('config', opts) |
|
1681 | fm = ui.formatter('config', opts) | |
1685 | for t, f in rcutil.rccomponents(): |
|
1682 | for t, f in rcutil.rccomponents(): | |
1686 | if t == 'path': |
|
1683 | if t == 'path': | |
1687 | ui.debug('read config from: %s\n' % f) |
|
1684 | ui.debug('read config from: %s\n' % f) | |
1688 | elif t == 'items': |
|
1685 | elif t == 'items': | |
1689 | for section, name, value, source in f: |
|
1686 | for section, name, value, source in f: | |
1690 | ui.debug('set config by: %s\n' % source) |
|
1687 | ui.debug('set config by: %s\n' % source) | |
1691 | else: |
|
1688 | else: | |
1692 | raise error.ProgrammingError('unknown rctype: %s' % t) |
|
1689 | raise error.ProgrammingError('unknown rctype: %s' % t) | |
1693 | untrusted = bool(opts.get('untrusted')) |
|
1690 | untrusted = bool(opts.get('untrusted')) | |
1694 |
|
1691 | |||
1695 | selsections = selentries = [] |
|
1692 | selsections = selentries = [] | |
1696 | if values: |
|
1693 | if values: | |
1697 | selsections = [v for v in values if '.' not in v] |
|
1694 | selsections = [v for v in values if '.' not in v] | |
1698 | selentries = [v for v in values if '.' in v] |
|
1695 | selentries = [v for v in values if '.' in v] | |
1699 | uniquesel = (len(selentries) == 1 and not selsections) |
|
1696 | uniquesel = (len(selentries) == 1 and not selsections) | |
1700 | selsections = set(selsections) |
|
1697 | selsections = set(selsections) | |
1701 | selentries = set(selentries) |
|
1698 | selentries = set(selentries) | |
1702 |
|
1699 | |||
1703 | matched = False |
|
1700 | matched = False | |
1704 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
1701 | for section, name, value in ui.walkconfig(untrusted=untrusted): | |
1705 | source = ui.configsource(section, name, untrusted) |
|
1702 | source = ui.configsource(section, name, untrusted) | |
1706 | value = pycompat.bytestr(value) |
|
1703 | value = pycompat.bytestr(value) | |
1707 | if fm.isplain(): |
|
1704 | if fm.isplain(): | |
1708 | source = source or 'none' |
|
1705 | source = source or 'none' | |
1709 | value = value.replace('\n', '\\n') |
|
1706 | value = value.replace('\n', '\\n') | |
1710 | entryname = section + '.' + name |
|
1707 | entryname = section + '.' + name | |
1711 | if values and not (section in selsections or entryname in selentries): |
|
1708 | if values and not (section in selsections or entryname in selentries): | |
1712 | continue |
|
1709 | continue | |
1713 | fm.startitem() |
|
1710 | fm.startitem() | |
1714 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1711 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | |
1715 | if uniquesel: |
|
1712 | if uniquesel: | |
1716 | fm.data(name=entryname) |
|
1713 | fm.data(name=entryname) | |
1717 | fm.write('value', '%s\n', value) |
|
1714 | fm.write('value', '%s\n', value) | |
1718 | else: |
|
1715 | else: | |
1719 | fm.write('name value', '%s=%s\n', entryname, value) |
|
1716 | fm.write('name value', '%s=%s\n', entryname, value) | |
1720 | matched = True |
|
1717 | matched = True | |
1721 | fm.end() |
|
1718 | fm.end() | |
1722 | if matched: |
|
1719 | if matched: | |
1723 | return 0 |
|
1720 | return 0 | |
1724 | return 1 |
|
1721 | return 1 | |
1725 |
|
1722 | |||
1726 | @command('copy|cp', |
|
1723 | @command('copy|cp', | |
1727 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1724 | [('A', 'after', None, _('record a copy that has already occurred')), | |
1728 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1725 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
1729 | ] + walkopts + dryrunopts, |
|
1726 | ] + walkopts + dryrunopts, | |
1730 | _('[OPTION]... [SOURCE]... DEST')) |
|
1727 | _('[OPTION]... [SOURCE]... DEST')) | |
1731 | def copy(ui, repo, *pats, **opts): |
|
1728 | def copy(ui, repo, *pats, **opts): | |
1732 | """mark files as copied for the next commit |
|
1729 | """mark files as copied for the next commit | |
1733 |
|
1730 | |||
1734 | Mark dest as having copies of source files. If dest is a |
|
1731 | Mark dest as having copies of source files. If dest is a | |
1735 | directory, copies are put in that directory. If dest is a file, |
|
1732 | directory, copies are put in that directory. If dest is a file, | |
1736 | the source must be a single file. |
|
1733 | the source must be a single file. | |
1737 |
|
1734 | |||
1738 | By default, this command copies the contents of files as they |
|
1735 | By default, this command copies the contents of files as they | |
1739 | exist in the working directory. If invoked with -A/--after, the |
|
1736 | exist in the working directory. If invoked with -A/--after, the | |
1740 | operation is recorded, but no copying is performed. |
|
1737 | operation is recorded, but no copying is performed. | |
1741 |
|
1738 | |||
1742 | This command takes effect with the next commit. To undo a copy |
|
1739 | This command takes effect with the next commit. To undo a copy | |
1743 | before that, see :hg:`revert`. |
|
1740 | before that, see :hg:`revert`. | |
1744 |
|
1741 | |||
1745 | Returns 0 on success, 1 if errors are encountered. |
|
1742 | Returns 0 on success, 1 if errors are encountered. | |
1746 | """ |
|
1743 | """ | |
1747 | opts = pycompat.byteskwargs(opts) |
|
1744 | opts = pycompat.byteskwargs(opts) | |
1748 | with repo.wlock(False): |
|
1745 | with repo.wlock(False): | |
1749 | return cmdutil.copy(ui, repo, pats, opts) |
|
1746 | return cmdutil.copy(ui, repo, pats, opts) | |
1750 |
|
1747 | |||
1751 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) |
|
1748 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) | |
1752 | def debugcommands(ui, cmd='', *args): |
|
1749 | def debugcommands(ui, cmd='', *args): | |
1753 | """list all available commands and options""" |
|
1750 | """list all available commands and options""" | |
1754 | for cmd, vals in sorted(table.iteritems()): |
|
1751 | for cmd, vals in sorted(table.iteritems()): | |
1755 | cmd = cmd.split('|')[0].strip('^') |
|
1752 | cmd = cmd.split('|')[0].strip('^') | |
1756 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1753 | opts = ', '.join([i[1] for i in vals[1]]) | |
1757 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1754 | ui.write('%s: %s\n' % (cmd, opts)) | |
1758 |
|
1755 | |||
1759 | @command('debugcomplete', |
|
1756 | @command('debugcomplete', | |
1760 | [('o', 'options', None, _('show the command options'))], |
|
1757 | [('o', 'options', None, _('show the command options'))], | |
1761 | _('[-o] CMD'), |
|
1758 | _('[-o] CMD'), | |
1762 | norepo=True) |
|
1759 | norepo=True) | |
1763 | def debugcomplete(ui, cmd='', **opts): |
|
1760 | def debugcomplete(ui, cmd='', **opts): | |
1764 | """returns the completion list associated with the given command""" |
|
1761 | """returns the completion list associated with the given command""" | |
1765 |
|
1762 | |||
1766 | if opts.get(r'options'): |
|
1763 | if opts.get(r'options'): | |
1767 | options = [] |
|
1764 | options = [] | |
1768 | otables = [globalopts] |
|
1765 | otables = [globalopts] | |
1769 | if cmd: |
|
1766 | if cmd: | |
1770 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1767 | aliases, entry = cmdutil.findcmd(cmd, table, False) | |
1771 | otables.append(entry[1]) |
|
1768 | otables.append(entry[1]) | |
1772 | for t in otables: |
|
1769 | for t in otables: | |
1773 | for o in t: |
|
1770 | for o in t: | |
1774 | if "(DEPRECATED)" in o[3]: |
|
1771 | if "(DEPRECATED)" in o[3]: | |
1775 | continue |
|
1772 | continue | |
1776 | if o[0]: |
|
1773 | if o[0]: | |
1777 | options.append('-%s' % o[0]) |
|
1774 | options.append('-%s' % o[0]) | |
1778 | options.append('--%s' % o[1]) |
|
1775 | options.append('--%s' % o[1]) | |
1779 | ui.write("%s\n" % "\n".join(options)) |
|
1776 | ui.write("%s\n" % "\n".join(options)) | |
1780 | return |
|
1777 | return | |
1781 |
|
1778 | |||
1782 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
1779 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) | |
1783 | if ui.verbose: |
|
1780 | if ui.verbose: | |
1784 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1781 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | |
1785 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1782 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) | |
1786 |
|
1783 | |||
1787 | @command('^diff', |
|
1784 | @command('^diff', | |
1788 | [('r', 'rev', [], _('revision'), _('REV')), |
|
1785 | [('r', 'rev', [], _('revision'), _('REV')), | |
1789 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
1786 | ('c', 'change', '', _('change made by revision'), _('REV')) | |
1790 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
1787 | ] + diffopts + diffopts2 + walkopts + subrepoopts, | |
1791 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
1788 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), | |
1792 | inferrepo=True, |
|
1789 | inferrepo=True, | |
1793 | intents={INTENT_READONLY}) |
|
1790 | intents={INTENT_READONLY}) | |
1794 | def diff(ui, repo, *pats, **opts): |
|
1791 | def diff(ui, repo, *pats, **opts): | |
1795 | """diff repository (or selected files) |
|
1792 | """diff repository (or selected files) | |
1796 |
|
1793 | |||
1797 | Show differences between revisions for the specified files. |
|
1794 | Show differences between revisions for the specified files. | |
1798 |
|
1795 | |||
1799 | Differences between files are shown using the unified diff format. |
|
1796 | Differences between files are shown using the unified diff format. | |
1800 |
|
1797 | |||
1801 | .. note:: |
|
1798 | .. note:: | |
1802 |
|
1799 | |||
1803 | :hg:`diff` may generate unexpected results for merges, as it will |
|
1800 | :hg:`diff` may generate unexpected results for merges, as it will | |
1804 | default to comparing against the working directory's first |
|
1801 | default to comparing against the working directory's first | |
1805 | parent changeset if no revisions are specified. |
|
1802 | parent changeset if no revisions are specified. | |
1806 |
|
1803 | |||
1807 | When two revision arguments are given, then changes are shown |
|
1804 | When two revision arguments are given, then changes are shown | |
1808 | between those revisions. If only one revision is specified then |
|
1805 | between those revisions. If only one revision is specified then | |
1809 | that revision is compared to the working directory, and, when no |
|
1806 | that revision is compared to the working directory, and, when no | |
1810 | revisions are specified, the working directory files are compared |
|
1807 | revisions are specified, the working directory files are compared | |
1811 | to its first parent. |
|
1808 | to its first parent. | |
1812 |
|
1809 | |||
1813 | Alternatively you can specify -c/--change with a revision to see |
|
1810 | Alternatively you can specify -c/--change with a revision to see | |
1814 | the changes in that changeset relative to its first parent. |
|
1811 | the changes in that changeset relative to its first parent. | |
1815 |
|
1812 | |||
1816 | Without the -a/--text option, diff will avoid generating diffs of |
|
1813 | Without the -a/--text option, diff will avoid generating diffs of | |
1817 | files it detects as binary. With -a, diff will generate a diff |
|
1814 | files it detects as binary. With -a, diff will generate a diff | |
1818 | anyway, probably with undesirable results. |
|
1815 | anyway, probably with undesirable results. | |
1819 |
|
1816 | |||
1820 | Use the -g/--git option to generate diffs in the git extended diff |
|
1817 | Use the -g/--git option to generate diffs in the git extended diff | |
1821 | format. For more information, read :hg:`help diffs`. |
|
1818 | format. For more information, read :hg:`help diffs`. | |
1822 |
|
1819 | |||
1823 | .. container:: verbose |
|
1820 | .. container:: verbose | |
1824 |
|
1821 | |||
1825 | Examples: |
|
1822 | Examples: | |
1826 |
|
1823 | |||
1827 | - compare a file in the current working directory to its parent:: |
|
1824 | - compare a file in the current working directory to its parent:: | |
1828 |
|
1825 | |||
1829 | hg diff foo.c |
|
1826 | hg diff foo.c | |
1830 |
|
1827 | |||
1831 | - compare two historical versions of a directory, with rename info:: |
|
1828 | - compare two historical versions of a directory, with rename info:: | |
1832 |
|
1829 | |||
1833 | hg diff --git -r 1.0:1.2 lib/ |
|
1830 | hg diff --git -r 1.0:1.2 lib/ | |
1834 |
|
1831 | |||
1835 | - get change stats relative to the last change on some date:: |
|
1832 | - get change stats relative to the last change on some date:: | |
1836 |
|
1833 | |||
1837 | hg diff --stat -r "date('may 2')" |
|
1834 | hg diff --stat -r "date('may 2')" | |
1838 |
|
1835 | |||
1839 | - diff all newly-added files that contain a keyword:: |
|
1836 | - diff all newly-added files that contain a keyword:: | |
1840 |
|
1837 | |||
1841 | hg diff "set:added() and grep(GNU)" |
|
1838 | hg diff "set:added() and grep(GNU)" | |
1842 |
|
1839 | |||
1843 | - compare a revision and its parents:: |
|
1840 | - compare a revision and its parents:: | |
1844 |
|
1841 | |||
1845 | hg diff -c 9353 # compare against first parent |
|
1842 | hg diff -c 9353 # compare against first parent | |
1846 | hg diff -r 9353^:9353 # same using revset syntax |
|
1843 | hg diff -r 9353^:9353 # same using revset syntax | |
1847 | hg diff -r 9353^2:9353 # compare against the second parent |
|
1844 | hg diff -r 9353^2:9353 # compare against the second parent | |
1848 |
|
1845 | |||
1849 | Returns 0 on success. |
|
1846 | Returns 0 on success. | |
1850 | """ |
|
1847 | """ | |
1851 |
|
1848 | |||
1852 | opts = pycompat.byteskwargs(opts) |
|
1849 | opts = pycompat.byteskwargs(opts) | |
1853 | revs = opts.get('rev') |
|
1850 | revs = opts.get('rev') | |
1854 | change = opts.get('change') |
|
1851 | change = opts.get('change') | |
1855 | stat = opts.get('stat') |
|
1852 | stat = opts.get('stat') | |
1856 | reverse = opts.get('reverse') |
|
1853 | reverse = opts.get('reverse') | |
1857 |
|
1854 | |||
1858 | if revs and change: |
|
1855 | if revs and change: | |
1859 | msg = _('cannot specify --rev and --change at the same time') |
|
1856 | msg = _('cannot specify --rev and --change at the same time') | |
1860 | raise error.Abort(msg) |
|
1857 | raise error.Abort(msg) | |
1861 | elif change: |
|
1858 | elif change: | |
1862 | repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') |
|
1859 | repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') | |
1863 | ctx2 = scmutil.revsingle(repo, change, None) |
|
1860 | ctx2 = scmutil.revsingle(repo, change, None) | |
1864 | ctx1 = ctx2.p1() |
|
1861 | ctx1 = ctx2.p1() | |
1865 | else: |
|
1862 | else: | |
1866 | repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') |
|
1863 | repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') | |
1867 | ctx1, ctx2 = scmutil.revpair(repo, revs) |
|
1864 | ctx1, ctx2 = scmutil.revpair(repo, revs) | |
1868 | node1, node2 = ctx1.node(), ctx2.node() |
|
1865 | node1, node2 = ctx1.node(), ctx2.node() | |
1869 |
|
1866 | |||
1870 | if reverse: |
|
1867 | if reverse: | |
1871 | node1, node2 = node2, node1 |
|
1868 | node1, node2 = node2, node1 | |
1872 |
|
1869 | |||
1873 | diffopts = patch.diffallopts(ui, opts) |
|
1870 | diffopts = patch.diffallopts(ui, opts) | |
1874 | m = scmutil.match(ctx2, pats, opts) |
|
1871 | m = scmutil.match(ctx2, pats, opts) | |
1875 | ui.pager('diff') |
|
1872 | ui.pager('diff') | |
1876 | logcmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
1873 | logcmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | |
1877 | listsubrepos=opts.get('subrepos'), |
|
1874 | listsubrepos=opts.get('subrepos'), | |
1878 | root=opts.get('root')) |
|
1875 | root=opts.get('root')) | |
1879 |
|
1876 | |||
1880 | @command('^export', |
|
1877 | @command('^export', | |
1881 | [('B', 'bookmark', '', |
|
1878 | [('B', 'bookmark', '', | |
1882 | _('export changes only reachable by given bookmark')), |
|
1879 | _('export changes only reachable by given bookmark')), | |
1883 | ('o', 'output', '', |
|
1880 | ('o', 'output', '', | |
1884 | _('print output to file with formatted name'), _('FORMAT')), |
|
1881 | _('print output to file with formatted name'), _('FORMAT')), | |
1885 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
1882 | ('', 'switch-parent', None, _('diff against the second parent')), | |
1886 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
1883 | ('r', 'rev', [], _('revisions to export'), _('REV')), | |
1887 | ] + diffopts + formatteropts, |
|
1884 | ] + diffopts + formatteropts, | |
1888 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), |
|
1885 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), | |
1889 | intents={INTENT_READONLY}) |
|
1886 | intents={INTENT_READONLY}) | |
1890 | def export(ui, repo, *changesets, **opts): |
|
1887 | def export(ui, repo, *changesets, **opts): | |
1891 | """dump the header and diffs for one or more changesets |
|
1888 | """dump the header and diffs for one or more changesets | |
1892 |
|
1889 | |||
1893 | Print the changeset header and diffs for one or more revisions. |
|
1890 | Print the changeset header and diffs for one or more revisions. | |
1894 | If no revision is given, the parent of the working directory is used. |
|
1891 | If no revision is given, the parent of the working directory is used. | |
1895 |
|
1892 | |||
1896 | The information shown in the changeset header is: author, date, |
|
1893 | The information shown in the changeset header is: author, date, | |
1897 | branch name (if non-default), changeset hash, parent(s) and commit |
|
1894 | branch name (if non-default), changeset hash, parent(s) and commit | |
1898 | comment. |
|
1895 | comment. | |
1899 |
|
1896 | |||
1900 | .. note:: |
|
1897 | .. note:: | |
1901 |
|
1898 | |||
1902 | :hg:`export` may generate unexpected diff output for merge |
|
1899 | :hg:`export` may generate unexpected diff output for merge | |
1903 | changesets, as it will compare the merge changeset against its |
|
1900 | changesets, as it will compare the merge changeset against its | |
1904 | first parent only. |
|
1901 | first parent only. | |
1905 |
|
1902 | |||
1906 | Output may be to a file, in which case the name of the file is |
|
1903 | Output may be to a file, in which case the name of the file is | |
1907 | given using a template string. See :hg:`help templates`. In addition |
|
1904 | given using a template string. See :hg:`help templates`. In addition | |
1908 | to the common template keywords, the following formatting rules are |
|
1905 | to the common template keywords, the following formatting rules are | |
1909 | supported: |
|
1906 | supported: | |
1910 |
|
1907 | |||
1911 | :``%%``: literal "%" character |
|
1908 | :``%%``: literal "%" character | |
1912 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1909 | :``%H``: changeset hash (40 hexadecimal digits) | |
1913 | :``%N``: number of patches being generated |
|
1910 | :``%N``: number of patches being generated | |
1914 | :``%R``: changeset revision number |
|
1911 | :``%R``: changeset revision number | |
1915 | :``%b``: basename of the exporting repository |
|
1912 | :``%b``: basename of the exporting repository | |
1916 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1913 | :``%h``: short-form changeset hash (12 hexadecimal digits) | |
1917 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
1914 | :``%m``: first line of the commit message (only alphanumeric characters) | |
1918 | :``%n``: zero-padded sequence number, starting at 1 |
|
1915 | :``%n``: zero-padded sequence number, starting at 1 | |
1919 | :``%r``: zero-padded changeset revision number |
|
1916 | :``%r``: zero-padded changeset revision number | |
1920 | :``\\``: literal "\\" character |
|
1917 | :``\\``: literal "\\" character | |
1921 |
|
1918 | |||
1922 | Without the -a/--text option, export will avoid generating diffs |
|
1919 | Without the -a/--text option, export will avoid generating diffs | |
1923 | of files it detects as binary. With -a, export will generate a |
|
1920 | of files it detects as binary. With -a, export will generate a | |
1924 | diff anyway, probably with undesirable results. |
|
1921 | diff anyway, probably with undesirable results. | |
1925 |
|
1922 | |||
1926 | With -B/--bookmark changesets reachable by the given bookmark are |
|
1923 | With -B/--bookmark changesets reachable by the given bookmark are | |
1927 | selected. |
|
1924 | selected. | |
1928 |
|
1925 | |||
1929 | Use the -g/--git option to generate diffs in the git extended diff |
|
1926 | Use the -g/--git option to generate diffs in the git extended diff | |
1930 | format. See :hg:`help diffs` for more information. |
|
1927 | format. See :hg:`help diffs` for more information. | |
1931 |
|
1928 | |||
1932 | With the --switch-parent option, the diff will be against the |
|
1929 | With the --switch-parent option, the diff will be against the | |
1933 | second parent. It can be useful to review a merge. |
|
1930 | second parent. It can be useful to review a merge. | |
1934 |
|
1931 | |||
1935 | .. container:: verbose |
|
1932 | .. container:: verbose | |
1936 |
|
1933 | |||
1937 | Examples: |
|
1934 | Examples: | |
1938 |
|
1935 | |||
1939 | - use export and import to transplant a bugfix to the current |
|
1936 | - use export and import to transplant a bugfix to the current | |
1940 | branch:: |
|
1937 | branch:: | |
1941 |
|
1938 | |||
1942 | hg export -r 9353 | hg import - |
|
1939 | hg export -r 9353 | hg import - | |
1943 |
|
1940 | |||
1944 | - export all the changesets between two revisions to a file with |
|
1941 | - export all the changesets between two revisions to a file with | |
1945 | rename information:: |
|
1942 | rename information:: | |
1946 |
|
1943 | |||
1947 | hg export --git -r 123:150 > changes.txt |
|
1944 | hg export --git -r 123:150 > changes.txt | |
1948 |
|
1945 | |||
1949 | - split outgoing changes into a series of patches with |
|
1946 | - split outgoing changes into a series of patches with | |
1950 | descriptive names:: |
|
1947 | descriptive names:: | |
1951 |
|
1948 | |||
1952 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
1949 | hg export -r "outgoing()" -o "%n-%m.patch" | |
1953 |
|
1950 | |||
1954 | Returns 0 on success. |
|
1951 | Returns 0 on success. | |
1955 | """ |
|
1952 | """ | |
1956 | opts = pycompat.byteskwargs(opts) |
|
1953 | opts = pycompat.byteskwargs(opts) | |
1957 | bookmark = opts.get('bookmark') |
|
1954 | bookmark = opts.get('bookmark') | |
1958 | changesets += tuple(opts.get('rev', [])) |
|
1955 | changesets += tuple(opts.get('rev', [])) | |
1959 |
|
1956 | |||
1960 | if bookmark and changesets: |
|
1957 | if bookmark and changesets: | |
1961 | raise error.Abort(_("-r and -B are mutually exclusive")) |
|
1958 | raise error.Abort(_("-r and -B are mutually exclusive")) | |
1962 |
|
1959 | |||
1963 | if bookmark: |
|
1960 | if bookmark: | |
1964 | if bookmark not in repo._bookmarks: |
|
1961 | if bookmark not in repo._bookmarks: | |
1965 | raise error.Abort(_("bookmark '%s' not found") % bookmark) |
|
1962 | raise error.Abort(_("bookmark '%s' not found") % bookmark) | |
1966 |
|
1963 | |||
1967 | revs = scmutil.bookmarkrevs(repo, bookmark) |
|
1964 | revs = scmutil.bookmarkrevs(repo, bookmark) | |
1968 | else: |
|
1965 | else: | |
1969 | if not changesets: |
|
1966 | if not changesets: | |
1970 | changesets = ['.'] |
|
1967 | changesets = ['.'] | |
1971 |
|
1968 | |||
1972 | repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn') |
|
1969 | repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn') | |
1973 | revs = scmutil.revrange(repo, changesets) |
|
1970 | revs = scmutil.revrange(repo, changesets) | |
1974 |
|
1971 | |||
1975 | if not revs: |
|
1972 | if not revs: | |
1976 | raise error.Abort(_("export requires at least one changeset")) |
|
1973 | raise error.Abort(_("export requires at least one changeset")) | |
1977 | if len(revs) > 1: |
|
1974 | if len(revs) > 1: | |
1978 | ui.note(_('exporting patches:\n')) |
|
1975 | ui.note(_('exporting patches:\n')) | |
1979 | else: |
|
1976 | else: | |
1980 | ui.note(_('exporting patch:\n')) |
|
1977 | ui.note(_('exporting patch:\n')) | |
1981 |
|
1978 | |||
1982 | fntemplate = opts.get('output') |
|
1979 | fntemplate = opts.get('output') | |
1983 | if cmdutil.isstdiofilename(fntemplate): |
|
1980 | if cmdutil.isstdiofilename(fntemplate): | |
1984 | fntemplate = '' |
|
1981 | fntemplate = '' | |
1985 |
|
1982 | |||
1986 | if fntemplate: |
|
1983 | if fntemplate: | |
1987 | fm = formatter.nullformatter(ui, 'export', opts) |
|
1984 | fm = formatter.nullformatter(ui, 'export', opts) | |
1988 | else: |
|
1985 | else: | |
1989 | ui.pager('export') |
|
1986 | ui.pager('export') | |
1990 | fm = ui.formatter('export', opts) |
|
1987 | fm = ui.formatter('export', opts) | |
1991 | with fm: |
|
1988 | with fm: | |
1992 | cmdutil.export(repo, revs, fm, fntemplate=fntemplate, |
|
1989 | cmdutil.export(repo, revs, fm, fntemplate=fntemplate, | |
1993 | switch_parent=opts.get('switch_parent'), |
|
1990 | switch_parent=opts.get('switch_parent'), | |
1994 | opts=patch.diffallopts(ui, opts)) |
|
1991 | opts=patch.diffallopts(ui, opts)) | |
1995 |
|
1992 | |||
1996 | @command('files', |
|
1993 | @command('files', | |
1997 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
1994 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | |
1998 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
1995 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
1999 | ] + walkopts + formatteropts + subrepoopts, |
|
1996 | ] + walkopts + formatteropts + subrepoopts, | |
2000 | _('[OPTION]... [FILE]...'), |
|
1997 | _('[OPTION]... [FILE]...'), | |
2001 | intents={INTENT_READONLY}) |
|
1998 | intents={INTENT_READONLY}) | |
2002 | def files(ui, repo, *pats, **opts): |
|
1999 | def files(ui, repo, *pats, **opts): | |
2003 | """list tracked files |
|
2000 | """list tracked files | |
2004 |
|
2001 | |||
2005 | Print files under Mercurial control in the working directory or |
|
2002 | Print files under Mercurial control in the working directory or | |
2006 | specified revision for given files (excluding removed files). |
|
2003 | specified revision for given files (excluding removed files). | |
2007 | Files can be specified as filenames or filesets. |
|
2004 | Files can be specified as filenames or filesets. | |
2008 |
|
2005 | |||
2009 | If no files are given to match, this command prints the names |
|
2006 | If no files are given to match, this command prints the names | |
2010 | of all files under Mercurial control. |
|
2007 | of all files under Mercurial control. | |
2011 |
|
2008 | |||
2012 | .. container:: verbose |
|
2009 | .. container:: verbose | |
2013 |
|
2010 | |||
2014 | Examples: |
|
2011 | Examples: | |
2015 |
|
2012 | |||
2016 | - list all files under the current directory:: |
|
2013 | - list all files under the current directory:: | |
2017 |
|
2014 | |||
2018 | hg files . |
|
2015 | hg files . | |
2019 |
|
2016 | |||
2020 | - shows sizes and flags for current revision:: |
|
2017 | - shows sizes and flags for current revision:: | |
2021 |
|
2018 | |||
2022 | hg files -vr . |
|
2019 | hg files -vr . | |
2023 |
|
2020 | |||
2024 | - list all files named README:: |
|
2021 | - list all files named README:: | |
2025 |
|
2022 | |||
2026 | hg files -I "**/README" |
|
2023 | hg files -I "**/README" | |
2027 |
|
2024 | |||
2028 | - list all binary files:: |
|
2025 | - list all binary files:: | |
2029 |
|
2026 | |||
2030 | hg files "set:binary()" |
|
2027 | hg files "set:binary()" | |
2031 |
|
2028 | |||
2032 | - find files containing a regular expression:: |
|
2029 | - find files containing a regular expression:: | |
2033 |
|
2030 | |||
2034 | hg files "set:grep('bob')" |
|
2031 | hg files "set:grep('bob')" | |
2035 |
|
2032 | |||
2036 | - search tracked file contents with xargs and grep:: |
|
2033 | - search tracked file contents with xargs and grep:: | |
2037 |
|
2034 | |||
2038 | hg files -0 | xargs -0 grep foo |
|
2035 | hg files -0 | xargs -0 grep foo | |
2039 |
|
2036 | |||
2040 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
2037 | See :hg:`help patterns` and :hg:`help filesets` for more information | |
2041 | on specifying file patterns. |
|
2038 | on specifying file patterns. | |
2042 |
|
2039 | |||
2043 | Returns 0 if a match is found, 1 otherwise. |
|
2040 | Returns 0 if a match is found, 1 otherwise. | |
2044 |
|
2041 | |||
2045 | """ |
|
2042 | """ | |
2046 |
|
2043 | |||
2047 | opts = pycompat.byteskwargs(opts) |
|
2044 | opts = pycompat.byteskwargs(opts) | |
2048 | rev = opts.get('rev') |
|
2045 | rev = opts.get('rev') | |
2049 | if rev: |
|
2046 | if rev: | |
2050 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
2047 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
2051 | ctx = scmutil.revsingle(repo, rev, None) |
|
2048 | ctx = scmutil.revsingle(repo, rev, None) | |
2052 |
|
2049 | |||
2053 | end = '\n' |
|
2050 | end = '\n' | |
2054 | if opts.get('print0'): |
|
2051 | if opts.get('print0'): | |
2055 | end = '\0' |
|
2052 | end = '\0' | |
2056 | fmt = '%s' + end |
|
2053 | fmt = '%s' + end | |
2057 |
|
2054 | |||
2058 | m = scmutil.match(ctx, pats, opts) |
|
2055 | m = scmutil.match(ctx, pats, opts) | |
2059 | ui.pager('files') |
|
2056 | ui.pager('files') | |
2060 | with ui.formatter('files', opts) as fm: |
|
2057 | with ui.formatter('files', opts) as fm: | |
2061 | return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) |
|
2058 | return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) | |
2062 |
|
2059 | |||
2063 | @command( |
|
2060 | @command( | |
2064 | '^forget', |
|
2061 | '^forget', | |
2065 | [('i', 'interactive', None, _('use interactive mode')), |
|
2062 | [('i', 'interactive', None, _('use interactive mode')), | |
2066 | ] + walkopts + dryrunopts, |
|
2063 | ] + walkopts + dryrunopts, | |
2067 | _('[OPTION]... FILE...'), inferrepo=True) |
|
2064 | _('[OPTION]... FILE...'), inferrepo=True) | |
2068 | def forget(ui, repo, *pats, **opts): |
|
2065 | def forget(ui, repo, *pats, **opts): | |
2069 | """forget the specified files on the next commit |
|
2066 | """forget the specified files on the next commit | |
2070 |
|
2067 | |||
2071 | Mark the specified files so they will no longer be tracked |
|
2068 | Mark the specified files so they will no longer be tracked | |
2072 | after the next commit. |
|
2069 | after the next commit. | |
2073 |
|
2070 | |||
2074 | This only removes files from the current branch, not from the |
|
2071 | This only removes files from the current branch, not from the | |
2075 | entire project history, and it does not delete them from the |
|
2072 | entire project history, and it does not delete them from the | |
2076 | working directory. |
|
2073 | working directory. | |
2077 |
|
2074 | |||
2078 | To delete the file from the working directory, see :hg:`remove`. |
|
2075 | To delete the file from the working directory, see :hg:`remove`. | |
2079 |
|
2076 | |||
2080 | To undo a forget before the next commit, see :hg:`add`. |
|
2077 | To undo a forget before the next commit, see :hg:`add`. | |
2081 |
|
2078 | |||
2082 | .. container:: verbose |
|
2079 | .. container:: verbose | |
2083 |
|
2080 | |||
2084 | Examples: |
|
2081 | Examples: | |
2085 |
|
2082 | |||
2086 | - forget newly-added binary files:: |
|
2083 | - forget newly-added binary files:: | |
2087 |
|
2084 | |||
2088 | hg forget "set:added() and binary()" |
|
2085 | hg forget "set:added() and binary()" | |
2089 |
|
2086 | |||
2090 | - forget files that would be excluded by .hgignore:: |
|
2087 | - forget files that would be excluded by .hgignore:: | |
2091 |
|
2088 | |||
2092 | hg forget "set:hgignore()" |
|
2089 | hg forget "set:hgignore()" | |
2093 |
|
2090 | |||
2094 | Returns 0 on success. |
|
2091 | Returns 0 on success. | |
2095 | """ |
|
2092 | """ | |
2096 |
|
2093 | |||
2097 | opts = pycompat.byteskwargs(opts) |
|
2094 | opts = pycompat.byteskwargs(opts) | |
2098 | if not pats: |
|
2095 | if not pats: | |
2099 | raise error.Abort(_('no files specified')) |
|
2096 | raise error.Abort(_('no files specified')) | |
2100 |
|
2097 | |||
2101 | m = scmutil.match(repo[None], pats, opts) |
|
2098 | m = scmutil.match(repo[None], pats, opts) | |
2102 | dryrun, interactive = opts.get('dry_run'), opts.get('interactive') |
|
2099 | dryrun, interactive = opts.get('dry_run'), opts.get('interactive') | |
2103 | rejected = cmdutil.forget(ui, repo, m, prefix="", |
|
2100 | rejected = cmdutil.forget(ui, repo, m, prefix="", | |
2104 | explicitonly=False, dryrun=dryrun, |
|
2101 | explicitonly=False, dryrun=dryrun, | |
2105 | interactive=interactive)[0] |
|
2102 | interactive=interactive)[0] | |
2106 | return rejected and 1 or 0 |
|
2103 | return rejected and 1 or 0 | |
2107 |
|
2104 | |||
2108 | @command( |
|
2105 | @command( | |
2109 | 'graft', |
|
2106 | 'graft', | |
2110 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
2107 | [('r', 'rev', [], _('revisions to graft'), _('REV')), | |
2111 | ('c', 'continue', False, _('resume interrupted graft')), |
|
2108 | ('c', 'continue', False, _('resume interrupted graft')), | |
2112 | ('', 'stop', False, _('stop interrupted graft')), |
|
2109 | ('', 'stop', False, _('stop interrupted graft')), | |
2113 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2110 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
2114 | ('', 'log', None, _('append graft info to log message')), |
|
2111 | ('', 'log', None, _('append graft info to log message')), | |
2115 | ('f', 'force', False, _('force graft')), |
|
2112 | ('f', 'force', False, _('force graft')), | |
2116 | ('D', 'currentdate', False, |
|
2113 | ('D', 'currentdate', False, | |
2117 | _('record the current date as commit date')), |
|
2114 | _('record the current date as commit date')), | |
2118 | ('U', 'currentuser', False, |
|
2115 | ('U', 'currentuser', False, | |
2119 | _('record the current user as committer'), _('DATE'))] |
|
2116 | _('record the current user as committer'), _('DATE'))] | |
2120 | + commitopts2 + mergetoolopts + dryrunopts, |
|
2117 | + commitopts2 + mergetoolopts + dryrunopts, | |
2121 | _('[OPTION]... [-r REV]... REV...')) |
|
2118 | _('[OPTION]... [-r REV]... REV...')) | |
2122 | def graft(ui, repo, *revs, **opts): |
|
2119 | def graft(ui, repo, *revs, **opts): | |
2123 | '''copy changes from other branches onto the current branch |
|
2120 | '''copy changes from other branches onto the current branch | |
2124 |
|
2121 | |||
2125 | This command uses Mercurial's merge logic to copy individual |
|
2122 | This command uses Mercurial's merge logic to copy individual | |
2126 | changes from other branches without merging branches in the |
|
2123 | changes from other branches without merging branches in the | |
2127 | history graph. This is sometimes known as 'backporting' or |
|
2124 | history graph. This is sometimes known as 'backporting' or | |
2128 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2125 | 'cherry-picking'. By default, graft will copy user, date, and | |
2129 | description from the source changesets. |
|
2126 | description from the source changesets. | |
2130 |
|
2127 | |||
2131 | Changesets that are ancestors of the current revision, that have |
|
2128 | Changesets that are ancestors of the current revision, that have | |
2132 | already been grafted, or that are merges will be skipped. |
|
2129 | already been grafted, or that are merges will be skipped. | |
2133 |
|
2130 | |||
2134 | If --log is specified, log messages will have a comment appended |
|
2131 | If --log is specified, log messages will have a comment appended | |
2135 | of the form:: |
|
2132 | of the form:: | |
2136 |
|
2133 | |||
2137 | (grafted from CHANGESETHASH) |
|
2134 | (grafted from CHANGESETHASH) | |
2138 |
|
2135 | |||
2139 | If --force is specified, revisions will be grafted even if they |
|
2136 | If --force is specified, revisions will be grafted even if they | |
2140 | are already ancestors of, or have been grafted to, the destination. |
|
2137 | are already ancestors of, or have been grafted to, the destination. | |
2141 | This is useful when the revisions have since been backed out. |
|
2138 | This is useful when the revisions have since been backed out. | |
2142 |
|
2139 | |||
2143 | If a graft merge results in conflicts, the graft process is |
|
2140 | If a graft merge results in conflicts, the graft process is | |
2144 | interrupted so that the current merge can be manually resolved. |
|
2141 | interrupted so that the current merge can be manually resolved. | |
2145 | Once all conflicts are addressed, the graft process can be |
|
2142 | Once all conflicts are addressed, the graft process can be | |
2146 | continued with the -c/--continue option. |
|
2143 | continued with the -c/--continue option. | |
2147 |
|
2144 | |||
2148 | The -c/--continue option reapplies all the earlier options. |
|
2145 | The -c/--continue option reapplies all the earlier options. | |
2149 |
|
2146 | |||
2150 | .. container:: verbose |
|
2147 | .. container:: verbose | |
2151 |
|
2148 | |||
2152 | Examples: |
|
2149 | Examples: | |
2153 |
|
2150 | |||
2154 | - copy a single change to the stable branch and edit its description:: |
|
2151 | - copy a single change to the stable branch and edit its description:: | |
2155 |
|
2152 | |||
2156 | hg update stable |
|
2153 | hg update stable | |
2157 | hg graft --edit 9393 |
|
2154 | hg graft --edit 9393 | |
2158 |
|
2155 | |||
2159 | - graft a range of changesets with one exception, updating dates:: |
|
2156 | - graft a range of changesets with one exception, updating dates:: | |
2160 |
|
2157 | |||
2161 | hg graft -D "2085::2093 and not 2091" |
|
2158 | hg graft -D "2085::2093 and not 2091" | |
2162 |
|
2159 | |||
2163 | - continue a graft after resolving conflicts:: |
|
2160 | - continue a graft after resolving conflicts:: | |
2164 |
|
2161 | |||
2165 | hg graft -c |
|
2162 | hg graft -c | |
2166 |
|
2163 | |||
2167 | - show the source of a grafted changeset:: |
|
2164 | - show the source of a grafted changeset:: | |
2168 |
|
2165 | |||
2169 | hg log --debug -r . |
|
2166 | hg log --debug -r . | |
2170 |
|
2167 | |||
2171 | - show revisions sorted by date:: |
|
2168 | - show revisions sorted by date:: | |
2172 |
|
2169 | |||
2173 | hg log -r "sort(all(), date)" |
|
2170 | hg log -r "sort(all(), date)" | |
2174 |
|
2171 | |||
2175 | See :hg:`help revisions` for more about specifying revisions. |
|
2172 | See :hg:`help revisions` for more about specifying revisions. | |
2176 |
|
2173 | |||
2177 | Returns 0 on successful completion. |
|
2174 | Returns 0 on successful completion. | |
2178 | ''' |
|
2175 | ''' | |
2179 | with repo.wlock(): |
|
2176 | with repo.wlock(): | |
2180 | return _dograft(ui, repo, *revs, **opts) |
|
2177 | return _dograft(ui, repo, *revs, **opts) | |
2181 |
|
2178 | |||
2182 | def _dograft(ui, repo, *revs, **opts): |
|
2179 | def _dograft(ui, repo, *revs, **opts): | |
2183 | opts = pycompat.byteskwargs(opts) |
|
2180 | opts = pycompat.byteskwargs(opts) | |
2184 | if revs and opts.get('rev'): |
|
2181 | if revs and opts.get('rev'): | |
2185 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' |
|
2182 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' | |
2186 | 'revision ordering!\n')) |
|
2183 | 'revision ordering!\n')) | |
2187 |
|
2184 | |||
2188 | revs = list(revs) |
|
2185 | revs = list(revs) | |
2189 | revs.extend(opts.get('rev')) |
|
2186 | revs.extend(opts.get('rev')) | |
2190 | # a dict of data to be stored in state file |
|
2187 | # a dict of data to be stored in state file | |
2191 | statedata = {} |
|
2188 | statedata = {} | |
2192 |
|
2189 | |||
2193 | if not opts.get('user') and opts.get('currentuser'): |
|
2190 | if not opts.get('user') and opts.get('currentuser'): | |
2194 | opts['user'] = ui.username() |
|
2191 | opts['user'] = ui.username() | |
2195 | if not opts.get('date') and opts.get('currentdate'): |
|
2192 | if not opts.get('date') and opts.get('currentdate'): | |
2196 | opts['date'] = "%d %d" % dateutil.makedate() |
|
2193 | opts['date'] = "%d %d" % dateutil.makedate() | |
2197 |
|
2194 | |||
2198 | editor = cmdutil.getcommiteditor(editform='graft', |
|
2195 | editor = cmdutil.getcommiteditor(editform='graft', | |
2199 | **pycompat.strkwargs(opts)) |
|
2196 | **pycompat.strkwargs(opts)) | |
2200 |
|
2197 | |||
2201 | cont = False |
|
2198 | cont = False | |
2202 | graftstate = statemod.cmdstate(repo, 'graftstate') |
|
2199 | graftstate = statemod.cmdstate(repo, 'graftstate') | |
2203 | if opts.get('stop'): |
|
2200 | if opts.get('stop'): | |
2204 | if opts.get('continue'): |
|
2201 | if opts.get('continue'): | |
2205 | raise error.Abort(_("cannot use '--continue' and " |
|
2202 | raise error.Abort(_("cannot use '--continue' and " | |
2206 | "'--stop' together")) |
|
2203 | "'--stop' together")) | |
2207 | if any((opts.get('edit'), opts.get('log'), opts.get('user'), |
|
2204 | if any((opts.get('edit'), opts.get('log'), opts.get('user'), | |
2208 | opts.get('date'), opts.get('currentdate'), |
|
2205 | opts.get('date'), opts.get('currentdate'), | |
2209 | opts.get('currentuser'), opts.get('rev'))): |
|
2206 | opts.get('currentuser'), opts.get('rev'))): | |
2210 | raise error.Abort(_("cannot specify any other flag with '--stop'")) |
|
2207 | raise error.Abort(_("cannot specify any other flag with '--stop'")) | |
2211 | return _stopgraft(ui, repo, graftstate) |
|
2208 | return _stopgraft(ui, repo, graftstate) | |
2212 | if opts.get('continue'): |
|
2209 | if opts.get('continue'): | |
2213 | cont = True |
|
2210 | cont = True | |
2214 | if revs: |
|
2211 | if revs: | |
2215 | raise error.Abort(_("can't specify --continue and revisions")) |
|
2212 | raise error.Abort(_("can't specify --continue and revisions")) | |
2216 | # read in unfinished revisions |
|
2213 | # read in unfinished revisions | |
2217 | if graftstate.exists(): |
|
2214 | if graftstate.exists(): | |
2218 | statedata = _readgraftstate(repo, graftstate) |
|
2215 | statedata = _readgraftstate(repo, graftstate) | |
2219 | if statedata.get('date'): |
|
2216 | if statedata.get('date'): | |
2220 | opts['date'] = statedata['date'] |
|
2217 | opts['date'] = statedata['date'] | |
2221 | if statedata.get('user'): |
|
2218 | if statedata.get('user'): | |
2222 | opts['user'] = statedata['user'] |
|
2219 | opts['user'] = statedata['user'] | |
2223 | if statedata.get('log'): |
|
2220 | if statedata.get('log'): | |
2224 | opts['log'] = True |
|
2221 | opts['log'] = True | |
2225 | nodes = statedata['nodes'] |
|
2222 | nodes = statedata['nodes'] | |
2226 | revs = [repo[node].rev() for node in nodes] |
|
2223 | revs = [repo[node].rev() for node in nodes] | |
2227 | else: |
|
2224 | else: | |
2228 | cmdutil.wrongtooltocontinue(repo, _('graft')) |
|
2225 | cmdutil.wrongtooltocontinue(repo, _('graft')) | |
2229 | else: |
|
2226 | else: | |
2230 | if not revs: |
|
2227 | if not revs: | |
2231 | raise error.Abort(_('no revisions specified')) |
|
2228 | raise error.Abort(_('no revisions specified')) | |
2232 | cmdutil.checkunfinished(repo) |
|
2229 | cmdutil.checkunfinished(repo) | |
2233 | cmdutil.bailifchanged(repo) |
|
2230 | cmdutil.bailifchanged(repo) | |
2234 | revs = scmutil.revrange(repo, revs) |
|
2231 | revs = scmutil.revrange(repo, revs) | |
2235 |
|
2232 | |||
2236 | skipped = set() |
|
2233 | skipped = set() | |
2237 | # check for merges |
|
2234 | # check for merges | |
2238 | for rev in repo.revs('%ld and merge()', revs): |
|
2235 | for rev in repo.revs('%ld and merge()', revs): | |
2239 | ui.warn(_('skipping ungraftable merge revision %d\n') % rev) |
|
2236 | ui.warn(_('skipping ungraftable merge revision %d\n') % rev) | |
2240 | skipped.add(rev) |
|
2237 | skipped.add(rev) | |
2241 | revs = [r for r in revs if r not in skipped] |
|
2238 | revs = [r for r in revs if r not in skipped] | |
2242 | if not revs: |
|
2239 | if not revs: | |
2243 | return -1 |
|
2240 | return -1 | |
2244 |
|
2241 | |||
2245 | # Don't check in the --continue case, in effect retaining --force across |
|
2242 | # Don't check in the --continue case, in effect retaining --force across | |
2246 | # --continues. That's because without --force, any revisions we decided to |
|
2243 | # --continues. That's because without --force, any revisions we decided to | |
2247 | # skip would have been filtered out here, so they wouldn't have made their |
|
2244 | # skip would have been filtered out here, so they wouldn't have made their | |
2248 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
2245 | # way to the graftstate. With --force, any revisions we would have otherwise | |
2249 | # skipped would not have been filtered out, and if they hadn't been applied |
|
2246 | # skipped would not have been filtered out, and if they hadn't been applied | |
2250 | # already, they'd have been in the graftstate. |
|
2247 | # already, they'd have been in the graftstate. | |
2251 | if not (cont or opts.get('force')): |
|
2248 | if not (cont or opts.get('force')): | |
2252 | # check for ancestors of dest branch |
|
2249 | # check for ancestors of dest branch | |
2253 | crev = repo['.'].rev() |
|
2250 | crev = repo['.'].rev() | |
2254 | ancestors = repo.changelog.ancestors([crev], inclusive=True) |
|
2251 | ancestors = repo.changelog.ancestors([crev], inclusive=True) | |
2255 | # XXX make this lazy in the future |
|
2252 | # XXX make this lazy in the future | |
2256 | # don't mutate while iterating, create a copy |
|
2253 | # don't mutate while iterating, create a copy | |
2257 | for rev in list(revs): |
|
2254 | for rev in list(revs): | |
2258 | if rev in ancestors: |
|
2255 | if rev in ancestors: | |
2259 | ui.warn(_('skipping ancestor revision %d:%s\n') % |
|
2256 | ui.warn(_('skipping ancestor revision %d:%s\n') % | |
2260 | (rev, repo[rev])) |
|
2257 | (rev, repo[rev])) | |
2261 | # XXX remove on list is slow |
|
2258 | # XXX remove on list is slow | |
2262 | revs.remove(rev) |
|
2259 | revs.remove(rev) | |
2263 | if not revs: |
|
2260 | if not revs: | |
2264 | return -1 |
|
2261 | return -1 | |
2265 |
|
2262 | |||
2266 | # analyze revs for earlier grafts |
|
2263 | # analyze revs for earlier grafts | |
2267 | ids = {} |
|
2264 | ids = {} | |
2268 | for ctx in repo.set("%ld", revs): |
|
2265 | for ctx in repo.set("%ld", revs): | |
2269 | ids[ctx.hex()] = ctx.rev() |
|
2266 | ids[ctx.hex()] = ctx.rev() | |
2270 | n = ctx.extra().get('source') |
|
2267 | n = ctx.extra().get('source') | |
2271 | if n: |
|
2268 | if n: | |
2272 | ids[n] = ctx.rev() |
|
2269 | ids[n] = ctx.rev() | |
2273 |
|
2270 | |||
2274 | # check ancestors for earlier grafts |
|
2271 | # check ancestors for earlier grafts | |
2275 | ui.debug('scanning for duplicate grafts\n') |
|
2272 | ui.debug('scanning for duplicate grafts\n') | |
2276 |
|
2273 | |||
2277 | # The only changesets we can be sure doesn't contain grafts of any |
|
2274 | # The only changesets we can be sure doesn't contain grafts of any | |
2278 | # revs, are the ones that are common ancestors of *all* revs: |
|
2275 | # revs, are the ones that are common ancestors of *all* revs: | |
2279 | for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): |
|
2276 | for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): | |
2280 | ctx = repo[rev] |
|
2277 | ctx = repo[rev] | |
2281 | n = ctx.extra().get('source') |
|
2278 | n = ctx.extra().get('source') | |
2282 | if n in ids: |
|
2279 | if n in ids: | |
2283 | try: |
|
2280 | try: | |
2284 | r = repo[n].rev() |
|
2281 | r = repo[n].rev() | |
2285 | except error.RepoLookupError: |
|
2282 | except error.RepoLookupError: | |
2286 | r = None |
|
2283 | r = None | |
2287 | if r in revs: |
|
2284 | if r in revs: | |
2288 | ui.warn(_('skipping revision %d:%s ' |
|
2285 | ui.warn(_('skipping revision %d:%s ' | |
2289 | '(already grafted to %d:%s)\n') |
|
2286 | '(already grafted to %d:%s)\n') | |
2290 | % (r, repo[r], rev, ctx)) |
|
2287 | % (r, repo[r], rev, ctx)) | |
2291 | revs.remove(r) |
|
2288 | revs.remove(r) | |
2292 | elif ids[n] in revs: |
|
2289 | elif ids[n] in revs: | |
2293 | if r is None: |
|
2290 | if r is None: | |
2294 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2291 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2295 | '(%d:%s also has unknown origin %s)\n') |
|
2292 | '(%d:%s also has unknown origin %s)\n') | |
2296 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) |
|
2293 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) | |
2297 | else: |
|
2294 | else: | |
2298 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2295 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2299 | '(%d:%s also has origin %d:%s)\n') |
|
2296 | '(%d:%s also has origin %d:%s)\n') | |
2300 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) |
|
2297 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) | |
2301 | revs.remove(ids[n]) |
|
2298 | revs.remove(ids[n]) | |
2302 | elif ctx.hex() in ids: |
|
2299 | elif ctx.hex() in ids: | |
2303 | r = ids[ctx.hex()] |
|
2300 | r = ids[ctx.hex()] | |
2304 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2301 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2305 | '(was grafted from %d:%s)\n') % |
|
2302 | '(was grafted from %d:%s)\n') % | |
2306 | (r, repo[r], rev, ctx)) |
|
2303 | (r, repo[r], rev, ctx)) | |
2307 | revs.remove(r) |
|
2304 | revs.remove(r) | |
2308 | if not revs: |
|
2305 | if not revs: | |
2309 | return -1 |
|
2306 | return -1 | |
2310 |
|
2307 | |||
2311 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
2308 | for pos, ctx in enumerate(repo.set("%ld", revs)): | |
2312 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
2309 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, | |
2313 | ctx.description().split('\n', 1)[0]) |
|
2310 | ctx.description().split('\n', 1)[0]) | |
2314 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
2311 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) | |
2315 | if names: |
|
2312 | if names: | |
2316 | desc += ' (%s)' % ' '.join(names) |
|
2313 | desc += ' (%s)' % ' '.join(names) | |
2317 | ui.status(_('grafting %s\n') % desc) |
|
2314 | ui.status(_('grafting %s\n') % desc) | |
2318 | if opts.get('dry_run'): |
|
2315 | if opts.get('dry_run'): | |
2319 | continue |
|
2316 | continue | |
2320 |
|
2317 | |||
2321 | source = ctx.extra().get('source') |
|
2318 | source = ctx.extra().get('source') | |
2322 | extra = {} |
|
2319 | extra = {} | |
2323 | if source: |
|
2320 | if source: | |
2324 | extra['source'] = source |
|
2321 | extra['source'] = source | |
2325 | extra['intermediate-source'] = ctx.hex() |
|
2322 | extra['intermediate-source'] = ctx.hex() | |
2326 | else: |
|
2323 | else: | |
2327 | extra['source'] = ctx.hex() |
|
2324 | extra['source'] = ctx.hex() | |
2328 | user = ctx.user() |
|
2325 | user = ctx.user() | |
2329 | if opts.get('user'): |
|
2326 | if opts.get('user'): | |
2330 | user = opts['user'] |
|
2327 | user = opts['user'] | |
2331 | statedata['user'] = user |
|
2328 | statedata['user'] = user | |
2332 | date = ctx.date() |
|
2329 | date = ctx.date() | |
2333 | if opts.get('date'): |
|
2330 | if opts.get('date'): | |
2334 | date = opts['date'] |
|
2331 | date = opts['date'] | |
2335 | statedata['date'] = date |
|
2332 | statedata['date'] = date | |
2336 | message = ctx.description() |
|
2333 | message = ctx.description() | |
2337 | if opts.get('log'): |
|
2334 | if opts.get('log'): | |
2338 | message += '\n(grafted from %s)' % ctx.hex() |
|
2335 | message += '\n(grafted from %s)' % ctx.hex() | |
2339 | statedata['log'] = True |
|
2336 | statedata['log'] = True | |
2340 |
|
2337 | |||
2341 | # we don't merge the first commit when continuing |
|
2338 | # we don't merge the first commit when continuing | |
2342 | if not cont: |
|
2339 | if not cont: | |
2343 | # perform the graft merge with p1(rev) as 'ancestor' |
|
2340 | # perform the graft merge with p1(rev) as 'ancestor' | |
2344 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
2341 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
2345 | with ui.configoverride(overrides, 'graft'): |
|
2342 | with ui.configoverride(overrides, 'graft'): | |
2346 | stats = mergemod.graft(repo, ctx, ctx.p1(), ['local', 'graft']) |
|
2343 | stats = mergemod.graft(repo, ctx, ctx.p1(), ['local', 'graft']) | |
2347 | # report any conflicts |
|
2344 | # report any conflicts | |
2348 | if stats.unresolvedcount > 0: |
|
2345 | if stats.unresolvedcount > 0: | |
2349 | # write out state for --continue |
|
2346 | # write out state for --continue | |
2350 | nodes = [repo[rev].hex() for rev in revs[pos:]] |
|
2347 | nodes = [repo[rev].hex() for rev in revs[pos:]] | |
2351 | statedata['nodes'] = nodes |
|
2348 | statedata['nodes'] = nodes | |
2352 | stateversion = 1 |
|
2349 | stateversion = 1 | |
2353 | graftstate.save(stateversion, statedata) |
|
2350 | graftstate.save(stateversion, statedata) | |
2354 | hint = _("use 'hg resolve' and 'hg graft --continue'") |
|
2351 | hint = _("use 'hg resolve' and 'hg graft --continue'") | |
2355 | raise error.Abort( |
|
2352 | raise error.Abort( | |
2356 | _("unresolved conflicts, can't continue"), |
|
2353 | _("unresolved conflicts, can't continue"), | |
2357 | hint=hint) |
|
2354 | hint=hint) | |
2358 | else: |
|
2355 | else: | |
2359 | cont = False |
|
2356 | cont = False | |
2360 |
|
2357 | |||
2361 | # commit |
|
2358 | # commit | |
2362 | node = repo.commit(text=message, user=user, |
|
2359 | node = repo.commit(text=message, user=user, | |
2363 | date=date, extra=extra, editor=editor) |
|
2360 | date=date, extra=extra, editor=editor) | |
2364 | if node is None: |
|
2361 | if node is None: | |
2365 | ui.warn( |
|
2362 | ui.warn( | |
2366 | _('note: graft of %d:%s created no changes to commit\n') % |
|
2363 | _('note: graft of %d:%s created no changes to commit\n') % | |
2367 | (ctx.rev(), ctx)) |
|
2364 | (ctx.rev(), ctx)) | |
2368 |
|
2365 | |||
2369 | # remove state when we complete successfully |
|
2366 | # remove state when we complete successfully | |
2370 | if not opts.get('dry_run'): |
|
2367 | if not opts.get('dry_run'): | |
2371 | graftstate.delete() |
|
2368 | graftstate.delete() | |
2372 |
|
2369 | |||
2373 | return 0 |
|
2370 | return 0 | |
2374 |
|
2371 | |||
2375 | def _readgraftstate(repo, graftstate): |
|
2372 | def _readgraftstate(repo, graftstate): | |
2376 | """read the graft state file and return a dict of the data stored in it""" |
|
2373 | """read the graft state file and return a dict of the data stored in it""" | |
2377 | try: |
|
2374 | try: | |
2378 | return graftstate.read() |
|
2375 | return graftstate.read() | |
2379 | except error.CorruptedState: |
|
2376 | except error.CorruptedState: | |
2380 | nodes = repo.vfs.read('graftstate').splitlines() |
|
2377 | nodes = repo.vfs.read('graftstate').splitlines() | |
2381 | return {'nodes': nodes} |
|
2378 | return {'nodes': nodes} | |
2382 |
|
2379 | |||
2383 | def _stopgraft(ui, repo, graftstate): |
|
2380 | def _stopgraft(ui, repo, graftstate): | |
2384 | """stop the interrupted graft""" |
|
2381 | """stop the interrupted graft""" | |
2385 | if not graftstate.exists(): |
|
2382 | if not graftstate.exists(): | |
2386 | raise error.Abort(_("no interrupted graft found")) |
|
2383 | raise error.Abort(_("no interrupted graft found")) | |
2387 | pctx = repo['.'] |
|
2384 | pctx = repo['.'] | |
2388 | hg.updaterepo(repo, pctx.node(), True) |
|
2385 | hg.updaterepo(repo, pctx.node(), True) | |
2389 | graftstate.delete() |
|
2386 | graftstate.delete() | |
2390 | ui.status(_("stopped the interrupted graft\n")) |
|
2387 | ui.status(_("stopped the interrupted graft\n")) | |
2391 | ui.status(_("working directory is now at %s\n") % pctx.hex()[:12]) |
|
2388 | ui.status(_("working directory is now at %s\n") % pctx.hex()[:12]) | |
2392 | return 0 |
|
2389 | return 0 | |
2393 |
|
2390 | |||
2394 | @command('grep', |
|
2391 | @command('grep', | |
2395 | [('0', 'print0', None, _('end fields with NUL')), |
|
2392 | [('0', 'print0', None, _('end fields with NUL')), | |
2396 | ('', 'all', None, _('print all revisions that match')), |
|
2393 | ('', 'all', None, _('print all revisions that match')), | |
2397 | ('a', 'text', None, _('treat all files as text')), |
|
2394 | ('a', 'text', None, _('treat all files as text')), | |
2398 | ('f', 'follow', None, |
|
2395 | ('f', 'follow', None, | |
2399 | _('follow changeset history,' |
|
2396 | _('follow changeset history,' | |
2400 | ' or file history across copies and renames')), |
|
2397 | ' or file history across copies and renames')), | |
2401 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2398 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2402 | ('l', 'files-with-matches', None, |
|
2399 | ('l', 'files-with-matches', None, | |
2403 | _('print only filenames and revisions that match')), |
|
2400 | _('print only filenames and revisions that match')), | |
2404 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2401 | ('n', 'line-number', None, _('print matching line numbers')), | |
2405 | ('r', 'rev', [], |
|
2402 | ('r', 'rev', [], | |
2406 | _('only search files changed within revision range'), _('REV')), |
|
2403 | _('only search files changed within revision range'), _('REV')), | |
2407 | ('', 'allfiles', False, |
|
2404 | ('', 'allfiles', False, | |
2408 | _('include all files in the changeset while grepping (EXPERIMENTAL)')), |
|
2405 | _('include all files in the changeset while grepping (EXPERIMENTAL)')), | |
2409 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2406 | ('u', 'user', None, _('list the author (long with -v)')), | |
2410 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2407 | ('d', 'date', None, _('list the date (short with -q)')), | |
2411 | ] + formatteropts + walkopts, |
|
2408 | ] + formatteropts + walkopts, | |
2412 | _('[OPTION]... PATTERN [FILE]...'), |
|
2409 | _('[OPTION]... PATTERN [FILE]...'), | |
2413 | inferrepo=True, |
|
2410 | inferrepo=True, | |
2414 | intents={INTENT_READONLY}) |
|
2411 | intents={INTENT_READONLY}) | |
2415 | def grep(ui, repo, pattern, *pats, **opts): |
|
2412 | def grep(ui, repo, pattern, *pats, **opts): | |
2416 | """search revision history for a pattern in specified files |
|
2413 | """search revision history for a pattern in specified files | |
2417 |
|
2414 | |||
2418 | Search revision history for a regular expression in the specified |
|
2415 | Search revision history for a regular expression in the specified | |
2419 | files or the entire project. |
|
2416 | files or the entire project. | |
2420 |
|
2417 | |||
2421 | By default, grep prints the most recent revision number for each |
|
2418 | By default, grep prints the most recent revision number for each | |
2422 | file in which it finds a match. To get it to print every revision |
|
2419 | file in which it finds a match. To get it to print every revision | |
2423 | that contains a change in match status ("-" for a match that becomes |
|
2420 | that contains a change in match status ("-" for a match that becomes | |
2424 | a non-match, or "+" for a non-match that becomes a match), use the |
|
2421 | a non-match, or "+" for a non-match that becomes a match), use the | |
2425 | --all flag. |
|
2422 | --all flag. | |
2426 |
|
2423 | |||
2427 | PATTERN can be any Python (roughly Perl-compatible) regular |
|
2424 | PATTERN can be any Python (roughly Perl-compatible) regular | |
2428 | expression. |
|
2425 | expression. | |
2429 |
|
2426 | |||
2430 | If no FILEs are specified (and -f/--follow isn't set), all files in |
|
2427 | If no FILEs are specified (and -f/--follow isn't set), all files in | |
2431 | the repository are searched, including those that don't exist in the |
|
2428 | the repository are searched, including those that don't exist in the | |
2432 | current branch or have been deleted in a prior changeset. |
|
2429 | current branch or have been deleted in a prior changeset. | |
2433 |
|
2430 | |||
2434 | Returns 0 if a match is found, 1 otherwise. |
|
2431 | Returns 0 if a match is found, 1 otherwise. | |
2435 | """ |
|
2432 | """ | |
2436 | opts = pycompat.byteskwargs(opts) |
|
2433 | opts = pycompat.byteskwargs(opts) | |
2437 | reflags = re.M |
|
2434 | reflags = re.M | |
2438 | if opts.get('ignore_case'): |
|
2435 | if opts.get('ignore_case'): | |
2439 | reflags |= re.I |
|
2436 | reflags |= re.I | |
2440 | try: |
|
2437 | try: | |
2441 | regexp = util.re.compile(pattern, reflags) |
|
2438 | regexp = util.re.compile(pattern, reflags) | |
2442 | except re.error as inst: |
|
2439 | except re.error as inst: | |
2443 | ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)) |
|
2440 | ui.warn(_("grep: invalid match pattern: %s\n") % pycompat.bytestr(inst)) | |
2444 | return 1 |
|
2441 | return 1 | |
2445 | sep, eol = ':', '\n' |
|
2442 | sep, eol = ':', '\n' | |
2446 | if opts.get('print0'): |
|
2443 | if opts.get('print0'): | |
2447 | sep = eol = '\0' |
|
2444 | sep = eol = '\0' | |
2448 |
|
2445 | |||
2449 | getfile = util.lrucachefunc(repo.file) |
|
2446 | getfile = util.lrucachefunc(repo.file) | |
2450 |
|
2447 | |||
2451 | def matchlines(body): |
|
2448 | def matchlines(body): | |
2452 | begin = 0 |
|
2449 | begin = 0 | |
2453 | linenum = 0 |
|
2450 | linenum = 0 | |
2454 | while begin < len(body): |
|
2451 | while begin < len(body): | |
2455 | match = regexp.search(body, begin) |
|
2452 | match = regexp.search(body, begin) | |
2456 | if not match: |
|
2453 | if not match: | |
2457 | break |
|
2454 | break | |
2458 | mstart, mend = match.span() |
|
2455 | mstart, mend = match.span() | |
2459 | linenum += body.count('\n', begin, mstart) + 1 |
|
2456 | linenum += body.count('\n', begin, mstart) + 1 | |
2460 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2457 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
2461 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
2458 | begin = body.find('\n', mend) + 1 or len(body) + 1 | |
2462 | lend = begin - 1 |
|
2459 | lend = begin - 1 | |
2463 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2460 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
2464 |
|
2461 | |||
2465 | class linestate(object): |
|
2462 | class linestate(object): | |
2466 | def __init__(self, line, linenum, colstart, colend): |
|
2463 | def __init__(self, line, linenum, colstart, colend): | |
2467 | self.line = line |
|
2464 | self.line = line | |
2468 | self.linenum = linenum |
|
2465 | self.linenum = linenum | |
2469 | self.colstart = colstart |
|
2466 | self.colstart = colstart | |
2470 | self.colend = colend |
|
2467 | self.colend = colend | |
2471 |
|
2468 | |||
2472 | def __hash__(self): |
|
2469 | def __hash__(self): | |
2473 | return hash((self.linenum, self.line)) |
|
2470 | return hash((self.linenum, self.line)) | |
2474 |
|
2471 | |||
2475 | def __eq__(self, other): |
|
2472 | def __eq__(self, other): | |
2476 | return self.line == other.line |
|
2473 | return self.line == other.line | |
2477 |
|
2474 | |||
2478 | def findpos(self): |
|
2475 | def findpos(self): | |
2479 | """Iterate all (start, end) indices of matches""" |
|
2476 | """Iterate all (start, end) indices of matches""" | |
2480 | yield self.colstart, self.colend |
|
2477 | yield self.colstart, self.colend | |
2481 | p = self.colend |
|
2478 | p = self.colend | |
2482 | while p < len(self.line): |
|
2479 | while p < len(self.line): | |
2483 | m = regexp.search(self.line, p) |
|
2480 | m = regexp.search(self.line, p) | |
2484 | if not m: |
|
2481 | if not m: | |
2485 | break |
|
2482 | break | |
2486 | yield m.span() |
|
2483 | yield m.span() | |
2487 | p = m.end() |
|
2484 | p = m.end() | |
2488 |
|
2485 | |||
2489 | matches = {} |
|
2486 | matches = {} | |
2490 | copies = {} |
|
2487 | copies = {} | |
2491 | def grepbody(fn, rev, body): |
|
2488 | def grepbody(fn, rev, body): | |
2492 | matches[rev].setdefault(fn, []) |
|
2489 | matches[rev].setdefault(fn, []) | |
2493 | m = matches[rev][fn] |
|
2490 | m = matches[rev][fn] | |
2494 | for lnum, cstart, cend, line in matchlines(body): |
|
2491 | for lnum, cstart, cend, line in matchlines(body): | |
2495 | s = linestate(line, lnum, cstart, cend) |
|
2492 | s = linestate(line, lnum, cstart, cend) | |
2496 | m.append(s) |
|
2493 | m.append(s) | |
2497 |
|
2494 | |||
2498 | def difflinestates(a, b): |
|
2495 | def difflinestates(a, b): | |
2499 | sm = difflib.SequenceMatcher(None, a, b) |
|
2496 | sm = difflib.SequenceMatcher(None, a, b) | |
2500 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2497 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | |
2501 | if tag == 'insert': |
|
2498 | if tag == 'insert': | |
2502 | for i in xrange(blo, bhi): |
|
2499 | for i in xrange(blo, bhi): | |
2503 | yield ('+', b[i]) |
|
2500 | yield ('+', b[i]) | |
2504 | elif tag == 'delete': |
|
2501 | elif tag == 'delete': | |
2505 | for i in xrange(alo, ahi): |
|
2502 | for i in xrange(alo, ahi): | |
2506 | yield ('-', a[i]) |
|
2503 | yield ('-', a[i]) | |
2507 | elif tag == 'replace': |
|
2504 | elif tag == 'replace': | |
2508 | for i in xrange(alo, ahi): |
|
2505 | for i in xrange(alo, ahi): | |
2509 | yield ('-', a[i]) |
|
2506 | yield ('-', a[i]) | |
2510 | for i in xrange(blo, bhi): |
|
2507 | for i in xrange(blo, bhi): | |
2511 | yield ('+', b[i]) |
|
2508 | yield ('+', b[i]) | |
2512 |
|
2509 | |||
2513 | def display(fm, fn, ctx, pstates, states): |
|
2510 | def display(fm, fn, ctx, pstates, states): | |
2514 | rev = scmutil.intrev(ctx) |
|
2511 | rev = scmutil.intrev(ctx) | |
2515 | if fm.isplain(): |
|
2512 | if fm.isplain(): | |
2516 | formatuser = ui.shortuser |
|
2513 | formatuser = ui.shortuser | |
2517 | else: |
|
2514 | else: | |
2518 | formatuser = str |
|
2515 | formatuser = str | |
2519 | if ui.quiet: |
|
2516 | if ui.quiet: | |
2520 | datefmt = '%Y-%m-%d' |
|
2517 | datefmt = '%Y-%m-%d' | |
2521 | else: |
|
2518 | else: | |
2522 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' |
|
2519 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' | |
2523 | found = False |
|
2520 | found = False | |
2524 | @util.cachefunc |
|
2521 | @util.cachefunc | |
2525 | def binary(): |
|
2522 | def binary(): | |
2526 | flog = getfile(fn) |
|
2523 | flog = getfile(fn) | |
2527 | try: |
|
2524 | try: | |
2528 | return stringutil.binary(flog.read(ctx.filenode(fn))) |
|
2525 | return stringutil.binary(flog.read(ctx.filenode(fn))) | |
2529 | except error.WdirUnsupported: |
|
2526 | except error.WdirUnsupported: | |
2530 | return ctx[fn].isbinary() |
|
2527 | return ctx[fn].isbinary() | |
2531 |
|
2528 | |||
2532 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} |
|
2529 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} | |
2533 | if opts.get('all'): |
|
2530 | if opts.get('all'): | |
2534 | iter = difflinestates(pstates, states) |
|
2531 | iter = difflinestates(pstates, states) | |
2535 | else: |
|
2532 | else: | |
2536 | iter = [('', l) for l in states] |
|
2533 | iter = [('', l) for l in states] | |
2537 | for change, l in iter: |
|
2534 | for change, l in iter: | |
2538 | fm.startitem() |
|
2535 | fm.startitem() | |
2539 | fm.data(node=fm.hexfunc(scmutil.binnode(ctx))) |
|
2536 | fm.data(node=fm.hexfunc(scmutil.binnode(ctx))) | |
2540 |
|
2537 | |||
2541 | cols = [ |
|
2538 | cols = [ | |
2542 | ('filename', fn, True), |
|
2539 | ('filename', fn, True), | |
2543 | ('rev', rev, True), |
|
2540 | ('rev', rev, True), | |
2544 | ('linenumber', l.linenum, opts.get('line_number')), |
|
2541 | ('linenumber', l.linenum, opts.get('line_number')), | |
2545 | ] |
|
2542 | ] | |
2546 | if opts.get('all'): |
|
2543 | if opts.get('all'): | |
2547 | cols.append(('change', change, True)) |
|
2544 | cols.append(('change', change, True)) | |
2548 | cols.extend([ |
|
2545 | cols.extend([ | |
2549 | ('user', formatuser(ctx.user()), opts.get('user')), |
|
2546 | ('user', formatuser(ctx.user()), opts.get('user')), | |
2550 | ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), |
|
2547 | ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), | |
2551 | ]) |
|
2548 | ]) | |
2552 | lastcol = next(name for name, data, cond in reversed(cols) if cond) |
|
2549 | lastcol = next(name for name, data, cond in reversed(cols) if cond) | |
2553 | for name, data, cond in cols: |
|
2550 | for name, data, cond in cols: | |
2554 | field = fieldnamemap.get(name, name) |
|
2551 | field = fieldnamemap.get(name, name) | |
2555 | fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) |
|
2552 | fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) | |
2556 | if cond and name != lastcol: |
|
2553 | if cond and name != lastcol: | |
2557 | fm.plain(sep, label='grep.sep') |
|
2554 | fm.plain(sep, label='grep.sep') | |
2558 | if not opts.get('files_with_matches'): |
|
2555 | if not opts.get('files_with_matches'): | |
2559 | fm.plain(sep, label='grep.sep') |
|
2556 | fm.plain(sep, label='grep.sep') | |
2560 | if not opts.get('text') and binary(): |
|
2557 | if not opts.get('text') and binary(): | |
2561 | fm.plain(_(" Binary file matches")) |
|
2558 | fm.plain(_(" Binary file matches")) | |
2562 | else: |
|
2559 | else: | |
2563 | displaymatches(fm.nested('texts', tmpl='{text}'), l) |
|
2560 | displaymatches(fm.nested('texts', tmpl='{text}'), l) | |
2564 | fm.plain(eol) |
|
2561 | fm.plain(eol) | |
2565 | found = True |
|
2562 | found = True | |
2566 | if opts.get('files_with_matches'): |
|
2563 | if opts.get('files_with_matches'): | |
2567 | break |
|
2564 | break | |
2568 | return found |
|
2565 | return found | |
2569 |
|
2566 | |||
2570 | def displaymatches(fm, l): |
|
2567 | def displaymatches(fm, l): | |
2571 | p = 0 |
|
2568 | p = 0 | |
2572 | for s, e in l.findpos(): |
|
2569 | for s, e in l.findpos(): | |
2573 | if p < s: |
|
2570 | if p < s: | |
2574 | fm.startitem() |
|
2571 | fm.startitem() | |
2575 | fm.write('text', '%s', l.line[p:s]) |
|
2572 | fm.write('text', '%s', l.line[p:s]) | |
2576 | fm.data(matched=False) |
|
2573 | fm.data(matched=False) | |
2577 | fm.startitem() |
|
2574 | fm.startitem() | |
2578 | fm.write('text', '%s', l.line[s:e], label='grep.match') |
|
2575 | fm.write('text', '%s', l.line[s:e], label='grep.match') | |
2579 | fm.data(matched=True) |
|
2576 | fm.data(matched=True) | |
2580 | p = e |
|
2577 | p = e | |
2581 | if p < len(l.line): |
|
2578 | if p < len(l.line): | |
2582 | fm.startitem() |
|
2579 | fm.startitem() | |
2583 | fm.write('text', '%s', l.line[p:]) |
|
2580 | fm.write('text', '%s', l.line[p:]) | |
2584 | fm.data(matched=False) |
|
2581 | fm.data(matched=False) | |
2585 | fm.end() |
|
2582 | fm.end() | |
2586 |
|
2583 | |||
2587 | skip = {} |
|
2584 | skip = {} | |
2588 | revfiles = {} |
|
2585 | revfiles = {} | |
2589 | match = scmutil.match(repo[None], pats, opts) |
|
2586 | match = scmutil.match(repo[None], pats, opts) | |
2590 | found = False |
|
2587 | found = False | |
2591 | follow = opts.get('follow') |
|
2588 | follow = opts.get('follow') | |
2592 |
|
2589 | |||
2593 | def prep(ctx, fns): |
|
2590 | def prep(ctx, fns): | |
2594 | rev = ctx.rev() |
|
2591 | rev = ctx.rev() | |
2595 | pctx = ctx.p1() |
|
2592 | pctx = ctx.p1() | |
2596 | parent = pctx.rev() |
|
2593 | parent = pctx.rev() | |
2597 | matches.setdefault(rev, {}) |
|
2594 | matches.setdefault(rev, {}) | |
2598 | matches.setdefault(parent, {}) |
|
2595 | matches.setdefault(parent, {}) | |
2599 | files = revfiles.setdefault(rev, []) |
|
2596 | files = revfiles.setdefault(rev, []) | |
2600 | for fn in fns: |
|
2597 | for fn in fns: | |
2601 | flog = getfile(fn) |
|
2598 | flog = getfile(fn) | |
2602 | try: |
|
2599 | try: | |
2603 | fnode = ctx.filenode(fn) |
|
2600 | fnode = ctx.filenode(fn) | |
2604 | except error.LookupError: |
|
2601 | except error.LookupError: | |
2605 | continue |
|
2602 | continue | |
2606 | try: |
|
2603 | try: | |
2607 | copied = flog.renamed(fnode) |
|
2604 | copied = flog.renamed(fnode) | |
2608 | except error.WdirUnsupported: |
|
2605 | except error.WdirUnsupported: | |
2609 | copied = ctx[fn].renamed() |
|
2606 | copied = ctx[fn].renamed() | |
2610 | copy = follow and copied and copied[0] |
|
2607 | copy = follow and copied and copied[0] | |
2611 | if copy: |
|
2608 | if copy: | |
2612 | copies.setdefault(rev, {})[fn] = copy |
|
2609 | copies.setdefault(rev, {})[fn] = copy | |
2613 | if fn in skip: |
|
2610 | if fn in skip: | |
2614 | if copy: |
|
2611 | if copy: | |
2615 | skip[copy] = True |
|
2612 | skip[copy] = True | |
2616 | continue |
|
2613 | continue | |
2617 | files.append(fn) |
|
2614 | files.append(fn) | |
2618 |
|
2615 | |||
2619 | if fn not in matches[rev]: |
|
2616 | if fn not in matches[rev]: | |
2620 | try: |
|
2617 | try: | |
2621 | content = flog.read(fnode) |
|
2618 | content = flog.read(fnode) | |
2622 | except error.WdirUnsupported: |
|
2619 | except error.WdirUnsupported: | |
2623 | content = ctx[fn].data() |
|
2620 | content = ctx[fn].data() | |
2624 | grepbody(fn, rev, content) |
|
2621 | grepbody(fn, rev, content) | |
2625 |
|
2622 | |||
2626 | pfn = copy or fn |
|
2623 | pfn = copy or fn | |
2627 | if pfn not in matches[parent]: |
|
2624 | if pfn not in matches[parent]: | |
2628 | try: |
|
2625 | try: | |
2629 | fnode = pctx.filenode(pfn) |
|
2626 | fnode = pctx.filenode(pfn) | |
2630 | grepbody(pfn, parent, flog.read(fnode)) |
|
2627 | grepbody(pfn, parent, flog.read(fnode)) | |
2631 | except error.LookupError: |
|
2628 | except error.LookupError: | |
2632 | pass |
|
2629 | pass | |
2633 |
|
2630 | |||
2634 | ui.pager('grep') |
|
2631 | ui.pager('grep') | |
2635 | fm = ui.formatter('grep', opts) |
|
2632 | fm = ui.formatter('grep', opts) | |
2636 | for ctx in cmdutil.walkchangerevs(repo, match, opts, prep): |
|
2633 | for ctx in cmdutil.walkchangerevs(repo, match, opts, prep): | |
2637 | rev = ctx.rev() |
|
2634 | rev = ctx.rev() | |
2638 | parent = ctx.p1().rev() |
|
2635 | parent = ctx.p1().rev() | |
2639 | for fn in sorted(revfiles.get(rev, [])): |
|
2636 | for fn in sorted(revfiles.get(rev, [])): | |
2640 | states = matches[rev][fn] |
|
2637 | states = matches[rev][fn] | |
2641 | copy = copies.get(rev, {}).get(fn) |
|
2638 | copy = copies.get(rev, {}).get(fn) | |
2642 | if fn in skip: |
|
2639 | if fn in skip: | |
2643 | if copy: |
|
2640 | if copy: | |
2644 | skip[copy] = True |
|
2641 | skip[copy] = True | |
2645 | continue |
|
2642 | continue | |
2646 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
2643 | pstates = matches.get(parent, {}).get(copy or fn, []) | |
2647 | if pstates or states: |
|
2644 | if pstates or states: | |
2648 | r = display(fm, fn, ctx, pstates, states) |
|
2645 | r = display(fm, fn, ctx, pstates, states) | |
2649 | found = found or r |
|
2646 | found = found or r | |
2650 | if r and not opts.get('all'): |
|
2647 | if r and not opts.get('all'): | |
2651 | skip[fn] = True |
|
2648 | skip[fn] = True | |
2652 | if copy: |
|
2649 | if copy: | |
2653 | skip[copy] = True |
|
2650 | skip[copy] = True | |
2654 | del revfiles[rev] |
|
2651 | del revfiles[rev] | |
2655 | # We will keep the matches dict for the duration of the window |
|
2652 | # We will keep the matches dict for the duration of the window | |
2656 | # clear the matches dict once the window is over |
|
2653 | # clear the matches dict once the window is over | |
2657 | if not revfiles: |
|
2654 | if not revfiles: | |
2658 | matches.clear() |
|
2655 | matches.clear() | |
2659 | fm.end() |
|
2656 | fm.end() | |
2660 |
|
2657 | |||
2661 | return not found |
|
2658 | return not found | |
2662 |
|
2659 | |||
2663 | @command('heads', |
|
2660 | @command('heads', | |
2664 | [('r', 'rev', '', |
|
2661 | [('r', 'rev', '', | |
2665 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
2662 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), | |
2666 | ('t', 'topo', False, _('show topological heads only')), |
|
2663 | ('t', 'topo', False, _('show topological heads only')), | |
2667 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
2664 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), | |
2668 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
2665 | ('c', 'closed', False, _('show normal and closed branch heads')), | |
2669 | ] + templateopts, |
|
2666 | ] + templateopts, | |
2670 | _('[-ct] [-r STARTREV] [REV]...'), |
|
2667 | _('[-ct] [-r STARTREV] [REV]...'), | |
2671 | intents={INTENT_READONLY}) |
|
2668 | intents={INTENT_READONLY}) | |
2672 | def heads(ui, repo, *branchrevs, **opts): |
|
2669 | def heads(ui, repo, *branchrevs, **opts): | |
2673 | """show branch heads |
|
2670 | """show branch heads | |
2674 |
|
2671 | |||
2675 | With no arguments, show all open branch heads in the repository. |
|
2672 | With no arguments, show all open branch heads in the repository. | |
2676 | Branch heads are changesets that have no descendants on the |
|
2673 | Branch heads are changesets that have no descendants on the | |
2677 | same branch. They are where development generally takes place and |
|
2674 | same branch. They are where development generally takes place and | |
2678 | are the usual targets for update and merge operations. |
|
2675 | are the usual targets for update and merge operations. | |
2679 |
|
2676 | |||
2680 | If one or more REVs are given, only open branch heads on the |
|
2677 | If one or more REVs are given, only open branch heads on the | |
2681 | branches associated with the specified changesets are shown. This |
|
2678 | branches associated with the specified changesets are shown. This | |
2682 | means that you can use :hg:`heads .` to see the heads on the |
|
2679 | means that you can use :hg:`heads .` to see the heads on the | |
2683 | currently checked-out branch. |
|
2680 | currently checked-out branch. | |
2684 |
|
2681 | |||
2685 | If -c/--closed is specified, also show branch heads marked closed |
|
2682 | If -c/--closed is specified, also show branch heads marked closed | |
2686 | (see :hg:`commit --close-branch`). |
|
2683 | (see :hg:`commit --close-branch`). | |
2687 |
|
2684 | |||
2688 | If STARTREV is specified, only those heads that are descendants of |
|
2685 | If STARTREV is specified, only those heads that are descendants of | |
2689 | STARTREV will be displayed. |
|
2686 | STARTREV will be displayed. | |
2690 |
|
2687 | |||
2691 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
2688 | If -t/--topo is specified, named branch mechanics will be ignored and only | |
2692 | topological heads (changesets with no children) will be shown. |
|
2689 | topological heads (changesets with no children) will be shown. | |
2693 |
|
2690 | |||
2694 | Returns 0 if matching heads are found, 1 if not. |
|
2691 | Returns 0 if matching heads are found, 1 if not. | |
2695 | """ |
|
2692 | """ | |
2696 |
|
2693 | |||
2697 | opts = pycompat.byteskwargs(opts) |
|
2694 | opts = pycompat.byteskwargs(opts) | |
2698 | start = None |
|
2695 | start = None | |
2699 | rev = opts.get('rev') |
|
2696 | rev = opts.get('rev') | |
2700 | if rev: |
|
2697 | if rev: | |
2701 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
2698 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
2702 | start = scmutil.revsingle(repo, rev, None).node() |
|
2699 | start = scmutil.revsingle(repo, rev, None).node() | |
2703 |
|
2700 | |||
2704 | if opts.get('topo'): |
|
2701 | if opts.get('topo'): | |
2705 | heads = [repo[h] for h in repo.heads(start)] |
|
2702 | heads = [repo[h] for h in repo.heads(start)] | |
2706 | else: |
|
2703 | else: | |
2707 | heads = [] |
|
2704 | heads = [] | |
2708 | for branch in repo.branchmap(): |
|
2705 | for branch in repo.branchmap(): | |
2709 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
2706 | heads += repo.branchheads(branch, start, opts.get('closed')) | |
2710 | heads = [repo[h] for h in heads] |
|
2707 | heads = [repo[h] for h in heads] | |
2711 |
|
2708 | |||
2712 | if branchrevs: |
|
2709 | if branchrevs: | |
2713 | branches = set(repo[r].branch() |
|
2710 | branches = set(repo[r].branch() | |
2714 | for r in scmutil.revrange(repo, branchrevs)) |
|
2711 | for r in scmutil.revrange(repo, branchrevs)) | |
2715 | heads = [h for h in heads if h.branch() in branches] |
|
2712 | heads = [h for h in heads if h.branch() in branches] | |
2716 |
|
2713 | |||
2717 | if opts.get('active') and branchrevs: |
|
2714 | if opts.get('active') and branchrevs: | |
2718 | dagheads = repo.heads(start) |
|
2715 | dagheads = repo.heads(start) | |
2719 | heads = [h for h in heads if h.node() in dagheads] |
|
2716 | heads = [h for h in heads if h.node() in dagheads] | |
2720 |
|
2717 | |||
2721 | if branchrevs: |
|
2718 | if branchrevs: | |
2722 | haveheads = set(h.branch() for h in heads) |
|
2719 | haveheads = set(h.branch() for h in heads) | |
2723 | if branches - haveheads: |
|
2720 | if branches - haveheads: | |
2724 | headless = ', '.join(b for b in branches - haveheads) |
|
2721 | headless = ', '.join(b for b in branches - haveheads) | |
2725 | msg = _('no open branch heads found on branches %s') |
|
2722 | msg = _('no open branch heads found on branches %s') | |
2726 | if opts.get('rev'): |
|
2723 | if opts.get('rev'): | |
2727 | msg += _(' (started at %s)') % opts['rev'] |
|
2724 | msg += _(' (started at %s)') % opts['rev'] | |
2728 | ui.warn((msg + '\n') % headless) |
|
2725 | ui.warn((msg + '\n') % headless) | |
2729 |
|
2726 | |||
2730 | if not heads: |
|
2727 | if not heads: | |
2731 | return 1 |
|
2728 | return 1 | |
2732 |
|
2729 | |||
2733 | ui.pager('heads') |
|
2730 | ui.pager('heads') | |
2734 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
2731 | heads = sorted(heads, key=lambda x: -x.rev()) | |
2735 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
2732 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | |
2736 | for ctx in heads: |
|
2733 | for ctx in heads: | |
2737 | displayer.show(ctx) |
|
2734 | displayer.show(ctx) | |
2738 | displayer.close() |
|
2735 | displayer.close() | |
2739 |
|
2736 | |||
2740 | @command('help', |
|
2737 | @command('help', | |
2741 | [('e', 'extension', None, _('show only help for extensions')), |
|
2738 | [('e', 'extension', None, _('show only help for extensions')), | |
2742 | ('c', 'command', None, _('show only help for commands')), |
|
2739 | ('c', 'command', None, _('show only help for commands')), | |
2743 | ('k', 'keyword', None, _('show topics matching keyword')), |
|
2740 | ('k', 'keyword', None, _('show topics matching keyword')), | |
2744 | ('s', 'system', [], _('show help for specific platform(s)')), |
|
2741 | ('s', 'system', [], _('show help for specific platform(s)')), | |
2745 | ], |
|
2742 | ], | |
2746 | _('[-ecks] [TOPIC]'), |
|
2743 | _('[-ecks] [TOPIC]'), | |
2747 | norepo=True, |
|
2744 | norepo=True, | |
2748 | intents={INTENT_READONLY}) |
|
2745 | intents={INTENT_READONLY}) | |
2749 | def help_(ui, name=None, **opts): |
|
2746 | def help_(ui, name=None, **opts): | |
2750 | """show help for a given topic or a help overview |
|
2747 | """show help for a given topic or a help overview | |
2751 |
|
2748 | |||
2752 | With no arguments, print a list of commands with short help messages. |
|
2749 | With no arguments, print a list of commands with short help messages. | |
2753 |
|
2750 | |||
2754 | Given a topic, extension, or command name, print help for that |
|
2751 | Given a topic, extension, or command name, print help for that | |
2755 | topic. |
|
2752 | topic. | |
2756 |
|
2753 | |||
2757 | Returns 0 if successful. |
|
2754 | Returns 0 if successful. | |
2758 | """ |
|
2755 | """ | |
2759 |
|
2756 | |||
2760 | keep = opts.get(r'system') or [] |
|
2757 | keep = opts.get(r'system') or [] | |
2761 | if len(keep) == 0: |
|
2758 | if len(keep) == 0: | |
2762 | if pycompat.sysplatform.startswith('win'): |
|
2759 | if pycompat.sysplatform.startswith('win'): | |
2763 | keep.append('windows') |
|
2760 | keep.append('windows') | |
2764 | elif pycompat.sysplatform == 'OpenVMS': |
|
2761 | elif pycompat.sysplatform == 'OpenVMS': | |
2765 | keep.append('vms') |
|
2762 | keep.append('vms') | |
2766 | elif pycompat.sysplatform == 'plan9': |
|
2763 | elif pycompat.sysplatform == 'plan9': | |
2767 | keep.append('plan9') |
|
2764 | keep.append('plan9') | |
2768 | else: |
|
2765 | else: | |
2769 | keep.append('unix') |
|
2766 | keep.append('unix') | |
2770 | keep.append(pycompat.sysplatform.lower()) |
|
2767 | keep.append(pycompat.sysplatform.lower()) | |
2771 | if ui.verbose: |
|
2768 | if ui.verbose: | |
2772 | keep.append('verbose') |
|
2769 | keep.append('verbose') | |
2773 |
|
2770 | |||
2774 | commands = sys.modules[__name__] |
|
2771 | commands = sys.modules[__name__] | |
2775 | formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) |
|
2772 | formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) | |
2776 | ui.pager('help') |
|
2773 | ui.pager('help') | |
2777 | ui.write(formatted) |
|
2774 | ui.write(formatted) | |
2778 |
|
2775 | |||
2779 |
|
2776 | |||
2780 | @command('identify|id', |
|
2777 | @command('identify|id', | |
2781 | [('r', 'rev', '', |
|
2778 | [('r', 'rev', '', | |
2782 | _('identify the specified revision'), _('REV')), |
|
2779 | _('identify the specified revision'), _('REV')), | |
2783 | ('n', 'num', None, _('show local revision number')), |
|
2780 | ('n', 'num', None, _('show local revision number')), | |
2784 | ('i', 'id', None, _('show global revision id')), |
|
2781 | ('i', 'id', None, _('show global revision id')), | |
2785 | ('b', 'branch', None, _('show branch')), |
|
2782 | ('b', 'branch', None, _('show branch')), | |
2786 | ('t', 'tags', None, _('show tags')), |
|
2783 | ('t', 'tags', None, _('show tags')), | |
2787 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
2784 | ('B', 'bookmarks', None, _('show bookmarks')), | |
2788 | ] + remoteopts + formatteropts, |
|
2785 | ] + remoteopts + formatteropts, | |
2789 | _('[-nibtB] [-r REV] [SOURCE]'), |
|
2786 | _('[-nibtB] [-r REV] [SOURCE]'), | |
2790 | optionalrepo=True, |
|
2787 | optionalrepo=True, | |
2791 | intents={INTENT_READONLY}) |
|
2788 | intents={INTENT_READONLY}) | |
2792 | def identify(ui, repo, source=None, rev=None, |
|
2789 | def identify(ui, repo, source=None, rev=None, | |
2793 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
2790 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): | |
2794 | """identify the working directory or specified revision |
|
2791 | """identify the working directory or specified revision | |
2795 |
|
2792 | |||
2796 | Print a summary identifying the repository state at REV using one or |
|
2793 | Print a summary identifying the repository state at REV using one or | |
2797 | two parent hash identifiers, followed by a "+" if the working |
|
2794 | two parent hash identifiers, followed by a "+" if the working | |
2798 | directory has uncommitted changes, the branch name (if not default), |
|
2795 | directory has uncommitted changes, the branch name (if not default), | |
2799 | a list of tags, and a list of bookmarks. |
|
2796 | a list of tags, and a list of bookmarks. | |
2800 |
|
2797 | |||
2801 | When REV is not given, print a summary of the current state of the |
|
2798 | When REV is not given, print a summary of the current state of the | |
2802 | repository including the working directory. Specify -r. to get information |
|
2799 | repository including the working directory. Specify -r. to get information | |
2803 | of the working directory parent without scanning uncommitted changes. |
|
2800 | of the working directory parent without scanning uncommitted changes. | |
2804 |
|
2801 | |||
2805 | Specifying a path to a repository root or Mercurial bundle will |
|
2802 | Specifying a path to a repository root or Mercurial bundle will | |
2806 | cause lookup to operate on that repository/bundle. |
|
2803 | cause lookup to operate on that repository/bundle. | |
2807 |
|
2804 | |||
2808 | .. container:: verbose |
|
2805 | .. container:: verbose | |
2809 |
|
2806 | |||
2810 | Examples: |
|
2807 | Examples: | |
2811 |
|
2808 | |||
2812 | - generate a build identifier for the working directory:: |
|
2809 | - generate a build identifier for the working directory:: | |
2813 |
|
2810 | |||
2814 | hg id --id > build-id.dat |
|
2811 | hg id --id > build-id.dat | |
2815 |
|
2812 | |||
2816 | - find the revision corresponding to a tag:: |
|
2813 | - find the revision corresponding to a tag:: | |
2817 |
|
2814 | |||
2818 | hg id -n -r 1.3 |
|
2815 | hg id -n -r 1.3 | |
2819 |
|
2816 | |||
2820 | - check the most recent revision of a remote repository:: |
|
2817 | - check the most recent revision of a remote repository:: | |
2821 |
|
2818 | |||
2822 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ |
|
2819 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ | |
2823 |
|
2820 | |||
2824 | See :hg:`log` for generating more information about specific revisions, |
|
2821 | See :hg:`log` for generating more information about specific revisions, | |
2825 | including full hash identifiers. |
|
2822 | including full hash identifiers. | |
2826 |
|
2823 | |||
2827 | Returns 0 if successful. |
|
2824 | Returns 0 if successful. | |
2828 | """ |
|
2825 | """ | |
2829 |
|
2826 | |||
2830 | opts = pycompat.byteskwargs(opts) |
|
2827 | opts = pycompat.byteskwargs(opts) | |
2831 | if not repo and not source: |
|
2828 | if not repo and not source: | |
2832 | raise error.Abort(_("there is no Mercurial repository here " |
|
2829 | raise error.Abort(_("there is no Mercurial repository here " | |
2833 | "(.hg not found)")) |
|
2830 | "(.hg not found)")) | |
2834 |
|
2831 | |||
2835 | if ui.debugflag: |
|
2832 | if ui.debugflag: | |
2836 | hexfunc = hex |
|
2833 | hexfunc = hex | |
2837 | else: |
|
2834 | else: | |
2838 | hexfunc = short |
|
2835 | hexfunc = short | |
2839 | default = not (num or id or branch or tags or bookmarks) |
|
2836 | default = not (num or id or branch or tags or bookmarks) | |
2840 | output = [] |
|
2837 | output = [] | |
2841 | revs = [] |
|
2838 | revs = [] | |
2842 |
|
2839 | |||
2843 | if source: |
|
2840 | if source: | |
2844 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
2841 | source, branches = hg.parseurl(ui.expandpath(source)) | |
2845 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
2842 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo | |
2846 | repo = peer.local() |
|
2843 | repo = peer.local() | |
2847 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
2844 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) | |
2848 |
|
2845 | |||
2849 | fm = ui.formatter('identify', opts) |
|
2846 | fm = ui.formatter('identify', opts) | |
2850 | fm.startitem() |
|
2847 | fm.startitem() | |
2851 |
|
2848 | |||
2852 | if not repo: |
|
2849 | if not repo: | |
2853 | if num or branch or tags: |
|
2850 | if num or branch or tags: | |
2854 | raise error.Abort( |
|
2851 | raise error.Abort( | |
2855 | _("can't query remote revision number, branch, or tags")) |
|
2852 | _("can't query remote revision number, branch, or tags")) | |
2856 | if not rev and revs: |
|
2853 | if not rev and revs: | |
2857 | rev = revs[0] |
|
2854 | rev = revs[0] | |
2858 | if not rev: |
|
2855 | if not rev: | |
2859 | rev = "tip" |
|
2856 | rev = "tip" | |
2860 |
|
2857 | |||
2861 | remoterev = peer.lookup(rev) |
|
2858 | remoterev = peer.lookup(rev) | |
2862 | hexrev = hexfunc(remoterev) |
|
2859 | hexrev = hexfunc(remoterev) | |
2863 | if default or id: |
|
2860 | if default or id: | |
2864 | output = [hexrev] |
|
2861 | output = [hexrev] | |
2865 | fm.data(id=hexrev) |
|
2862 | fm.data(id=hexrev) | |
2866 |
|
2863 | |||
2867 | def getbms(): |
|
2864 | def getbms(): | |
2868 | bms = [] |
|
2865 | bms = [] | |
2869 |
|
2866 | |||
2870 | if 'bookmarks' in peer.listkeys('namespaces'): |
|
2867 | if 'bookmarks' in peer.listkeys('namespaces'): | |
2871 | hexremoterev = hex(remoterev) |
|
2868 | hexremoterev = hex(remoterev) | |
2872 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() |
|
2869 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() | |
2873 | if bmr == hexremoterev] |
|
2870 | if bmr == hexremoterev] | |
2874 |
|
2871 | |||
2875 | return sorted(bms) |
|
2872 | return sorted(bms) | |
2876 |
|
2873 | |||
2877 | bms = getbms() |
|
2874 | bms = getbms() | |
2878 | if bookmarks: |
|
2875 | if bookmarks: | |
2879 | output.extend(bms) |
|
2876 | output.extend(bms) | |
2880 | elif default and not ui.quiet: |
|
2877 | elif default and not ui.quiet: | |
2881 | # multiple bookmarks for a single parent separated by '/' |
|
2878 | # multiple bookmarks for a single parent separated by '/' | |
2882 | bm = '/'.join(bms) |
|
2879 | bm = '/'.join(bms) | |
2883 | if bm: |
|
2880 | if bm: | |
2884 | output.append(bm) |
|
2881 | output.append(bm) | |
2885 |
|
2882 | |||
2886 | fm.data(node=hex(remoterev)) |
|
2883 | fm.data(node=hex(remoterev)) | |
2887 | fm.data(bookmarks=fm.formatlist(bms, name='bookmark')) |
|
2884 | fm.data(bookmarks=fm.formatlist(bms, name='bookmark')) | |
2888 | else: |
|
2885 | else: | |
2889 | if rev: |
|
2886 | if rev: | |
2890 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
2887 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
2891 | ctx = scmutil.revsingle(repo, rev, None) |
|
2888 | ctx = scmutil.revsingle(repo, rev, None) | |
2892 |
|
2889 | |||
2893 | if ctx.rev() is None: |
|
2890 | if ctx.rev() is None: | |
2894 | ctx = repo[None] |
|
2891 | ctx = repo[None] | |
2895 | parents = ctx.parents() |
|
2892 | parents = ctx.parents() | |
2896 | taglist = [] |
|
2893 | taglist = [] | |
2897 | for p in parents: |
|
2894 | for p in parents: | |
2898 | taglist.extend(p.tags()) |
|
2895 | taglist.extend(p.tags()) | |
2899 |
|
2896 | |||
2900 | dirty = "" |
|
2897 | dirty = "" | |
2901 | if ctx.dirty(missing=True, merge=False, branch=False): |
|
2898 | if ctx.dirty(missing=True, merge=False, branch=False): | |
2902 | dirty = '+' |
|
2899 | dirty = '+' | |
2903 | fm.data(dirty=dirty) |
|
2900 | fm.data(dirty=dirty) | |
2904 |
|
2901 | |||
2905 | hexoutput = [hexfunc(p.node()) for p in parents] |
|
2902 | hexoutput = [hexfunc(p.node()) for p in parents] | |
2906 | if default or id: |
|
2903 | if default or id: | |
2907 | output = ["%s%s" % ('+'.join(hexoutput), dirty)] |
|
2904 | output = ["%s%s" % ('+'.join(hexoutput), dirty)] | |
2908 | fm.data(id="%s%s" % ('+'.join(hexoutput), dirty)) |
|
2905 | fm.data(id="%s%s" % ('+'.join(hexoutput), dirty)) | |
2909 |
|
2906 | |||
2910 | if num: |
|
2907 | if num: | |
2911 | numoutput = ["%d" % p.rev() for p in parents] |
|
2908 | numoutput = ["%d" % p.rev() for p in parents] | |
2912 | output.append("%s%s" % ('+'.join(numoutput), dirty)) |
|
2909 | output.append("%s%s" % ('+'.join(numoutput), dirty)) | |
2913 |
|
2910 | |||
2914 | fn = fm.nested('parents', tmpl='{rev}:{node|formatnode}', sep=' ') |
|
2911 | fn = fm.nested('parents', tmpl='{rev}:{node|formatnode}', sep=' ') | |
2915 | for p in parents: |
|
2912 | for p in parents: | |
2916 | fn.startitem() |
|
2913 | fn.startitem() | |
2917 | fn.data(rev=p.rev()) |
|
2914 | fn.data(rev=p.rev()) | |
2918 | fn.data(node=p.hex()) |
|
2915 | fn.data(node=p.hex()) | |
2919 | fn.context(ctx=p) |
|
2916 | fn.context(ctx=p) | |
2920 | fn.end() |
|
2917 | fn.end() | |
2921 | else: |
|
2918 | else: | |
2922 | hexoutput = hexfunc(ctx.node()) |
|
2919 | hexoutput = hexfunc(ctx.node()) | |
2923 | if default or id: |
|
2920 | if default or id: | |
2924 | output = [hexoutput] |
|
2921 | output = [hexoutput] | |
2925 | fm.data(id=hexoutput) |
|
2922 | fm.data(id=hexoutput) | |
2926 |
|
2923 | |||
2927 | if num: |
|
2924 | if num: | |
2928 | output.append(pycompat.bytestr(ctx.rev())) |
|
2925 | output.append(pycompat.bytestr(ctx.rev())) | |
2929 | taglist = ctx.tags() |
|
2926 | taglist = ctx.tags() | |
2930 |
|
2927 | |||
2931 | if default and not ui.quiet: |
|
2928 | if default and not ui.quiet: | |
2932 | b = ctx.branch() |
|
2929 | b = ctx.branch() | |
2933 | if b != 'default': |
|
2930 | if b != 'default': | |
2934 | output.append("(%s)" % b) |
|
2931 | output.append("(%s)" % b) | |
2935 |
|
2932 | |||
2936 | # multiple tags for a single parent separated by '/' |
|
2933 | # multiple tags for a single parent separated by '/' | |
2937 | t = '/'.join(taglist) |
|
2934 | t = '/'.join(taglist) | |
2938 | if t: |
|
2935 | if t: | |
2939 | output.append(t) |
|
2936 | output.append(t) | |
2940 |
|
2937 | |||
2941 | # multiple bookmarks for a single parent separated by '/' |
|
2938 | # multiple bookmarks for a single parent separated by '/' | |
2942 | bm = '/'.join(ctx.bookmarks()) |
|
2939 | bm = '/'.join(ctx.bookmarks()) | |
2943 | if bm: |
|
2940 | if bm: | |
2944 | output.append(bm) |
|
2941 | output.append(bm) | |
2945 | else: |
|
2942 | else: | |
2946 | if branch: |
|
2943 | if branch: | |
2947 | output.append(ctx.branch()) |
|
2944 | output.append(ctx.branch()) | |
2948 |
|
2945 | |||
2949 | if tags: |
|
2946 | if tags: | |
2950 | output.extend(taglist) |
|
2947 | output.extend(taglist) | |
2951 |
|
2948 | |||
2952 | if bookmarks: |
|
2949 | if bookmarks: | |
2953 | output.extend(ctx.bookmarks()) |
|
2950 | output.extend(ctx.bookmarks()) | |
2954 |
|
2951 | |||
2955 | fm.data(node=ctx.hex()) |
|
2952 | fm.data(node=ctx.hex()) | |
2956 | fm.data(branch=ctx.branch()) |
|
2953 | fm.data(branch=ctx.branch()) | |
2957 | fm.data(tags=fm.formatlist(taglist, name='tag', sep=':')) |
|
2954 | fm.data(tags=fm.formatlist(taglist, name='tag', sep=':')) | |
2958 | fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark')) |
|
2955 | fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark')) | |
2959 | fm.context(ctx=ctx) |
|
2956 | fm.context(ctx=ctx) | |
2960 |
|
2957 | |||
2961 | fm.plain("%s\n" % ' '.join(output)) |
|
2958 | fm.plain("%s\n" % ' '.join(output)) | |
2962 | fm.end() |
|
2959 | fm.end() | |
2963 |
|
2960 | |||
2964 | @command('import|patch', |
|
2961 | @command('import|patch', | |
2965 | [('p', 'strip', 1, |
|
2962 | [('p', 'strip', 1, | |
2966 | _('directory strip option for patch. This has the same ' |
|
2963 | _('directory strip option for patch. This has the same ' | |
2967 | 'meaning as the corresponding patch option'), _('NUM')), |
|
2964 | 'meaning as the corresponding patch option'), _('NUM')), | |
2968 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
2965 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), | |
2969 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2966 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
2970 | ('f', 'force', None, |
|
2967 | ('f', 'force', None, | |
2971 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), |
|
2968 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), | |
2972 | ('', 'no-commit', None, |
|
2969 | ('', 'no-commit', None, | |
2973 | _("don't commit, just update the working directory")), |
|
2970 | _("don't commit, just update the working directory")), | |
2974 | ('', 'bypass', None, |
|
2971 | ('', 'bypass', None, | |
2975 | _("apply patch without touching the working directory")), |
|
2972 | _("apply patch without touching the working directory")), | |
2976 | ('', 'partial', None, |
|
2973 | ('', 'partial', None, | |
2977 | _('commit even if some hunks fail')), |
|
2974 | _('commit even if some hunks fail')), | |
2978 | ('', 'exact', None, |
|
2975 | ('', 'exact', None, | |
2979 | _('abort if patch would apply lossily')), |
|
2976 | _('abort if patch would apply lossily')), | |
2980 | ('', 'prefix', '', |
|
2977 | ('', 'prefix', '', | |
2981 | _('apply patch to subdirectory'), _('DIR')), |
|
2978 | _('apply patch to subdirectory'), _('DIR')), | |
2982 | ('', 'import-branch', None, |
|
2979 | ('', 'import-branch', None, | |
2983 | _('use any branch information in patch (implied by --exact)'))] + |
|
2980 | _('use any branch information in patch (implied by --exact)'))] + | |
2984 | commitopts + commitopts2 + similarityopts, |
|
2981 | commitopts + commitopts2 + similarityopts, | |
2985 | _('[OPTION]... PATCH...')) |
|
2982 | _('[OPTION]... PATCH...')) | |
2986 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
2983 | def import_(ui, repo, patch1=None, *patches, **opts): | |
2987 | """import an ordered set of patches |
|
2984 | """import an ordered set of patches | |
2988 |
|
2985 | |||
2989 | Import a list of patches and commit them individually (unless |
|
2986 | Import a list of patches and commit them individually (unless | |
2990 | --no-commit is specified). |
|
2987 | --no-commit is specified). | |
2991 |
|
2988 | |||
2992 | To read a patch from standard input (stdin), use "-" as the patch |
|
2989 | To read a patch from standard input (stdin), use "-" as the patch | |
2993 | name. If a URL is specified, the patch will be downloaded from |
|
2990 | name. If a URL is specified, the patch will be downloaded from | |
2994 | there. |
|
2991 | there. | |
2995 |
|
2992 | |||
2996 | Import first applies changes to the working directory (unless |
|
2993 | Import first applies changes to the working directory (unless | |
2997 | --bypass is specified), import will abort if there are outstanding |
|
2994 | --bypass is specified), import will abort if there are outstanding | |
2998 | changes. |
|
2995 | changes. | |
2999 |
|
2996 | |||
3000 | Use --bypass to apply and commit patches directly to the |
|
2997 | Use --bypass to apply and commit patches directly to the | |
3001 | repository, without affecting the working directory. Without |
|
2998 | repository, without affecting the working directory. Without | |
3002 | --exact, patches will be applied on top of the working directory |
|
2999 | --exact, patches will be applied on top of the working directory | |
3003 | parent revision. |
|
3000 | parent revision. | |
3004 |
|
3001 | |||
3005 | You can import a patch straight from a mail message. Even patches |
|
3002 | You can import a patch straight from a mail message. Even patches | |
3006 | as attachments work (to use the body part, it must have type |
|
3003 | as attachments work (to use the body part, it must have type | |
3007 | text/plain or text/x-patch). From and Subject headers of email |
|
3004 | text/plain or text/x-patch). From and Subject headers of email | |
3008 | message are used as default committer and commit message. All |
|
3005 | message are used as default committer and commit message. All | |
3009 | text/plain body parts before first diff are added to the commit |
|
3006 | text/plain body parts before first diff are added to the commit | |
3010 | message. |
|
3007 | message. | |
3011 |
|
3008 | |||
3012 | If the imported patch was generated by :hg:`export`, user and |
|
3009 | If the imported patch was generated by :hg:`export`, user and | |
3013 | description from patch override values from message headers and |
|
3010 | description from patch override values from message headers and | |
3014 | body. Values given on command line with -m/--message and -u/--user |
|
3011 | body. Values given on command line with -m/--message and -u/--user | |
3015 | override these. |
|
3012 | override these. | |
3016 |
|
3013 | |||
3017 | If --exact is specified, import will set the working directory to |
|
3014 | If --exact is specified, import will set the working directory to | |
3018 | the parent of each patch before applying it, and will abort if the |
|
3015 | the parent of each patch before applying it, and will abort if the | |
3019 | resulting changeset has a different ID than the one recorded in |
|
3016 | resulting changeset has a different ID than the one recorded in | |
3020 | the patch. This will guard against various ways that portable |
|
3017 | the patch. This will guard against various ways that portable | |
3021 | patch formats and mail systems might fail to transfer Mercurial |
|
3018 | patch formats and mail systems might fail to transfer Mercurial | |
3022 | data or metadata. See :hg:`bundle` for lossless transmission. |
|
3019 | data or metadata. See :hg:`bundle` for lossless transmission. | |
3023 |
|
3020 | |||
3024 | Use --partial to ensure a changeset will be created from the patch |
|
3021 | Use --partial to ensure a changeset will be created from the patch | |
3025 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
3022 | even if some hunks fail to apply. Hunks that fail to apply will be | |
3026 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
3023 | written to a <target-file>.rej file. Conflicts can then be resolved | |
3027 | by hand before :hg:`commit --amend` is run to update the created |
|
3024 | by hand before :hg:`commit --amend` is run to update the created | |
3028 | changeset. This flag exists to let people import patches that |
|
3025 | changeset. This flag exists to let people import patches that | |
3029 | partially apply without losing the associated metadata (author, |
|
3026 | partially apply without losing the associated metadata (author, | |
3030 | date, description, ...). |
|
3027 | date, description, ...). | |
3031 |
|
3028 | |||
3032 | .. note:: |
|
3029 | .. note:: | |
3033 |
|
3030 | |||
3034 | When no hunks apply cleanly, :hg:`import --partial` will create |
|
3031 | When no hunks apply cleanly, :hg:`import --partial` will create | |
3035 | an empty changeset, importing only the patch metadata. |
|
3032 | an empty changeset, importing only the patch metadata. | |
3036 |
|
3033 | |||
3037 | With -s/--similarity, hg will attempt to discover renames and |
|
3034 | With -s/--similarity, hg will attempt to discover renames and | |
3038 | copies in the patch in the same way as :hg:`addremove`. |
|
3035 | copies in the patch in the same way as :hg:`addremove`. | |
3039 |
|
3036 | |||
3040 | It is possible to use external patch programs to perform the patch |
|
3037 | It is possible to use external patch programs to perform the patch | |
3041 | by setting the ``ui.patch`` configuration option. For the default |
|
3038 | by setting the ``ui.patch`` configuration option. For the default | |
3042 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
3039 | internal tool, the fuzz can also be configured via ``patch.fuzz``. | |
3043 | See :hg:`help config` for more information about configuration |
|
3040 | See :hg:`help config` for more information about configuration | |
3044 | files and how to use these options. |
|
3041 | files and how to use these options. | |
3045 |
|
3042 | |||
3046 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3043 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
3047 |
|
3044 | |||
3048 | .. container:: verbose |
|
3045 | .. container:: verbose | |
3049 |
|
3046 | |||
3050 | Examples: |
|
3047 | Examples: | |
3051 |
|
3048 | |||
3052 | - import a traditional patch from a website and detect renames:: |
|
3049 | - import a traditional patch from a website and detect renames:: | |
3053 |
|
3050 | |||
3054 | hg import -s 80 http://example.com/bugfix.patch |
|
3051 | hg import -s 80 http://example.com/bugfix.patch | |
3055 |
|
3052 | |||
3056 | - import a changeset from an hgweb server:: |
|
3053 | - import a changeset from an hgweb server:: | |
3057 |
|
3054 | |||
3058 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa |
|
3055 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa | |
3059 |
|
3056 | |||
3060 | - import all the patches in an Unix-style mbox:: |
|
3057 | - import all the patches in an Unix-style mbox:: | |
3061 |
|
3058 | |||
3062 | hg import incoming-patches.mbox |
|
3059 | hg import incoming-patches.mbox | |
3063 |
|
3060 | |||
3064 | - import patches from stdin:: |
|
3061 | - import patches from stdin:: | |
3065 |
|
3062 | |||
3066 | hg import - |
|
3063 | hg import - | |
3067 |
|
3064 | |||
3068 | - attempt to exactly restore an exported changeset (not always |
|
3065 | - attempt to exactly restore an exported changeset (not always | |
3069 | possible):: |
|
3066 | possible):: | |
3070 |
|
3067 | |||
3071 | hg import --exact proposed-fix.patch |
|
3068 | hg import --exact proposed-fix.patch | |
3072 |
|
3069 | |||
3073 | - use an external tool to apply a patch which is too fuzzy for |
|
3070 | - use an external tool to apply a patch which is too fuzzy for | |
3074 | the default internal tool. |
|
3071 | the default internal tool. | |
3075 |
|
3072 | |||
3076 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
3073 | hg import --config ui.patch="patch --merge" fuzzy.patch | |
3077 |
|
3074 | |||
3078 | - change the default fuzzing from 2 to a less strict 7 |
|
3075 | - change the default fuzzing from 2 to a less strict 7 | |
3079 |
|
3076 | |||
3080 | hg import --config ui.fuzz=7 fuzz.patch |
|
3077 | hg import --config ui.fuzz=7 fuzz.patch | |
3081 |
|
3078 | |||
3082 | Returns 0 on success, 1 on partial success (see --partial). |
|
3079 | Returns 0 on success, 1 on partial success (see --partial). | |
3083 | """ |
|
3080 | """ | |
3084 |
|
3081 | |||
3085 | opts = pycompat.byteskwargs(opts) |
|
3082 | opts = pycompat.byteskwargs(opts) | |
3086 | if not patch1: |
|
3083 | if not patch1: | |
3087 | raise error.Abort(_('need at least one patch to import')) |
|
3084 | raise error.Abort(_('need at least one patch to import')) | |
3088 |
|
3085 | |||
3089 | patches = (patch1,) + patches |
|
3086 | patches = (patch1,) + patches | |
3090 |
|
3087 | |||
3091 | date = opts.get('date') |
|
3088 | date = opts.get('date') | |
3092 | if date: |
|
3089 | if date: | |
3093 | opts['date'] = dateutil.parsedate(date) |
|
3090 | opts['date'] = dateutil.parsedate(date) | |
3094 |
|
3091 | |||
3095 | exact = opts.get('exact') |
|
3092 | exact = opts.get('exact') | |
3096 | update = not opts.get('bypass') |
|
3093 | update = not opts.get('bypass') | |
3097 | if not update and opts.get('no_commit'): |
|
3094 | if not update and opts.get('no_commit'): | |
3098 | raise error.Abort(_('cannot use --no-commit with --bypass')) |
|
3095 | raise error.Abort(_('cannot use --no-commit with --bypass')) | |
3099 | try: |
|
3096 | try: | |
3100 | sim = float(opts.get('similarity') or 0) |
|
3097 | sim = float(opts.get('similarity') or 0) | |
3101 | except ValueError: |
|
3098 | except ValueError: | |
3102 | raise error.Abort(_('similarity must be a number')) |
|
3099 | raise error.Abort(_('similarity must be a number')) | |
3103 | if sim < 0 or sim > 100: |
|
3100 | if sim < 0 or sim > 100: | |
3104 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
3101 | raise error.Abort(_('similarity must be between 0 and 100')) | |
3105 | if sim and not update: |
|
3102 | if sim and not update: | |
3106 | raise error.Abort(_('cannot use --similarity with --bypass')) |
|
3103 | raise error.Abort(_('cannot use --similarity with --bypass')) | |
3107 | if exact: |
|
3104 | if exact: | |
3108 | if opts.get('edit'): |
|
3105 | if opts.get('edit'): | |
3109 | raise error.Abort(_('cannot use --exact with --edit')) |
|
3106 | raise error.Abort(_('cannot use --exact with --edit')) | |
3110 | if opts.get('prefix'): |
|
3107 | if opts.get('prefix'): | |
3111 | raise error.Abort(_('cannot use --exact with --prefix')) |
|
3108 | raise error.Abort(_('cannot use --exact with --prefix')) | |
3112 |
|
3109 | |||
3113 | base = opts["base"] |
|
3110 | base = opts["base"] | |
3114 | dsguard = lock = tr = None |
|
|||
3115 | msgs = [] |
|
3111 | msgs = [] | |
3116 | ret = 0 |
|
3112 | ret = 0 | |
3117 |
|
3113 | |||
3118 | with repo.wlock(): |
|
3114 | with repo.wlock(): | |
3119 |
|
|
3115 | if update: | |
3120 | if update: |
|
3116 | cmdutil.checkunfinished(repo) | |
3121 | cmdutil.checkunfinished(repo) |
|
3117 | if (exact or not opts.get('force')): | |
3122 | if (exact or not opts.get('force')): |
|
3118 | cmdutil.bailifchanged(repo) | |
3123 | cmdutil.bailifchanged(repo) |
|
3119 | ||
3124 |
|
3120 | if not opts.get('no_commit'): | ||
3125 | if not opts.get('no_commit'): |
|
3121 | lock = repo.lock | |
3126 | lock = repo.lock() |
|
3122 | tr = lambda: repo.transaction('import') | |
3127 | tr = repo.transaction('import') |
|
3123 | dsguard = util.nullcontextmanager | |
3128 |
|
|
3124 | else: | |
3129 | dsguard = dirstateguard.dirstateguard(repo, 'import') |
|
3125 | lock = util.nullcontextmanager | |
|
3126 | tr = util.nullcontextmanager | |||
|
3127 | dsguard = lambda: dirstateguard.dirstateguard(repo, 'import') | |||
|
3128 | with lock(), tr(), dsguard(): | |||
3130 | parents = repo[None].parents() |
|
3129 | parents = repo[None].parents() | |
3131 | for patchurl in patches: |
|
3130 | for patchurl in patches: | |
3132 | if patchurl == '-': |
|
3131 | if patchurl == '-': | |
3133 | ui.status(_('applying patch from stdin\n')) |
|
3132 | ui.status(_('applying patch from stdin\n')) | |
3134 | patchfile = ui.fin |
|
3133 | patchfile = ui.fin | |
3135 | patchurl = 'stdin' # for error message |
|
3134 | patchurl = 'stdin' # for error message | |
3136 | else: |
|
3135 | else: | |
3137 | patchurl = os.path.join(base, patchurl) |
|
3136 | patchurl = os.path.join(base, patchurl) | |
3138 | ui.status(_('applying %s\n') % patchurl) |
|
3137 | ui.status(_('applying %s\n') % patchurl) | |
3139 | patchfile = hg.openpath(ui, patchurl) |
|
3138 | patchfile = hg.openpath(ui, patchurl) | |
3140 |
|
3139 | |||
3141 | haspatch = False |
|
3140 | haspatch = False | |
3142 | for hunk in patch.split(patchfile): |
|
3141 | for hunk in patch.split(patchfile): | |
3143 | with patch.extract(ui, hunk) as patchdata: |
|
3142 | with patch.extract(ui, hunk) as patchdata: | |
3144 | msg, node, rej = cmdutil.tryimportone(ui, repo, |
|
3143 | msg, node, rej = cmdutil.tryimportone(ui, repo, | |
3145 | patchdata, |
|
3144 | patchdata, | |
3146 | parents, opts, |
|
3145 | parents, opts, | |
3147 | msgs, hg.clean) |
|
3146 | msgs, hg.clean) | |
3148 | if msg: |
|
3147 | if msg: | |
3149 | haspatch = True |
|
3148 | haspatch = True | |
3150 | ui.note(msg + '\n') |
|
3149 | ui.note(msg + '\n') | |
3151 | if update or exact: |
|
3150 | if update or exact: | |
3152 | parents = repo[None].parents() |
|
3151 | parents = repo[None].parents() | |
3153 | else: |
|
3152 | else: | |
3154 | parents = [repo[node]] |
|
3153 | parents = [repo[node]] | |
3155 | if rej: |
|
3154 | if rej: | |
3156 | ui.write_err(_("patch applied partially\n")) |
|
3155 | ui.write_err(_("patch applied partially\n")) | |
3157 | ui.write_err(_("(fix the .rej files and run " |
|
3156 | ui.write_err(_("(fix the .rej files and run " | |
3158 | "`hg commit --amend`)\n")) |
|
3157 | "`hg commit --amend`)\n")) | |
3159 | ret = 1 |
|
3158 | ret = 1 | |
3160 | break |
|
3159 | break | |
3161 |
|
3160 | |||
3162 | if not haspatch: |
|
3161 | if not haspatch: | |
3163 | raise error.Abort(_('%s: no diffs found') % patchurl) |
|
3162 | raise error.Abort(_('%s: no diffs found') % patchurl) | |
3164 |
|
3163 | |||
3165 | if tr: |
|
|||
3166 | tr.close() |
|
|||
3167 | if msgs: |
|
3164 | if msgs: | |
3168 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3165 | repo.savecommitmessage('\n* * *\n'.join(msgs)) | |
3169 | if dsguard: |
|
3166 | return ret | |
3170 | dsguard.close() |
|
|||
3171 | return ret |
|
|||
3172 | finally: |
|
|||
3173 | if tr: |
|
|||
3174 | tr.release() |
|
|||
3175 | release(lock, dsguard) |
|
|||
3176 |
|
3167 | |||
3177 | @command('incoming|in', |
|
3168 | @command('incoming|in', | |
3178 | [('f', 'force', None, |
|
3169 | [('f', 'force', None, | |
3179 | _('run even if remote repository is unrelated')), |
|
3170 | _('run even if remote repository is unrelated')), | |
3180 | ('n', 'newest-first', None, _('show newest record first')), |
|
3171 | ('n', 'newest-first', None, _('show newest record first')), | |
3181 | ('', 'bundle', '', |
|
3172 | ('', 'bundle', '', | |
3182 | _('file to store the bundles into'), _('FILE')), |
|
3173 | _('file to store the bundles into'), _('FILE')), | |
3183 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3174 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
3184 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3175 | ('B', 'bookmarks', False, _("compare bookmarks")), | |
3185 | ('b', 'branch', [], |
|
3176 | ('b', 'branch', [], | |
3186 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3177 | _('a specific branch you would like to pull'), _('BRANCH')), | |
3187 | ] + logopts + remoteopts + subrepoopts, |
|
3178 | ] + logopts + remoteopts + subrepoopts, | |
3188 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3179 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) | |
3189 | def incoming(ui, repo, source="default", **opts): |
|
3180 | def incoming(ui, repo, source="default", **opts): | |
3190 | """show new changesets found in source |
|
3181 | """show new changesets found in source | |
3191 |
|
3182 | |||
3192 | Show new changesets found in the specified path/URL or the default |
|
3183 | Show new changesets found in the specified path/URL or the default | |
3193 | pull location. These are the changesets that would have been pulled |
|
3184 | pull location. These are the changesets that would have been pulled | |
3194 | by :hg:`pull` at the time you issued this command. |
|
3185 | by :hg:`pull` at the time you issued this command. | |
3195 |
|
3186 | |||
3196 | See pull for valid source format details. |
|
3187 | See pull for valid source format details. | |
3197 |
|
3188 | |||
3198 | .. container:: verbose |
|
3189 | .. container:: verbose | |
3199 |
|
3190 | |||
3200 | With -B/--bookmarks, the result of bookmark comparison between |
|
3191 | With -B/--bookmarks, the result of bookmark comparison between | |
3201 | local and remote repositories is displayed. With -v/--verbose, |
|
3192 | local and remote repositories is displayed. With -v/--verbose, | |
3202 | status is also displayed for each bookmark like below:: |
|
3193 | status is also displayed for each bookmark like below:: | |
3203 |
|
3194 | |||
3204 | BM1 01234567890a added |
|
3195 | BM1 01234567890a added | |
3205 | BM2 1234567890ab advanced |
|
3196 | BM2 1234567890ab advanced | |
3206 | BM3 234567890abc diverged |
|
3197 | BM3 234567890abc diverged | |
3207 | BM4 34567890abcd changed |
|
3198 | BM4 34567890abcd changed | |
3208 |
|
3199 | |||
3209 | The action taken locally when pulling depends on the |
|
3200 | The action taken locally when pulling depends on the | |
3210 | status of each bookmark: |
|
3201 | status of each bookmark: | |
3211 |
|
3202 | |||
3212 | :``added``: pull will create it |
|
3203 | :``added``: pull will create it | |
3213 | :``advanced``: pull will update it |
|
3204 | :``advanced``: pull will update it | |
3214 | :``diverged``: pull will create a divergent bookmark |
|
3205 | :``diverged``: pull will create a divergent bookmark | |
3215 | :``changed``: result depends on remote changesets |
|
3206 | :``changed``: result depends on remote changesets | |
3216 |
|
3207 | |||
3217 | From the point of view of pulling behavior, bookmark |
|
3208 | From the point of view of pulling behavior, bookmark | |
3218 | existing only in the remote repository are treated as ``added``, |
|
3209 | existing only in the remote repository are treated as ``added``, | |
3219 | even if it is in fact locally deleted. |
|
3210 | even if it is in fact locally deleted. | |
3220 |
|
3211 | |||
3221 | .. container:: verbose |
|
3212 | .. container:: verbose | |
3222 |
|
3213 | |||
3223 | For remote repository, using --bundle avoids downloading the |
|
3214 | For remote repository, using --bundle avoids downloading the | |
3224 | changesets twice if the incoming is followed by a pull. |
|
3215 | changesets twice if the incoming is followed by a pull. | |
3225 |
|
3216 | |||
3226 | Examples: |
|
3217 | Examples: | |
3227 |
|
3218 | |||
3228 | - show incoming changes with patches and full description:: |
|
3219 | - show incoming changes with patches and full description:: | |
3229 |
|
3220 | |||
3230 | hg incoming -vp |
|
3221 | hg incoming -vp | |
3231 |
|
3222 | |||
3232 | - show incoming changes excluding merges, store a bundle:: |
|
3223 | - show incoming changes excluding merges, store a bundle:: | |
3233 |
|
3224 | |||
3234 | hg in -vpM --bundle incoming.hg |
|
3225 | hg in -vpM --bundle incoming.hg | |
3235 | hg pull incoming.hg |
|
3226 | hg pull incoming.hg | |
3236 |
|
3227 | |||
3237 | - briefly list changes inside a bundle:: |
|
3228 | - briefly list changes inside a bundle:: | |
3238 |
|
3229 | |||
3239 | hg in changes.hg -T "{desc|firstline}\\n" |
|
3230 | hg in changes.hg -T "{desc|firstline}\\n" | |
3240 |
|
3231 | |||
3241 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3232 | Returns 0 if there are incoming changes, 1 otherwise. | |
3242 | """ |
|
3233 | """ | |
3243 | opts = pycompat.byteskwargs(opts) |
|
3234 | opts = pycompat.byteskwargs(opts) | |
3244 | if opts.get('graph'): |
|
3235 | if opts.get('graph'): | |
3245 | logcmdutil.checkunsupportedgraphflags([], opts) |
|
3236 | logcmdutil.checkunsupportedgraphflags([], opts) | |
3246 | def display(other, chlist, displayer): |
|
3237 | def display(other, chlist, displayer): | |
3247 | revdag = logcmdutil.graphrevs(other, chlist, opts) |
|
3238 | revdag = logcmdutil.graphrevs(other, chlist, opts) | |
3248 | logcmdutil.displaygraph(ui, repo, revdag, displayer, |
|
3239 | logcmdutil.displaygraph(ui, repo, revdag, displayer, | |
3249 | graphmod.asciiedges) |
|
3240 | graphmod.asciiedges) | |
3250 |
|
3241 | |||
3251 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
3242 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) | |
3252 | return 0 |
|
3243 | return 0 | |
3253 |
|
3244 | |||
3254 | if opts.get('bundle') and opts.get('subrepos'): |
|
3245 | if opts.get('bundle') and opts.get('subrepos'): | |
3255 | raise error.Abort(_('cannot combine --bundle and --subrepos')) |
|
3246 | raise error.Abort(_('cannot combine --bundle and --subrepos')) | |
3256 |
|
3247 | |||
3257 | if opts.get('bookmarks'): |
|
3248 | if opts.get('bookmarks'): | |
3258 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3249 | source, branches = hg.parseurl(ui.expandpath(source), | |
3259 | opts.get('branch')) |
|
3250 | opts.get('branch')) | |
3260 | other = hg.peer(repo, opts, source) |
|
3251 | other = hg.peer(repo, opts, source) | |
3261 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3252 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3262 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3253 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3263 | return 0 |
|
3254 | return 0 | |
3264 | ui.pager('incoming') |
|
3255 | ui.pager('incoming') | |
3265 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3256 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | |
3266 | return bookmarks.incoming(ui, repo, other) |
|
3257 | return bookmarks.incoming(ui, repo, other) | |
3267 |
|
3258 | |||
3268 | repo._subtoppath = ui.expandpath(source) |
|
3259 | repo._subtoppath = ui.expandpath(source) | |
3269 | try: |
|
3260 | try: | |
3270 | return hg.incoming(ui, repo, source, opts) |
|
3261 | return hg.incoming(ui, repo, source, opts) | |
3271 | finally: |
|
3262 | finally: | |
3272 | del repo._subtoppath |
|
3263 | del repo._subtoppath | |
3273 |
|
3264 | |||
3274 |
|
3265 | |||
3275 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), |
|
3266 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), | |
3276 | norepo=True) |
|
3267 | norepo=True) | |
3277 | def init(ui, dest=".", **opts): |
|
3268 | def init(ui, dest=".", **opts): | |
3278 | """create a new repository in the given directory |
|
3269 | """create a new repository in the given directory | |
3279 |
|
3270 | |||
3280 | Initialize a new repository in the given directory. If the given |
|
3271 | Initialize a new repository in the given directory. If the given | |
3281 | directory does not exist, it will be created. |
|
3272 | directory does not exist, it will be created. | |
3282 |
|
3273 | |||
3283 | If no directory is given, the current directory is used. |
|
3274 | If no directory is given, the current directory is used. | |
3284 |
|
3275 | |||
3285 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3276 | It is possible to specify an ``ssh://`` URL as the destination. | |
3286 | See :hg:`help urls` for more information. |
|
3277 | See :hg:`help urls` for more information. | |
3287 |
|
3278 | |||
3288 | Returns 0 on success. |
|
3279 | Returns 0 on success. | |
3289 | """ |
|
3280 | """ | |
3290 | opts = pycompat.byteskwargs(opts) |
|
3281 | opts = pycompat.byteskwargs(opts) | |
3291 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
3282 | hg.peer(ui, opts, ui.expandpath(dest), create=True) | |
3292 |
|
3283 | |||
3293 | @command('locate', |
|
3284 | @command('locate', | |
3294 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3285 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | |
3295 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3286 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
3296 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3287 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), | |
3297 | ] + walkopts, |
|
3288 | ] + walkopts, | |
3298 | _('[OPTION]... [PATTERN]...')) |
|
3289 | _('[OPTION]... [PATTERN]...')) | |
3299 | def locate(ui, repo, *pats, **opts): |
|
3290 | def locate(ui, repo, *pats, **opts): | |
3300 | """locate files matching specific patterns (DEPRECATED) |
|
3291 | """locate files matching specific patterns (DEPRECATED) | |
3301 |
|
3292 | |||
3302 | Print files under Mercurial control in the working directory whose |
|
3293 | Print files under Mercurial control in the working directory whose | |
3303 | names match the given patterns. |
|
3294 | names match the given patterns. | |
3304 |
|
3295 | |||
3305 | By default, this command searches all directories in the working |
|
3296 | By default, this command searches all directories in the working | |
3306 | directory. To search just the current directory and its |
|
3297 | directory. To search just the current directory and its | |
3307 | subdirectories, use "--include .". |
|
3298 | subdirectories, use "--include .". | |
3308 |
|
3299 | |||
3309 | If no patterns are given to match, this command prints the names |
|
3300 | If no patterns are given to match, this command prints the names | |
3310 | of all files under Mercurial control in the working directory. |
|
3301 | of all files under Mercurial control in the working directory. | |
3311 |
|
3302 | |||
3312 | If you want to feed the output of this command into the "xargs" |
|
3303 | If you want to feed the output of this command into the "xargs" | |
3313 | command, use the -0 option to both this command and "xargs". This |
|
3304 | command, use the -0 option to both this command and "xargs". This | |
3314 | will avoid the problem of "xargs" treating single filenames that |
|
3305 | will avoid the problem of "xargs" treating single filenames that | |
3315 | contain whitespace as multiple filenames. |
|
3306 | contain whitespace as multiple filenames. | |
3316 |
|
3307 | |||
3317 | See :hg:`help files` for a more versatile command. |
|
3308 | See :hg:`help files` for a more versatile command. | |
3318 |
|
3309 | |||
3319 | Returns 0 if a match is found, 1 otherwise. |
|
3310 | Returns 0 if a match is found, 1 otherwise. | |
3320 | """ |
|
3311 | """ | |
3321 | opts = pycompat.byteskwargs(opts) |
|
3312 | opts = pycompat.byteskwargs(opts) | |
3322 | if opts.get('print0'): |
|
3313 | if opts.get('print0'): | |
3323 | end = '\0' |
|
3314 | end = '\0' | |
3324 | else: |
|
3315 | else: | |
3325 | end = '\n' |
|
3316 | end = '\n' | |
3326 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3317 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | |
3327 |
|
3318 | |||
3328 | ret = 1 |
|
3319 | ret = 1 | |
3329 | m = scmutil.match(ctx, pats, opts, default='relglob', |
|
3320 | m = scmutil.match(ctx, pats, opts, default='relglob', | |
3330 | badfn=lambda x, y: False) |
|
3321 | badfn=lambda x, y: False) | |
3331 |
|
3322 | |||
3332 | ui.pager('locate') |
|
3323 | ui.pager('locate') | |
3333 | if ctx.rev() is None: |
|
3324 | if ctx.rev() is None: | |
3334 | # When run on the working copy, "locate" includes removed files, so |
|
3325 | # When run on the working copy, "locate" includes removed files, so | |
3335 | # we get the list of files from the dirstate. |
|
3326 | # we get the list of files from the dirstate. | |
3336 | filesgen = sorted(repo.dirstate.matches(m)) |
|
3327 | filesgen = sorted(repo.dirstate.matches(m)) | |
3337 | else: |
|
3328 | else: | |
3338 | filesgen = ctx.matches(m) |
|
3329 | filesgen = ctx.matches(m) | |
3339 | for abs in filesgen: |
|
3330 | for abs in filesgen: | |
3340 | if opts.get('fullpath'): |
|
3331 | if opts.get('fullpath'): | |
3341 | ui.write(repo.wjoin(abs), end) |
|
3332 | ui.write(repo.wjoin(abs), end) | |
3342 | else: |
|
3333 | else: | |
3343 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3334 | ui.write(((pats and m.rel(abs)) or abs), end) | |
3344 | ret = 0 |
|
3335 | ret = 0 | |
3345 |
|
3336 | |||
3346 | return ret |
|
3337 | return ret | |
3347 |
|
3338 | |||
3348 | @command('^log|history', |
|
3339 | @command('^log|history', | |
3349 | [('f', 'follow', None, |
|
3340 | [('f', 'follow', None, | |
3350 | _('follow changeset history, or file history across copies and renames')), |
|
3341 | _('follow changeset history, or file history across copies and renames')), | |
3351 | ('', 'follow-first', None, |
|
3342 | ('', 'follow-first', None, | |
3352 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
3343 | _('only follow the first parent of merge changesets (DEPRECATED)')), | |
3353 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3344 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), | |
3354 | ('C', 'copies', None, _('show copied files')), |
|
3345 | ('C', 'copies', None, _('show copied files')), | |
3355 | ('k', 'keyword', [], |
|
3346 | ('k', 'keyword', [], | |
3356 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3347 | _('do case-insensitive search for a given text'), _('TEXT')), | |
3357 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), |
|
3348 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), | |
3358 | ('L', 'line-range', [], |
|
3349 | ('L', 'line-range', [], | |
3359 | _('follow line range of specified file (EXPERIMENTAL)'), |
|
3350 | _('follow line range of specified file (EXPERIMENTAL)'), | |
3360 | _('FILE,RANGE')), |
|
3351 | _('FILE,RANGE')), | |
3361 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3352 | ('', 'removed', None, _('include revisions where files were removed')), | |
3362 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
3353 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), | |
3363 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3354 | ('u', 'user', [], _('revisions committed by user'), _('USER')), | |
3364 | ('', 'only-branch', [], |
|
3355 | ('', 'only-branch', [], | |
3365 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3356 | _('show only changesets within the given named branch (DEPRECATED)'), | |
3366 | _('BRANCH')), |
|
3357 | _('BRANCH')), | |
3367 | ('b', 'branch', [], |
|
3358 | ('b', 'branch', [], | |
3368 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3359 | _('show changesets within the given named branch'), _('BRANCH')), | |
3369 | ('P', 'prune', [], |
|
3360 | ('P', 'prune', [], | |
3370 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3361 | _('do not display revision or any of its ancestors'), _('REV')), | |
3371 | ] + logopts + walkopts, |
|
3362 | ] + logopts + walkopts, | |
3372 | _('[OPTION]... [FILE]'), |
|
3363 | _('[OPTION]... [FILE]'), | |
3373 | inferrepo=True, |
|
3364 | inferrepo=True, | |
3374 | intents={INTENT_READONLY}) |
|
3365 | intents={INTENT_READONLY}) | |
3375 | def log(ui, repo, *pats, **opts): |
|
3366 | def log(ui, repo, *pats, **opts): | |
3376 | """show revision history of entire repository or files |
|
3367 | """show revision history of entire repository or files | |
3377 |
|
3368 | |||
3378 | Print the revision history of the specified files or the entire |
|
3369 | Print the revision history of the specified files or the entire | |
3379 | project. |
|
3370 | project. | |
3380 |
|
3371 | |||
3381 | If no revision range is specified, the default is ``tip:0`` unless |
|
3372 | If no revision range is specified, the default is ``tip:0`` unless | |
3382 | --follow is set, in which case the working directory parent is |
|
3373 | --follow is set, in which case the working directory parent is | |
3383 | used as the starting revision. |
|
3374 | used as the starting revision. | |
3384 |
|
3375 | |||
3385 | File history is shown without following rename or copy history of |
|
3376 | File history is shown without following rename or copy history of | |
3386 | files. Use -f/--follow with a filename to follow history across |
|
3377 | files. Use -f/--follow with a filename to follow history across | |
3387 | renames and copies. --follow without a filename will only show |
|
3378 | renames and copies. --follow without a filename will only show | |
3388 | ancestors of the starting revision. |
|
3379 | ancestors of the starting revision. | |
3389 |
|
3380 | |||
3390 | By default this command prints revision number and changeset id, |
|
3381 | By default this command prints revision number and changeset id, | |
3391 | tags, non-trivial parents, user, date and time, and a summary for |
|
3382 | tags, non-trivial parents, user, date and time, and a summary for | |
3392 | each commit. When the -v/--verbose switch is used, the list of |
|
3383 | each commit. When the -v/--verbose switch is used, the list of | |
3393 | changed files and full commit message are shown. |
|
3384 | changed files and full commit message are shown. | |
3394 |
|
3385 | |||
3395 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
3386 | With --graph the revisions are shown as an ASCII art DAG with the most | |
3396 | recent changeset at the top. |
|
3387 | recent changeset at the top. | |
3397 | 'o' is a changeset, '@' is a working directory parent, '_' closes a branch, |
|
3388 | 'o' is a changeset, '@' is a working directory parent, '_' closes a branch, | |
3398 | 'x' is obsolete, '*' is unstable, and '+' represents a fork where the |
|
3389 | 'x' is obsolete, '*' is unstable, and '+' represents a fork where the | |
3399 | changeset from the lines below is a parent of the 'o' merge on the same |
|
3390 | changeset from the lines below is a parent of the 'o' merge on the same | |
3400 | line. |
|
3391 | line. | |
3401 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place |
|
3392 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place | |
3402 | of a '|' indicates one or more revisions in a path are omitted. |
|
3393 | of a '|' indicates one or more revisions in a path are omitted. | |
3403 |
|
3394 | |||
3404 | .. container:: verbose |
|
3395 | .. container:: verbose | |
3405 |
|
3396 | |||
3406 | Use -L/--line-range FILE,M:N options to follow the history of lines |
|
3397 | Use -L/--line-range FILE,M:N options to follow the history of lines | |
3407 | from M to N in FILE. With -p/--patch only diff hunks affecting |
|
3398 | from M to N in FILE. With -p/--patch only diff hunks affecting | |
3408 | specified line range will be shown. This option requires --follow; |
|
3399 | specified line range will be shown. This option requires --follow; | |
3409 | it can be specified multiple times. Currently, this option is not |
|
3400 | it can be specified multiple times. Currently, this option is not | |
3410 | compatible with --graph. This option is experimental. |
|
3401 | compatible with --graph. This option is experimental. | |
3411 |
|
3402 | |||
3412 | .. note:: |
|
3403 | .. note:: | |
3413 |
|
3404 | |||
3414 | :hg:`log --patch` may generate unexpected diff output for merge |
|
3405 | :hg:`log --patch` may generate unexpected diff output for merge | |
3415 | changesets, as it will only compare the merge changeset against |
|
3406 | changesets, as it will only compare the merge changeset against | |
3416 | its first parent. Also, only files different from BOTH parents |
|
3407 | its first parent. Also, only files different from BOTH parents | |
3417 | will appear in files:. |
|
3408 | will appear in files:. | |
3418 |
|
3409 | |||
3419 | .. note:: |
|
3410 | .. note:: | |
3420 |
|
3411 | |||
3421 | For performance reasons, :hg:`log FILE` may omit duplicate changes |
|
3412 | For performance reasons, :hg:`log FILE` may omit duplicate changes | |
3422 | made on branches and will not show removals or mode changes. To |
|
3413 | made on branches and will not show removals or mode changes. To | |
3423 | see all such changes, use the --removed switch. |
|
3414 | see all such changes, use the --removed switch. | |
3424 |
|
3415 | |||
3425 | .. container:: verbose |
|
3416 | .. container:: verbose | |
3426 |
|
3417 | |||
3427 | .. note:: |
|
3418 | .. note:: | |
3428 |
|
3419 | |||
3429 | The history resulting from -L/--line-range options depends on diff |
|
3420 | The history resulting from -L/--line-range options depends on diff | |
3430 | options; for instance if white-spaces are ignored, respective changes |
|
3421 | options; for instance if white-spaces are ignored, respective changes | |
3431 | with only white-spaces in specified line range will not be listed. |
|
3422 | with only white-spaces in specified line range will not be listed. | |
3432 |
|
3423 | |||
3433 | .. container:: verbose |
|
3424 | .. container:: verbose | |
3434 |
|
3425 | |||
3435 | Some examples: |
|
3426 | Some examples: | |
3436 |
|
3427 | |||
3437 | - changesets with full descriptions and file lists:: |
|
3428 | - changesets with full descriptions and file lists:: | |
3438 |
|
3429 | |||
3439 | hg log -v |
|
3430 | hg log -v | |
3440 |
|
3431 | |||
3441 | - changesets ancestral to the working directory:: |
|
3432 | - changesets ancestral to the working directory:: | |
3442 |
|
3433 | |||
3443 | hg log -f |
|
3434 | hg log -f | |
3444 |
|
3435 | |||
3445 | - last 10 commits on the current branch:: |
|
3436 | - last 10 commits on the current branch:: | |
3446 |
|
3437 | |||
3447 | hg log -l 10 -b . |
|
3438 | hg log -l 10 -b . | |
3448 |
|
3439 | |||
3449 | - changesets showing all modifications of a file, including removals:: |
|
3440 | - changesets showing all modifications of a file, including removals:: | |
3450 |
|
3441 | |||
3451 | hg log --removed file.c |
|
3442 | hg log --removed file.c | |
3452 |
|
3443 | |||
3453 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
3444 | - all changesets that touch a directory, with diffs, excluding merges:: | |
3454 |
|
3445 | |||
3455 | hg log -Mp lib/ |
|
3446 | hg log -Mp lib/ | |
3456 |
|
3447 | |||
3457 | - all revision numbers that match a keyword:: |
|
3448 | - all revision numbers that match a keyword:: | |
3458 |
|
3449 | |||
3459 | hg log -k bug --template "{rev}\\n" |
|
3450 | hg log -k bug --template "{rev}\\n" | |
3460 |
|
3451 | |||
3461 | - the full hash identifier of the working directory parent:: |
|
3452 | - the full hash identifier of the working directory parent:: | |
3462 |
|
3453 | |||
3463 | hg log -r . --template "{node}\\n" |
|
3454 | hg log -r . --template "{node}\\n" | |
3464 |
|
3455 | |||
3465 | - list available log templates:: |
|
3456 | - list available log templates:: | |
3466 |
|
3457 | |||
3467 | hg log -T list |
|
3458 | hg log -T list | |
3468 |
|
3459 | |||
3469 | - check if a given changeset is included in a tagged release:: |
|
3460 | - check if a given changeset is included in a tagged release:: | |
3470 |
|
3461 | |||
3471 | hg log -r "a21ccf and ancestor(1.9)" |
|
3462 | hg log -r "a21ccf and ancestor(1.9)" | |
3472 |
|
3463 | |||
3473 | - find all changesets by some user in a date range:: |
|
3464 | - find all changesets by some user in a date range:: | |
3474 |
|
3465 | |||
3475 | hg log -k alice -d "may 2008 to jul 2008" |
|
3466 | hg log -k alice -d "may 2008 to jul 2008" | |
3476 |
|
3467 | |||
3477 | - summary of all changesets after the last tag:: |
|
3468 | - summary of all changesets after the last tag:: | |
3478 |
|
3469 | |||
3479 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
3470 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" | |
3480 |
|
3471 | |||
3481 | - changesets touching lines 13 to 23 for file.c:: |
|
3472 | - changesets touching lines 13 to 23 for file.c:: | |
3482 |
|
3473 | |||
3483 | hg log -L file.c,13:23 |
|
3474 | hg log -L file.c,13:23 | |
3484 |
|
3475 | |||
3485 | - changesets touching lines 13 to 23 for file.c and lines 2 to 6 of |
|
3476 | - changesets touching lines 13 to 23 for file.c and lines 2 to 6 of | |
3486 | main.c with patch:: |
|
3477 | main.c with patch:: | |
3487 |
|
3478 | |||
3488 | hg log -L file.c,13:23 -L main.c,2:6 -p |
|
3479 | hg log -L file.c,13:23 -L main.c,2:6 -p | |
3489 |
|
3480 | |||
3490 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3481 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
3491 |
|
3482 | |||
3492 | See :hg:`help revisions` for more about specifying and ordering |
|
3483 | See :hg:`help revisions` for more about specifying and ordering | |
3493 | revisions. |
|
3484 | revisions. | |
3494 |
|
3485 | |||
3495 | See :hg:`help templates` for more about pre-packaged styles and |
|
3486 | See :hg:`help templates` for more about pre-packaged styles and | |
3496 | specifying custom templates. The default template used by the log |
|
3487 | specifying custom templates. The default template used by the log | |
3497 | command can be customized via the ``ui.logtemplate`` configuration |
|
3488 | command can be customized via the ``ui.logtemplate`` configuration | |
3498 | setting. |
|
3489 | setting. | |
3499 |
|
3490 | |||
3500 | Returns 0 on success. |
|
3491 | Returns 0 on success. | |
3501 |
|
3492 | |||
3502 | """ |
|
3493 | """ | |
3503 | opts = pycompat.byteskwargs(opts) |
|
3494 | opts = pycompat.byteskwargs(opts) | |
3504 | linerange = opts.get('line_range') |
|
3495 | linerange = opts.get('line_range') | |
3505 |
|
3496 | |||
3506 | if linerange and not opts.get('follow'): |
|
3497 | if linerange and not opts.get('follow'): | |
3507 | raise error.Abort(_('--line-range requires --follow')) |
|
3498 | raise error.Abort(_('--line-range requires --follow')) | |
3508 |
|
3499 | |||
3509 | if linerange and pats: |
|
3500 | if linerange and pats: | |
3510 | # TODO: take pats as patterns with no line-range filter |
|
3501 | # TODO: take pats as patterns with no line-range filter | |
3511 | raise error.Abort( |
|
3502 | raise error.Abort( | |
3512 | _('FILE arguments are not compatible with --line-range option') |
|
3503 | _('FILE arguments are not compatible with --line-range option') | |
3513 | ) |
|
3504 | ) | |
3514 |
|
3505 | |||
3515 | repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn') |
|
3506 | repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn') | |
3516 | revs, differ = logcmdutil.getrevs(repo, pats, opts) |
|
3507 | revs, differ = logcmdutil.getrevs(repo, pats, opts) | |
3517 | if linerange: |
|
3508 | if linerange: | |
3518 | # TODO: should follow file history from logcmdutil._initialrevs(), |
|
3509 | # TODO: should follow file history from logcmdutil._initialrevs(), | |
3519 | # then filter the result by logcmdutil._makerevset() and --limit |
|
3510 | # then filter the result by logcmdutil._makerevset() and --limit | |
3520 | revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) |
|
3511 | revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts) | |
3521 |
|
3512 | |||
3522 | getrenamed = None |
|
3513 | getrenamed = None | |
3523 | if opts.get('copies'): |
|
3514 | if opts.get('copies'): | |
3524 | endrev = None |
|
3515 | endrev = None | |
3525 | if revs: |
|
3516 | if revs: | |
3526 | endrev = revs.max() + 1 |
|
3517 | endrev = revs.max() + 1 | |
3527 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3518 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | |
3528 |
|
3519 | |||
3529 | ui.pager('log') |
|
3520 | ui.pager('log') | |
3530 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ, |
|
3521 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ, | |
3531 | buffered=True) |
|
3522 | buffered=True) | |
3532 | if opts.get('graph'): |
|
3523 | if opts.get('graph'): | |
3533 | displayfn = logcmdutil.displaygraphrevs |
|
3524 | displayfn = logcmdutil.displaygraphrevs | |
3534 | else: |
|
3525 | else: | |
3535 | displayfn = logcmdutil.displayrevs |
|
3526 | displayfn = logcmdutil.displayrevs | |
3536 | displayfn(ui, repo, revs, displayer, getrenamed) |
|
3527 | displayfn(ui, repo, revs, displayer, getrenamed) | |
3537 |
|
3528 | |||
3538 | @command('manifest', |
|
3529 | @command('manifest', | |
3539 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
3530 | [('r', 'rev', '', _('revision to display'), _('REV')), | |
3540 | ('', 'all', False, _("list files from all revisions"))] |
|
3531 | ('', 'all', False, _("list files from all revisions"))] | |
3541 | + formatteropts, |
|
3532 | + formatteropts, | |
3542 | _('[-r REV]'), |
|
3533 | _('[-r REV]'), | |
3543 | intents={INTENT_READONLY}) |
|
3534 | intents={INTENT_READONLY}) | |
3544 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
3535 | def manifest(ui, repo, node=None, rev=None, **opts): | |
3545 | """output the current or given revision of the project manifest |
|
3536 | """output the current or given revision of the project manifest | |
3546 |
|
3537 | |||
3547 | Print a list of version controlled files for the given revision. |
|
3538 | Print a list of version controlled files for the given revision. | |
3548 | If no revision is given, the first parent of the working directory |
|
3539 | If no revision is given, the first parent of the working directory | |
3549 | is used, or the null revision if no revision is checked out. |
|
3540 | is used, or the null revision if no revision is checked out. | |
3550 |
|
3541 | |||
3551 | With -v, print file permissions, symlink and executable bits. |
|
3542 | With -v, print file permissions, symlink and executable bits. | |
3552 | With --debug, print file revision hashes. |
|
3543 | With --debug, print file revision hashes. | |
3553 |
|
3544 | |||
3554 | If option --all is specified, the list of all files from all revisions |
|
3545 | If option --all is specified, the list of all files from all revisions | |
3555 | is printed. This includes deleted and renamed files. |
|
3546 | is printed. This includes deleted and renamed files. | |
3556 |
|
3547 | |||
3557 | Returns 0 on success. |
|
3548 | Returns 0 on success. | |
3558 | """ |
|
3549 | """ | |
3559 | opts = pycompat.byteskwargs(opts) |
|
3550 | opts = pycompat.byteskwargs(opts) | |
3560 | fm = ui.formatter('manifest', opts) |
|
3551 | fm = ui.formatter('manifest', opts) | |
3561 |
|
3552 | |||
3562 | if opts.get('all'): |
|
3553 | if opts.get('all'): | |
3563 | if rev or node: |
|
3554 | if rev or node: | |
3564 | raise error.Abort(_("can't specify a revision with --all")) |
|
3555 | raise error.Abort(_("can't specify a revision with --all")) | |
3565 |
|
3556 | |||
3566 | res = set() |
|
3557 | res = set() | |
3567 | for rev in repo: |
|
3558 | for rev in repo: | |
3568 | ctx = repo[rev] |
|
3559 | ctx = repo[rev] | |
3569 | res |= set(ctx.files()) |
|
3560 | res |= set(ctx.files()) | |
3570 |
|
3561 | |||
3571 | ui.pager('manifest') |
|
3562 | ui.pager('manifest') | |
3572 | for f in sorted(res): |
|
3563 | for f in sorted(res): | |
3573 | fm.startitem() |
|
3564 | fm.startitem() | |
3574 | fm.write("path", '%s\n', f) |
|
3565 | fm.write("path", '%s\n', f) | |
3575 | fm.end() |
|
3566 | fm.end() | |
3576 | return |
|
3567 | return | |
3577 |
|
3568 | |||
3578 | if rev and node: |
|
3569 | if rev and node: | |
3579 | raise error.Abort(_("please specify just one revision")) |
|
3570 | raise error.Abort(_("please specify just one revision")) | |
3580 |
|
3571 | |||
3581 | if not node: |
|
3572 | if not node: | |
3582 | node = rev |
|
3573 | node = rev | |
3583 |
|
3574 | |||
3584 | char = {'l': '@', 'x': '*', '': '', 't': 'd'} |
|
3575 | char = {'l': '@', 'x': '*', '': '', 't': 'd'} | |
3585 | mode = {'l': '644', 'x': '755', '': '644', 't': '755'} |
|
3576 | mode = {'l': '644', 'x': '755', '': '644', 't': '755'} | |
3586 | if node: |
|
3577 | if node: | |
3587 | repo = scmutil.unhidehashlikerevs(repo, [node], 'nowarn') |
|
3578 | repo = scmutil.unhidehashlikerevs(repo, [node], 'nowarn') | |
3588 | ctx = scmutil.revsingle(repo, node) |
|
3579 | ctx = scmutil.revsingle(repo, node) | |
3589 | mf = ctx.manifest() |
|
3580 | mf = ctx.manifest() | |
3590 | ui.pager('manifest') |
|
3581 | ui.pager('manifest') | |
3591 | for f in ctx: |
|
3582 | for f in ctx: | |
3592 | fm.startitem() |
|
3583 | fm.startitem() | |
3593 | fl = ctx[f].flags() |
|
3584 | fl = ctx[f].flags() | |
3594 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) |
|
3585 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) | |
3595 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) |
|
3586 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) | |
3596 | fm.write('path', '%s\n', f) |
|
3587 | fm.write('path', '%s\n', f) | |
3597 | fm.end() |
|
3588 | fm.end() | |
3598 |
|
3589 | |||
3599 | @command('^merge', |
|
3590 | @command('^merge', | |
3600 | [('f', 'force', None, |
|
3591 | [('f', 'force', None, | |
3601 | _('force a merge including outstanding changes (DEPRECATED)')), |
|
3592 | _('force a merge including outstanding changes (DEPRECATED)')), | |
3602 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
3593 | ('r', 'rev', '', _('revision to merge'), _('REV')), | |
3603 | ('P', 'preview', None, |
|
3594 | ('P', 'preview', None, | |
3604 | _('review revisions to merge (no merge is performed)')), |
|
3595 | _('review revisions to merge (no merge is performed)')), | |
3605 | ('', 'abort', None, _('abort the ongoing merge')), |
|
3596 | ('', 'abort', None, _('abort the ongoing merge')), | |
3606 | ] + mergetoolopts, |
|
3597 | ] + mergetoolopts, | |
3607 | _('[-P] [[-r] REV]')) |
|
3598 | _('[-P] [[-r] REV]')) | |
3608 | def merge(ui, repo, node=None, **opts): |
|
3599 | def merge(ui, repo, node=None, **opts): | |
3609 | """merge another revision into working directory |
|
3600 | """merge another revision into working directory | |
3610 |
|
3601 | |||
3611 | The current working directory is updated with all changes made in |
|
3602 | The current working directory is updated with all changes made in | |
3612 | the requested revision since the last common predecessor revision. |
|
3603 | the requested revision since the last common predecessor revision. | |
3613 |
|
3604 | |||
3614 | Files that changed between either parent are marked as changed for |
|
3605 | Files that changed between either parent are marked as changed for | |
3615 | the next commit and a commit must be performed before any further |
|
3606 | the next commit and a commit must be performed before any further | |
3616 | updates to the repository are allowed. The next commit will have |
|
3607 | updates to the repository are allowed. The next commit will have | |
3617 | two parents. |
|
3608 | two parents. | |
3618 |
|
3609 | |||
3619 | ``--tool`` can be used to specify the merge tool used for file |
|
3610 | ``--tool`` can be used to specify the merge tool used for file | |
3620 | merges. It overrides the HGMERGE environment variable and your |
|
3611 | merges. It overrides the HGMERGE environment variable and your | |
3621 | configuration files. See :hg:`help merge-tools` for options. |
|
3612 | configuration files. See :hg:`help merge-tools` for options. | |
3622 |
|
3613 | |||
3623 | If no revision is specified, the working directory's parent is a |
|
3614 | If no revision is specified, the working directory's parent is a | |
3624 | head revision, and the current branch contains exactly one other |
|
3615 | head revision, and the current branch contains exactly one other | |
3625 | head, the other head is merged with by default. Otherwise, an |
|
3616 | head, the other head is merged with by default. Otherwise, an | |
3626 | explicit revision with which to merge with must be provided. |
|
3617 | explicit revision with which to merge with must be provided. | |
3627 |
|
3618 | |||
3628 | See :hg:`help resolve` for information on handling file conflicts. |
|
3619 | See :hg:`help resolve` for information on handling file conflicts. | |
3629 |
|
3620 | |||
3630 | To undo an uncommitted merge, use :hg:`merge --abort` which |
|
3621 | To undo an uncommitted merge, use :hg:`merge --abort` which | |
3631 | will check out a clean copy of the original merge parent, losing |
|
3622 | will check out a clean copy of the original merge parent, losing | |
3632 | all changes. |
|
3623 | all changes. | |
3633 |
|
3624 | |||
3634 | Returns 0 on success, 1 if there are unresolved files. |
|
3625 | Returns 0 on success, 1 if there are unresolved files. | |
3635 | """ |
|
3626 | """ | |
3636 |
|
3627 | |||
3637 | opts = pycompat.byteskwargs(opts) |
|
3628 | opts = pycompat.byteskwargs(opts) | |
3638 | abort = opts.get('abort') |
|
3629 | abort = opts.get('abort') | |
3639 | if abort and repo.dirstate.p2() == nullid: |
|
3630 | if abort and repo.dirstate.p2() == nullid: | |
3640 | cmdutil.wrongtooltocontinue(repo, _('merge')) |
|
3631 | cmdutil.wrongtooltocontinue(repo, _('merge')) | |
3641 | if abort: |
|
3632 | if abort: | |
3642 | if node: |
|
3633 | if node: | |
3643 | raise error.Abort(_("cannot specify a node with --abort")) |
|
3634 | raise error.Abort(_("cannot specify a node with --abort")) | |
3644 | if opts.get('rev'): |
|
3635 | if opts.get('rev'): | |
3645 | raise error.Abort(_("cannot specify both --rev and --abort")) |
|
3636 | raise error.Abort(_("cannot specify both --rev and --abort")) | |
3646 | if opts.get('preview'): |
|
3637 | if opts.get('preview'): | |
3647 | raise error.Abort(_("cannot specify --preview with --abort")) |
|
3638 | raise error.Abort(_("cannot specify --preview with --abort")) | |
3648 | if opts.get('rev') and node: |
|
3639 | if opts.get('rev') and node: | |
3649 | raise error.Abort(_("please specify just one revision")) |
|
3640 | raise error.Abort(_("please specify just one revision")) | |
3650 | if not node: |
|
3641 | if not node: | |
3651 | node = opts.get('rev') |
|
3642 | node = opts.get('rev') | |
3652 |
|
3643 | |||
3653 | if node: |
|
3644 | if node: | |
3654 | node = scmutil.revsingle(repo, node).node() |
|
3645 | node = scmutil.revsingle(repo, node).node() | |
3655 |
|
3646 | |||
3656 | if not node and not abort: |
|
3647 | if not node and not abort: | |
3657 | node = repo[destutil.destmerge(repo)].node() |
|
3648 | node = repo[destutil.destmerge(repo)].node() | |
3658 |
|
3649 | |||
3659 | if opts.get('preview'): |
|
3650 | if opts.get('preview'): | |
3660 | # find nodes that are ancestors of p2 but not of p1 |
|
3651 | # find nodes that are ancestors of p2 but not of p1 | |
3661 | p1 = repo.lookup('.') |
|
3652 | p1 = repo.lookup('.') | |
3662 | p2 = node |
|
3653 | p2 = node | |
3663 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
3654 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) | |
3664 |
|
3655 | |||
3665 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
3656 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | |
3666 | for node in nodes: |
|
3657 | for node in nodes: | |
3667 | displayer.show(repo[node]) |
|
3658 | displayer.show(repo[node]) | |
3668 | displayer.close() |
|
3659 | displayer.close() | |
3669 | return 0 |
|
3660 | return 0 | |
3670 |
|
3661 | |||
3671 | # ui.forcemerge is an internal variable, do not document |
|
3662 | # ui.forcemerge is an internal variable, do not document | |
3672 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
3663 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
3673 | with ui.configoverride(overrides, 'merge'): |
|
3664 | with ui.configoverride(overrides, 'merge'): | |
3674 | force = opts.get('force') |
|
3665 | force = opts.get('force') | |
3675 | labels = ['working copy', 'merge rev'] |
|
3666 | labels = ['working copy', 'merge rev'] | |
3676 | return hg.merge(repo, node, force=force, mergeforce=force, |
|
3667 | return hg.merge(repo, node, force=force, mergeforce=force, | |
3677 | labels=labels, abort=abort) |
|
3668 | labels=labels, abort=abort) | |
3678 |
|
3669 | |||
3679 | @command('outgoing|out', |
|
3670 | @command('outgoing|out', | |
3680 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
3671 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
3681 | ('r', 'rev', [], |
|
3672 | ('r', 'rev', [], | |
3682 | _('a changeset intended to be included in the destination'), _('REV')), |
|
3673 | _('a changeset intended to be included in the destination'), _('REV')), | |
3683 | ('n', 'newest-first', None, _('show newest record first')), |
|
3674 | ('n', 'newest-first', None, _('show newest record first')), | |
3684 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
3675 | ('B', 'bookmarks', False, _('compare bookmarks')), | |
3685 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
3676 | ('b', 'branch', [], _('a specific branch you would like to push'), | |
3686 | _('BRANCH')), |
|
3677 | _('BRANCH')), | |
3687 | ] + logopts + remoteopts + subrepoopts, |
|
3678 | ] + logopts + remoteopts + subrepoopts, | |
3688 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
3679 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) | |
3689 | def outgoing(ui, repo, dest=None, **opts): |
|
3680 | def outgoing(ui, repo, dest=None, **opts): | |
3690 | """show changesets not found in the destination |
|
3681 | """show changesets not found in the destination | |
3691 |
|
3682 | |||
3692 | Show changesets not found in the specified destination repository |
|
3683 | Show changesets not found in the specified destination repository | |
3693 | or the default push location. These are the changesets that would |
|
3684 | or the default push location. These are the changesets that would | |
3694 | be pushed if a push was requested. |
|
3685 | be pushed if a push was requested. | |
3695 |
|
3686 | |||
3696 | See pull for details of valid destination formats. |
|
3687 | See pull for details of valid destination formats. | |
3697 |
|
3688 | |||
3698 | .. container:: verbose |
|
3689 | .. container:: verbose | |
3699 |
|
3690 | |||
3700 | With -B/--bookmarks, the result of bookmark comparison between |
|
3691 | With -B/--bookmarks, the result of bookmark comparison between | |
3701 | local and remote repositories is displayed. With -v/--verbose, |
|
3692 | local and remote repositories is displayed. With -v/--verbose, | |
3702 | status is also displayed for each bookmark like below:: |
|
3693 | status is also displayed for each bookmark like below:: | |
3703 |
|
3694 | |||
3704 | BM1 01234567890a added |
|
3695 | BM1 01234567890a added | |
3705 | BM2 deleted |
|
3696 | BM2 deleted | |
3706 | BM3 234567890abc advanced |
|
3697 | BM3 234567890abc advanced | |
3707 | BM4 34567890abcd diverged |
|
3698 | BM4 34567890abcd diverged | |
3708 | BM5 4567890abcde changed |
|
3699 | BM5 4567890abcde changed | |
3709 |
|
3700 | |||
3710 | The action taken when pushing depends on the |
|
3701 | The action taken when pushing depends on the | |
3711 | status of each bookmark: |
|
3702 | status of each bookmark: | |
3712 |
|
3703 | |||
3713 | :``added``: push with ``-B`` will create it |
|
3704 | :``added``: push with ``-B`` will create it | |
3714 | :``deleted``: push with ``-B`` will delete it |
|
3705 | :``deleted``: push with ``-B`` will delete it | |
3715 | :``advanced``: push will update it |
|
3706 | :``advanced``: push will update it | |
3716 | :``diverged``: push with ``-B`` will update it |
|
3707 | :``diverged``: push with ``-B`` will update it | |
3717 | :``changed``: push with ``-B`` will update it |
|
3708 | :``changed``: push with ``-B`` will update it | |
3718 |
|
3709 | |||
3719 | From the point of view of pushing behavior, bookmarks |
|
3710 | From the point of view of pushing behavior, bookmarks | |
3720 | existing only in the remote repository are treated as |
|
3711 | existing only in the remote repository are treated as | |
3721 | ``deleted``, even if it is in fact added remotely. |
|
3712 | ``deleted``, even if it is in fact added remotely. | |
3722 |
|
3713 | |||
3723 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
3714 | Returns 0 if there are outgoing changes, 1 otherwise. | |
3724 | """ |
|
3715 | """ | |
3725 | # hg._outgoing() needs to re-resolve the path in order to handle #branch |
|
3716 | # hg._outgoing() needs to re-resolve the path in order to handle #branch | |
3726 | # style URLs, so don't overwrite dest. |
|
3717 | # style URLs, so don't overwrite dest. | |
3727 | path = ui.paths.getpath(dest, default=('default-push', 'default')) |
|
3718 | path = ui.paths.getpath(dest, default=('default-push', 'default')) | |
3728 | if not path: |
|
3719 | if not path: | |
3729 | raise error.Abort(_('default repository not configured!'), |
|
3720 | raise error.Abort(_('default repository not configured!'), | |
3730 | hint=_("see 'hg help config.paths'")) |
|
3721 | hint=_("see 'hg help config.paths'")) | |
3731 |
|
3722 | |||
3732 | opts = pycompat.byteskwargs(opts) |
|
3723 | opts = pycompat.byteskwargs(opts) | |
3733 | if opts.get('graph'): |
|
3724 | if opts.get('graph'): | |
3734 | logcmdutil.checkunsupportedgraphflags([], opts) |
|
3725 | logcmdutil.checkunsupportedgraphflags([], opts) | |
3735 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
3726 | o, other = hg._outgoing(ui, repo, dest, opts) | |
3736 | if not o: |
|
3727 | if not o: | |
3737 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3728 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | |
3738 | return |
|
3729 | return | |
3739 |
|
3730 | |||
3740 | revdag = logcmdutil.graphrevs(repo, o, opts) |
|
3731 | revdag = logcmdutil.graphrevs(repo, o, opts) | |
3741 | ui.pager('outgoing') |
|
3732 | ui.pager('outgoing') | |
3742 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, buffered=True) |
|
3733 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts, buffered=True) | |
3743 | logcmdutil.displaygraph(ui, repo, revdag, displayer, |
|
3734 | logcmdutil.displaygraph(ui, repo, revdag, displayer, | |
3744 | graphmod.asciiedges) |
|
3735 | graphmod.asciiedges) | |
3745 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3736 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | |
3746 | return 0 |
|
3737 | return 0 | |
3747 |
|
3738 | |||
3748 | if opts.get('bookmarks'): |
|
3739 | if opts.get('bookmarks'): | |
3749 | dest = path.pushloc or path.loc |
|
3740 | dest = path.pushloc or path.loc | |
3750 | other = hg.peer(repo, opts, dest) |
|
3741 | other = hg.peer(repo, opts, dest) | |
3751 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3742 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3752 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3743 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3753 | return 0 |
|
3744 | return 0 | |
3754 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
3745 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | |
3755 | ui.pager('outgoing') |
|
3746 | ui.pager('outgoing') | |
3756 | return bookmarks.outgoing(ui, repo, other) |
|
3747 | return bookmarks.outgoing(ui, repo, other) | |
3757 |
|
3748 | |||
3758 | repo._subtoppath = path.pushloc or path.loc |
|
3749 | repo._subtoppath = path.pushloc or path.loc | |
3759 | try: |
|
3750 | try: | |
3760 | return hg.outgoing(ui, repo, dest, opts) |
|
3751 | return hg.outgoing(ui, repo, dest, opts) | |
3761 | finally: |
|
3752 | finally: | |
3762 | del repo._subtoppath |
|
3753 | del repo._subtoppath | |
3763 |
|
3754 | |||
3764 | @command('parents', |
|
3755 | @command('parents', | |
3765 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
3756 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), | |
3766 | ] + templateopts, |
|
3757 | ] + templateopts, | |
3767 | _('[-r REV] [FILE]'), |
|
3758 | _('[-r REV] [FILE]'), | |
3768 | inferrepo=True) |
|
3759 | inferrepo=True) | |
3769 | def parents(ui, repo, file_=None, **opts): |
|
3760 | def parents(ui, repo, file_=None, **opts): | |
3770 | """show the parents of the working directory or revision (DEPRECATED) |
|
3761 | """show the parents of the working directory or revision (DEPRECATED) | |
3771 |
|
3762 | |||
3772 | Print the working directory's parent revisions. If a revision is |
|
3763 | Print the working directory's parent revisions. If a revision is | |
3773 | given via -r/--rev, the parent of that revision will be printed. |
|
3764 | given via -r/--rev, the parent of that revision will be printed. | |
3774 | If a file argument is given, the revision in which the file was |
|
3765 | If a file argument is given, the revision in which the file was | |
3775 | last changed (before the working directory revision or the |
|
3766 | last changed (before the working directory revision or the | |
3776 | argument to --rev if given) is printed. |
|
3767 | argument to --rev if given) is printed. | |
3777 |
|
3768 | |||
3778 | This command is equivalent to:: |
|
3769 | This command is equivalent to:: | |
3779 |
|
3770 | |||
3780 | hg log -r "p1()+p2()" or |
|
3771 | hg log -r "p1()+p2()" or | |
3781 | hg log -r "p1(REV)+p2(REV)" or |
|
3772 | hg log -r "p1(REV)+p2(REV)" or | |
3782 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or |
|
3773 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or | |
3783 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" |
|
3774 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" | |
3784 |
|
3775 | |||
3785 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
3776 | See :hg:`summary` and :hg:`help revsets` for related information. | |
3786 |
|
3777 | |||
3787 | Returns 0 on success. |
|
3778 | Returns 0 on success. | |
3788 | """ |
|
3779 | """ | |
3789 |
|
3780 | |||
3790 | opts = pycompat.byteskwargs(opts) |
|
3781 | opts = pycompat.byteskwargs(opts) | |
3791 | rev = opts.get('rev') |
|
3782 | rev = opts.get('rev') | |
3792 | if rev: |
|
3783 | if rev: | |
3793 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
3784 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
3794 | ctx = scmutil.revsingle(repo, rev, None) |
|
3785 | ctx = scmutil.revsingle(repo, rev, None) | |
3795 |
|
3786 | |||
3796 | if file_: |
|
3787 | if file_: | |
3797 | m = scmutil.match(ctx, (file_,), opts) |
|
3788 | m = scmutil.match(ctx, (file_,), opts) | |
3798 | if m.anypats() or len(m.files()) != 1: |
|
3789 | if m.anypats() or len(m.files()) != 1: | |
3799 | raise error.Abort(_('can only specify an explicit filename')) |
|
3790 | raise error.Abort(_('can only specify an explicit filename')) | |
3800 | file_ = m.files()[0] |
|
3791 | file_ = m.files()[0] | |
3801 | filenodes = [] |
|
3792 | filenodes = [] | |
3802 | for cp in ctx.parents(): |
|
3793 | for cp in ctx.parents(): | |
3803 | if not cp: |
|
3794 | if not cp: | |
3804 | continue |
|
3795 | continue | |
3805 | try: |
|
3796 | try: | |
3806 | filenodes.append(cp.filenode(file_)) |
|
3797 | filenodes.append(cp.filenode(file_)) | |
3807 | except error.LookupError: |
|
3798 | except error.LookupError: | |
3808 | pass |
|
3799 | pass | |
3809 | if not filenodes: |
|
3800 | if not filenodes: | |
3810 | raise error.Abort(_("'%s' not found in manifest!") % file_) |
|
3801 | raise error.Abort(_("'%s' not found in manifest!") % file_) | |
3811 | p = [] |
|
3802 | p = [] | |
3812 | for fn in filenodes: |
|
3803 | for fn in filenodes: | |
3813 | fctx = repo.filectx(file_, fileid=fn) |
|
3804 | fctx = repo.filectx(file_, fileid=fn) | |
3814 | p.append(fctx.node()) |
|
3805 | p.append(fctx.node()) | |
3815 | else: |
|
3806 | else: | |
3816 | p = [cp.node() for cp in ctx.parents()] |
|
3807 | p = [cp.node() for cp in ctx.parents()] | |
3817 |
|
3808 | |||
3818 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
3809 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | |
3819 | for n in p: |
|
3810 | for n in p: | |
3820 | if n != nullid: |
|
3811 | if n != nullid: | |
3821 | displayer.show(repo[n]) |
|
3812 | displayer.show(repo[n]) | |
3822 | displayer.close() |
|
3813 | displayer.close() | |
3823 |
|
3814 | |||
3824 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True, |
|
3815 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True, | |
3825 | intents={INTENT_READONLY}) |
|
3816 | intents={INTENT_READONLY}) | |
3826 | def paths(ui, repo, search=None, **opts): |
|
3817 | def paths(ui, repo, search=None, **opts): | |
3827 | """show aliases for remote repositories |
|
3818 | """show aliases for remote repositories | |
3828 |
|
3819 | |||
3829 | Show definition of symbolic path name NAME. If no name is given, |
|
3820 | Show definition of symbolic path name NAME. If no name is given, | |
3830 | show definition of all available names. |
|
3821 | show definition of all available names. | |
3831 |
|
3822 | |||
3832 | Option -q/--quiet suppresses all output when searching for NAME |
|
3823 | Option -q/--quiet suppresses all output when searching for NAME | |
3833 | and shows only the path names when listing all definitions. |
|
3824 | and shows only the path names when listing all definitions. | |
3834 |
|
3825 | |||
3835 | Path names are defined in the [paths] section of your |
|
3826 | Path names are defined in the [paths] section of your | |
3836 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
3827 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a | |
3837 | repository, ``.hg/hgrc`` is used, too. |
|
3828 | repository, ``.hg/hgrc`` is used, too. | |
3838 |
|
3829 | |||
3839 | The path names ``default`` and ``default-push`` have a special |
|
3830 | The path names ``default`` and ``default-push`` have a special | |
3840 | meaning. When performing a push or pull operation, they are used |
|
3831 | meaning. When performing a push or pull operation, they are used | |
3841 | as fallbacks if no location is specified on the command-line. |
|
3832 | as fallbacks if no location is specified on the command-line. | |
3842 | When ``default-push`` is set, it will be used for push and |
|
3833 | When ``default-push`` is set, it will be used for push and | |
3843 | ``default`` will be used for pull; otherwise ``default`` is used |
|
3834 | ``default`` will be used for pull; otherwise ``default`` is used | |
3844 | as the fallback for both. When cloning a repository, the clone |
|
3835 | as the fallback for both. When cloning a repository, the clone | |
3845 | source is written as ``default`` in ``.hg/hgrc``. |
|
3836 | source is written as ``default`` in ``.hg/hgrc``. | |
3846 |
|
3837 | |||
3847 | .. note:: |
|
3838 | .. note:: | |
3848 |
|
3839 | |||
3849 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
3840 | ``default`` and ``default-push`` apply to all inbound (e.g. | |
3850 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` |
|
3841 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` | |
3851 | and :hg:`bundle`) operations. |
|
3842 | and :hg:`bundle`) operations. | |
3852 |
|
3843 | |||
3853 | See :hg:`help urls` for more information. |
|
3844 | See :hg:`help urls` for more information. | |
3854 |
|
3845 | |||
3855 | Returns 0 on success. |
|
3846 | Returns 0 on success. | |
3856 | """ |
|
3847 | """ | |
3857 |
|
3848 | |||
3858 | opts = pycompat.byteskwargs(opts) |
|
3849 | opts = pycompat.byteskwargs(opts) | |
3859 | ui.pager('paths') |
|
3850 | ui.pager('paths') | |
3860 | if search: |
|
3851 | if search: | |
3861 | pathitems = [(name, path) for name, path in ui.paths.iteritems() |
|
3852 | pathitems = [(name, path) for name, path in ui.paths.iteritems() | |
3862 | if name == search] |
|
3853 | if name == search] | |
3863 | else: |
|
3854 | else: | |
3864 | pathitems = sorted(ui.paths.iteritems()) |
|
3855 | pathitems = sorted(ui.paths.iteritems()) | |
3865 |
|
3856 | |||
3866 | fm = ui.formatter('paths', opts) |
|
3857 | fm = ui.formatter('paths', opts) | |
3867 | if fm.isplain(): |
|
3858 | if fm.isplain(): | |
3868 | hidepassword = util.hidepassword |
|
3859 | hidepassword = util.hidepassword | |
3869 | else: |
|
3860 | else: | |
3870 | hidepassword = bytes |
|
3861 | hidepassword = bytes | |
3871 | if ui.quiet: |
|
3862 | if ui.quiet: | |
3872 | namefmt = '%s\n' |
|
3863 | namefmt = '%s\n' | |
3873 | else: |
|
3864 | else: | |
3874 | namefmt = '%s = ' |
|
3865 | namefmt = '%s = ' | |
3875 | showsubopts = not search and not ui.quiet |
|
3866 | showsubopts = not search and not ui.quiet | |
3876 |
|
3867 | |||
3877 | for name, path in pathitems: |
|
3868 | for name, path in pathitems: | |
3878 | fm.startitem() |
|
3869 | fm.startitem() | |
3879 | fm.condwrite(not search, 'name', namefmt, name) |
|
3870 | fm.condwrite(not search, 'name', namefmt, name) | |
3880 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) |
|
3871 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) | |
3881 | for subopt, value in sorted(path.suboptions.items()): |
|
3872 | for subopt, value in sorted(path.suboptions.items()): | |
3882 | assert subopt not in ('name', 'url') |
|
3873 | assert subopt not in ('name', 'url') | |
3883 | if showsubopts: |
|
3874 | if showsubopts: | |
3884 | fm.plain('%s:%s = ' % (name, subopt)) |
|
3875 | fm.plain('%s:%s = ' % (name, subopt)) | |
3885 | fm.condwrite(showsubopts, subopt, '%s\n', value) |
|
3876 | fm.condwrite(showsubopts, subopt, '%s\n', value) | |
3886 |
|
3877 | |||
3887 | fm.end() |
|
3878 | fm.end() | |
3888 |
|
3879 | |||
3889 | if search and not pathitems: |
|
3880 | if search and not pathitems: | |
3890 | if not ui.quiet: |
|
3881 | if not ui.quiet: | |
3891 | ui.warn(_("not found!\n")) |
|
3882 | ui.warn(_("not found!\n")) | |
3892 | return 1 |
|
3883 | return 1 | |
3893 | else: |
|
3884 | else: | |
3894 | return 0 |
|
3885 | return 0 | |
3895 |
|
3886 | |||
3896 | @command('phase', |
|
3887 | @command('phase', | |
3897 | [('p', 'public', False, _('set changeset phase to public')), |
|
3888 | [('p', 'public', False, _('set changeset phase to public')), | |
3898 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
3889 | ('d', 'draft', False, _('set changeset phase to draft')), | |
3899 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
3890 | ('s', 'secret', False, _('set changeset phase to secret')), | |
3900 | ('f', 'force', False, _('allow to move boundary backward')), |
|
3891 | ('f', 'force', False, _('allow to move boundary backward')), | |
3901 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
3892 | ('r', 'rev', [], _('target revision'), _('REV')), | |
3902 | ], |
|
3893 | ], | |
3903 | _('[-p|-d|-s] [-f] [-r] [REV...]')) |
|
3894 | _('[-p|-d|-s] [-f] [-r] [REV...]')) | |
3904 | def phase(ui, repo, *revs, **opts): |
|
3895 | def phase(ui, repo, *revs, **opts): | |
3905 | """set or show the current phase name |
|
3896 | """set or show the current phase name | |
3906 |
|
3897 | |||
3907 | With no argument, show the phase name of the current revision(s). |
|
3898 | With no argument, show the phase name of the current revision(s). | |
3908 |
|
3899 | |||
3909 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
3900 | With one of -p/--public, -d/--draft or -s/--secret, change the | |
3910 | phase value of the specified revisions. |
|
3901 | phase value of the specified revisions. | |
3911 |
|
3902 | |||
3912 | Unless -f/--force is specified, :hg:`phase` won't move changesets from a |
|
3903 | Unless -f/--force is specified, :hg:`phase` won't move changesets from a | |
3913 | lower phase to a higher phase. Phases are ordered as follows:: |
|
3904 | lower phase to a higher phase. Phases are ordered as follows:: | |
3914 |
|
3905 | |||
3915 | public < draft < secret |
|
3906 | public < draft < secret | |
3916 |
|
3907 | |||
3917 | Returns 0 on success, 1 if some phases could not be changed. |
|
3908 | Returns 0 on success, 1 if some phases could not be changed. | |
3918 |
|
3909 | |||
3919 | (For more information about the phases concept, see :hg:`help phases`.) |
|
3910 | (For more information about the phases concept, see :hg:`help phases`.) | |
3920 | """ |
|
3911 | """ | |
3921 | opts = pycompat.byteskwargs(opts) |
|
3912 | opts = pycompat.byteskwargs(opts) | |
3922 | # search for a unique phase argument |
|
3913 | # search for a unique phase argument | |
3923 | targetphase = None |
|
3914 | targetphase = None | |
3924 | for idx, name in enumerate(phases.phasenames): |
|
3915 | for idx, name in enumerate(phases.phasenames): | |
3925 | if opts[name]: |
|
3916 | if opts[name]: | |
3926 | if targetphase is not None: |
|
3917 | if targetphase is not None: | |
3927 | raise error.Abort(_('only one phase can be specified')) |
|
3918 | raise error.Abort(_('only one phase can be specified')) | |
3928 | targetphase = idx |
|
3919 | targetphase = idx | |
3929 |
|
3920 | |||
3930 | # look for specified revision |
|
3921 | # look for specified revision | |
3931 | revs = list(revs) |
|
3922 | revs = list(revs) | |
3932 | revs.extend(opts['rev']) |
|
3923 | revs.extend(opts['rev']) | |
3933 | if not revs: |
|
3924 | if not revs: | |
3934 | # display both parents as the second parent phase can influence |
|
3925 | # display both parents as the second parent phase can influence | |
3935 | # the phase of a merge commit |
|
3926 | # the phase of a merge commit | |
3936 | revs = [c.rev() for c in repo[None].parents()] |
|
3927 | revs = [c.rev() for c in repo[None].parents()] | |
3937 |
|
3928 | |||
3938 | revs = scmutil.revrange(repo, revs) |
|
3929 | revs = scmutil.revrange(repo, revs) | |
3939 |
|
3930 | |||
3940 | ret = 0 |
|
3931 | ret = 0 | |
3941 | if targetphase is None: |
|
3932 | if targetphase is None: | |
3942 | # display |
|
3933 | # display | |
3943 | for r in revs: |
|
3934 | for r in revs: | |
3944 | ctx = repo[r] |
|
3935 | ctx = repo[r] | |
3945 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
3936 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | |
3946 | else: |
|
3937 | else: | |
3947 | with repo.lock(), repo.transaction("phase") as tr: |
|
3938 | with repo.lock(), repo.transaction("phase") as tr: | |
3948 | # set phase |
|
3939 | # set phase | |
3949 | if not revs: |
|
3940 | if not revs: | |
3950 | raise error.Abort(_('empty revision set')) |
|
3941 | raise error.Abort(_('empty revision set')) | |
3951 | nodes = [repo[r].node() for r in revs] |
|
3942 | nodes = [repo[r].node() for r in revs] | |
3952 | # moving revision from public to draft may hide them |
|
3943 | # moving revision from public to draft may hide them | |
3953 | # We have to check result on an unfiltered repository |
|
3944 | # We have to check result on an unfiltered repository | |
3954 | unfi = repo.unfiltered() |
|
3945 | unfi = repo.unfiltered() | |
3955 | getphase = unfi._phasecache.phase |
|
3946 | getphase = unfi._phasecache.phase | |
3956 | olddata = [getphase(unfi, r) for r in unfi] |
|
3947 | olddata = [getphase(unfi, r) for r in unfi] | |
3957 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
3948 | phases.advanceboundary(repo, tr, targetphase, nodes) | |
3958 | if opts['force']: |
|
3949 | if opts['force']: | |
3959 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
3950 | phases.retractboundary(repo, tr, targetphase, nodes) | |
3960 | getphase = unfi._phasecache.phase |
|
3951 | getphase = unfi._phasecache.phase | |
3961 | newdata = [getphase(unfi, r) for r in unfi] |
|
3952 | newdata = [getphase(unfi, r) for r in unfi] | |
3962 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
3953 | changes = sum(newdata[r] != olddata[r] for r in unfi) | |
3963 | cl = unfi.changelog |
|
3954 | cl = unfi.changelog | |
3964 | rejected = [n for n in nodes |
|
3955 | rejected = [n for n in nodes | |
3965 | if newdata[cl.rev(n)] < targetphase] |
|
3956 | if newdata[cl.rev(n)] < targetphase] | |
3966 | if rejected: |
|
3957 | if rejected: | |
3967 | ui.warn(_('cannot move %i changesets to a higher ' |
|
3958 | ui.warn(_('cannot move %i changesets to a higher ' | |
3968 | 'phase, use --force\n') % len(rejected)) |
|
3959 | 'phase, use --force\n') % len(rejected)) | |
3969 | ret = 1 |
|
3960 | ret = 1 | |
3970 | if changes: |
|
3961 | if changes: | |
3971 | msg = _('phase changed for %i changesets\n') % changes |
|
3962 | msg = _('phase changed for %i changesets\n') % changes | |
3972 | if ret: |
|
3963 | if ret: | |
3973 | ui.status(msg) |
|
3964 | ui.status(msg) | |
3974 | else: |
|
3965 | else: | |
3975 | ui.note(msg) |
|
3966 | ui.note(msg) | |
3976 | else: |
|
3967 | else: | |
3977 | ui.warn(_('no phases changed\n')) |
|
3968 | ui.warn(_('no phases changed\n')) | |
3978 | return ret |
|
3969 | return ret | |
3979 |
|
3970 | |||
3980 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): |
|
3971 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): | |
3981 | """Run after a changegroup has been added via pull/unbundle |
|
3972 | """Run after a changegroup has been added via pull/unbundle | |
3982 |
|
3973 | |||
3983 | This takes arguments below: |
|
3974 | This takes arguments below: | |
3984 |
|
3975 | |||
3985 | :modheads: change of heads by pull/unbundle |
|
3976 | :modheads: change of heads by pull/unbundle | |
3986 | :optupdate: updating working directory is needed or not |
|
3977 | :optupdate: updating working directory is needed or not | |
3987 | :checkout: update destination revision (or None to default destination) |
|
3978 | :checkout: update destination revision (or None to default destination) | |
3988 | :brev: a name, which might be a bookmark to be activated after updating |
|
3979 | :brev: a name, which might be a bookmark to be activated after updating | |
3989 | """ |
|
3980 | """ | |
3990 | if modheads == 0: |
|
3981 | if modheads == 0: | |
3991 | return |
|
3982 | return | |
3992 | if optupdate: |
|
3983 | if optupdate: | |
3993 | try: |
|
3984 | try: | |
3994 | return hg.updatetotally(ui, repo, checkout, brev) |
|
3985 | return hg.updatetotally(ui, repo, checkout, brev) | |
3995 | except error.UpdateAbort as inst: |
|
3986 | except error.UpdateAbort as inst: | |
3996 | msg = _("not updating: %s") % stringutil.forcebytestr(inst) |
|
3987 | msg = _("not updating: %s") % stringutil.forcebytestr(inst) | |
3997 | hint = inst.hint |
|
3988 | hint = inst.hint | |
3998 | raise error.UpdateAbort(msg, hint=hint) |
|
3989 | raise error.UpdateAbort(msg, hint=hint) | |
3999 | if modheads > 1: |
|
3990 | if modheads > 1: | |
4000 | currentbranchheads = len(repo.branchheads()) |
|
3991 | currentbranchheads = len(repo.branchheads()) | |
4001 | if currentbranchheads == modheads: |
|
3992 | if currentbranchheads == modheads: | |
4002 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
3993 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
4003 | elif currentbranchheads > 1: |
|
3994 | elif currentbranchheads > 1: | |
4004 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
3995 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " | |
4005 | "merge)\n")) |
|
3996 | "merge)\n")) | |
4006 | else: |
|
3997 | else: | |
4007 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
3998 | ui.status(_("(run 'hg heads' to see heads)\n")) | |
4008 | elif not ui.configbool('commands', 'update.requiredest'): |
|
3999 | elif not ui.configbool('commands', 'update.requiredest'): | |
4009 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
4000 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
4010 |
|
4001 | |||
4011 | @command('^pull', |
|
4002 | @command('^pull', | |
4012 | [('u', 'update', None, |
|
4003 | [('u', 'update', None, | |
4013 | _('update to new branch head if new descendants were pulled')), |
|
4004 | _('update to new branch head if new descendants were pulled')), | |
4014 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
4005 | ('f', 'force', None, _('run even when remote repository is unrelated')), | |
4015 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
4006 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
4016 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
4007 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), | |
4017 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
4008 | ('b', 'branch', [], _('a specific branch you would like to pull'), | |
4018 | _('BRANCH')), |
|
4009 | _('BRANCH')), | |
4019 | ] + remoteopts, |
|
4010 | ] + remoteopts, | |
4020 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
4011 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) | |
4021 | def pull(ui, repo, source="default", **opts): |
|
4012 | def pull(ui, repo, source="default", **opts): | |
4022 | """pull changes from the specified source |
|
4013 | """pull changes from the specified source | |
4023 |
|
4014 | |||
4024 | Pull changes from a remote repository to a local one. |
|
4015 | Pull changes from a remote repository to a local one. | |
4025 |
|
4016 | |||
4026 | This finds all changes from the repository at the specified path |
|
4017 | This finds all changes from the repository at the specified path | |
4027 | or URL and adds them to a local repository (the current one unless |
|
4018 | or URL and adds them to a local repository (the current one unless | |
4028 | -R is specified). By default, this does not update the copy of the |
|
4019 | -R is specified). By default, this does not update the copy of the | |
4029 | project in the working directory. |
|
4020 | project in the working directory. | |
4030 |
|
4021 | |||
4031 | When cloning from servers that support it, Mercurial may fetch |
|
4022 | When cloning from servers that support it, Mercurial may fetch | |
4032 | pre-generated data. When this is done, hooks operating on incoming |
|
4023 | pre-generated data. When this is done, hooks operating on incoming | |
4033 | changesets and changegroups may fire more than once, once for each |
|
4024 | changesets and changegroups may fire more than once, once for each | |
4034 | pre-generated bundle and as well as for any additional remaining |
|
4025 | pre-generated bundle and as well as for any additional remaining | |
4035 | data. See :hg:`help -e clonebundles` for more. |
|
4026 | data. See :hg:`help -e clonebundles` for more. | |
4036 |
|
4027 | |||
4037 | Use :hg:`incoming` if you want to see what would have been added |
|
4028 | Use :hg:`incoming` if you want to see what would have been added | |
4038 | by a pull at the time you issued this command. If you then decide |
|
4029 | by a pull at the time you issued this command. If you then decide | |
4039 | to add those changes to the repository, you should use :hg:`pull |
|
4030 | to add those changes to the repository, you should use :hg:`pull | |
4040 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
4031 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. | |
4041 |
|
4032 | |||
4042 | If SOURCE is omitted, the 'default' path will be used. |
|
4033 | If SOURCE is omitted, the 'default' path will be used. | |
4043 | See :hg:`help urls` for more information. |
|
4034 | See :hg:`help urls` for more information. | |
4044 |
|
4035 | |||
4045 | Specifying bookmark as ``.`` is equivalent to specifying the active |
|
4036 | Specifying bookmark as ``.`` is equivalent to specifying the active | |
4046 | bookmark's name. |
|
4037 | bookmark's name. | |
4047 |
|
4038 | |||
4048 | Returns 0 on success, 1 if an update had unresolved files. |
|
4039 | Returns 0 on success, 1 if an update had unresolved files. | |
4049 | """ |
|
4040 | """ | |
4050 |
|
4041 | |||
4051 | opts = pycompat.byteskwargs(opts) |
|
4042 | opts = pycompat.byteskwargs(opts) | |
4052 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): |
|
4043 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): | |
4053 | msg = _('update destination required by configuration') |
|
4044 | msg = _('update destination required by configuration') | |
4054 | hint = _('use hg pull followed by hg update DEST') |
|
4045 | hint = _('use hg pull followed by hg update DEST') | |
4055 | raise error.Abort(msg, hint=hint) |
|
4046 | raise error.Abort(msg, hint=hint) | |
4056 |
|
4047 | |||
4057 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
4048 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | |
4058 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
4049 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) | |
4059 | other = hg.peer(repo, opts, source) |
|
4050 | other = hg.peer(repo, opts, source) | |
4060 | try: |
|
4051 | try: | |
4061 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
4052 | revs, checkout = hg.addbranchrevs(repo, other, branches, | |
4062 | opts.get('rev')) |
|
4053 | opts.get('rev')) | |
4063 |
|
4054 | |||
4064 |
|
4055 | |||
4065 | pullopargs = {} |
|
4056 | pullopargs = {} | |
4066 | if opts.get('bookmark'): |
|
4057 | if opts.get('bookmark'): | |
4067 | if not revs: |
|
4058 | if not revs: | |
4068 | revs = [] |
|
4059 | revs = [] | |
4069 | # The list of bookmark used here is not the one used to actually |
|
4060 | # The list of bookmark used here is not the one used to actually | |
4070 | # update the bookmark name. This can result in the revision pulled |
|
4061 | # update the bookmark name. This can result in the revision pulled | |
4071 | # not ending up with the name of the bookmark because of a race |
|
4062 | # not ending up with the name of the bookmark because of a race | |
4072 | # condition on the server. (See issue 4689 for details) |
|
4063 | # condition on the server. (See issue 4689 for details) | |
4073 | remotebookmarks = other.listkeys('bookmarks') |
|
4064 | remotebookmarks = other.listkeys('bookmarks') | |
4074 | remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) |
|
4065 | remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) | |
4075 | pullopargs['remotebookmarks'] = remotebookmarks |
|
4066 | pullopargs['remotebookmarks'] = remotebookmarks | |
4076 | for b in opts['bookmark']: |
|
4067 | for b in opts['bookmark']: | |
4077 | b = repo._bookmarks.expandname(b) |
|
4068 | b = repo._bookmarks.expandname(b) | |
4078 | if b not in remotebookmarks: |
|
4069 | if b not in remotebookmarks: | |
4079 | raise error.Abort(_('remote bookmark %s not found!') % b) |
|
4070 | raise error.Abort(_('remote bookmark %s not found!') % b) | |
4080 | revs.append(hex(remotebookmarks[b])) |
|
4071 | revs.append(hex(remotebookmarks[b])) | |
4081 |
|
4072 | |||
4082 | if revs: |
|
4073 | if revs: | |
4083 | try: |
|
4074 | try: | |
4084 | # When 'rev' is a bookmark name, we cannot guarantee that it |
|
4075 | # When 'rev' is a bookmark name, we cannot guarantee that it | |
4085 | # will be updated with that name because of a race condition |
|
4076 | # will be updated with that name because of a race condition | |
4086 | # server side. (See issue 4689 for details) |
|
4077 | # server side. (See issue 4689 for details) | |
4087 | oldrevs = revs |
|
4078 | oldrevs = revs | |
4088 | revs = [] # actually, nodes |
|
4079 | revs = [] # actually, nodes | |
4089 | for r in oldrevs: |
|
4080 | for r in oldrevs: | |
4090 | with other.commandexecutor() as e: |
|
4081 | with other.commandexecutor() as e: | |
4091 | node = e.callcommand('lookup', {'key': r}).result() |
|
4082 | node = e.callcommand('lookup', {'key': r}).result() | |
4092 |
|
4083 | |||
4093 | revs.append(node) |
|
4084 | revs.append(node) | |
4094 | if r == checkout: |
|
4085 | if r == checkout: | |
4095 | checkout = node |
|
4086 | checkout = node | |
4096 | except error.CapabilityError: |
|
4087 | except error.CapabilityError: | |
4097 | err = _("other repository doesn't support revision lookup, " |
|
4088 | err = _("other repository doesn't support revision lookup, " | |
4098 | "so a rev cannot be specified.") |
|
4089 | "so a rev cannot be specified.") | |
4099 | raise error.Abort(err) |
|
4090 | raise error.Abort(err) | |
4100 |
|
4091 | |||
4101 | wlock = util.nullcontextmanager() |
|
4092 | wlock = util.nullcontextmanager() | |
4102 | if opts.get('update'): |
|
4093 | if opts.get('update'): | |
4103 | wlock = repo.wlock() |
|
4094 | wlock = repo.wlock() | |
4104 | with wlock: |
|
4095 | with wlock: | |
4105 | pullopargs.update(opts.get('opargs', {})) |
|
4096 | pullopargs.update(opts.get('opargs', {})) | |
4106 | modheads = exchange.pull(repo, other, heads=revs, |
|
4097 | modheads = exchange.pull(repo, other, heads=revs, | |
4107 | force=opts.get('force'), |
|
4098 | force=opts.get('force'), | |
4108 | bookmarks=opts.get('bookmark', ()), |
|
4099 | bookmarks=opts.get('bookmark', ()), | |
4109 | opargs=pullopargs).cgresult |
|
4100 | opargs=pullopargs).cgresult | |
4110 |
|
4101 | |||
4111 | # brev is a name, which might be a bookmark to be activated at |
|
4102 | # brev is a name, which might be a bookmark to be activated at | |
4112 | # the end of the update. In other words, it is an explicit |
|
4103 | # the end of the update. In other words, it is an explicit | |
4113 | # destination of the update |
|
4104 | # destination of the update | |
4114 | brev = None |
|
4105 | brev = None | |
4115 |
|
4106 | |||
4116 | if checkout: |
|
4107 | if checkout: | |
4117 | checkout = repo.changelog.rev(checkout) |
|
4108 | checkout = repo.changelog.rev(checkout) | |
4118 |
|
4109 | |||
4119 | # order below depends on implementation of |
|
4110 | # order below depends on implementation of | |
4120 | # hg.addbranchrevs(). opts['bookmark'] is ignored, |
|
4111 | # hg.addbranchrevs(). opts['bookmark'] is ignored, | |
4121 | # because 'checkout' is determined without it. |
|
4112 | # because 'checkout' is determined without it. | |
4122 | if opts.get('rev'): |
|
4113 | if opts.get('rev'): | |
4123 | brev = opts['rev'][0] |
|
4114 | brev = opts['rev'][0] | |
4124 | elif opts.get('branch'): |
|
4115 | elif opts.get('branch'): | |
4125 | brev = opts['branch'][0] |
|
4116 | brev = opts['branch'][0] | |
4126 | else: |
|
4117 | else: | |
4127 | brev = branches[0] |
|
4118 | brev = branches[0] | |
4128 | repo._subtoppath = source |
|
4119 | repo._subtoppath = source | |
4129 | try: |
|
4120 | try: | |
4130 | ret = postincoming(ui, repo, modheads, opts.get('update'), |
|
4121 | ret = postincoming(ui, repo, modheads, opts.get('update'), | |
4131 | checkout, brev) |
|
4122 | checkout, brev) | |
4132 |
|
4123 | |||
4133 | finally: |
|
4124 | finally: | |
4134 | del repo._subtoppath |
|
4125 | del repo._subtoppath | |
4135 |
|
4126 | |||
4136 | finally: |
|
4127 | finally: | |
4137 | other.close() |
|
4128 | other.close() | |
4138 | return ret |
|
4129 | return ret | |
4139 |
|
4130 | |||
4140 | @command('^push', |
|
4131 | @command('^push', | |
4141 | [('f', 'force', None, _('force push')), |
|
4132 | [('f', 'force', None, _('force push')), | |
4142 | ('r', 'rev', [], |
|
4133 | ('r', 'rev', [], | |
4143 | _('a changeset intended to be included in the destination'), |
|
4134 | _('a changeset intended to be included in the destination'), | |
4144 | _('REV')), |
|
4135 | _('REV')), | |
4145 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
4136 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), | |
4146 | ('b', 'branch', [], |
|
4137 | ('b', 'branch', [], | |
4147 | _('a specific branch you would like to push'), _('BRANCH')), |
|
4138 | _('a specific branch you would like to push'), _('BRANCH')), | |
4148 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
4139 | ('', 'new-branch', False, _('allow pushing a new branch')), | |
4149 | ('', 'pushvars', [], _('variables that can be sent to server (ADVANCED)')), |
|
4140 | ('', 'pushvars', [], _('variables that can be sent to server (ADVANCED)')), | |
4150 | ] + remoteopts, |
|
4141 | ] + remoteopts, | |
4151 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
4142 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) | |
4152 | def push(ui, repo, dest=None, **opts): |
|
4143 | def push(ui, repo, dest=None, **opts): | |
4153 | """push changes to the specified destination |
|
4144 | """push changes to the specified destination | |
4154 |
|
4145 | |||
4155 | Push changesets from the local repository to the specified |
|
4146 | Push changesets from the local repository to the specified | |
4156 | destination. |
|
4147 | destination. | |
4157 |
|
4148 | |||
4158 | This operation is symmetrical to pull: it is identical to a pull |
|
4149 | This operation is symmetrical to pull: it is identical to a pull | |
4159 | in the destination repository from the current one. |
|
4150 | in the destination repository from the current one. | |
4160 |
|
4151 | |||
4161 | By default, push will not allow creation of new heads at the |
|
4152 | By default, push will not allow creation of new heads at the | |
4162 | destination, since multiple heads would make it unclear which head |
|
4153 | destination, since multiple heads would make it unclear which head | |
4163 | to use. In this situation, it is recommended to pull and merge |
|
4154 | to use. In this situation, it is recommended to pull and merge | |
4164 | before pushing. |
|
4155 | before pushing. | |
4165 |
|
4156 | |||
4166 | Use --new-branch if you want to allow push to create a new named |
|
4157 | Use --new-branch if you want to allow push to create a new named | |
4167 | branch that is not present at the destination. This allows you to |
|
4158 | branch that is not present at the destination. This allows you to | |
4168 | only create a new branch without forcing other changes. |
|
4159 | only create a new branch without forcing other changes. | |
4169 |
|
4160 | |||
4170 | .. note:: |
|
4161 | .. note:: | |
4171 |
|
4162 | |||
4172 | Extra care should be taken with the -f/--force option, |
|
4163 | Extra care should be taken with the -f/--force option, | |
4173 | which will push all new heads on all branches, an action which will |
|
4164 | which will push all new heads on all branches, an action which will | |
4174 | almost always cause confusion for collaborators. |
|
4165 | almost always cause confusion for collaborators. | |
4175 |
|
4166 | |||
4176 | If -r/--rev is used, the specified revision and all its ancestors |
|
4167 | If -r/--rev is used, the specified revision and all its ancestors | |
4177 | will be pushed to the remote repository. |
|
4168 | will be pushed to the remote repository. | |
4178 |
|
4169 | |||
4179 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
4170 | If -B/--bookmark is used, the specified bookmarked revision, its | |
4180 | ancestors, and the bookmark will be pushed to the remote |
|
4171 | ancestors, and the bookmark will be pushed to the remote | |
4181 | repository. Specifying ``.`` is equivalent to specifying the active |
|
4172 | repository. Specifying ``.`` is equivalent to specifying the active | |
4182 | bookmark's name. |
|
4173 | bookmark's name. | |
4183 |
|
4174 | |||
4184 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
4175 | Please see :hg:`help urls` for important details about ``ssh://`` | |
4185 | URLs. If DESTINATION is omitted, a default path will be used. |
|
4176 | URLs. If DESTINATION is omitted, a default path will be used. | |
4186 |
|
4177 | |||
4187 | .. container:: verbose |
|
4178 | .. container:: verbose | |
4188 |
|
4179 | |||
4189 | The --pushvars option sends strings to the server that become |
|
4180 | The --pushvars option sends strings to the server that become | |
4190 | environment variables prepended with ``HG_USERVAR_``. For example, |
|
4181 | environment variables prepended with ``HG_USERVAR_``. For example, | |
4191 | ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with |
|
4182 | ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with | |
4192 | ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment. |
|
4183 | ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment. | |
4193 |
|
4184 | |||
4194 | pushvars can provide for user-overridable hooks as well as set debug |
|
4185 | pushvars can provide for user-overridable hooks as well as set debug | |
4195 | levels. One example is having a hook that blocks commits containing |
|
4186 | levels. One example is having a hook that blocks commits containing | |
4196 | conflict markers, but enables the user to override the hook if the file |
|
4187 | conflict markers, but enables the user to override the hook if the file | |
4197 | is using conflict markers for testing purposes or the file format has |
|
4188 | is using conflict markers for testing purposes or the file format has | |
4198 | strings that look like conflict markers. |
|
4189 | strings that look like conflict markers. | |
4199 |
|
4190 | |||
4200 | By default, servers will ignore `--pushvars`. To enable it add the |
|
4191 | By default, servers will ignore `--pushvars`. To enable it add the | |
4201 | following to your configuration file:: |
|
4192 | following to your configuration file:: | |
4202 |
|
4193 | |||
4203 | [push] |
|
4194 | [push] | |
4204 | pushvars.server = true |
|
4195 | pushvars.server = true | |
4205 |
|
4196 | |||
4206 | Returns 0 if push was successful, 1 if nothing to push. |
|
4197 | Returns 0 if push was successful, 1 if nothing to push. | |
4207 | """ |
|
4198 | """ | |
4208 |
|
4199 | |||
4209 | opts = pycompat.byteskwargs(opts) |
|
4200 | opts = pycompat.byteskwargs(opts) | |
4210 | if opts.get('bookmark'): |
|
4201 | if opts.get('bookmark'): | |
4211 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') |
|
4202 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') | |
4212 | for b in opts['bookmark']: |
|
4203 | for b in opts['bookmark']: | |
4213 | # translate -B options to -r so changesets get pushed |
|
4204 | # translate -B options to -r so changesets get pushed | |
4214 | b = repo._bookmarks.expandname(b) |
|
4205 | b = repo._bookmarks.expandname(b) | |
4215 | if b in repo._bookmarks: |
|
4206 | if b in repo._bookmarks: | |
4216 | opts.setdefault('rev', []).append(b) |
|
4207 | opts.setdefault('rev', []).append(b) | |
4217 | else: |
|
4208 | else: | |
4218 | # if we try to push a deleted bookmark, translate it to null |
|
4209 | # if we try to push a deleted bookmark, translate it to null | |
4219 | # this lets simultaneous -r, -b options continue working |
|
4210 | # this lets simultaneous -r, -b options continue working | |
4220 | opts.setdefault('rev', []).append("null") |
|
4211 | opts.setdefault('rev', []).append("null") | |
4221 |
|
4212 | |||
4222 | path = ui.paths.getpath(dest, default=('default-push', 'default')) |
|
4213 | path = ui.paths.getpath(dest, default=('default-push', 'default')) | |
4223 | if not path: |
|
4214 | if not path: | |
4224 | raise error.Abort(_('default repository not configured!'), |
|
4215 | raise error.Abort(_('default repository not configured!'), | |
4225 | hint=_("see 'hg help config.paths'")) |
|
4216 | hint=_("see 'hg help config.paths'")) | |
4226 | dest = path.pushloc or path.loc |
|
4217 | dest = path.pushloc or path.loc | |
4227 | branches = (path.branch, opts.get('branch') or []) |
|
4218 | branches = (path.branch, opts.get('branch') or []) | |
4228 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
4219 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) | |
4229 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
4220 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) | |
4230 | other = hg.peer(repo, opts, dest) |
|
4221 | other = hg.peer(repo, opts, dest) | |
4231 |
|
4222 | |||
4232 | if revs: |
|
4223 | if revs: | |
4233 | revs = [repo[r].node() for r in scmutil.revrange(repo, revs)] |
|
4224 | revs = [repo[r].node() for r in scmutil.revrange(repo, revs)] | |
4234 | if not revs: |
|
4225 | if not revs: | |
4235 | raise error.Abort(_("specified revisions evaluate to an empty set"), |
|
4226 | raise error.Abort(_("specified revisions evaluate to an empty set"), | |
4236 | hint=_("use different revision arguments")) |
|
4227 | hint=_("use different revision arguments")) | |
4237 | elif path.pushrev: |
|
4228 | elif path.pushrev: | |
4238 | # It doesn't make any sense to specify ancestor revisions. So limit |
|
4229 | # It doesn't make any sense to specify ancestor revisions. So limit | |
4239 | # to DAG heads to make discovery simpler. |
|
4230 | # to DAG heads to make discovery simpler. | |
4240 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) |
|
4231 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) | |
4241 | revs = scmutil.revrange(repo, [expr]) |
|
4232 | revs = scmutil.revrange(repo, [expr]) | |
4242 | revs = [repo[rev].node() for rev in revs] |
|
4233 | revs = [repo[rev].node() for rev in revs] | |
4243 | if not revs: |
|
4234 | if not revs: | |
4244 | raise error.Abort(_('default push revset for path evaluates to an ' |
|
4235 | raise error.Abort(_('default push revset for path evaluates to an ' | |
4245 | 'empty set')) |
|
4236 | 'empty set')) | |
4246 |
|
4237 | |||
4247 | repo._subtoppath = dest |
|
4238 | repo._subtoppath = dest | |
4248 | try: |
|
4239 | try: | |
4249 | # push subrepos depth-first for coherent ordering |
|
4240 | # push subrepos depth-first for coherent ordering | |
4250 | c = repo['.'] |
|
4241 | c = repo['.'] | |
4251 | subs = c.substate # only repos that are committed |
|
4242 | subs = c.substate # only repos that are committed | |
4252 | for s in sorted(subs): |
|
4243 | for s in sorted(subs): | |
4253 | result = c.sub(s).push(opts) |
|
4244 | result = c.sub(s).push(opts) | |
4254 | if result == 0: |
|
4245 | if result == 0: | |
4255 | return not result |
|
4246 | return not result | |
4256 | finally: |
|
4247 | finally: | |
4257 | del repo._subtoppath |
|
4248 | del repo._subtoppath | |
4258 |
|
4249 | |||
4259 | opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it |
|
4250 | opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it | |
4260 | opargs.setdefault('pushvars', []).extend(opts.get('pushvars', [])) |
|
4251 | opargs.setdefault('pushvars', []).extend(opts.get('pushvars', [])) | |
4261 |
|
4252 | |||
4262 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, |
|
4253 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, | |
4263 | newbranch=opts.get('new_branch'), |
|
4254 | newbranch=opts.get('new_branch'), | |
4264 | bookmarks=opts.get('bookmark', ()), |
|
4255 | bookmarks=opts.get('bookmark', ()), | |
4265 | opargs=opargs) |
|
4256 | opargs=opargs) | |
4266 |
|
4257 | |||
4267 | result = not pushop.cgresult |
|
4258 | result = not pushop.cgresult | |
4268 |
|
4259 | |||
4269 | if pushop.bkresult is not None: |
|
4260 | if pushop.bkresult is not None: | |
4270 | if pushop.bkresult == 2: |
|
4261 | if pushop.bkresult == 2: | |
4271 | result = 2 |
|
4262 | result = 2 | |
4272 | elif not result and pushop.bkresult: |
|
4263 | elif not result and pushop.bkresult: | |
4273 | result = 2 |
|
4264 | result = 2 | |
4274 |
|
4265 | |||
4275 | return result |
|
4266 | return result | |
4276 |
|
4267 | |||
4277 | @command('recover', []) |
|
4268 | @command('recover', []) | |
4278 | def recover(ui, repo): |
|
4269 | def recover(ui, repo): | |
4279 | """roll back an interrupted transaction |
|
4270 | """roll back an interrupted transaction | |
4280 |
|
4271 | |||
4281 | Recover from an interrupted commit or pull. |
|
4272 | Recover from an interrupted commit or pull. | |
4282 |
|
4273 | |||
4283 | This command tries to fix the repository status after an |
|
4274 | This command tries to fix the repository status after an | |
4284 | interrupted operation. It should only be necessary when Mercurial |
|
4275 | interrupted operation. It should only be necessary when Mercurial | |
4285 | suggests it. |
|
4276 | suggests it. | |
4286 |
|
4277 | |||
4287 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
4278 | Returns 0 if successful, 1 if nothing to recover or verify fails. | |
4288 | """ |
|
4279 | """ | |
4289 | if repo.recover(): |
|
4280 | if repo.recover(): | |
4290 | return hg.verify(repo) |
|
4281 | return hg.verify(repo) | |
4291 | return 1 |
|
4282 | return 1 | |
4292 |
|
4283 | |||
4293 | @command('^remove|rm', |
|
4284 | @command('^remove|rm', | |
4294 | [('A', 'after', None, _('record delete for missing files')), |
|
4285 | [('A', 'after', None, _('record delete for missing files')), | |
4295 | ('f', 'force', None, |
|
4286 | ('f', 'force', None, | |
4296 | _('forget added files, delete modified files')), |
|
4287 | _('forget added files, delete modified files')), | |
4297 | ] + subrepoopts + walkopts + dryrunopts, |
|
4288 | ] + subrepoopts + walkopts + dryrunopts, | |
4298 | _('[OPTION]... FILE...'), |
|
4289 | _('[OPTION]... FILE...'), | |
4299 | inferrepo=True) |
|
4290 | inferrepo=True) | |
4300 | def remove(ui, repo, *pats, **opts): |
|
4291 | def remove(ui, repo, *pats, **opts): | |
4301 | """remove the specified files on the next commit |
|
4292 | """remove the specified files on the next commit | |
4302 |
|
4293 | |||
4303 | Schedule the indicated files for removal from the current branch. |
|
4294 | Schedule the indicated files for removal from the current branch. | |
4304 |
|
4295 | |||
4305 | This command schedules the files to be removed at the next commit. |
|
4296 | This command schedules the files to be removed at the next commit. | |
4306 | To undo a remove before that, see :hg:`revert`. To undo added |
|
4297 | To undo a remove before that, see :hg:`revert`. To undo added | |
4307 | files, see :hg:`forget`. |
|
4298 | files, see :hg:`forget`. | |
4308 |
|
4299 | |||
4309 | .. container:: verbose |
|
4300 | .. container:: verbose | |
4310 |
|
4301 | |||
4311 | -A/--after can be used to remove only files that have already |
|
4302 | -A/--after can be used to remove only files that have already | |
4312 | been deleted, -f/--force can be used to force deletion, and -Af |
|
4303 | been deleted, -f/--force can be used to force deletion, and -Af | |
4313 | can be used to remove files from the next revision without |
|
4304 | can be used to remove files from the next revision without | |
4314 | deleting them from the working directory. |
|
4305 | deleting them from the working directory. | |
4315 |
|
4306 | |||
4316 | The following table details the behavior of remove for different |
|
4307 | The following table details the behavior of remove for different | |
4317 | file states (columns) and option combinations (rows). The file |
|
4308 | file states (columns) and option combinations (rows). The file | |
4318 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
4309 | states are Added [A], Clean [C], Modified [M] and Missing [!] | |
4319 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
4310 | (as reported by :hg:`status`). The actions are Warn, Remove | |
4320 | (from branch) and Delete (from disk): |
|
4311 | (from branch) and Delete (from disk): | |
4321 |
|
4312 | |||
4322 | ========= == == == == |
|
4313 | ========= == == == == | |
4323 | opt/state A C M ! |
|
4314 | opt/state A C M ! | |
4324 | ========= == == == == |
|
4315 | ========= == == == == | |
4325 | none W RD W R |
|
4316 | none W RD W R | |
4326 | -f R RD RD R |
|
4317 | -f R RD RD R | |
4327 | -A W W W R |
|
4318 | -A W W W R | |
4328 | -Af R R R R |
|
4319 | -Af R R R R | |
4329 | ========= == == == == |
|
4320 | ========= == == == == | |
4330 |
|
4321 | |||
4331 | .. note:: |
|
4322 | .. note:: | |
4332 |
|
4323 | |||
4333 | :hg:`remove` never deletes files in Added [A] state from the |
|
4324 | :hg:`remove` never deletes files in Added [A] state from the | |
4334 | working directory, not even if ``--force`` is specified. |
|
4325 | working directory, not even if ``--force`` is specified. | |
4335 |
|
4326 | |||
4336 | Returns 0 on success, 1 if any warnings encountered. |
|
4327 | Returns 0 on success, 1 if any warnings encountered. | |
4337 | """ |
|
4328 | """ | |
4338 |
|
4329 | |||
4339 | opts = pycompat.byteskwargs(opts) |
|
4330 | opts = pycompat.byteskwargs(opts) | |
4340 | after, force = opts.get('after'), opts.get('force') |
|
4331 | after, force = opts.get('after'), opts.get('force') | |
4341 | dryrun = opts.get('dry_run') |
|
4332 | dryrun = opts.get('dry_run') | |
4342 | if not pats and not after: |
|
4333 | if not pats and not after: | |
4343 | raise error.Abort(_('no files specified')) |
|
4334 | raise error.Abort(_('no files specified')) | |
4344 |
|
4335 | |||
4345 | m = scmutil.match(repo[None], pats, opts) |
|
4336 | m = scmutil.match(repo[None], pats, opts) | |
4346 | subrepos = opts.get('subrepos') |
|
4337 | subrepos = opts.get('subrepos') | |
4347 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos, |
|
4338 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos, | |
4348 | dryrun=dryrun) |
|
4339 | dryrun=dryrun) | |
4349 |
|
4340 | |||
4350 | @command('rename|move|mv', |
|
4341 | @command('rename|move|mv', | |
4351 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
4342 | [('A', 'after', None, _('record a rename that has already occurred')), | |
4352 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
4343 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
4353 | ] + walkopts + dryrunopts, |
|
4344 | ] + walkopts + dryrunopts, | |
4354 | _('[OPTION]... SOURCE... DEST')) |
|
4345 | _('[OPTION]... SOURCE... DEST')) | |
4355 | def rename(ui, repo, *pats, **opts): |
|
4346 | def rename(ui, repo, *pats, **opts): | |
4356 | """rename files; equivalent of copy + remove |
|
4347 | """rename files; equivalent of copy + remove | |
4357 |
|
4348 | |||
4358 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
4349 | Mark dest as copies of sources; mark sources for deletion. If dest | |
4359 | is a directory, copies are put in that directory. If dest is a |
|
4350 | is a directory, copies are put in that directory. If dest is a | |
4360 | file, there can only be one source. |
|
4351 | file, there can only be one source. | |
4361 |
|
4352 | |||
4362 | By default, this command copies the contents of files as they |
|
4353 | By default, this command copies the contents of files as they | |
4363 | exist in the working directory. If invoked with -A/--after, the |
|
4354 | exist in the working directory. If invoked with -A/--after, the | |
4364 | operation is recorded, but no copying is performed. |
|
4355 | operation is recorded, but no copying is performed. | |
4365 |
|
4356 | |||
4366 | This command takes effect at the next commit. To undo a rename |
|
4357 | This command takes effect at the next commit. To undo a rename | |
4367 | before that, see :hg:`revert`. |
|
4358 | before that, see :hg:`revert`. | |
4368 |
|
4359 | |||
4369 | Returns 0 on success, 1 if errors are encountered. |
|
4360 | Returns 0 on success, 1 if errors are encountered. | |
4370 | """ |
|
4361 | """ | |
4371 | opts = pycompat.byteskwargs(opts) |
|
4362 | opts = pycompat.byteskwargs(opts) | |
4372 | with repo.wlock(False): |
|
4363 | with repo.wlock(False): | |
4373 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
4364 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | |
4374 |
|
4365 | |||
4375 | @command('resolve', |
|
4366 | @command('resolve', | |
4376 | [('a', 'all', None, _('select all unresolved files')), |
|
4367 | [('a', 'all', None, _('select all unresolved files')), | |
4377 | ('l', 'list', None, _('list state of files needing merge')), |
|
4368 | ('l', 'list', None, _('list state of files needing merge')), | |
4378 | ('m', 'mark', None, _('mark files as resolved')), |
|
4369 | ('m', 'mark', None, _('mark files as resolved')), | |
4379 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
4370 | ('u', 'unmark', None, _('mark files as unresolved')), | |
4380 | ('n', 'no-status', None, _('hide status prefix'))] |
|
4371 | ('n', 'no-status', None, _('hide status prefix'))] | |
4381 | + mergetoolopts + walkopts + formatteropts, |
|
4372 | + mergetoolopts + walkopts + formatteropts, | |
4382 | _('[OPTION]... [FILE]...'), |
|
4373 | _('[OPTION]... [FILE]...'), | |
4383 | inferrepo=True) |
|
4374 | inferrepo=True) | |
4384 | def resolve(ui, repo, *pats, **opts): |
|
4375 | def resolve(ui, repo, *pats, **opts): | |
4385 | """redo merges or set/view the merge status of files |
|
4376 | """redo merges or set/view the merge status of files | |
4386 |
|
4377 | |||
4387 | Merges with unresolved conflicts are often the result of |
|
4378 | Merges with unresolved conflicts are often the result of | |
4388 | non-interactive merging using the ``internal:merge`` configuration |
|
4379 | non-interactive merging using the ``internal:merge`` configuration | |
4389 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
4380 | setting, or a command-line merge tool like ``diff3``. The resolve | |
4390 | command is used to manage the files involved in a merge, after |
|
4381 | command is used to manage the files involved in a merge, after | |
4391 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
4382 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | |
4392 | working directory must have two parents). See :hg:`help |
|
4383 | working directory must have two parents). See :hg:`help | |
4393 | merge-tools` for information on configuring merge tools. |
|
4384 | merge-tools` for information on configuring merge tools. | |
4394 |
|
4385 | |||
4395 | The resolve command can be used in the following ways: |
|
4386 | The resolve command can be used in the following ways: | |
4396 |
|
4387 | |||
4397 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
4388 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | |
4398 | files, discarding any previous merge attempts. Re-merging is not |
|
4389 | files, discarding any previous merge attempts. Re-merging is not | |
4399 | performed for files already marked as resolved. Use ``--all/-a`` |
|
4390 | performed for files already marked as resolved. Use ``--all/-a`` | |
4400 | to select all unresolved files. ``--tool`` can be used to specify |
|
4391 | to select all unresolved files. ``--tool`` can be used to specify | |
4401 | the merge tool used for the given files. It overrides the HGMERGE |
|
4392 | the merge tool used for the given files. It overrides the HGMERGE | |
4402 | environment variable and your configuration files. Previous file |
|
4393 | environment variable and your configuration files. Previous file | |
4403 | contents are saved with a ``.orig`` suffix. |
|
4394 | contents are saved with a ``.orig`` suffix. | |
4404 |
|
4395 | |||
4405 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
4396 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved | |
4406 | (e.g. after having manually fixed-up the files). The default is |
|
4397 | (e.g. after having manually fixed-up the files). The default is | |
4407 | to mark all unresolved files. |
|
4398 | to mark all unresolved files. | |
4408 |
|
4399 | |||
4409 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
4400 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The | |
4410 | default is to mark all resolved files. |
|
4401 | default is to mark all resolved files. | |
4411 |
|
4402 | |||
4412 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
4403 | - :hg:`resolve -l`: list files which had or still have conflicts. | |
4413 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
4404 | In the printed list, ``U`` = unresolved and ``R`` = resolved. | |
4414 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter |
|
4405 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter | |
4415 | the list. See :hg:`help filesets` for details. |
|
4406 | the list. See :hg:`help filesets` for details. | |
4416 |
|
4407 | |||
4417 | .. note:: |
|
4408 | .. note:: | |
4418 |
|
4409 | |||
4419 | Mercurial will not let you commit files with unresolved merge |
|
4410 | Mercurial will not let you commit files with unresolved merge | |
4420 | conflicts. You must use :hg:`resolve -m ...` before you can |
|
4411 | conflicts. You must use :hg:`resolve -m ...` before you can | |
4421 | commit after a conflicting merge. |
|
4412 | commit after a conflicting merge. | |
4422 |
|
4413 | |||
4423 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
4414 | Returns 0 on success, 1 if any files fail a resolve attempt. | |
4424 | """ |
|
4415 | """ | |
4425 |
|
4416 | |||
4426 | opts = pycompat.byteskwargs(opts) |
|
4417 | opts = pycompat.byteskwargs(opts) | |
4427 | flaglist = 'all mark unmark list no_status'.split() |
|
4418 | flaglist = 'all mark unmark list no_status'.split() | |
4428 | all, mark, unmark, show, nostatus = \ |
|
4419 | all, mark, unmark, show, nostatus = \ | |
4429 | [opts.get(o) for o in flaglist] |
|
4420 | [opts.get(o) for o in flaglist] | |
4430 |
|
4421 | |||
4431 | if (show and (mark or unmark)) or (mark and unmark): |
|
4422 | if (show and (mark or unmark)) or (mark and unmark): | |
4432 | raise error.Abort(_("too many options specified")) |
|
4423 | raise error.Abort(_("too many options specified")) | |
4433 | if pats and all: |
|
4424 | if pats and all: | |
4434 | raise error.Abort(_("can't specify --all and patterns")) |
|
4425 | raise error.Abort(_("can't specify --all and patterns")) | |
4435 | if not (all or pats or show or mark or unmark): |
|
4426 | if not (all or pats or show or mark or unmark): | |
4436 | raise error.Abort(_('no files or directories specified'), |
|
4427 | raise error.Abort(_('no files or directories specified'), | |
4437 | hint=('use --all to re-merge all unresolved files')) |
|
4428 | hint=('use --all to re-merge all unresolved files')) | |
4438 |
|
4429 | |||
4439 | if show: |
|
4430 | if show: | |
4440 | ui.pager('resolve') |
|
4431 | ui.pager('resolve') | |
4441 | fm = ui.formatter('resolve', opts) |
|
4432 | fm = ui.formatter('resolve', opts) | |
4442 | ms = mergemod.mergestate.read(repo) |
|
4433 | ms = mergemod.mergestate.read(repo) | |
4443 | m = scmutil.match(repo[None], pats, opts) |
|
4434 | m = scmutil.match(repo[None], pats, opts) | |
4444 |
|
4435 | |||
4445 | # Labels and keys based on merge state. Unresolved path conflicts show |
|
4436 | # Labels and keys based on merge state. Unresolved path conflicts show | |
4446 | # as 'P'. Resolved path conflicts show as 'R', the same as normal |
|
4437 | # as 'P'. Resolved path conflicts show as 'R', the same as normal | |
4447 | # resolved conflicts. |
|
4438 | # resolved conflicts. | |
4448 | mergestateinfo = { |
|
4439 | mergestateinfo = { | |
4449 | mergemod.MERGE_RECORD_UNRESOLVED: ('resolve.unresolved', 'U'), |
|
4440 | mergemod.MERGE_RECORD_UNRESOLVED: ('resolve.unresolved', 'U'), | |
4450 | mergemod.MERGE_RECORD_RESOLVED: ('resolve.resolved', 'R'), |
|
4441 | mergemod.MERGE_RECORD_RESOLVED: ('resolve.resolved', 'R'), | |
4451 | mergemod.MERGE_RECORD_UNRESOLVED_PATH: ('resolve.unresolved', 'P'), |
|
4442 | mergemod.MERGE_RECORD_UNRESOLVED_PATH: ('resolve.unresolved', 'P'), | |
4452 | mergemod.MERGE_RECORD_RESOLVED_PATH: ('resolve.resolved', 'R'), |
|
4443 | mergemod.MERGE_RECORD_RESOLVED_PATH: ('resolve.resolved', 'R'), | |
4453 | mergemod.MERGE_RECORD_DRIVER_RESOLVED: ('resolve.driverresolved', |
|
4444 | mergemod.MERGE_RECORD_DRIVER_RESOLVED: ('resolve.driverresolved', | |
4454 | 'D'), |
|
4445 | 'D'), | |
4455 | } |
|
4446 | } | |
4456 |
|
4447 | |||
4457 | for f in ms: |
|
4448 | for f in ms: | |
4458 | if not m(f): |
|
4449 | if not m(f): | |
4459 | continue |
|
4450 | continue | |
4460 |
|
4451 | |||
4461 | label, key = mergestateinfo[ms[f]] |
|
4452 | label, key = mergestateinfo[ms[f]] | |
4462 | fm.startitem() |
|
4453 | fm.startitem() | |
4463 | fm.condwrite(not nostatus, 'status', '%s ', key, label=label) |
|
4454 | fm.condwrite(not nostatus, 'status', '%s ', key, label=label) | |
4464 | fm.write('path', '%s\n', f, label=label) |
|
4455 | fm.write('path', '%s\n', f, label=label) | |
4465 | fm.end() |
|
4456 | fm.end() | |
4466 | return 0 |
|
4457 | return 0 | |
4467 |
|
4458 | |||
4468 | with repo.wlock(): |
|
4459 | with repo.wlock(): | |
4469 | ms = mergemod.mergestate.read(repo) |
|
4460 | ms = mergemod.mergestate.read(repo) | |
4470 |
|
4461 | |||
4471 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
4462 | if not (ms.active() or repo.dirstate.p2() != nullid): | |
4472 | raise error.Abort( |
|
4463 | raise error.Abort( | |
4473 | _('resolve command not applicable when not merging')) |
|
4464 | _('resolve command not applicable when not merging')) | |
4474 |
|
4465 | |||
4475 | wctx = repo[None] |
|
4466 | wctx = repo[None] | |
4476 |
|
4467 | |||
4477 | if (ms.mergedriver |
|
4468 | if (ms.mergedriver | |
4478 | and ms.mdstate() == mergemod.MERGE_DRIVER_STATE_UNMARKED): |
|
4469 | and ms.mdstate() == mergemod.MERGE_DRIVER_STATE_UNMARKED): | |
4479 | proceed = mergemod.driverpreprocess(repo, ms, wctx) |
|
4470 | proceed = mergemod.driverpreprocess(repo, ms, wctx) | |
4480 | ms.commit() |
|
4471 | ms.commit() | |
4481 | # allow mark and unmark to go through |
|
4472 | # allow mark and unmark to go through | |
4482 | if not mark and not unmark and not proceed: |
|
4473 | if not mark and not unmark and not proceed: | |
4483 | return 1 |
|
4474 | return 1 | |
4484 |
|
4475 | |||
4485 | m = scmutil.match(wctx, pats, opts) |
|
4476 | m = scmutil.match(wctx, pats, opts) | |
4486 | ret = 0 |
|
4477 | ret = 0 | |
4487 | didwork = False |
|
4478 | didwork = False | |
4488 | runconclude = False |
|
4479 | runconclude = False | |
4489 |
|
4480 | |||
4490 | tocomplete = [] |
|
4481 | tocomplete = [] | |
4491 | for f in ms: |
|
4482 | for f in ms: | |
4492 | if not m(f): |
|
4483 | if not m(f): | |
4493 | continue |
|
4484 | continue | |
4494 |
|
4485 | |||
4495 | didwork = True |
|
4486 | didwork = True | |
4496 |
|
4487 | |||
4497 | # don't let driver-resolved files be marked, and run the conclude |
|
4488 | # don't let driver-resolved files be marked, and run the conclude | |
4498 | # step if asked to resolve |
|
4489 | # step if asked to resolve | |
4499 | if ms[f] == mergemod.MERGE_RECORD_DRIVER_RESOLVED: |
|
4490 | if ms[f] == mergemod.MERGE_RECORD_DRIVER_RESOLVED: | |
4500 | exact = m.exact(f) |
|
4491 | exact = m.exact(f) | |
4501 | if mark: |
|
4492 | if mark: | |
4502 | if exact: |
|
4493 | if exact: | |
4503 | ui.warn(_('not marking %s as it is driver-resolved\n') |
|
4494 | ui.warn(_('not marking %s as it is driver-resolved\n') | |
4504 | % f) |
|
4495 | % f) | |
4505 | elif unmark: |
|
4496 | elif unmark: | |
4506 | if exact: |
|
4497 | if exact: | |
4507 | ui.warn(_('not unmarking %s as it is driver-resolved\n') |
|
4498 | ui.warn(_('not unmarking %s as it is driver-resolved\n') | |
4508 | % f) |
|
4499 | % f) | |
4509 | else: |
|
4500 | else: | |
4510 | runconclude = True |
|
4501 | runconclude = True | |
4511 | continue |
|
4502 | continue | |
4512 |
|
4503 | |||
4513 | # path conflicts must be resolved manually |
|
4504 | # path conflicts must be resolved manually | |
4514 | if ms[f] in (mergemod.MERGE_RECORD_UNRESOLVED_PATH, |
|
4505 | if ms[f] in (mergemod.MERGE_RECORD_UNRESOLVED_PATH, | |
4515 | mergemod.MERGE_RECORD_RESOLVED_PATH): |
|
4506 | mergemod.MERGE_RECORD_RESOLVED_PATH): | |
4516 | if mark: |
|
4507 | if mark: | |
4517 | ms.mark(f, mergemod.MERGE_RECORD_RESOLVED_PATH) |
|
4508 | ms.mark(f, mergemod.MERGE_RECORD_RESOLVED_PATH) | |
4518 | elif unmark: |
|
4509 | elif unmark: | |
4519 | ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED_PATH) |
|
4510 | ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED_PATH) | |
4520 | elif ms[f] == mergemod.MERGE_RECORD_UNRESOLVED_PATH: |
|
4511 | elif ms[f] == mergemod.MERGE_RECORD_UNRESOLVED_PATH: | |
4521 | ui.warn(_('%s: path conflict must be resolved manually\n') |
|
4512 | ui.warn(_('%s: path conflict must be resolved manually\n') | |
4522 | % f) |
|
4513 | % f) | |
4523 | continue |
|
4514 | continue | |
4524 |
|
4515 | |||
4525 | if mark: |
|
4516 | if mark: | |
4526 | ms.mark(f, mergemod.MERGE_RECORD_RESOLVED) |
|
4517 | ms.mark(f, mergemod.MERGE_RECORD_RESOLVED) | |
4527 | elif unmark: |
|
4518 | elif unmark: | |
4528 | ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED) |
|
4519 | ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED) | |
4529 | else: |
|
4520 | else: | |
4530 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
4521 | # backup pre-resolve (merge uses .orig for its own purposes) | |
4531 | a = repo.wjoin(f) |
|
4522 | a = repo.wjoin(f) | |
4532 | try: |
|
4523 | try: | |
4533 | util.copyfile(a, a + ".resolve") |
|
4524 | util.copyfile(a, a + ".resolve") | |
4534 | except (IOError, OSError) as inst: |
|
4525 | except (IOError, OSError) as inst: | |
4535 | if inst.errno != errno.ENOENT: |
|
4526 | if inst.errno != errno.ENOENT: | |
4536 | raise |
|
4527 | raise | |
4537 |
|
4528 | |||
4538 | try: |
|
4529 | try: | |
4539 | # preresolve file |
|
4530 | # preresolve file | |
4540 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
4531 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
4541 | with ui.configoverride(overrides, 'resolve'): |
|
4532 | with ui.configoverride(overrides, 'resolve'): | |
4542 | complete, r = ms.preresolve(f, wctx) |
|
4533 | complete, r = ms.preresolve(f, wctx) | |
4543 | if not complete: |
|
4534 | if not complete: | |
4544 | tocomplete.append(f) |
|
4535 | tocomplete.append(f) | |
4545 | elif r: |
|
4536 | elif r: | |
4546 | ret = 1 |
|
4537 | ret = 1 | |
4547 | finally: |
|
4538 | finally: | |
4548 | ms.commit() |
|
4539 | ms.commit() | |
4549 |
|
4540 | |||
4550 | # replace filemerge's .orig file with our resolve file, but only |
|
4541 | # replace filemerge's .orig file with our resolve file, but only | |
4551 | # for merges that are complete |
|
4542 | # for merges that are complete | |
4552 | if complete: |
|
4543 | if complete: | |
4553 | try: |
|
4544 | try: | |
4554 | util.rename(a + ".resolve", |
|
4545 | util.rename(a + ".resolve", | |
4555 | scmutil.origpath(ui, repo, a)) |
|
4546 | scmutil.origpath(ui, repo, a)) | |
4556 | except OSError as inst: |
|
4547 | except OSError as inst: | |
4557 | if inst.errno != errno.ENOENT: |
|
4548 | if inst.errno != errno.ENOENT: | |
4558 | raise |
|
4549 | raise | |
4559 |
|
4550 | |||
4560 | for f in tocomplete: |
|
4551 | for f in tocomplete: | |
4561 | try: |
|
4552 | try: | |
4562 | # resolve file |
|
4553 | # resolve file | |
4563 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
|
4554 | overrides = {('ui', 'forcemerge'): opts.get('tool', '')} | |
4564 | with ui.configoverride(overrides, 'resolve'): |
|
4555 | with ui.configoverride(overrides, 'resolve'): | |
4565 | r = ms.resolve(f, wctx) |
|
4556 | r = ms.resolve(f, wctx) | |
4566 | if r: |
|
4557 | if r: | |
4567 | ret = 1 |
|
4558 | ret = 1 | |
4568 | finally: |
|
4559 | finally: | |
4569 | ms.commit() |
|
4560 | ms.commit() | |
4570 |
|
4561 | |||
4571 | # replace filemerge's .orig file with our resolve file |
|
4562 | # replace filemerge's .orig file with our resolve file | |
4572 | a = repo.wjoin(f) |
|
4563 | a = repo.wjoin(f) | |
4573 | try: |
|
4564 | try: | |
4574 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) |
|
4565 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) | |
4575 | except OSError as inst: |
|
4566 | except OSError as inst: | |
4576 | if inst.errno != errno.ENOENT: |
|
4567 | if inst.errno != errno.ENOENT: | |
4577 | raise |
|
4568 | raise | |
4578 |
|
4569 | |||
4579 | ms.commit() |
|
4570 | ms.commit() | |
4580 | ms.recordactions() |
|
4571 | ms.recordactions() | |
4581 |
|
4572 | |||
4582 | if not didwork and pats: |
|
4573 | if not didwork and pats: | |
4583 | hint = None |
|
4574 | hint = None | |
4584 | if not any([p for p in pats if p.find(':') >= 0]): |
|
4575 | if not any([p for p in pats if p.find(':') >= 0]): | |
4585 | pats = ['path:%s' % p for p in pats] |
|
4576 | pats = ['path:%s' % p for p in pats] | |
4586 | m = scmutil.match(wctx, pats, opts) |
|
4577 | m = scmutil.match(wctx, pats, opts) | |
4587 | for f in ms: |
|
4578 | for f in ms: | |
4588 | if not m(f): |
|
4579 | if not m(f): | |
4589 | continue |
|
4580 | continue | |
4590 | flags = ''.join(['-%s ' % o[0:1] for o in flaglist |
|
4581 | flags = ''.join(['-%s ' % o[0:1] for o in flaglist | |
4591 | if opts.get(o)]) |
|
4582 | if opts.get(o)]) | |
4592 | hint = _("(try: hg resolve %s%s)\n") % ( |
|
4583 | hint = _("(try: hg resolve %s%s)\n") % ( | |
4593 | flags, |
|
4584 | flags, | |
4594 | ' '.join(pats)) |
|
4585 | ' '.join(pats)) | |
4595 | break |
|
4586 | break | |
4596 | ui.warn(_("arguments do not match paths that need resolving\n")) |
|
4587 | ui.warn(_("arguments do not match paths that need resolving\n")) | |
4597 | if hint: |
|
4588 | if hint: | |
4598 | ui.warn(hint) |
|
4589 | ui.warn(hint) | |
4599 | elif ms.mergedriver and ms.mdstate() != 's': |
|
4590 | elif ms.mergedriver and ms.mdstate() != 's': | |
4600 | # run conclude step when either a driver-resolved file is requested |
|
4591 | # run conclude step when either a driver-resolved file is requested | |
4601 | # or there are no driver-resolved files |
|
4592 | # or there are no driver-resolved files | |
4602 | # we can't use 'ret' to determine whether any files are unresolved |
|
4593 | # we can't use 'ret' to determine whether any files are unresolved | |
4603 | # because we might not have tried to resolve some |
|
4594 | # because we might not have tried to resolve some | |
4604 | if ((runconclude or not list(ms.driverresolved())) |
|
4595 | if ((runconclude or not list(ms.driverresolved())) | |
4605 | and not list(ms.unresolved())): |
|
4596 | and not list(ms.unresolved())): | |
4606 | proceed = mergemod.driverconclude(repo, ms, wctx) |
|
4597 | proceed = mergemod.driverconclude(repo, ms, wctx) | |
4607 | ms.commit() |
|
4598 | ms.commit() | |
4608 | if not proceed: |
|
4599 | if not proceed: | |
4609 | return 1 |
|
4600 | return 1 | |
4610 |
|
4601 | |||
4611 | # Nudge users into finishing an unfinished operation |
|
4602 | # Nudge users into finishing an unfinished operation | |
4612 | unresolvedf = list(ms.unresolved()) |
|
4603 | unresolvedf = list(ms.unresolved()) | |
4613 | driverresolvedf = list(ms.driverresolved()) |
|
4604 | driverresolvedf = list(ms.driverresolved()) | |
4614 | if not unresolvedf and not driverresolvedf: |
|
4605 | if not unresolvedf and not driverresolvedf: | |
4615 | ui.status(_('(no more unresolved files)\n')) |
|
4606 | ui.status(_('(no more unresolved files)\n')) | |
4616 | cmdutil.checkafterresolved(repo) |
|
4607 | cmdutil.checkafterresolved(repo) | |
4617 | elif not unresolvedf: |
|
4608 | elif not unresolvedf: | |
4618 | ui.status(_('(no more unresolved files -- ' |
|
4609 | ui.status(_('(no more unresolved files -- ' | |
4619 | 'run "hg resolve --all" to conclude)\n')) |
|
4610 | 'run "hg resolve --all" to conclude)\n')) | |
4620 |
|
4611 | |||
4621 | return ret |
|
4612 | return ret | |
4622 |
|
4613 | |||
4623 | @command('revert', |
|
4614 | @command('revert', | |
4624 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4615 | [('a', 'all', None, _('revert all changes when no arguments given')), | |
4625 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4616 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
4626 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4617 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), | |
4627 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
4618 | ('C', 'no-backup', None, _('do not save backup copies of files')), | |
4628 | ('i', 'interactive', None, _('interactively select the changes')), |
|
4619 | ('i', 'interactive', None, _('interactively select the changes')), | |
4629 | ] + walkopts + dryrunopts, |
|
4620 | ] + walkopts + dryrunopts, | |
4630 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4621 | _('[OPTION]... [-r REV] [NAME]...')) | |
4631 | def revert(ui, repo, *pats, **opts): |
|
4622 | def revert(ui, repo, *pats, **opts): | |
4632 | """restore files to their checkout state |
|
4623 | """restore files to their checkout state | |
4633 |
|
4624 | |||
4634 | .. note:: |
|
4625 | .. note:: | |
4635 |
|
4626 | |||
4636 | To check out earlier revisions, you should use :hg:`update REV`. |
|
4627 | To check out earlier revisions, you should use :hg:`update REV`. | |
4637 | To cancel an uncommitted merge (and lose your changes), |
|
4628 | To cancel an uncommitted merge (and lose your changes), | |
4638 | use :hg:`merge --abort`. |
|
4629 | use :hg:`merge --abort`. | |
4639 |
|
4630 | |||
4640 | With no revision specified, revert the specified files or directories |
|
4631 | With no revision specified, revert the specified files or directories | |
4641 | to the contents they had in the parent of the working directory. |
|
4632 | to the contents they had in the parent of the working directory. | |
4642 | This restores the contents of files to an unmodified |
|
4633 | This restores the contents of files to an unmodified | |
4643 | state and unschedules adds, removes, copies, and renames. If the |
|
4634 | state and unschedules adds, removes, copies, and renames. If the | |
4644 | working directory has two parents, you must explicitly specify a |
|
4635 | working directory has two parents, you must explicitly specify a | |
4645 | revision. |
|
4636 | revision. | |
4646 |
|
4637 | |||
4647 | Using the -r/--rev or -d/--date options, revert the given files or |
|
4638 | Using the -r/--rev or -d/--date options, revert the given files or | |
4648 | directories to their states as of a specific revision. Because |
|
4639 | directories to their states as of a specific revision. Because | |
4649 | revert does not change the working directory parents, this will |
|
4640 | revert does not change the working directory parents, this will | |
4650 | cause these files to appear modified. This can be helpful to "back |
|
4641 | cause these files to appear modified. This can be helpful to "back | |
4651 | out" some or all of an earlier change. See :hg:`backout` for a |
|
4642 | out" some or all of an earlier change. See :hg:`backout` for a | |
4652 | related method. |
|
4643 | related method. | |
4653 |
|
4644 | |||
4654 | Modified files are saved with a .orig suffix before reverting. |
|
4645 | Modified files are saved with a .orig suffix before reverting. | |
4655 | To disable these backups, use --no-backup. It is possible to store |
|
4646 | To disable these backups, use --no-backup. It is possible to store | |
4656 | the backup files in a custom directory relative to the root of the |
|
4647 | the backup files in a custom directory relative to the root of the | |
4657 | repository by setting the ``ui.origbackuppath`` configuration |
|
4648 | repository by setting the ``ui.origbackuppath`` configuration | |
4658 | option. |
|
4649 | option. | |
4659 |
|
4650 | |||
4660 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4651 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
4661 |
|
4652 | |||
4662 | See :hg:`help backout` for a way to reverse the effect of an |
|
4653 | See :hg:`help backout` for a way to reverse the effect of an | |
4663 | earlier changeset. |
|
4654 | earlier changeset. | |
4664 |
|
4655 | |||
4665 | Returns 0 on success. |
|
4656 | Returns 0 on success. | |
4666 | """ |
|
4657 | """ | |
4667 |
|
4658 | |||
4668 | opts = pycompat.byteskwargs(opts) |
|
4659 | opts = pycompat.byteskwargs(opts) | |
4669 | if opts.get("date"): |
|
4660 | if opts.get("date"): | |
4670 | if opts.get("rev"): |
|
4661 | if opts.get("rev"): | |
4671 | raise error.Abort(_("you can't specify a revision and a date")) |
|
4662 | raise error.Abort(_("you can't specify a revision and a date")) | |
4672 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4663 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | |
4673 |
|
4664 | |||
4674 | parent, p2 = repo.dirstate.parents() |
|
4665 | parent, p2 = repo.dirstate.parents() | |
4675 | if not opts.get('rev') and p2 != nullid: |
|
4666 | if not opts.get('rev') and p2 != nullid: | |
4676 | # revert after merge is a trap for new users (issue2915) |
|
4667 | # revert after merge is a trap for new users (issue2915) | |
4677 | raise error.Abort(_('uncommitted merge with no revision specified'), |
|
4668 | raise error.Abort(_('uncommitted merge with no revision specified'), | |
4678 | hint=_("use 'hg update' or see 'hg help revert'")) |
|
4669 | hint=_("use 'hg update' or see 'hg help revert'")) | |
4679 |
|
4670 | |||
4680 | rev = opts.get('rev') |
|
4671 | rev = opts.get('rev') | |
4681 | if rev: |
|
4672 | if rev: | |
4682 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
4673 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
4683 | ctx = scmutil.revsingle(repo, rev) |
|
4674 | ctx = scmutil.revsingle(repo, rev) | |
4684 |
|
4675 | |||
4685 | if (not (pats or opts.get('include') or opts.get('exclude') or |
|
4676 | if (not (pats or opts.get('include') or opts.get('exclude') or | |
4686 | opts.get('all') or opts.get('interactive'))): |
|
4677 | opts.get('all') or opts.get('interactive'))): | |
4687 | msg = _("no files or directories specified") |
|
4678 | msg = _("no files or directories specified") | |
4688 | if p2 != nullid: |
|
4679 | if p2 != nullid: | |
4689 | hint = _("uncommitted merge, use --all to discard all changes," |
|
4680 | hint = _("uncommitted merge, use --all to discard all changes," | |
4690 | " or 'hg update -C .' to abort the merge") |
|
4681 | " or 'hg update -C .' to abort the merge") | |
4691 | raise error.Abort(msg, hint=hint) |
|
4682 | raise error.Abort(msg, hint=hint) | |
4692 | dirty = any(repo.status()) |
|
4683 | dirty = any(repo.status()) | |
4693 | node = ctx.node() |
|
4684 | node = ctx.node() | |
4694 | if node != parent: |
|
4685 | if node != parent: | |
4695 | if dirty: |
|
4686 | if dirty: | |
4696 | hint = _("uncommitted changes, use --all to discard all" |
|
4687 | hint = _("uncommitted changes, use --all to discard all" | |
4697 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
4688 | " changes, or 'hg update %s' to update") % ctx.rev() | |
4698 | else: |
|
4689 | else: | |
4699 | hint = _("use --all to revert all files," |
|
4690 | hint = _("use --all to revert all files," | |
4700 | " or 'hg update %s' to update") % ctx.rev() |
|
4691 | " or 'hg update %s' to update") % ctx.rev() | |
4701 | elif dirty: |
|
4692 | elif dirty: | |
4702 | hint = _("uncommitted changes, use --all to discard all changes") |
|
4693 | hint = _("uncommitted changes, use --all to discard all changes") | |
4703 | else: |
|
4694 | else: | |
4704 | hint = _("use --all to revert all files") |
|
4695 | hint = _("use --all to revert all files") | |
4705 | raise error.Abort(msg, hint=hint) |
|
4696 | raise error.Abort(msg, hint=hint) | |
4706 |
|
4697 | |||
4707 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, |
|
4698 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, | |
4708 | **pycompat.strkwargs(opts)) |
|
4699 | **pycompat.strkwargs(opts)) | |
4709 |
|
4700 | |||
4710 | @command('rollback', dryrunopts + |
|
4701 | @command('rollback', dryrunopts + | |
4711 | [('f', 'force', False, _('ignore safety measures'))]) |
|
4702 | [('f', 'force', False, _('ignore safety measures'))]) | |
4712 | def rollback(ui, repo, **opts): |
|
4703 | def rollback(ui, repo, **opts): | |
4713 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
4704 | """roll back the last transaction (DANGEROUS) (DEPRECATED) | |
4714 |
|
4705 | |||
4715 | Please use :hg:`commit --amend` instead of rollback to correct |
|
4706 | Please use :hg:`commit --amend` instead of rollback to correct | |
4716 | mistakes in the last commit. |
|
4707 | mistakes in the last commit. | |
4717 |
|
4708 | |||
4718 | This command should be used with care. There is only one level of |
|
4709 | This command should be used with care. There is only one level of | |
4719 | rollback, and there is no way to undo a rollback. It will also |
|
4710 | rollback, and there is no way to undo a rollback. It will also | |
4720 | restore the dirstate at the time of the last transaction, losing |
|
4711 | restore the dirstate at the time of the last transaction, losing | |
4721 | any dirstate changes since that time. This command does not alter |
|
4712 | any dirstate changes since that time. This command does not alter | |
4722 | the working directory. |
|
4713 | the working directory. | |
4723 |
|
4714 | |||
4724 | Transactions are used to encapsulate the effects of all commands |
|
4715 | Transactions are used to encapsulate the effects of all commands | |
4725 | that create new changesets or propagate existing changesets into a |
|
4716 | that create new changesets or propagate existing changesets into a | |
4726 | repository. |
|
4717 | repository. | |
4727 |
|
4718 | |||
4728 | .. container:: verbose |
|
4719 | .. container:: verbose | |
4729 |
|
4720 | |||
4730 | For example, the following commands are transactional, and their |
|
4721 | For example, the following commands are transactional, and their | |
4731 | effects can be rolled back: |
|
4722 | effects can be rolled back: | |
4732 |
|
4723 | |||
4733 | - commit |
|
4724 | - commit | |
4734 | - import |
|
4725 | - import | |
4735 | - pull |
|
4726 | - pull | |
4736 | - push (with this repository as the destination) |
|
4727 | - push (with this repository as the destination) | |
4737 | - unbundle |
|
4728 | - unbundle | |
4738 |
|
4729 | |||
4739 | To avoid permanent data loss, rollback will refuse to rollback a |
|
4730 | To avoid permanent data loss, rollback will refuse to rollback a | |
4740 | commit transaction if it isn't checked out. Use --force to |
|
4731 | commit transaction if it isn't checked out. Use --force to | |
4741 | override this protection. |
|
4732 | override this protection. | |
4742 |
|
4733 | |||
4743 | The rollback command can be entirely disabled by setting the |
|
4734 | The rollback command can be entirely disabled by setting the | |
4744 | ``ui.rollback`` configuration setting to false. If you're here |
|
4735 | ``ui.rollback`` configuration setting to false. If you're here | |
4745 | because you want to use rollback and it's disabled, you can |
|
4736 | because you want to use rollback and it's disabled, you can | |
4746 | re-enable the command by setting ``ui.rollback`` to true. |
|
4737 | re-enable the command by setting ``ui.rollback`` to true. | |
4747 |
|
4738 | |||
4748 | This command is not intended for use on public repositories. Once |
|
4739 | This command is not intended for use on public repositories. Once | |
4749 | changes are visible for pull by other users, rolling a transaction |
|
4740 | changes are visible for pull by other users, rolling a transaction | |
4750 | back locally is ineffective (someone else may already have pulled |
|
4741 | back locally is ineffective (someone else may already have pulled | |
4751 | the changes). Furthermore, a race is possible with readers of the |
|
4742 | the changes). Furthermore, a race is possible with readers of the | |
4752 | repository; for example an in-progress pull from the repository |
|
4743 | repository; for example an in-progress pull from the repository | |
4753 | may fail if a rollback is performed. |
|
4744 | may fail if a rollback is performed. | |
4754 |
|
4745 | |||
4755 | Returns 0 on success, 1 if no rollback data is available. |
|
4746 | Returns 0 on success, 1 if no rollback data is available. | |
4756 | """ |
|
4747 | """ | |
4757 | if not ui.configbool('ui', 'rollback'): |
|
4748 | if not ui.configbool('ui', 'rollback'): | |
4758 | raise error.Abort(_('rollback is disabled because it is unsafe'), |
|
4749 | raise error.Abort(_('rollback is disabled because it is unsafe'), | |
4759 | hint=('see `hg help -v rollback` for information')) |
|
4750 | hint=('see `hg help -v rollback` for information')) | |
4760 | return repo.rollback(dryrun=opts.get(r'dry_run'), |
|
4751 | return repo.rollback(dryrun=opts.get(r'dry_run'), | |
4761 | force=opts.get(r'force')) |
|
4752 | force=opts.get(r'force')) | |
4762 |
|
4753 | |||
4763 | @command('root', [], intents={INTENT_READONLY}) |
|
4754 | @command('root', [], intents={INTENT_READONLY}) | |
4764 | def root(ui, repo): |
|
4755 | def root(ui, repo): | |
4765 | """print the root (top) of the current working directory |
|
4756 | """print the root (top) of the current working directory | |
4766 |
|
4757 | |||
4767 | Print the root directory of the current repository. |
|
4758 | Print the root directory of the current repository. | |
4768 |
|
4759 | |||
4769 | Returns 0 on success. |
|
4760 | Returns 0 on success. | |
4770 | """ |
|
4761 | """ | |
4771 | ui.write(repo.root + "\n") |
|
4762 | ui.write(repo.root + "\n") | |
4772 |
|
4763 | |||
4773 | @command('^serve', |
|
4764 | @command('^serve', | |
4774 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
4765 | [('A', 'accesslog', '', _('name of access log file to write to'), | |
4775 | _('FILE')), |
|
4766 | _('FILE')), | |
4776 | ('d', 'daemon', None, _('run server in background')), |
|
4767 | ('d', 'daemon', None, _('run server in background')), | |
4777 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), |
|
4768 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), | |
4778 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
4769 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), | |
4779 | # use string type, then we can check if something was passed |
|
4770 | # use string type, then we can check if something was passed | |
4780 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
4771 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), | |
4781 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
4772 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), | |
4782 | _('ADDR')), |
|
4773 | _('ADDR')), | |
4783 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
4774 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), | |
4784 | _('PREFIX')), |
|
4775 | _('PREFIX')), | |
4785 | ('n', 'name', '', |
|
4776 | ('n', 'name', '', | |
4786 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
4777 | _('name to show in web pages (default: working directory)'), _('NAME')), | |
4787 | ('', 'web-conf', '', |
|
4778 | ('', 'web-conf', '', | |
4788 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), |
|
4779 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), | |
4789 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
4780 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), | |
4790 | _('FILE')), |
|
4781 | _('FILE')), | |
4791 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
4782 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), | |
4792 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), |
|
4783 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), | |
4793 | ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')), |
|
4784 | ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')), | |
4794 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
4785 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), | |
4795 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
4786 | ('', 'style', '', _('template style to use'), _('STYLE')), | |
4796 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
4787 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), | |
4797 | ('', 'certificate', '', _('SSL certificate file'), _('FILE')), |
|
4788 | ('', 'certificate', '', _('SSL certificate file'), _('FILE')), | |
4798 | ('', 'print-url', None, _('start and print only the URL'))] |
|
4789 | ('', 'print-url', None, _('start and print only the URL'))] | |
4799 | + subrepoopts, |
|
4790 | + subrepoopts, | |
4800 | _('[OPTION]...'), |
|
4791 | _('[OPTION]...'), | |
4801 | optionalrepo=True) |
|
4792 | optionalrepo=True) | |
4802 | def serve(ui, repo, **opts): |
|
4793 | def serve(ui, repo, **opts): | |
4803 | """start stand-alone webserver |
|
4794 | """start stand-alone webserver | |
4804 |
|
4795 | |||
4805 | Start a local HTTP repository browser and pull server. You can use |
|
4796 | Start a local HTTP repository browser and pull server. You can use | |
4806 | this for ad-hoc sharing and browsing of repositories. It is |
|
4797 | this for ad-hoc sharing and browsing of repositories. It is | |
4807 | recommended to use a real web server to serve a repository for |
|
4798 | recommended to use a real web server to serve a repository for | |
4808 | longer periods of time. |
|
4799 | longer periods of time. | |
4809 |
|
4800 | |||
4810 | Please note that the server does not implement access control. |
|
4801 | Please note that the server does not implement access control. | |
4811 | This means that, by default, anybody can read from the server and |
|
4802 | This means that, by default, anybody can read from the server and | |
4812 | nobody can write to it by default. Set the ``web.allow-push`` |
|
4803 | nobody can write to it by default. Set the ``web.allow-push`` | |
4813 | option to ``*`` to allow everybody to push to the server. You |
|
4804 | option to ``*`` to allow everybody to push to the server. You | |
4814 | should use a real web server if you need to authenticate users. |
|
4805 | should use a real web server if you need to authenticate users. | |
4815 |
|
4806 | |||
4816 | By default, the server logs accesses to stdout and errors to |
|
4807 | By default, the server logs accesses to stdout and errors to | |
4817 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
4808 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to | |
4818 | files. |
|
4809 | files. | |
4819 |
|
4810 | |||
4820 | To have the server choose a free port number to listen on, specify |
|
4811 | To have the server choose a free port number to listen on, specify | |
4821 | a port number of 0; in this case, the server will print the port |
|
4812 | a port number of 0; in this case, the server will print the port | |
4822 | number it uses. |
|
4813 | number it uses. | |
4823 |
|
4814 | |||
4824 | Returns 0 on success. |
|
4815 | Returns 0 on success. | |
4825 | """ |
|
4816 | """ | |
4826 |
|
4817 | |||
4827 | opts = pycompat.byteskwargs(opts) |
|
4818 | opts = pycompat.byteskwargs(opts) | |
4828 | if opts["stdio"] and opts["cmdserver"]: |
|
4819 | if opts["stdio"] and opts["cmdserver"]: | |
4829 | raise error.Abort(_("cannot use --stdio with --cmdserver")) |
|
4820 | raise error.Abort(_("cannot use --stdio with --cmdserver")) | |
4830 | if opts["print_url"] and ui.verbose: |
|
4821 | if opts["print_url"] and ui.verbose: | |
4831 | raise error.Abort(_("cannot use --print-url with --verbose")) |
|
4822 | raise error.Abort(_("cannot use --print-url with --verbose")) | |
4832 |
|
4823 | |||
4833 | if opts["stdio"]: |
|
4824 | if opts["stdio"]: | |
4834 | if repo is None: |
|
4825 | if repo is None: | |
4835 | raise error.RepoError(_("there is no Mercurial repository here" |
|
4826 | raise error.RepoError(_("there is no Mercurial repository here" | |
4836 | " (.hg not found)")) |
|
4827 | " (.hg not found)")) | |
4837 | s = wireprotoserver.sshserver(ui, repo) |
|
4828 | s = wireprotoserver.sshserver(ui, repo) | |
4838 | s.serve_forever() |
|
4829 | s.serve_forever() | |
4839 |
|
4830 | |||
4840 | service = server.createservice(ui, repo, opts) |
|
4831 | service = server.createservice(ui, repo, opts) | |
4841 | return server.runservice(opts, initfn=service.init, runfn=service.run) |
|
4832 | return server.runservice(opts, initfn=service.init, runfn=service.run) | |
4842 |
|
4833 | |||
4843 | _NOTTERSE = 'nothing' |
|
4834 | _NOTTERSE = 'nothing' | |
4844 |
|
4835 | |||
4845 | @command('^status|st', |
|
4836 | @command('^status|st', | |
4846 | [('A', 'all', None, _('show status of all files')), |
|
4837 | [('A', 'all', None, _('show status of all files')), | |
4847 | ('m', 'modified', None, _('show only modified files')), |
|
4838 | ('m', 'modified', None, _('show only modified files')), | |
4848 | ('a', 'added', None, _('show only added files')), |
|
4839 | ('a', 'added', None, _('show only added files')), | |
4849 | ('r', 'removed', None, _('show only removed files')), |
|
4840 | ('r', 'removed', None, _('show only removed files')), | |
4850 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
4841 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
4851 | ('c', 'clean', None, _('show only files without changes')), |
|
4842 | ('c', 'clean', None, _('show only files without changes')), | |
4852 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
4843 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
4853 | ('i', 'ignored', None, _('show only ignored files')), |
|
4844 | ('i', 'ignored', None, _('show only ignored files')), | |
4854 | ('n', 'no-status', None, _('hide status prefix')), |
|
4845 | ('n', 'no-status', None, _('hide status prefix')), | |
4855 | ('t', 'terse', _NOTTERSE, _('show the terse output (EXPERIMENTAL)')), |
|
4846 | ('t', 'terse', _NOTTERSE, _('show the terse output (EXPERIMENTAL)')), | |
4856 | ('C', 'copies', None, _('show source of copied files')), |
|
4847 | ('C', 'copies', None, _('show source of copied files')), | |
4857 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4848 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
4858 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
4849 | ('', 'rev', [], _('show difference from revision'), _('REV')), | |
4859 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
4850 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), | |
4860 | ] + walkopts + subrepoopts + formatteropts, |
|
4851 | ] + walkopts + subrepoopts + formatteropts, | |
4861 | _('[OPTION]... [FILE]...'), |
|
4852 | _('[OPTION]... [FILE]...'), | |
4862 | inferrepo=True, |
|
4853 | inferrepo=True, | |
4863 | intents={INTENT_READONLY}) |
|
4854 | intents={INTENT_READONLY}) | |
4864 | def status(ui, repo, *pats, **opts): |
|
4855 | def status(ui, repo, *pats, **opts): | |
4865 | """show changed files in the working directory |
|
4856 | """show changed files in the working directory | |
4866 |
|
4857 | |||
4867 | Show status of files in the repository. If names are given, only |
|
4858 | Show status of files in the repository. If names are given, only | |
4868 | files that match are shown. Files that are clean or ignored or |
|
4859 | files that match are shown. Files that are clean or ignored or | |
4869 | the source of a copy/move operation, are not listed unless |
|
4860 | the source of a copy/move operation, are not listed unless | |
4870 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
4861 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. | |
4871 | Unless options described with "show only ..." are given, the |
|
4862 | Unless options described with "show only ..." are given, the | |
4872 | options -mardu are used. |
|
4863 | options -mardu are used. | |
4873 |
|
4864 | |||
4874 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
4865 | Option -q/--quiet hides untracked (unknown and ignored) files | |
4875 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
4866 | unless explicitly requested with -u/--unknown or -i/--ignored. | |
4876 |
|
4867 | |||
4877 | .. note:: |
|
4868 | .. note:: | |
4878 |
|
4869 | |||
4879 | :hg:`status` may appear to disagree with diff if permissions have |
|
4870 | :hg:`status` may appear to disagree with diff if permissions have | |
4880 | changed or a merge has occurred. The standard diff format does |
|
4871 | changed or a merge has occurred. The standard diff format does | |
4881 | not report permission changes and diff only reports changes |
|
4872 | not report permission changes and diff only reports changes | |
4882 | relative to one merge parent. |
|
4873 | relative to one merge parent. | |
4883 |
|
4874 | |||
4884 | If one revision is given, it is used as the base revision. |
|
4875 | If one revision is given, it is used as the base revision. | |
4885 | If two revisions are given, the differences between them are |
|
4876 | If two revisions are given, the differences between them are | |
4886 | shown. The --change option can also be used as a shortcut to list |
|
4877 | shown. The --change option can also be used as a shortcut to list | |
4887 | the changed files of a revision from its first parent. |
|
4878 | the changed files of a revision from its first parent. | |
4888 |
|
4879 | |||
4889 | The codes used to show the status of files are:: |
|
4880 | The codes used to show the status of files are:: | |
4890 |
|
4881 | |||
4891 | M = modified |
|
4882 | M = modified | |
4892 | A = added |
|
4883 | A = added | |
4893 | R = removed |
|
4884 | R = removed | |
4894 | C = clean |
|
4885 | C = clean | |
4895 | ! = missing (deleted by non-hg command, but still tracked) |
|
4886 | ! = missing (deleted by non-hg command, but still tracked) | |
4896 | ? = not tracked |
|
4887 | ? = not tracked | |
4897 | I = ignored |
|
4888 | I = ignored | |
4898 | = origin of the previous file (with --copies) |
|
4889 | = origin of the previous file (with --copies) | |
4899 |
|
4890 | |||
4900 | .. container:: verbose |
|
4891 | .. container:: verbose | |
4901 |
|
4892 | |||
4902 | The -t/--terse option abbreviates the output by showing only the directory |
|
4893 | The -t/--terse option abbreviates the output by showing only the directory | |
4903 | name if all the files in it share the same status. The option takes an |
|
4894 | name if all the files in it share the same status. The option takes an | |
4904 | argument indicating the statuses to abbreviate: 'm' for 'modified', 'a' |
|
4895 | argument indicating the statuses to abbreviate: 'm' for 'modified', 'a' | |
4905 | for 'added', 'r' for 'removed', 'd' for 'deleted', 'u' for 'unknown', 'i' |
|
4896 | for 'added', 'r' for 'removed', 'd' for 'deleted', 'u' for 'unknown', 'i' | |
4906 | for 'ignored' and 'c' for clean. |
|
4897 | for 'ignored' and 'c' for clean. | |
4907 |
|
4898 | |||
4908 | It abbreviates only those statuses which are passed. Note that clean and |
|
4899 | It abbreviates only those statuses which are passed. Note that clean and | |
4909 | ignored files are not displayed with '--terse ic' unless the -c/--clean |
|
4900 | ignored files are not displayed with '--terse ic' unless the -c/--clean | |
4910 | and -i/--ignored options are also used. |
|
4901 | and -i/--ignored options are also used. | |
4911 |
|
4902 | |||
4912 | The -v/--verbose option shows information when the repository is in an |
|
4903 | The -v/--verbose option shows information when the repository is in an | |
4913 | unfinished merge, shelve, rebase state etc. You can have this behavior |
|
4904 | unfinished merge, shelve, rebase state etc. You can have this behavior | |
4914 | turned on by default by enabling the ``commands.status.verbose`` option. |
|
4905 | turned on by default by enabling the ``commands.status.verbose`` option. | |
4915 |
|
4906 | |||
4916 | You can skip displaying some of these states by setting |
|
4907 | You can skip displaying some of these states by setting | |
4917 | ``commands.status.skipstates`` to one or more of: 'bisect', 'graft', |
|
4908 | ``commands.status.skipstates`` to one or more of: 'bisect', 'graft', | |
4918 | 'histedit', 'merge', 'rebase', or 'unshelve'. |
|
4909 | 'histedit', 'merge', 'rebase', or 'unshelve'. | |
4919 |
|
4910 | |||
4920 | Examples: |
|
4911 | Examples: | |
4921 |
|
4912 | |||
4922 | - show changes in the working directory relative to a |
|
4913 | - show changes in the working directory relative to a | |
4923 | changeset:: |
|
4914 | changeset:: | |
4924 |
|
4915 | |||
4925 | hg status --rev 9353 |
|
4916 | hg status --rev 9353 | |
4926 |
|
4917 | |||
4927 | - show changes in the working directory relative to the |
|
4918 | - show changes in the working directory relative to the | |
4928 | current directory (see :hg:`help patterns` for more information):: |
|
4919 | current directory (see :hg:`help patterns` for more information):: | |
4929 |
|
4920 | |||
4930 | hg status re: |
|
4921 | hg status re: | |
4931 |
|
4922 | |||
4932 | - show all changes including copies in an existing changeset:: |
|
4923 | - show all changes including copies in an existing changeset:: | |
4933 |
|
4924 | |||
4934 | hg status --copies --change 9353 |
|
4925 | hg status --copies --change 9353 | |
4935 |
|
4926 | |||
4936 | - get a NUL separated list of added files, suitable for xargs:: |
|
4927 | - get a NUL separated list of added files, suitable for xargs:: | |
4937 |
|
4928 | |||
4938 | hg status -an0 |
|
4929 | hg status -an0 | |
4939 |
|
4930 | |||
4940 | - show more information about the repository status, abbreviating |
|
4931 | - show more information about the repository status, abbreviating | |
4941 | added, removed, modified, deleted, and untracked paths:: |
|
4932 | added, removed, modified, deleted, and untracked paths:: | |
4942 |
|
4933 | |||
4943 | hg status -v -t mardu |
|
4934 | hg status -v -t mardu | |
4944 |
|
4935 | |||
4945 | Returns 0 on success. |
|
4936 | Returns 0 on success. | |
4946 |
|
4937 | |||
4947 | """ |
|
4938 | """ | |
4948 |
|
4939 | |||
4949 | opts = pycompat.byteskwargs(opts) |
|
4940 | opts = pycompat.byteskwargs(opts) | |
4950 | revs = opts.get('rev') |
|
4941 | revs = opts.get('rev') | |
4951 | change = opts.get('change') |
|
4942 | change = opts.get('change') | |
4952 | terse = opts.get('terse') |
|
4943 | terse = opts.get('terse') | |
4953 | if terse is _NOTTERSE: |
|
4944 | if terse is _NOTTERSE: | |
4954 | if revs: |
|
4945 | if revs: | |
4955 | terse = '' |
|
4946 | terse = '' | |
4956 | else: |
|
4947 | else: | |
4957 | terse = ui.config('commands', 'status.terse') |
|
4948 | terse = ui.config('commands', 'status.terse') | |
4958 |
|
4949 | |||
4959 | if revs and change: |
|
4950 | if revs and change: | |
4960 | msg = _('cannot specify --rev and --change at the same time') |
|
4951 | msg = _('cannot specify --rev and --change at the same time') | |
4961 | raise error.Abort(msg) |
|
4952 | raise error.Abort(msg) | |
4962 | elif revs and terse: |
|
4953 | elif revs and terse: | |
4963 | msg = _('cannot use --terse with --rev') |
|
4954 | msg = _('cannot use --terse with --rev') | |
4964 | raise error.Abort(msg) |
|
4955 | raise error.Abort(msg) | |
4965 | elif change: |
|
4956 | elif change: | |
4966 | repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') |
|
4957 | repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') | |
4967 | ctx2 = scmutil.revsingle(repo, change, None) |
|
4958 | ctx2 = scmutil.revsingle(repo, change, None) | |
4968 | ctx1 = ctx2.p1() |
|
4959 | ctx1 = ctx2.p1() | |
4969 | else: |
|
4960 | else: | |
4970 | repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') |
|
4961 | repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') | |
4971 | ctx1, ctx2 = scmutil.revpair(repo, revs) |
|
4962 | ctx1, ctx2 = scmutil.revpair(repo, revs) | |
4972 |
|
4963 | |||
4973 | if pats or ui.configbool('commands', 'status.relative'): |
|
4964 | if pats or ui.configbool('commands', 'status.relative'): | |
4974 | cwd = repo.getcwd() |
|
4965 | cwd = repo.getcwd() | |
4975 | else: |
|
4966 | else: | |
4976 | cwd = '' |
|
4967 | cwd = '' | |
4977 |
|
4968 | |||
4978 | if opts.get('print0'): |
|
4969 | if opts.get('print0'): | |
4979 | end = '\0' |
|
4970 | end = '\0' | |
4980 | else: |
|
4971 | else: | |
4981 | end = '\n' |
|
4972 | end = '\n' | |
4982 | copy = {} |
|
4973 | copy = {} | |
4983 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
4974 | states = 'modified added removed deleted unknown ignored clean'.split() | |
4984 | show = [k for k in states if opts.get(k)] |
|
4975 | show = [k for k in states if opts.get(k)] | |
4985 | if opts.get('all'): |
|
4976 | if opts.get('all'): | |
4986 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
4977 | show += ui.quiet and (states[:4] + ['clean']) or states | |
4987 |
|
4978 | |||
4988 | if not show: |
|
4979 | if not show: | |
4989 | if ui.quiet: |
|
4980 | if ui.quiet: | |
4990 | show = states[:4] |
|
4981 | show = states[:4] | |
4991 | else: |
|
4982 | else: | |
4992 | show = states[:5] |
|
4983 | show = states[:5] | |
4993 |
|
4984 | |||
4994 | m = scmutil.match(ctx2, pats, opts) |
|
4985 | m = scmutil.match(ctx2, pats, opts) | |
4995 | if terse: |
|
4986 | if terse: | |
4996 | # we need to compute clean and unknown to terse |
|
4987 | # we need to compute clean and unknown to terse | |
4997 | stat = repo.status(ctx1.node(), ctx2.node(), m, |
|
4988 | stat = repo.status(ctx1.node(), ctx2.node(), m, | |
4998 | 'ignored' in show or 'i' in terse, |
|
4989 | 'ignored' in show or 'i' in terse, | |
4999 | True, True, opts.get('subrepos')) |
|
4990 | True, True, opts.get('subrepos')) | |
5000 |
|
4991 | |||
5001 | stat = cmdutil.tersedir(stat, terse) |
|
4992 | stat = cmdutil.tersedir(stat, terse) | |
5002 | else: |
|
4993 | else: | |
5003 | stat = repo.status(ctx1.node(), ctx2.node(), m, |
|
4994 | stat = repo.status(ctx1.node(), ctx2.node(), m, | |
5004 | 'ignored' in show, 'clean' in show, |
|
4995 | 'ignored' in show, 'clean' in show, | |
5005 | 'unknown' in show, opts.get('subrepos')) |
|
4996 | 'unknown' in show, opts.get('subrepos')) | |
5006 |
|
4997 | |||
5007 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) |
|
4998 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) | |
5008 |
|
4999 | |||
5009 | if (opts.get('all') or opts.get('copies') |
|
5000 | if (opts.get('all') or opts.get('copies') | |
5010 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): |
|
5001 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): | |
5011 | copy = copies.pathcopies(ctx1, ctx2, m) |
|
5002 | copy = copies.pathcopies(ctx1, ctx2, m) | |
5012 |
|
5003 | |||
5013 | ui.pager('status') |
|
5004 | ui.pager('status') | |
5014 | fm = ui.formatter('status', opts) |
|
5005 | fm = ui.formatter('status', opts) | |
5015 | fmt = '%s' + end |
|
5006 | fmt = '%s' + end | |
5016 | showchar = not opts.get('no_status') |
|
5007 | showchar = not opts.get('no_status') | |
5017 |
|
5008 | |||
5018 | for state, char, files in changestates: |
|
5009 | for state, char, files in changestates: | |
5019 | if state in show: |
|
5010 | if state in show: | |
5020 | label = 'status.' + state |
|
5011 | label = 'status.' + state | |
5021 | for f in files: |
|
5012 | for f in files: | |
5022 | fm.startitem() |
|
5013 | fm.startitem() | |
5023 | fm.condwrite(showchar, 'status', '%s ', char, label=label) |
|
5014 | fm.condwrite(showchar, 'status', '%s ', char, label=label) | |
5024 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) |
|
5015 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) | |
5025 | if f in copy: |
|
5016 | if f in copy: | |
5026 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
5017 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), | |
5027 | label='status.copied') |
|
5018 | label='status.copied') | |
5028 |
|
5019 | |||
5029 | if ((ui.verbose or ui.configbool('commands', 'status.verbose')) |
|
5020 | if ((ui.verbose or ui.configbool('commands', 'status.verbose')) | |
5030 | and not ui.plain()): |
|
5021 | and not ui.plain()): | |
5031 | cmdutil.morestatus(repo, fm) |
|
5022 | cmdutil.morestatus(repo, fm) | |
5032 | fm.end() |
|
5023 | fm.end() | |
5033 |
|
5024 | |||
5034 | @command('^summary|sum', |
|
5025 | @command('^summary|sum', | |
5035 | [('', 'remote', None, _('check for push and pull'))], |
|
5026 | [('', 'remote', None, _('check for push and pull'))], | |
5036 | '[--remote]', |
|
5027 | '[--remote]', | |
5037 | intents={INTENT_READONLY}) |
|
5028 | intents={INTENT_READONLY}) | |
5038 | def summary(ui, repo, **opts): |
|
5029 | def summary(ui, repo, **opts): | |
5039 | """summarize working directory state |
|
5030 | """summarize working directory state | |
5040 |
|
5031 | |||
5041 | This generates a brief summary of the working directory state, |
|
5032 | This generates a brief summary of the working directory state, | |
5042 | including parents, branch, commit status, phase and available updates. |
|
5033 | including parents, branch, commit status, phase and available updates. | |
5043 |
|
5034 | |||
5044 | With the --remote option, this will check the default paths for |
|
5035 | With the --remote option, this will check the default paths for | |
5045 | incoming and outgoing changes. This can be time-consuming. |
|
5036 | incoming and outgoing changes. This can be time-consuming. | |
5046 |
|
5037 | |||
5047 | Returns 0 on success. |
|
5038 | Returns 0 on success. | |
5048 | """ |
|
5039 | """ | |
5049 |
|
5040 | |||
5050 | opts = pycompat.byteskwargs(opts) |
|
5041 | opts = pycompat.byteskwargs(opts) | |
5051 | ui.pager('summary') |
|
5042 | ui.pager('summary') | |
5052 | ctx = repo[None] |
|
5043 | ctx = repo[None] | |
5053 | parents = ctx.parents() |
|
5044 | parents = ctx.parents() | |
5054 | pnode = parents[0].node() |
|
5045 | pnode = parents[0].node() | |
5055 | marks = [] |
|
5046 | marks = [] | |
5056 |
|
5047 | |||
5057 | ms = None |
|
5048 | ms = None | |
5058 | try: |
|
5049 | try: | |
5059 | ms = mergemod.mergestate.read(repo) |
|
5050 | ms = mergemod.mergestate.read(repo) | |
5060 | except error.UnsupportedMergeRecords as e: |
|
5051 | except error.UnsupportedMergeRecords as e: | |
5061 | s = ' '.join(e.recordtypes) |
|
5052 | s = ' '.join(e.recordtypes) | |
5062 | ui.warn( |
|
5053 | ui.warn( | |
5063 | _('warning: merge state has unsupported record types: %s\n') % s) |
|
5054 | _('warning: merge state has unsupported record types: %s\n') % s) | |
5064 | unresolved = [] |
|
5055 | unresolved = [] | |
5065 | else: |
|
5056 | else: | |
5066 | unresolved = list(ms.unresolved()) |
|
5057 | unresolved = list(ms.unresolved()) | |
5067 |
|
5058 | |||
5068 | for p in parents: |
|
5059 | for p in parents: | |
5069 | # label with log.changeset (instead of log.parent) since this |
|
5060 | # label with log.changeset (instead of log.parent) since this | |
5070 | # shows a working directory parent *changeset*: |
|
5061 | # shows a working directory parent *changeset*: | |
5071 | # i18n: column positioning for "hg summary" |
|
5062 | # i18n: column positioning for "hg summary" | |
5072 | ui.write(_('parent: %d:%s ') % (p.rev(), p), |
|
5063 | ui.write(_('parent: %d:%s ') % (p.rev(), p), | |
5073 | label=logcmdutil.changesetlabels(p)) |
|
5064 | label=logcmdutil.changesetlabels(p)) | |
5074 | ui.write(' '.join(p.tags()), label='log.tag') |
|
5065 | ui.write(' '.join(p.tags()), label='log.tag') | |
5075 | if p.bookmarks(): |
|
5066 | if p.bookmarks(): | |
5076 | marks.extend(p.bookmarks()) |
|
5067 | marks.extend(p.bookmarks()) | |
5077 | if p.rev() == -1: |
|
5068 | if p.rev() == -1: | |
5078 | if not len(repo): |
|
5069 | if not len(repo): | |
5079 | ui.write(_(' (empty repository)')) |
|
5070 | ui.write(_(' (empty repository)')) | |
5080 | else: |
|
5071 | else: | |
5081 | ui.write(_(' (no revision checked out)')) |
|
5072 | ui.write(_(' (no revision checked out)')) | |
5082 | if p.obsolete(): |
|
5073 | if p.obsolete(): | |
5083 | ui.write(_(' (obsolete)')) |
|
5074 | ui.write(_(' (obsolete)')) | |
5084 | if p.isunstable(): |
|
5075 | if p.isunstable(): | |
5085 | instabilities = (ui.label(instability, 'trouble.%s' % instability) |
|
5076 | instabilities = (ui.label(instability, 'trouble.%s' % instability) | |
5086 | for instability in p.instabilities()) |
|
5077 | for instability in p.instabilities()) | |
5087 | ui.write(' (' |
|
5078 | ui.write(' (' | |
5088 | + ', '.join(instabilities) |
|
5079 | + ', '.join(instabilities) | |
5089 | + ')') |
|
5080 | + ')') | |
5090 | ui.write('\n') |
|
5081 | ui.write('\n') | |
5091 | if p.description(): |
|
5082 | if p.description(): | |
5092 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
5083 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', | |
5093 | label='log.summary') |
|
5084 | label='log.summary') | |
5094 |
|
5085 | |||
5095 | branch = ctx.branch() |
|
5086 | branch = ctx.branch() | |
5096 | bheads = repo.branchheads(branch) |
|
5087 | bheads = repo.branchheads(branch) | |
5097 | # i18n: column positioning for "hg summary" |
|
5088 | # i18n: column positioning for "hg summary" | |
5098 | m = _('branch: %s\n') % branch |
|
5089 | m = _('branch: %s\n') % branch | |
5099 | if branch != 'default': |
|
5090 | if branch != 'default': | |
5100 | ui.write(m, label='log.branch') |
|
5091 | ui.write(m, label='log.branch') | |
5101 | else: |
|
5092 | else: | |
5102 | ui.status(m, label='log.branch') |
|
5093 | ui.status(m, label='log.branch') | |
5103 |
|
5094 | |||
5104 | if marks: |
|
5095 | if marks: | |
5105 | active = repo._activebookmark |
|
5096 | active = repo._activebookmark | |
5106 | # i18n: column positioning for "hg summary" |
|
5097 | # i18n: column positioning for "hg summary" | |
5107 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
5098 | ui.write(_('bookmarks:'), label='log.bookmark') | |
5108 | if active is not None: |
|
5099 | if active is not None: | |
5109 | if active in marks: |
|
5100 | if active in marks: | |
5110 | ui.write(' *' + active, label=bookmarks.activebookmarklabel) |
|
5101 | ui.write(' *' + active, label=bookmarks.activebookmarklabel) | |
5111 | marks.remove(active) |
|
5102 | marks.remove(active) | |
5112 | else: |
|
5103 | else: | |
5113 | ui.write(' [%s]' % active, label=bookmarks.activebookmarklabel) |
|
5104 | ui.write(' [%s]' % active, label=bookmarks.activebookmarklabel) | |
5114 | for m in marks: |
|
5105 | for m in marks: | |
5115 | ui.write(' ' + m, label='log.bookmark') |
|
5106 | ui.write(' ' + m, label='log.bookmark') | |
5116 | ui.write('\n', label='log.bookmark') |
|
5107 | ui.write('\n', label='log.bookmark') | |
5117 |
|
5108 | |||
5118 | status = repo.status(unknown=True) |
|
5109 | status = repo.status(unknown=True) | |
5119 |
|
5110 | |||
5120 | c = repo.dirstate.copies() |
|
5111 | c = repo.dirstate.copies() | |
5121 | copied, renamed = [], [] |
|
5112 | copied, renamed = [], [] | |
5122 | for d, s in c.iteritems(): |
|
5113 | for d, s in c.iteritems(): | |
5123 | if s in status.removed: |
|
5114 | if s in status.removed: | |
5124 | status.removed.remove(s) |
|
5115 | status.removed.remove(s) | |
5125 | renamed.append(d) |
|
5116 | renamed.append(d) | |
5126 | else: |
|
5117 | else: | |
5127 | copied.append(d) |
|
5118 | copied.append(d) | |
5128 | if d in status.added: |
|
5119 | if d in status.added: | |
5129 | status.added.remove(d) |
|
5120 | status.added.remove(d) | |
5130 |
|
5121 | |||
5131 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
5122 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | |
5132 |
|
5123 | |||
5133 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
|
5124 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), | |
5134 | (ui.label(_('%d added'), 'status.added'), status.added), |
|
5125 | (ui.label(_('%d added'), 'status.added'), status.added), | |
5135 | (ui.label(_('%d removed'), 'status.removed'), status.removed), |
|
5126 | (ui.label(_('%d removed'), 'status.removed'), status.removed), | |
5136 | (ui.label(_('%d renamed'), 'status.copied'), renamed), |
|
5127 | (ui.label(_('%d renamed'), 'status.copied'), renamed), | |
5137 | (ui.label(_('%d copied'), 'status.copied'), copied), |
|
5128 | (ui.label(_('%d copied'), 'status.copied'), copied), | |
5138 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
|
5129 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), | |
5139 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
|
5130 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), | |
5140 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
|
5131 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), | |
5141 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
|
5132 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] | |
5142 | t = [] |
|
5133 | t = [] | |
5143 | for l, s in labels: |
|
5134 | for l, s in labels: | |
5144 | if s: |
|
5135 | if s: | |
5145 | t.append(l % len(s)) |
|
5136 | t.append(l % len(s)) | |
5146 |
|
5137 | |||
5147 | t = ', '.join(t) |
|
5138 | t = ', '.join(t) | |
5148 | cleanworkdir = False |
|
5139 | cleanworkdir = False | |
5149 |
|
5140 | |||
5150 | if repo.vfs.exists('graftstate'): |
|
5141 | if repo.vfs.exists('graftstate'): | |
5151 | t += _(' (graft in progress)') |
|
5142 | t += _(' (graft in progress)') | |
5152 | if repo.vfs.exists('updatestate'): |
|
5143 | if repo.vfs.exists('updatestate'): | |
5153 | t += _(' (interrupted update)') |
|
5144 | t += _(' (interrupted update)') | |
5154 | elif len(parents) > 1: |
|
5145 | elif len(parents) > 1: | |
5155 | t += _(' (merge)') |
|
5146 | t += _(' (merge)') | |
5156 | elif branch != parents[0].branch(): |
|
5147 | elif branch != parents[0].branch(): | |
5157 | t += _(' (new branch)') |
|
5148 | t += _(' (new branch)') | |
5158 | elif (parents[0].closesbranch() and |
|
5149 | elif (parents[0].closesbranch() and | |
5159 | pnode in repo.branchheads(branch, closed=True)): |
|
5150 | pnode in repo.branchheads(branch, closed=True)): | |
5160 | t += _(' (head closed)') |
|
5151 | t += _(' (head closed)') | |
5161 | elif not (status.modified or status.added or status.removed or renamed or |
|
5152 | elif not (status.modified or status.added or status.removed or renamed or | |
5162 | copied or subs): |
|
5153 | copied or subs): | |
5163 | t += _(' (clean)') |
|
5154 | t += _(' (clean)') | |
5164 | cleanworkdir = True |
|
5155 | cleanworkdir = True | |
5165 | elif pnode not in bheads: |
|
5156 | elif pnode not in bheads: | |
5166 | t += _(' (new branch head)') |
|
5157 | t += _(' (new branch head)') | |
5167 |
|
5158 | |||
5168 | if parents: |
|
5159 | if parents: | |
5169 | pendingphase = max(p.phase() for p in parents) |
|
5160 | pendingphase = max(p.phase() for p in parents) | |
5170 | else: |
|
5161 | else: | |
5171 | pendingphase = phases.public |
|
5162 | pendingphase = phases.public | |
5172 |
|
5163 | |||
5173 | if pendingphase > phases.newcommitphase(ui): |
|
5164 | if pendingphase > phases.newcommitphase(ui): | |
5174 | t += ' (%s)' % phases.phasenames[pendingphase] |
|
5165 | t += ' (%s)' % phases.phasenames[pendingphase] | |
5175 |
|
5166 | |||
5176 | if cleanworkdir: |
|
5167 | if cleanworkdir: | |
5177 | # i18n: column positioning for "hg summary" |
|
5168 | # i18n: column positioning for "hg summary" | |
5178 | ui.status(_('commit: %s\n') % t.strip()) |
|
5169 | ui.status(_('commit: %s\n') % t.strip()) | |
5179 | else: |
|
5170 | else: | |
5180 | # i18n: column positioning for "hg summary" |
|
5171 | # i18n: column positioning for "hg summary" | |
5181 | ui.write(_('commit: %s\n') % t.strip()) |
|
5172 | ui.write(_('commit: %s\n') % t.strip()) | |
5182 |
|
5173 | |||
5183 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
5174 | # all ancestors of branch heads - all ancestors of parent = new csets | |
5184 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], |
|
5175 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], | |
5185 | bheads)) |
|
5176 | bheads)) | |
5186 |
|
5177 | |||
5187 | if new == 0: |
|
5178 | if new == 0: | |
5188 | # i18n: column positioning for "hg summary" |
|
5179 | # i18n: column positioning for "hg summary" | |
5189 | ui.status(_('update: (current)\n')) |
|
5180 | ui.status(_('update: (current)\n')) | |
5190 | elif pnode not in bheads: |
|
5181 | elif pnode not in bheads: | |
5191 | # i18n: column positioning for "hg summary" |
|
5182 | # i18n: column positioning for "hg summary" | |
5192 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
5183 | ui.write(_('update: %d new changesets (update)\n') % new) | |
5193 | else: |
|
5184 | else: | |
5194 | # i18n: column positioning for "hg summary" |
|
5185 | # i18n: column positioning for "hg summary" | |
5195 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
5186 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | |
5196 | (new, len(bheads))) |
|
5187 | (new, len(bheads))) | |
5197 |
|
5188 | |||
5198 | t = [] |
|
5189 | t = [] | |
5199 | draft = len(repo.revs('draft()')) |
|
5190 | draft = len(repo.revs('draft()')) | |
5200 | if draft: |
|
5191 | if draft: | |
5201 | t.append(_('%d draft') % draft) |
|
5192 | t.append(_('%d draft') % draft) | |
5202 | secret = len(repo.revs('secret()')) |
|
5193 | secret = len(repo.revs('secret()')) | |
5203 | if secret: |
|
5194 | if secret: | |
5204 | t.append(_('%d secret') % secret) |
|
5195 | t.append(_('%d secret') % secret) | |
5205 |
|
5196 | |||
5206 | if draft or secret: |
|
5197 | if draft or secret: | |
5207 | ui.status(_('phases: %s\n') % ', '.join(t)) |
|
5198 | ui.status(_('phases: %s\n') % ', '.join(t)) | |
5208 |
|
5199 | |||
5209 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
5200 | if obsolete.isenabled(repo, obsolete.createmarkersopt): | |
5210 | for trouble in ("orphan", "contentdivergent", "phasedivergent"): |
|
5201 | for trouble in ("orphan", "contentdivergent", "phasedivergent"): | |
5211 | numtrouble = len(repo.revs(trouble + "()")) |
|
5202 | numtrouble = len(repo.revs(trouble + "()")) | |
5212 | # We write all the possibilities to ease translation |
|
5203 | # We write all the possibilities to ease translation | |
5213 | troublemsg = { |
|
5204 | troublemsg = { | |
5214 | "orphan": _("orphan: %d changesets"), |
|
5205 | "orphan": _("orphan: %d changesets"), | |
5215 | "contentdivergent": _("content-divergent: %d changesets"), |
|
5206 | "contentdivergent": _("content-divergent: %d changesets"), | |
5216 | "phasedivergent": _("phase-divergent: %d changesets"), |
|
5207 | "phasedivergent": _("phase-divergent: %d changesets"), | |
5217 | } |
|
5208 | } | |
5218 | if numtrouble > 0: |
|
5209 | if numtrouble > 0: | |
5219 | ui.status(troublemsg[trouble] % numtrouble + "\n") |
|
5210 | ui.status(troublemsg[trouble] % numtrouble + "\n") | |
5220 |
|
5211 | |||
5221 | cmdutil.summaryhooks(ui, repo) |
|
5212 | cmdutil.summaryhooks(ui, repo) | |
5222 |
|
5213 | |||
5223 | if opts.get('remote'): |
|
5214 | if opts.get('remote'): | |
5224 | needsincoming, needsoutgoing = True, True |
|
5215 | needsincoming, needsoutgoing = True, True | |
5225 | else: |
|
5216 | else: | |
5226 | needsincoming, needsoutgoing = False, False |
|
5217 | needsincoming, needsoutgoing = False, False | |
5227 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
5218 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): | |
5228 | if i: |
|
5219 | if i: | |
5229 | needsincoming = True |
|
5220 | needsincoming = True | |
5230 | if o: |
|
5221 | if o: | |
5231 | needsoutgoing = True |
|
5222 | needsoutgoing = True | |
5232 | if not needsincoming and not needsoutgoing: |
|
5223 | if not needsincoming and not needsoutgoing: | |
5233 | return |
|
5224 | return | |
5234 |
|
5225 | |||
5235 | def getincoming(): |
|
5226 | def getincoming(): | |
5236 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
5227 | source, branches = hg.parseurl(ui.expandpath('default')) | |
5237 | sbranch = branches[0] |
|
5228 | sbranch = branches[0] | |
5238 | try: |
|
5229 | try: | |
5239 | other = hg.peer(repo, {}, source) |
|
5230 | other = hg.peer(repo, {}, source) | |
5240 | except error.RepoError: |
|
5231 | except error.RepoError: | |
5241 | if opts.get('remote'): |
|
5232 | if opts.get('remote'): | |
5242 | raise |
|
5233 | raise | |
5243 | return source, sbranch, None, None, None |
|
5234 | return source, sbranch, None, None, None | |
5244 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
5235 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) | |
5245 | if revs: |
|
5236 | if revs: | |
5246 | revs = [other.lookup(rev) for rev in revs] |
|
5237 | revs = [other.lookup(rev) for rev in revs] | |
5247 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
5238 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | |
5248 | repo.ui.pushbuffer() |
|
5239 | repo.ui.pushbuffer() | |
5249 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
5240 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) | |
5250 | repo.ui.popbuffer() |
|
5241 | repo.ui.popbuffer() | |
5251 | return source, sbranch, other, commoninc, commoninc[1] |
|
5242 | return source, sbranch, other, commoninc, commoninc[1] | |
5252 |
|
5243 | |||
5253 | if needsincoming: |
|
5244 | if needsincoming: | |
5254 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
5245 | source, sbranch, sother, commoninc, incoming = getincoming() | |
5255 | else: |
|
5246 | else: | |
5256 | source = sbranch = sother = commoninc = incoming = None |
|
5247 | source = sbranch = sother = commoninc = incoming = None | |
5257 |
|
5248 | |||
5258 | def getoutgoing(): |
|
5249 | def getoutgoing(): | |
5259 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
5250 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | |
5260 | dbranch = branches[0] |
|
5251 | dbranch = branches[0] | |
5261 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
5252 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | |
5262 | if source != dest: |
|
5253 | if source != dest: | |
5263 | try: |
|
5254 | try: | |
5264 | dother = hg.peer(repo, {}, dest) |
|
5255 | dother = hg.peer(repo, {}, dest) | |
5265 | except error.RepoError: |
|
5256 | except error.RepoError: | |
5266 | if opts.get('remote'): |
|
5257 | if opts.get('remote'): | |
5267 | raise |
|
5258 | raise | |
5268 | return dest, dbranch, None, None |
|
5259 | return dest, dbranch, None, None | |
5269 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
5260 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) | |
5270 | elif sother is None: |
|
5261 | elif sother is None: | |
5271 | # there is no explicit destination peer, but source one is invalid |
|
5262 | # there is no explicit destination peer, but source one is invalid | |
5272 | return dest, dbranch, None, None |
|
5263 | return dest, dbranch, None, None | |
5273 | else: |
|
5264 | else: | |
5274 | dother = sother |
|
5265 | dother = sother | |
5275 | if (source != dest or (sbranch is not None and sbranch != dbranch)): |
|
5266 | if (source != dest or (sbranch is not None and sbranch != dbranch)): | |
5276 | common = None |
|
5267 | common = None | |
5277 | else: |
|
5268 | else: | |
5278 | common = commoninc |
|
5269 | common = commoninc | |
5279 | if revs: |
|
5270 | if revs: | |
5280 | revs = [repo.lookup(rev) for rev in revs] |
|
5271 | revs = [repo.lookup(rev) for rev in revs] | |
5281 | repo.ui.pushbuffer() |
|
5272 | repo.ui.pushbuffer() | |
5282 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, |
|
5273 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, | |
5283 | commoninc=common) |
|
5274 | commoninc=common) | |
5284 | repo.ui.popbuffer() |
|
5275 | repo.ui.popbuffer() | |
5285 | return dest, dbranch, dother, outgoing |
|
5276 | return dest, dbranch, dother, outgoing | |
5286 |
|
5277 | |||
5287 | if needsoutgoing: |
|
5278 | if needsoutgoing: | |
5288 | dest, dbranch, dother, outgoing = getoutgoing() |
|
5279 | dest, dbranch, dother, outgoing = getoutgoing() | |
5289 | else: |
|
5280 | else: | |
5290 | dest = dbranch = dother = outgoing = None |
|
5281 | dest = dbranch = dother = outgoing = None | |
5291 |
|
5282 | |||
5292 | if opts.get('remote'): |
|
5283 | if opts.get('remote'): | |
5293 | t = [] |
|
5284 | t = [] | |
5294 | if incoming: |
|
5285 | if incoming: | |
5295 | t.append(_('1 or more incoming')) |
|
5286 | t.append(_('1 or more incoming')) | |
5296 | o = outgoing.missing |
|
5287 | o = outgoing.missing | |
5297 | if o: |
|
5288 | if o: | |
5298 | t.append(_('%d outgoing') % len(o)) |
|
5289 | t.append(_('%d outgoing') % len(o)) | |
5299 | other = dother or sother |
|
5290 | other = dother or sother | |
5300 | if 'bookmarks' in other.listkeys('namespaces'): |
|
5291 | if 'bookmarks' in other.listkeys('namespaces'): | |
5301 | counts = bookmarks.summary(repo, other) |
|
5292 | counts = bookmarks.summary(repo, other) | |
5302 | if counts[0] > 0: |
|
5293 | if counts[0] > 0: | |
5303 | t.append(_('%d incoming bookmarks') % counts[0]) |
|
5294 | t.append(_('%d incoming bookmarks') % counts[0]) | |
5304 | if counts[1] > 0: |
|
5295 | if counts[1] > 0: | |
5305 | t.append(_('%d outgoing bookmarks') % counts[1]) |
|
5296 | t.append(_('%d outgoing bookmarks') % counts[1]) | |
5306 |
|
5297 | |||
5307 | if t: |
|
5298 | if t: | |
5308 | # i18n: column positioning for "hg summary" |
|
5299 | # i18n: column positioning for "hg summary" | |
5309 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
5300 | ui.write(_('remote: %s\n') % (', '.join(t))) | |
5310 | else: |
|
5301 | else: | |
5311 | # i18n: column positioning for "hg summary" |
|
5302 | # i18n: column positioning for "hg summary" | |
5312 | ui.status(_('remote: (synced)\n')) |
|
5303 | ui.status(_('remote: (synced)\n')) | |
5313 |
|
5304 | |||
5314 | cmdutil.summaryremotehooks(ui, repo, opts, |
|
5305 | cmdutil.summaryremotehooks(ui, repo, opts, | |
5315 | ((source, sbranch, sother, commoninc), |
|
5306 | ((source, sbranch, sother, commoninc), | |
5316 | (dest, dbranch, dother, outgoing))) |
|
5307 | (dest, dbranch, dother, outgoing))) | |
5317 |
|
5308 | |||
5318 | @command('tag', |
|
5309 | @command('tag', | |
5319 | [('f', 'force', None, _('force tag')), |
|
5310 | [('f', 'force', None, _('force tag')), | |
5320 | ('l', 'local', None, _('make the tag local')), |
|
5311 | ('l', 'local', None, _('make the tag local')), | |
5321 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
5312 | ('r', 'rev', '', _('revision to tag'), _('REV')), | |
5322 | ('', 'remove', None, _('remove a tag')), |
|
5313 | ('', 'remove', None, _('remove a tag')), | |
5323 | # -l/--local is already there, commitopts cannot be used |
|
5314 | # -l/--local is already there, commitopts cannot be used | |
5324 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
5315 | ('e', 'edit', None, _('invoke editor on commit messages')), | |
5325 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), |
|
5316 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), | |
5326 | ] + commitopts2, |
|
5317 | ] + commitopts2, | |
5327 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
5318 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) | |
5328 | def tag(ui, repo, name1, *names, **opts): |
|
5319 | def tag(ui, repo, name1, *names, **opts): | |
5329 | """add one or more tags for the current or given revision |
|
5320 | """add one or more tags for the current or given revision | |
5330 |
|
5321 | |||
5331 | Name a particular revision using <name>. |
|
5322 | Name a particular revision using <name>. | |
5332 |
|
5323 | |||
5333 | Tags are used to name particular revisions of the repository and are |
|
5324 | Tags are used to name particular revisions of the repository and are | |
5334 | very useful to compare different revisions, to go back to significant |
|
5325 | very useful to compare different revisions, to go back to significant | |
5335 | earlier versions or to mark branch points as releases, etc. Changing |
|
5326 | earlier versions or to mark branch points as releases, etc. Changing | |
5336 | an existing tag is normally disallowed; use -f/--force to override. |
|
5327 | an existing tag is normally disallowed; use -f/--force to override. | |
5337 |
|
5328 | |||
5338 | If no revision is given, the parent of the working directory is |
|
5329 | If no revision is given, the parent of the working directory is | |
5339 | used. |
|
5330 | used. | |
5340 |
|
5331 | |||
5341 | To facilitate version control, distribution, and merging of tags, |
|
5332 | To facilitate version control, distribution, and merging of tags, | |
5342 | they are stored as a file named ".hgtags" which is managed similarly |
|
5333 | they are stored as a file named ".hgtags" which is managed similarly | |
5343 | to other project files and can be hand-edited if necessary. This |
|
5334 | to other project files and can be hand-edited if necessary. This | |
5344 | also means that tagging creates a new commit. The file |
|
5335 | also means that tagging creates a new commit. The file | |
5345 | ".hg/localtags" is used for local tags (not shared among |
|
5336 | ".hg/localtags" is used for local tags (not shared among | |
5346 | repositories). |
|
5337 | repositories). | |
5347 |
|
5338 | |||
5348 | Tag commits are usually made at the head of a branch. If the parent |
|
5339 | Tag commits are usually made at the head of a branch. If the parent | |
5349 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
5340 | of the working directory is not a branch head, :hg:`tag` aborts; use | |
5350 | -f/--force to force the tag commit to be based on a non-head |
|
5341 | -f/--force to force the tag commit to be based on a non-head | |
5351 | changeset. |
|
5342 | changeset. | |
5352 |
|
5343 | |||
5353 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5344 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
5354 |
|
5345 | |||
5355 | Since tag names have priority over branch names during revision |
|
5346 | Since tag names have priority over branch names during revision | |
5356 | lookup, using an existing branch name as a tag name is discouraged. |
|
5347 | lookup, using an existing branch name as a tag name is discouraged. | |
5357 |
|
5348 | |||
5358 | Returns 0 on success. |
|
5349 | Returns 0 on success. | |
5359 | """ |
|
5350 | """ | |
5360 | opts = pycompat.byteskwargs(opts) |
|
5351 | opts = pycompat.byteskwargs(opts) | |
5361 | with repo.wlock(), repo.lock(): |
|
5352 | with repo.wlock(), repo.lock(): | |
5362 | rev_ = "." |
|
5353 | rev_ = "." | |
5363 | names = [t.strip() for t in (name1,) + names] |
|
5354 | names = [t.strip() for t in (name1,) + names] | |
5364 | if len(names) != len(set(names)): |
|
5355 | if len(names) != len(set(names)): | |
5365 | raise error.Abort(_('tag names must be unique')) |
|
5356 | raise error.Abort(_('tag names must be unique')) | |
5366 | for n in names: |
|
5357 | for n in names: | |
5367 | scmutil.checknewlabel(repo, n, 'tag') |
|
5358 | scmutil.checknewlabel(repo, n, 'tag') | |
5368 | if not n: |
|
5359 | if not n: | |
5369 | raise error.Abort(_('tag names cannot consist entirely of ' |
|
5360 | raise error.Abort(_('tag names cannot consist entirely of ' | |
5370 | 'whitespace')) |
|
5361 | 'whitespace')) | |
5371 | if opts.get('rev') and opts.get('remove'): |
|
5362 | if opts.get('rev') and opts.get('remove'): | |
5372 | raise error.Abort(_("--rev and --remove are incompatible")) |
|
5363 | raise error.Abort(_("--rev and --remove are incompatible")) | |
5373 | if opts.get('rev'): |
|
5364 | if opts.get('rev'): | |
5374 | rev_ = opts['rev'] |
|
5365 | rev_ = opts['rev'] | |
5375 | message = opts.get('message') |
|
5366 | message = opts.get('message') | |
5376 | if opts.get('remove'): |
|
5367 | if opts.get('remove'): | |
5377 | if opts.get('local'): |
|
5368 | if opts.get('local'): | |
5378 | expectedtype = 'local' |
|
5369 | expectedtype = 'local' | |
5379 | else: |
|
5370 | else: | |
5380 | expectedtype = 'global' |
|
5371 | expectedtype = 'global' | |
5381 |
|
5372 | |||
5382 | for n in names: |
|
5373 | for n in names: | |
5383 | if not repo.tagtype(n): |
|
5374 | if not repo.tagtype(n): | |
5384 | raise error.Abort(_("tag '%s' does not exist") % n) |
|
5375 | raise error.Abort(_("tag '%s' does not exist") % n) | |
5385 | if repo.tagtype(n) != expectedtype: |
|
5376 | if repo.tagtype(n) != expectedtype: | |
5386 | if expectedtype == 'global': |
|
5377 | if expectedtype == 'global': | |
5387 | raise error.Abort(_("tag '%s' is not a global tag") % n) |
|
5378 | raise error.Abort(_("tag '%s' is not a global tag") % n) | |
5388 | else: |
|
5379 | else: | |
5389 | raise error.Abort(_("tag '%s' is not a local tag") % n) |
|
5380 | raise error.Abort(_("tag '%s' is not a local tag") % n) | |
5390 | rev_ = 'null' |
|
5381 | rev_ = 'null' | |
5391 | if not message: |
|
5382 | if not message: | |
5392 | # we don't translate commit messages |
|
5383 | # we don't translate commit messages | |
5393 | message = 'Removed tag %s' % ', '.join(names) |
|
5384 | message = 'Removed tag %s' % ', '.join(names) | |
5394 | elif not opts.get('force'): |
|
5385 | elif not opts.get('force'): | |
5395 | for n in names: |
|
5386 | for n in names: | |
5396 | if n in repo.tags(): |
|
5387 | if n in repo.tags(): | |
5397 | raise error.Abort(_("tag '%s' already exists " |
|
5388 | raise error.Abort(_("tag '%s' already exists " | |
5398 | "(use -f to force)") % n) |
|
5389 | "(use -f to force)") % n) | |
5399 | if not opts.get('local'): |
|
5390 | if not opts.get('local'): | |
5400 | p1, p2 = repo.dirstate.parents() |
|
5391 | p1, p2 = repo.dirstate.parents() | |
5401 | if p2 != nullid: |
|
5392 | if p2 != nullid: | |
5402 | raise error.Abort(_('uncommitted merge')) |
|
5393 | raise error.Abort(_('uncommitted merge')) | |
5403 | bheads = repo.branchheads() |
|
5394 | bheads = repo.branchheads() | |
5404 | if not opts.get('force') and bheads and p1 not in bheads: |
|
5395 | if not opts.get('force') and bheads and p1 not in bheads: | |
5405 | raise error.Abort(_('working directory is not at a branch head ' |
|
5396 | raise error.Abort(_('working directory is not at a branch head ' | |
5406 | '(use -f to force)')) |
|
5397 | '(use -f to force)')) | |
5407 | node = scmutil.revsingle(repo, rev_).node() |
|
5398 | node = scmutil.revsingle(repo, rev_).node() | |
5408 |
|
5399 | |||
5409 | if not message: |
|
5400 | if not message: | |
5410 | # we don't translate commit messages |
|
5401 | # we don't translate commit messages | |
5411 | message = ('Added tag %s for changeset %s' % |
|
5402 | message = ('Added tag %s for changeset %s' % | |
5412 | (', '.join(names), short(node))) |
|
5403 | (', '.join(names), short(node))) | |
5413 |
|
5404 | |||
5414 | date = opts.get('date') |
|
5405 | date = opts.get('date') | |
5415 | if date: |
|
5406 | if date: | |
5416 | date = dateutil.parsedate(date) |
|
5407 | date = dateutil.parsedate(date) | |
5417 |
|
5408 | |||
5418 | if opts.get('remove'): |
|
5409 | if opts.get('remove'): | |
5419 | editform = 'tag.remove' |
|
5410 | editform = 'tag.remove' | |
5420 | else: |
|
5411 | else: | |
5421 | editform = 'tag.add' |
|
5412 | editform = 'tag.add' | |
5422 | editor = cmdutil.getcommiteditor(editform=editform, |
|
5413 | editor = cmdutil.getcommiteditor(editform=editform, | |
5423 | **pycompat.strkwargs(opts)) |
|
5414 | **pycompat.strkwargs(opts)) | |
5424 |
|
5415 | |||
5425 | # don't allow tagging the null rev |
|
5416 | # don't allow tagging the null rev | |
5426 | if (not opts.get('remove') and |
|
5417 | if (not opts.get('remove') and | |
5427 | scmutil.revsingle(repo, rev_).rev() == nullrev): |
|
5418 | scmutil.revsingle(repo, rev_).rev() == nullrev): | |
5428 | raise error.Abort(_("cannot tag null revision")) |
|
5419 | raise error.Abort(_("cannot tag null revision")) | |
5429 |
|
5420 | |||
5430 | tagsmod.tag(repo, names, node, message, opts.get('local'), |
|
5421 | tagsmod.tag(repo, names, node, message, opts.get('local'), | |
5431 | opts.get('user'), date, editor=editor) |
|
5422 | opts.get('user'), date, editor=editor) | |
5432 |
|
5423 | |||
5433 | @command('tags', formatteropts, '', intents={INTENT_READONLY}) |
|
5424 | @command('tags', formatteropts, '', intents={INTENT_READONLY}) | |
5434 | def tags(ui, repo, **opts): |
|
5425 | def tags(ui, repo, **opts): | |
5435 | """list repository tags |
|
5426 | """list repository tags | |
5436 |
|
5427 | |||
5437 | This lists both regular and local tags. When the -v/--verbose |
|
5428 | This lists both regular and local tags. When the -v/--verbose | |
5438 | switch is used, a third column "local" is printed for local tags. |
|
5429 | switch is used, a third column "local" is printed for local tags. | |
5439 | When the -q/--quiet switch is used, only the tag name is printed. |
|
5430 | When the -q/--quiet switch is used, only the tag name is printed. | |
5440 |
|
5431 | |||
5441 | Returns 0 on success. |
|
5432 | Returns 0 on success. | |
5442 | """ |
|
5433 | """ | |
5443 |
|
5434 | |||
5444 | opts = pycompat.byteskwargs(opts) |
|
5435 | opts = pycompat.byteskwargs(opts) | |
5445 | ui.pager('tags') |
|
5436 | ui.pager('tags') | |
5446 | fm = ui.formatter('tags', opts) |
|
5437 | fm = ui.formatter('tags', opts) | |
5447 | hexfunc = fm.hexfunc |
|
5438 | hexfunc = fm.hexfunc | |
5448 | tagtype = "" |
|
5439 | tagtype = "" | |
5449 |
|
5440 | |||
5450 | for t, n in reversed(repo.tagslist()): |
|
5441 | for t, n in reversed(repo.tagslist()): | |
5451 | hn = hexfunc(n) |
|
5442 | hn = hexfunc(n) | |
5452 | label = 'tags.normal' |
|
5443 | label = 'tags.normal' | |
5453 | tagtype = '' |
|
5444 | tagtype = '' | |
5454 | if repo.tagtype(t) == 'local': |
|
5445 | if repo.tagtype(t) == 'local': | |
5455 | label = 'tags.local' |
|
5446 | label = 'tags.local' | |
5456 | tagtype = 'local' |
|
5447 | tagtype = 'local' | |
5457 |
|
5448 | |||
5458 | fm.startitem() |
|
5449 | fm.startitem() | |
5459 | fm.write('tag', '%s', t, label=label) |
|
5450 | fm.write('tag', '%s', t, label=label) | |
5460 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' |
|
5451 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' | |
5461 | fm.condwrite(not ui.quiet, 'rev node', fmt, |
|
5452 | fm.condwrite(not ui.quiet, 'rev node', fmt, | |
5462 | repo.changelog.rev(n), hn, label=label) |
|
5453 | repo.changelog.rev(n), hn, label=label) | |
5463 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', |
|
5454 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', | |
5464 | tagtype, label=label) |
|
5455 | tagtype, label=label) | |
5465 | fm.plain('\n') |
|
5456 | fm.plain('\n') | |
5466 | fm.end() |
|
5457 | fm.end() | |
5467 |
|
5458 | |||
5468 | @command('tip', |
|
5459 | @command('tip', | |
5469 | [('p', 'patch', None, _('show patch')), |
|
5460 | [('p', 'patch', None, _('show patch')), | |
5470 | ('g', 'git', None, _('use git extended diff format')), |
|
5461 | ('g', 'git', None, _('use git extended diff format')), | |
5471 | ] + templateopts, |
|
5462 | ] + templateopts, | |
5472 | _('[-p] [-g]')) |
|
5463 | _('[-p] [-g]')) | |
5473 | def tip(ui, repo, **opts): |
|
5464 | def tip(ui, repo, **opts): | |
5474 | """show the tip revision (DEPRECATED) |
|
5465 | """show the tip revision (DEPRECATED) | |
5475 |
|
5466 | |||
5476 | The tip revision (usually just called the tip) is the changeset |
|
5467 | The tip revision (usually just called the tip) is the changeset | |
5477 | most recently added to the repository (and therefore the most |
|
5468 | most recently added to the repository (and therefore the most | |
5478 | recently changed head). |
|
5469 | recently changed head). | |
5479 |
|
5470 | |||
5480 | If you have just made a commit, that commit will be the tip. If |
|
5471 | If you have just made a commit, that commit will be the tip. If | |
5481 | you have just pulled changes from another repository, the tip of |
|
5472 | you have just pulled changes from another repository, the tip of | |
5482 | that repository becomes the current tip. The "tip" tag is special |
|
5473 | that repository becomes the current tip. The "tip" tag is special | |
5483 | and cannot be renamed or assigned to a different changeset. |
|
5474 | and cannot be renamed or assigned to a different changeset. | |
5484 |
|
5475 | |||
5485 | This command is deprecated, please use :hg:`heads` instead. |
|
5476 | This command is deprecated, please use :hg:`heads` instead. | |
5486 |
|
5477 | |||
5487 | Returns 0 on success. |
|
5478 | Returns 0 on success. | |
5488 | """ |
|
5479 | """ | |
5489 | opts = pycompat.byteskwargs(opts) |
|
5480 | opts = pycompat.byteskwargs(opts) | |
5490 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
5481 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) | |
5491 | displayer.show(repo['tip']) |
|
5482 | displayer.show(repo['tip']) | |
5492 | displayer.close() |
|
5483 | displayer.close() | |
5493 |
|
5484 | |||
5494 | @command('unbundle', |
|
5485 | @command('unbundle', | |
5495 | [('u', 'update', None, |
|
5486 | [('u', 'update', None, | |
5496 | _('update to new branch head if changesets were unbundled'))], |
|
5487 | _('update to new branch head if changesets were unbundled'))], | |
5497 | _('[-u] FILE...')) |
|
5488 | _('[-u] FILE...')) | |
5498 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
5489 | def unbundle(ui, repo, fname1, *fnames, **opts): | |
5499 | """apply one or more bundle files |
|
5490 | """apply one or more bundle files | |
5500 |
|
5491 | |||
5501 | Apply one or more bundle files generated by :hg:`bundle`. |
|
5492 | Apply one or more bundle files generated by :hg:`bundle`. | |
5502 |
|
5493 | |||
5503 | Returns 0 on success, 1 if an update has unresolved files. |
|
5494 | Returns 0 on success, 1 if an update has unresolved files. | |
5504 | """ |
|
5495 | """ | |
5505 | fnames = (fname1,) + fnames |
|
5496 | fnames = (fname1,) + fnames | |
5506 |
|
5497 | |||
5507 | with repo.lock(): |
|
5498 | with repo.lock(): | |
5508 | for fname in fnames: |
|
5499 | for fname in fnames: | |
5509 | f = hg.openpath(ui, fname) |
|
5500 | f = hg.openpath(ui, fname) | |
5510 | gen = exchange.readbundle(ui, f, fname) |
|
5501 | gen = exchange.readbundle(ui, f, fname) | |
5511 | if isinstance(gen, streamclone.streamcloneapplier): |
|
5502 | if isinstance(gen, streamclone.streamcloneapplier): | |
5512 | raise error.Abort( |
|
5503 | raise error.Abort( | |
5513 | _('packed bundles cannot be applied with ' |
|
5504 | _('packed bundles cannot be applied with ' | |
5514 | '"hg unbundle"'), |
|
5505 | '"hg unbundle"'), | |
5515 | hint=_('use "hg debugapplystreamclonebundle"')) |
|
5506 | hint=_('use "hg debugapplystreamclonebundle"')) | |
5516 | url = 'bundle:' + fname |
|
5507 | url = 'bundle:' + fname | |
5517 | try: |
|
5508 | try: | |
5518 | txnname = 'unbundle' |
|
5509 | txnname = 'unbundle' | |
5519 | if not isinstance(gen, bundle2.unbundle20): |
|
5510 | if not isinstance(gen, bundle2.unbundle20): | |
5520 | txnname = 'unbundle\n%s' % util.hidepassword(url) |
|
5511 | txnname = 'unbundle\n%s' % util.hidepassword(url) | |
5521 | with repo.transaction(txnname) as tr: |
|
5512 | with repo.transaction(txnname) as tr: | |
5522 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', |
|
5513 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', | |
5523 | url=url) |
|
5514 | url=url) | |
5524 | except error.BundleUnknownFeatureError as exc: |
|
5515 | except error.BundleUnknownFeatureError as exc: | |
5525 | raise error.Abort( |
|
5516 | raise error.Abort( | |
5526 | _('%s: unknown bundle feature, %s') % (fname, exc), |
|
5517 | _('%s: unknown bundle feature, %s') % (fname, exc), | |
5527 | hint=_("see https://mercurial-scm.org/" |
|
5518 | hint=_("see https://mercurial-scm.org/" | |
5528 | "wiki/BundleFeature for more " |
|
5519 | "wiki/BundleFeature for more " | |
5529 | "information")) |
|
5520 | "information")) | |
5530 | modheads = bundle2.combinechangegroupresults(op) |
|
5521 | modheads = bundle2.combinechangegroupresults(op) | |
5531 |
|
5522 | |||
5532 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) |
|
5523 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) | |
5533 |
|
5524 | |||
5534 | @command('^update|up|checkout|co', |
|
5525 | @command('^update|up|checkout|co', | |
5535 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
5526 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), | |
5536 | ('c', 'check', None, _('require clean working directory')), |
|
5527 | ('c', 'check', None, _('require clean working directory')), | |
5537 | ('m', 'merge', None, _('merge uncommitted changes')), |
|
5528 | ('m', 'merge', None, _('merge uncommitted changes')), | |
5538 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5529 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
5539 | ('r', 'rev', '', _('revision'), _('REV')) |
|
5530 | ('r', 'rev', '', _('revision'), _('REV')) | |
5540 | ] + mergetoolopts, |
|
5531 | ] + mergetoolopts, | |
5541 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) |
|
5532 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) | |
5542 | def update(ui, repo, node=None, **opts): |
|
5533 | def update(ui, repo, node=None, **opts): | |
5543 | """update working directory (or switch revisions) |
|
5534 | """update working directory (or switch revisions) | |
5544 |
|
5535 | |||
5545 | Update the repository's working directory to the specified |
|
5536 | Update the repository's working directory to the specified | |
5546 | changeset. If no changeset is specified, update to the tip of the |
|
5537 | changeset. If no changeset is specified, update to the tip of the | |
5547 | current named branch and move the active bookmark (see :hg:`help |
|
5538 | current named branch and move the active bookmark (see :hg:`help | |
5548 | bookmarks`). |
|
5539 | bookmarks`). | |
5549 |
|
5540 | |||
5550 | Update sets the working directory's parent revision to the specified |
|
5541 | Update sets the working directory's parent revision to the specified | |
5551 | changeset (see :hg:`help parents`). |
|
5542 | changeset (see :hg:`help parents`). | |
5552 |
|
5543 | |||
5553 | If the changeset is not a descendant or ancestor of the working |
|
5544 | If the changeset is not a descendant or ancestor of the working | |
5554 | directory's parent and there are uncommitted changes, the update is |
|
5545 | directory's parent and there are uncommitted changes, the update is | |
5555 | aborted. With the -c/--check option, the working directory is checked |
|
5546 | aborted. With the -c/--check option, the working directory is checked | |
5556 | for uncommitted changes; if none are found, the working directory is |
|
5547 | for uncommitted changes; if none are found, the working directory is | |
5557 | updated to the specified changeset. |
|
5548 | updated to the specified changeset. | |
5558 |
|
5549 | |||
5559 | .. container:: verbose |
|
5550 | .. container:: verbose | |
5560 |
|
5551 | |||
5561 | The -C/--clean, -c/--check, and -m/--merge options control what |
|
5552 | The -C/--clean, -c/--check, and -m/--merge options control what | |
5562 | happens if the working directory contains uncommitted changes. |
|
5553 | happens if the working directory contains uncommitted changes. | |
5563 | At most of one of them can be specified. |
|
5554 | At most of one of them can be specified. | |
5564 |
|
5555 | |||
5565 | 1. If no option is specified, and if |
|
5556 | 1. If no option is specified, and if | |
5566 | the requested changeset is an ancestor or descendant of |
|
5557 | the requested changeset is an ancestor or descendant of | |
5567 | the working directory's parent, the uncommitted changes |
|
5558 | the working directory's parent, the uncommitted changes | |
5568 | are merged into the requested changeset and the merged |
|
5559 | are merged into the requested changeset and the merged | |
5569 | result is left uncommitted. If the requested changeset is |
|
5560 | result is left uncommitted. If the requested changeset is | |
5570 | not an ancestor or descendant (that is, it is on another |
|
5561 | not an ancestor or descendant (that is, it is on another | |
5571 | branch), the update is aborted and the uncommitted changes |
|
5562 | branch), the update is aborted and the uncommitted changes | |
5572 | are preserved. |
|
5563 | are preserved. | |
5573 |
|
5564 | |||
5574 | 2. With the -m/--merge option, the update is allowed even if the |
|
5565 | 2. With the -m/--merge option, the update is allowed even if the | |
5575 | requested changeset is not an ancestor or descendant of |
|
5566 | requested changeset is not an ancestor or descendant of | |
5576 | the working directory's parent. |
|
5567 | the working directory's parent. | |
5577 |
|
5568 | |||
5578 | 3. With the -c/--check option, the update is aborted and the |
|
5569 | 3. With the -c/--check option, the update is aborted and the | |
5579 | uncommitted changes are preserved. |
|
5570 | uncommitted changes are preserved. | |
5580 |
|
5571 | |||
5581 | 4. With the -C/--clean option, uncommitted changes are discarded and |
|
5572 | 4. With the -C/--clean option, uncommitted changes are discarded and | |
5582 | the working directory is updated to the requested changeset. |
|
5573 | the working directory is updated to the requested changeset. | |
5583 |
|
5574 | |||
5584 | To cancel an uncommitted merge (and lose your changes), use |
|
5575 | To cancel an uncommitted merge (and lose your changes), use | |
5585 | :hg:`merge --abort`. |
|
5576 | :hg:`merge --abort`. | |
5586 |
|
5577 | |||
5587 | Use null as the changeset to remove the working directory (like |
|
5578 | Use null as the changeset to remove the working directory (like | |
5588 | :hg:`clone -U`). |
|
5579 | :hg:`clone -U`). | |
5589 |
|
5580 | |||
5590 | If you want to revert just one file to an older revision, use |
|
5581 | If you want to revert just one file to an older revision, use | |
5591 | :hg:`revert [-r REV] NAME`. |
|
5582 | :hg:`revert [-r REV] NAME`. | |
5592 |
|
5583 | |||
5593 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5584 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
5594 |
|
5585 | |||
5595 | Returns 0 on success, 1 if there are unresolved files. |
|
5586 | Returns 0 on success, 1 if there are unresolved files. | |
5596 | """ |
|
5587 | """ | |
5597 | rev = opts.get(r'rev') |
|
5588 | rev = opts.get(r'rev') | |
5598 | date = opts.get(r'date') |
|
5589 | date = opts.get(r'date') | |
5599 | clean = opts.get(r'clean') |
|
5590 | clean = opts.get(r'clean') | |
5600 | check = opts.get(r'check') |
|
5591 | check = opts.get(r'check') | |
5601 | merge = opts.get(r'merge') |
|
5592 | merge = opts.get(r'merge') | |
5602 | if rev and node: |
|
5593 | if rev and node: | |
5603 | raise error.Abort(_("please specify just one revision")) |
|
5594 | raise error.Abort(_("please specify just one revision")) | |
5604 |
|
5595 | |||
5605 | if ui.configbool('commands', 'update.requiredest'): |
|
5596 | if ui.configbool('commands', 'update.requiredest'): | |
5606 | if not node and not rev and not date: |
|
5597 | if not node and not rev and not date: | |
5607 | raise error.Abort(_('you must specify a destination'), |
|
5598 | raise error.Abort(_('you must specify a destination'), | |
5608 | hint=_('for example: hg update ".::"')) |
|
5599 | hint=_('for example: hg update ".::"')) | |
5609 |
|
5600 | |||
5610 | if rev is None or rev == '': |
|
5601 | if rev is None or rev == '': | |
5611 | rev = node |
|
5602 | rev = node | |
5612 |
|
5603 | |||
5613 | if date and rev is not None: |
|
5604 | if date and rev is not None: | |
5614 | raise error.Abort(_("you can't specify a revision and a date")) |
|
5605 | raise error.Abort(_("you can't specify a revision and a date")) | |
5615 |
|
5606 | |||
5616 | if len([x for x in (clean, check, merge) if x]) > 1: |
|
5607 | if len([x for x in (clean, check, merge) if x]) > 1: | |
5617 | raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " |
|
5608 | raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " | |
5618 | "or -m/--merge")) |
|
5609 | "or -m/--merge")) | |
5619 |
|
5610 | |||
5620 | updatecheck = None |
|
5611 | updatecheck = None | |
5621 | if check: |
|
5612 | if check: | |
5622 | updatecheck = 'abort' |
|
5613 | updatecheck = 'abort' | |
5623 | elif merge: |
|
5614 | elif merge: | |
5624 | updatecheck = 'none' |
|
5615 | updatecheck = 'none' | |
5625 |
|
5616 | |||
5626 | with repo.wlock(): |
|
5617 | with repo.wlock(): | |
5627 | cmdutil.clearunfinished(repo) |
|
5618 | cmdutil.clearunfinished(repo) | |
5628 |
|
5619 | |||
5629 | if date: |
|
5620 | if date: | |
5630 | rev = cmdutil.finddate(ui, repo, date) |
|
5621 | rev = cmdutil.finddate(ui, repo, date) | |
5631 |
|
5622 | |||
5632 | # if we defined a bookmark, we have to remember the original name |
|
5623 | # if we defined a bookmark, we have to remember the original name | |
5633 | brev = rev |
|
5624 | brev = rev | |
5634 | if rev: |
|
5625 | if rev: | |
5635 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
|
5626 | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | |
5636 | ctx = scmutil.revsingle(repo, rev, rev) |
|
5627 | ctx = scmutil.revsingle(repo, rev, rev) | |
5637 | rev = ctx.rev() |
|
5628 | rev = ctx.rev() | |
5638 | hidden = ctx.hidden() |
|
5629 | hidden = ctx.hidden() | |
5639 | overrides = {('ui', 'forcemerge'): opts.get(r'tool', '')} |
|
5630 | overrides = {('ui', 'forcemerge'): opts.get(r'tool', '')} | |
5640 | with ui.configoverride(overrides, 'update'): |
|
5631 | with ui.configoverride(overrides, 'update'): | |
5641 | ret = hg.updatetotally(ui, repo, rev, brev, clean=clean, |
|
5632 | ret = hg.updatetotally(ui, repo, rev, brev, clean=clean, | |
5642 | updatecheck=updatecheck) |
|
5633 | updatecheck=updatecheck) | |
5643 | if hidden: |
|
5634 | if hidden: | |
5644 | ctxstr = ctx.hex()[:12] |
|
5635 | ctxstr = ctx.hex()[:12] | |
5645 | ui.warn(_("updated to hidden changeset %s\n") % ctxstr) |
|
5636 | ui.warn(_("updated to hidden changeset %s\n") % ctxstr) | |
5646 |
|
5637 | |||
5647 | if ctx.obsolete(): |
|
5638 | if ctx.obsolete(): | |
5648 | obsfatemsg = obsutil._getfilteredreason(repo, ctxstr, ctx) |
|
5639 | obsfatemsg = obsutil._getfilteredreason(repo, ctxstr, ctx) | |
5649 | ui.warn("(%s)\n" % obsfatemsg) |
|
5640 | ui.warn("(%s)\n" % obsfatemsg) | |
5650 | return ret |
|
5641 | return ret | |
5651 |
|
5642 | |||
5652 | @command('verify', []) |
|
5643 | @command('verify', []) | |
5653 | def verify(ui, repo): |
|
5644 | def verify(ui, repo): | |
5654 | """verify the integrity of the repository |
|
5645 | """verify the integrity of the repository | |
5655 |
|
5646 | |||
5656 | Verify the integrity of the current repository. |
|
5647 | Verify the integrity of the current repository. | |
5657 |
|
5648 | |||
5658 | This will perform an extensive check of the repository's |
|
5649 | This will perform an extensive check of the repository's | |
5659 | integrity, validating the hashes and checksums of each entry in |
|
5650 | integrity, validating the hashes and checksums of each entry in | |
5660 | the changelog, manifest, and tracked files, as well as the |
|
5651 | the changelog, manifest, and tracked files, as well as the | |
5661 | integrity of their crosslinks and indices. |
|
5652 | integrity of their crosslinks and indices. | |
5662 |
|
5653 | |||
5663 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
5654 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption | |
5664 | for more information about recovery from corruption of the |
|
5655 | for more information about recovery from corruption of the | |
5665 | repository. |
|
5656 | repository. | |
5666 |
|
5657 | |||
5667 | Returns 0 on success, 1 if errors are encountered. |
|
5658 | Returns 0 on success, 1 if errors are encountered. | |
5668 | """ |
|
5659 | """ | |
5669 | return hg.verify(repo) |
|
5660 | return hg.verify(repo) | |
5670 |
|
5661 | |||
5671 | @command('version', [] + formatteropts, norepo=True, |
|
5662 | @command('version', [] + formatteropts, norepo=True, | |
5672 | intents={INTENT_READONLY}) |
|
5663 | intents={INTENT_READONLY}) | |
5673 | def version_(ui, **opts): |
|
5664 | def version_(ui, **opts): | |
5674 | """output version and copyright information""" |
|
5665 | """output version and copyright information""" | |
5675 | opts = pycompat.byteskwargs(opts) |
|
5666 | opts = pycompat.byteskwargs(opts) | |
5676 | if ui.verbose: |
|
5667 | if ui.verbose: | |
5677 | ui.pager('version') |
|
5668 | ui.pager('version') | |
5678 | fm = ui.formatter("version", opts) |
|
5669 | fm = ui.formatter("version", opts) | |
5679 | fm.startitem() |
|
5670 | fm.startitem() | |
5680 | fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), |
|
5671 | fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), | |
5681 | util.version()) |
|
5672 | util.version()) | |
5682 | license = _( |
|
5673 | license = _( | |
5683 | "(see https://mercurial-scm.org for more information)\n" |
|
5674 | "(see https://mercurial-scm.org for more information)\n" | |
5684 | "\nCopyright (C) 2005-2018 Matt Mackall and others\n" |
|
5675 | "\nCopyright (C) 2005-2018 Matt Mackall and others\n" | |
5685 | "This is free software; see the source for copying conditions. " |
|
5676 | "This is free software; see the source for copying conditions. " | |
5686 | "There is NO\nwarranty; " |
|
5677 | "There is NO\nwarranty; " | |
5687 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5678 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
5688 | ) |
|
5679 | ) | |
5689 | if not ui.quiet: |
|
5680 | if not ui.quiet: | |
5690 | fm.plain(license) |
|
5681 | fm.plain(license) | |
5691 |
|
5682 | |||
5692 | if ui.verbose: |
|
5683 | if ui.verbose: | |
5693 | fm.plain(_("\nEnabled extensions:\n\n")) |
|
5684 | fm.plain(_("\nEnabled extensions:\n\n")) | |
5694 | # format names and versions into columns |
|
5685 | # format names and versions into columns | |
5695 | names = [] |
|
5686 | names = [] | |
5696 | vers = [] |
|
5687 | vers = [] | |
5697 | isinternals = [] |
|
5688 | isinternals = [] | |
5698 | for name, module in extensions.extensions(): |
|
5689 | for name, module in extensions.extensions(): | |
5699 | names.append(name) |
|
5690 | names.append(name) | |
5700 | vers.append(extensions.moduleversion(module) or None) |
|
5691 | vers.append(extensions.moduleversion(module) or None) | |
5701 | isinternals.append(extensions.ismoduleinternal(module)) |
|
5692 | isinternals.append(extensions.ismoduleinternal(module)) | |
5702 | fn = fm.nested("extensions", tmpl='{name}\n') |
|
5693 | fn = fm.nested("extensions", tmpl='{name}\n') | |
5703 | if names: |
|
5694 | if names: | |
5704 | namefmt = " %%-%ds " % max(len(n) for n in names) |
|
5695 | namefmt = " %%-%ds " % max(len(n) for n in names) | |
5705 | places = [_("external"), _("internal")] |
|
5696 | places = [_("external"), _("internal")] | |
5706 | for n, v, p in zip(names, vers, isinternals): |
|
5697 | for n, v, p in zip(names, vers, isinternals): | |
5707 | fn.startitem() |
|
5698 | fn.startitem() | |
5708 | fn.condwrite(ui.verbose, "name", namefmt, n) |
|
5699 | fn.condwrite(ui.verbose, "name", namefmt, n) | |
5709 | if ui.verbose: |
|
5700 | if ui.verbose: | |
5710 | fn.plain("%s " % places[p]) |
|
5701 | fn.plain("%s " % places[p]) | |
5711 | fn.data(bundled=p) |
|
5702 | fn.data(bundled=p) | |
5712 | fn.condwrite(ui.verbose and v, "ver", "%s", v) |
|
5703 | fn.condwrite(ui.verbose and v, "ver", "%s", v) | |
5713 | if ui.verbose: |
|
5704 | if ui.verbose: | |
5714 | fn.plain("\n") |
|
5705 | fn.plain("\n") | |
5715 | fn.end() |
|
5706 | fn.end() | |
5716 | fm.end() |
|
5707 | fm.end() | |
5717 |
|
5708 | |||
5718 | def loadcmdtable(ui, name, cmdtable): |
|
5709 | def loadcmdtable(ui, name, cmdtable): | |
5719 | """Load command functions from specified cmdtable |
|
5710 | """Load command functions from specified cmdtable | |
5720 | """ |
|
5711 | """ | |
5721 | overrides = [cmd for cmd in cmdtable if cmd in table] |
|
5712 | overrides = [cmd for cmd in cmdtable if cmd in table] | |
5722 | if overrides: |
|
5713 | if overrides: | |
5723 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
5714 | ui.warn(_("extension '%s' overrides commands: %s\n") | |
5724 | % (name, " ".join(overrides))) |
|
5715 | % (name, " ".join(overrides))) | |
5725 | table.update(cmdtable) |
|
5716 | table.update(cmdtable) |
General Comments 0
You need to be logged in to leave comments.
Login now