Show More
@@ -1,5491 +1,5491 | |||||
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, |
|
43 | lock as lockmod, | |
44 | merge as mergemod, |
|
44 | merge as mergemod, | |
45 | obsolete, |
|
45 | obsolete, | |
46 | patch, |
|
46 | patch, | |
47 | phases, |
|
47 | phases, | |
48 | pycompat, |
|
48 | pycompat, | |
49 | rcutil, |
|
49 | rcutil, | |
50 | registrar, |
|
50 | registrar, | |
51 | revsetlang, |
|
51 | revsetlang, | |
52 | scmutil, |
|
52 | scmutil, | |
53 | server, |
|
53 | server, | |
54 | sshserver, |
|
54 | sshserver, | |
55 | streamclone, |
|
55 | streamclone, | |
56 | tags as tagsmod, |
|
56 | tags as tagsmod, | |
57 | templatekw, |
|
57 | templatekw, | |
58 | ui as uimod, |
|
58 | ui as uimod, | |
59 | util, |
|
59 | util, | |
60 | ) |
|
60 | ) | |
61 |
|
61 | |||
62 | release = lockmod.release |
|
62 | release = lockmod.release | |
63 |
|
63 | |||
64 | table = {} |
|
64 | table = {} | |
65 | table.update(debugcommandsmod.command._table) |
|
65 | table.update(debugcommandsmod.command._table) | |
66 |
|
66 | |||
67 | command = registrar.command(table) |
|
67 | command = registrar.command(table) | |
68 |
|
68 | |||
69 | # common command options |
|
69 | # common command options | |
70 |
|
70 | |||
71 | globalopts = [ |
|
71 | globalopts = [ | |
72 | ('R', 'repository', '', |
|
72 | ('R', 'repository', '', | |
73 | _('repository root directory or name of overlay bundle file'), |
|
73 | _('repository root directory or name of overlay bundle file'), | |
74 | _('REPO')), |
|
74 | _('REPO')), | |
75 | ('', 'cwd', '', |
|
75 | ('', 'cwd', '', | |
76 | _('change working directory'), _('DIR')), |
|
76 | _('change working directory'), _('DIR')), | |
77 | ('y', 'noninteractive', None, |
|
77 | ('y', 'noninteractive', None, | |
78 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
78 | _('do not prompt, automatically pick the first choice for all prompts')), | |
79 | ('q', 'quiet', None, _('suppress output')), |
|
79 | ('q', 'quiet', None, _('suppress output')), | |
80 | ('v', 'verbose', None, _('enable additional output')), |
|
80 | ('v', 'verbose', None, _('enable additional output')), | |
81 | ('', 'color', '', |
|
81 | ('', 'color', '', | |
82 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords |
|
82 | # i18n: 'always', 'auto', 'never', and 'debug' are keywords | |
83 | # and should not be translated |
|
83 | # and should not be translated | |
84 | _("when to colorize (boolean, always, auto, never, or debug)"), |
|
84 | _("when to colorize (boolean, always, auto, never, or debug)"), | |
85 | _('TYPE')), |
|
85 | _('TYPE')), | |
86 | ('', 'config', [], |
|
86 | ('', 'config', [], | |
87 | _('set/override config option (use \'section.name=value\')'), |
|
87 | _('set/override config option (use \'section.name=value\')'), | |
88 | _('CONFIG')), |
|
88 | _('CONFIG')), | |
89 | ('', 'debug', None, _('enable debugging output')), |
|
89 | ('', 'debug', None, _('enable debugging output')), | |
90 | ('', 'debugger', None, _('start debugger')), |
|
90 | ('', 'debugger', None, _('start debugger')), | |
91 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
91 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), | |
92 | _('ENCODE')), |
|
92 | _('ENCODE')), | |
93 | ('', 'encodingmode', encoding.encodingmode, |
|
93 | ('', 'encodingmode', encoding.encodingmode, | |
94 | _('set the charset encoding mode'), _('MODE')), |
|
94 | _('set the charset encoding mode'), _('MODE')), | |
95 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
95 | ('', 'traceback', None, _('always print a traceback on exception')), | |
96 | ('', 'time', None, _('time how long the command takes')), |
|
96 | ('', 'time', None, _('time how long the command takes')), | |
97 | ('', 'profile', None, _('print command execution profile')), |
|
97 | ('', 'profile', None, _('print command execution profile')), | |
98 | ('', 'version', None, _('output version information and exit')), |
|
98 | ('', 'version', None, _('output version information and exit')), | |
99 | ('h', 'help', None, _('display help and exit')), |
|
99 | ('h', 'help', None, _('display help and exit')), | |
100 | ('', 'hidden', False, _('consider hidden changesets')), |
|
100 | ('', 'hidden', False, _('consider hidden changesets')), | |
101 | ('', 'pager', 'auto', |
|
101 | ('', 'pager', 'auto', | |
102 | _("when to paginate (boolean, always, auto, or never)"), _('TYPE')), |
|
102 | _("when to paginate (boolean, always, auto, or never)"), _('TYPE')), | |
103 | ] |
|
103 | ] | |
104 |
|
104 | |||
105 | dryrunopts = cmdutil.dryrunopts |
|
105 | dryrunopts = cmdutil.dryrunopts | |
106 | remoteopts = cmdutil.remoteopts |
|
106 | remoteopts = cmdutil.remoteopts | |
107 | walkopts = cmdutil.walkopts |
|
107 | walkopts = cmdutil.walkopts | |
108 | commitopts = cmdutil.commitopts |
|
108 | commitopts = cmdutil.commitopts | |
109 | commitopts2 = cmdutil.commitopts2 |
|
109 | commitopts2 = cmdutil.commitopts2 | |
110 | formatteropts = cmdutil.formatteropts |
|
110 | formatteropts = cmdutil.formatteropts | |
111 | templateopts = cmdutil.templateopts |
|
111 | templateopts = cmdutil.templateopts | |
112 | logopts = cmdutil.logopts |
|
112 | logopts = cmdutil.logopts | |
113 | diffopts = cmdutil.diffopts |
|
113 | diffopts = cmdutil.diffopts | |
114 | diffwsopts = cmdutil.diffwsopts |
|
114 | diffwsopts = cmdutil.diffwsopts | |
115 | diffopts2 = cmdutil.diffopts2 |
|
115 | diffopts2 = cmdutil.diffopts2 | |
116 | mergetoolopts = cmdutil.mergetoolopts |
|
116 | mergetoolopts = cmdutil.mergetoolopts | |
117 | similarityopts = cmdutil.similarityopts |
|
117 | similarityopts = cmdutil.similarityopts | |
118 | subrepoopts = cmdutil.subrepoopts |
|
118 | subrepoopts = cmdutil.subrepoopts | |
119 | debugrevlogopts = cmdutil.debugrevlogopts |
|
119 | debugrevlogopts = cmdutil.debugrevlogopts | |
120 |
|
120 | |||
121 | # Commands start here, listed alphabetically |
|
121 | # Commands start here, listed alphabetically | |
122 |
|
122 | |||
123 | @command('^add', |
|
123 | @command('^add', | |
124 | walkopts + subrepoopts + dryrunopts, |
|
124 | walkopts + subrepoopts + dryrunopts, | |
125 | _('[OPTION]... [FILE]...'), |
|
125 | _('[OPTION]... [FILE]...'), | |
126 | inferrepo=True) |
|
126 | inferrepo=True) | |
127 | def add(ui, repo, *pats, **opts): |
|
127 | def add(ui, repo, *pats, **opts): | |
128 | """add the specified files on the next commit |
|
128 | """add the specified files on the next commit | |
129 |
|
129 | |||
130 | Schedule files to be version controlled and added to the |
|
130 | Schedule files to be version controlled and added to the | |
131 | repository. |
|
131 | repository. | |
132 |
|
132 | |||
133 | The files will be added to the repository at the next commit. To |
|
133 | The files will be added to the repository at the next commit. To | |
134 | undo an add before that, see :hg:`forget`. |
|
134 | undo an add before that, see :hg:`forget`. | |
135 |
|
135 | |||
136 | If no names are given, add all files to the repository (except |
|
136 | If no names are given, add all files to the repository (except | |
137 | files matching ``.hgignore``). |
|
137 | files matching ``.hgignore``). | |
138 |
|
138 | |||
139 | .. container:: verbose |
|
139 | .. container:: verbose | |
140 |
|
140 | |||
141 | Examples: |
|
141 | Examples: | |
142 |
|
142 | |||
143 | - New (unknown) files are added |
|
143 | - New (unknown) files are added | |
144 | automatically by :hg:`add`:: |
|
144 | automatically by :hg:`add`:: | |
145 |
|
145 | |||
146 | $ ls |
|
146 | $ ls | |
147 | foo.c |
|
147 | foo.c | |
148 | $ hg status |
|
148 | $ hg status | |
149 | ? foo.c |
|
149 | ? foo.c | |
150 | $ hg add |
|
150 | $ hg add | |
151 | adding foo.c |
|
151 | adding foo.c | |
152 | $ hg status |
|
152 | $ hg status | |
153 | A foo.c |
|
153 | A foo.c | |
154 |
|
154 | |||
155 | - Specific files to be added can be specified:: |
|
155 | - Specific files to be added can be specified:: | |
156 |
|
156 | |||
157 | $ ls |
|
157 | $ ls | |
158 | bar.c foo.c |
|
158 | bar.c foo.c | |
159 | $ hg status |
|
159 | $ hg status | |
160 | ? bar.c |
|
160 | ? bar.c | |
161 | ? foo.c |
|
161 | ? foo.c | |
162 | $ hg add bar.c |
|
162 | $ hg add bar.c | |
163 | $ hg status |
|
163 | $ hg status | |
164 | A bar.c |
|
164 | A bar.c | |
165 | ? foo.c |
|
165 | ? foo.c | |
166 |
|
166 | |||
167 | Returns 0 if all files are successfully added. |
|
167 | Returns 0 if all files are successfully added. | |
168 | """ |
|
168 | """ | |
169 |
|
169 | |||
170 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) |
|
170 | m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts)) | |
171 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) |
|
171 | rejected = cmdutil.add(ui, repo, m, "", False, **opts) | |
172 | return rejected and 1 or 0 |
|
172 | return rejected and 1 or 0 | |
173 |
|
173 | |||
174 | @command('addremove', |
|
174 | @command('addremove', | |
175 | similarityopts + subrepoopts + walkopts + dryrunopts, |
|
175 | similarityopts + subrepoopts + walkopts + dryrunopts, | |
176 | _('[OPTION]... [FILE]...'), |
|
176 | _('[OPTION]... [FILE]...'), | |
177 | inferrepo=True) |
|
177 | inferrepo=True) | |
178 | def addremove(ui, repo, *pats, **opts): |
|
178 | def addremove(ui, repo, *pats, **opts): | |
179 | """add all new files, delete all missing files |
|
179 | """add all new files, delete all missing files | |
180 |
|
180 | |||
181 | Add all new files and remove all missing files from the |
|
181 | Add all new files and remove all missing files from the | |
182 | repository. |
|
182 | repository. | |
183 |
|
183 | |||
184 | Unless names are given, new files are ignored if they match any of |
|
184 | Unless names are given, new files are ignored if they match any of | |
185 | the patterns in ``.hgignore``. As with add, these changes take |
|
185 | the patterns in ``.hgignore``. As with add, these changes take | |
186 | effect at the next commit. |
|
186 | effect at the next commit. | |
187 |
|
187 | |||
188 | Use the -s/--similarity option to detect renamed files. This |
|
188 | Use the -s/--similarity option to detect renamed files. This | |
189 | option takes a percentage between 0 (disabled) and 100 (files must |
|
189 | option takes a percentage between 0 (disabled) and 100 (files must | |
190 | be identical) as its parameter. With a parameter greater than 0, |
|
190 | be identical) as its parameter. With a parameter greater than 0, | |
191 | this compares every removed file with every added file and records |
|
191 | this compares every removed file with every added file and records | |
192 | those similar enough as renames. Detecting renamed files this way |
|
192 | those similar enough as renames. Detecting renamed files this way | |
193 | can be expensive. After using this option, :hg:`status -C` can be |
|
193 | can be expensive. After using this option, :hg:`status -C` can be | |
194 | used to check which files were identified as moved or renamed. If |
|
194 | used to check which files were identified as moved or renamed. If | |
195 | not specified, -s/--similarity defaults to 100 and only renames of |
|
195 | not specified, -s/--similarity defaults to 100 and only renames of | |
196 | identical files are detected. |
|
196 | identical files are detected. | |
197 |
|
197 | |||
198 | .. container:: verbose |
|
198 | .. container:: verbose | |
199 |
|
199 | |||
200 | Examples: |
|
200 | Examples: | |
201 |
|
201 | |||
202 | - A number of files (bar.c and foo.c) are new, |
|
202 | - A number of files (bar.c and foo.c) are new, | |
203 | while foobar.c has been removed (without using :hg:`remove`) |
|
203 | while foobar.c has been removed (without using :hg:`remove`) | |
204 | from the repository:: |
|
204 | from the repository:: | |
205 |
|
205 | |||
206 | $ ls |
|
206 | $ ls | |
207 | bar.c foo.c |
|
207 | bar.c foo.c | |
208 | $ hg status |
|
208 | $ hg status | |
209 | ! foobar.c |
|
209 | ! foobar.c | |
210 | ? bar.c |
|
210 | ? bar.c | |
211 | ? foo.c |
|
211 | ? foo.c | |
212 | $ hg addremove |
|
212 | $ hg addremove | |
213 | adding bar.c |
|
213 | adding bar.c | |
214 | adding foo.c |
|
214 | adding foo.c | |
215 | removing foobar.c |
|
215 | removing foobar.c | |
216 | $ hg status |
|
216 | $ hg status | |
217 | A bar.c |
|
217 | A bar.c | |
218 | A foo.c |
|
218 | A foo.c | |
219 | R foobar.c |
|
219 | R foobar.c | |
220 |
|
220 | |||
221 | - A file foobar.c was moved to foo.c without using :hg:`rename`. |
|
221 | - A file foobar.c was moved to foo.c without using :hg:`rename`. | |
222 | Afterwards, it was edited slightly:: |
|
222 | Afterwards, it was edited slightly:: | |
223 |
|
223 | |||
224 | $ ls |
|
224 | $ ls | |
225 | foo.c |
|
225 | foo.c | |
226 | $ hg status |
|
226 | $ hg status | |
227 | ! foobar.c |
|
227 | ! foobar.c | |
228 | ? foo.c |
|
228 | ? foo.c | |
229 | $ hg addremove --similarity 90 |
|
229 | $ hg addremove --similarity 90 | |
230 | removing foobar.c |
|
230 | removing foobar.c | |
231 | adding foo.c |
|
231 | adding foo.c | |
232 | recording removal of foobar.c as rename to foo.c (94% similar) |
|
232 | recording removal of foobar.c as rename to foo.c (94% similar) | |
233 | $ hg status -C |
|
233 | $ hg status -C | |
234 | A foo.c |
|
234 | A foo.c | |
235 | foobar.c |
|
235 | foobar.c | |
236 | R foobar.c |
|
236 | R foobar.c | |
237 |
|
237 | |||
238 | Returns 0 if all files are successfully added. |
|
238 | Returns 0 if all files are successfully added. | |
239 | """ |
|
239 | """ | |
240 | opts = pycompat.byteskwargs(opts) |
|
240 | opts = pycompat.byteskwargs(opts) | |
241 | try: |
|
241 | try: | |
242 | sim = float(opts.get('similarity') or 100) |
|
242 | sim = float(opts.get('similarity') or 100) | |
243 | except ValueError: |
|
243 | except ValueError: | |
244 | raise error.Abort(_('similarity must be a number')) |
|
244 | raise error.Abort(_('similarity must be a number')) | |
245 | if sim < 0 or sim > 100: |
|
245 | if sim < 0 or sim > 100: | |
246 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
246 | raise error.Abort(_('similarity must be between 0 and 100')) | |
247 | matcher = scmutil.match(repo[None], pats, opts) |
|
247 | matcher = scmutil.match(repo[None], pats, opts) | |
248 | return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0) |
|
248 | return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0) | |
249 |
|
249 | |||
250 | @command('^annotate|blame', |
|
250 | @command('^annotate|blame', | |
251 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
251 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), | |
252 | ('', 'follow', None, |
|
252 | ('', 'follow', None, | |
253 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
253 | _('follow copies/renames and list the filename (DEPRECATED)')), | |
254 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
254 | ('', 'no-follow', None, _("don't follow copies and renames")), | |
255 | ('a', 'text', None, _('treat all files as text')), |
|
255 | ('a', 'text', None, _('treat all files as text')), | |
256 | ('u', 'user', None, _('list the author (long with -v)')), |
|
256 | ('u', 'user', None, _('list the author (long with -v)')), | |
257 | ('f', 'file', None, _('list the filename')), |
|
257 | ('f', 'file', None, _('list the filename')), | |
258 | ('d', 'date', None, _('list the date (short with -q)')), |
|
258 | ('d', 'date', None, _('list the date (short with -q)')), | |
259 | ('n', 'number', None, _('list the revision number (default)')), |
|
259 | ('n', 'number', None, _('list the revision number (default)')), | |
260 | ('c', 'changeset', None, _('list the changeset')), |
|
260 | ('c', 'changeset', None, _('list the changeset')), | |
261 | ('l', 'line-number', None, _('show line number at the first appearance')), |
|
261 | ('l', 'line-number', None, _('show line number at the first appearance')), | |
262 | ('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')), |
|
262 | ('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')), | |
263 | ] + diffwsopts + walkopts + formatteropts, |
|
263 | ] + diffwsopts + walkopts + formatteropts, | |
264 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
|
264 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), | |
265 | inferrepo=True) |
|
265 | inferrepo=True) | |
266 | def annotate(ui, repo, *pats, **opts): |
|
266 | def annotate(ui, repo, *pats, **opts): | |
267 | """show changeset information by line for each file |
|
267 | """show changeset information by line for each file | |
268 |
|
268 | |||
269 | List changes in files, showing the revision id responsible for |
|
269 | List changes in files, showing the revision id responsible for | |
270 | each line. |
|
270 | each line. | |
271 |
|
271 | |||
272 | This command is useful for discovering when a change was made and |
|
272 | This command is useful for discovering when a change was made and | |
273 | by whom. |
|
273 | by whom. | |
274 |
|
274 | |||
275 | If you include --file, --user, or --date, the revision number is |
|
275 | If you include --file, --user, or --date, the revision number is | |
276 | suppressed unless you also include --number. |
|
276 | suppressed unless you also include --number. | |
277 |
|
277 | |||
278 | Without the -a/--text option, annotate will avoid processing files |
|
278 | Without the -a/--text option, annotate will avoid processing files | |
279 | it detects as binary. With -a, annotate will annotate the file |
|
279 | it detects as binary. With -a, annotate will annotate the file | |
280 | anyway, although the results will probably be neither useful |
|
280 | anyway, although the results will probably be neither useful | |
281 | nor desirable. |
|
281 | nor desirable. | |
282 |
|
282 | |||
283 | Returns 0 on success. |
|
283 | Returns 0 on success. | |
284 | """ |
|
284 | """ | |
285 | opts = pycompat.byteskwargs(opts) |
|
285 | opts = pycompat.byteskwargs(opts) | |
286 | if not pats: |
|
286 | if not pats: | |
287 | raise error.Abort(_('at least one filename or pattern is required')) |
|
287 | raise error.Abort(_('at least one filename or pattern is required')) | |
288 |
|
288 | |||
289 | if opts.get('follow'): |
|
289 | if opts.get('follow'): | |
290 | # --follow is deprecated and now just an alias for -f/--file |
|
290 | # --follow is deprecated and now just an alias for -f/--file | |
291 | # to mimic the behavior of Mercurial before version 1.5 |
|
291 | # to mimic the behavior of Mercurial before version 1.5 | |
292 | opts['file'] = True |
|
292 | opts['file'] = True | |
293 |
|
293 | |||
294 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
294 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
295 |
|
295 | |||
296 | rootfm = ui.formatter('annotate', opts) |
|
296 | rootfm = ui.formatter('annotate', opts) | |
297 | if ui.quiet: |
|
297 | if ui.quiet: | |
298 | datefunc = util.shortdate |
|
298 | datefunc = util.shortdate | |
299 | else: |
|
299 | else: | |
300 | datefunc = util.datestr |
|
300 | datefunc = util.datestr | |
301 | if ctx.rev() is None: |
|
301 | if ctx.rev() is None: | |
302 | def hexfn(node): |
|
302 | def hexfn(node): | |
303 | if node is None: |
|
303 | if node is None: | |
304 | return None |
|
304 | return None | |
305 | else: |
|
305 | else: | |
306 | return rootfm.hexfunc(node) |
|
306 | return rootfm.hexfunc(node) | |
307 | if opts.get('changeset'): |
|
307 | if opts.get('changeset'): | |
308 | # omit "+" suffix which is appended to node hex |
|
308 | # omit "+" suffix which is appended to node hex | |
309 | def formatrev(rev): |
|
309 | def formatrev(rev): | |
310 | if rev is None: |
|
310 | if rev is None: | |
311 | return '%d' % ctx.p1().rev() |
|
311 | return '%d' % ctx.p1().rev() | |
312 | else: |
|
312 | else: | |
313 | return '%d' % rev |
|
313 | return '%d' % rev | |
314 | else: |
|
314 | else: | |
315 | def formatrev(rev): |
|
315 | def formatrev(rev): | |
316 | if rev is None: |
|
316 | if rev is None: | |
317 | return '%d+' % ctx.p1().rev() |
|
317 | return '%d+' % ctx.p1().rev() | |
318 | else: |
|
318 | else: | |
319 | return '%d ' % rev |
|
319 | return '%d ' % rev | |
320 | def formathex(hex): |
|
320 | def formathex(hex): | |
321 | if hex is None: |
|
321 | if hex is None: | |
322 | return '%s+' % rootfm.hexfunc(ctx.p1().node()) |
|
322 | return '%s+' % rootfm.hexfunc(ctx.p1().node()) | |
323 | else: |
|
323 | else: | |
324 | return '%s ' % hex |
|
324 | return '%s ' % hex | |
325 | else: |
|
325 | else: | |
326 | hexfn = rootfm.hexfunc |
|
326 | hexfn = rootfm.hexfunc | |
327 | formatrev = formathex = pycompat.bytestr |
|
327 | formatrev = formathex = pycompat.bytestr | |
328 |
|
328 | |||
329 |
opmap = [('user', ' ', lambda x: x |
|
329 | opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser), | |
330 |
('number', ' ', lambda x: x |
|
330 | ('number', ' ', lambda x: x.fctx.rev(), formatrev), | |
331 |
('changeset', ' ', lambda x: hexfn(x |
|
331 | ('changeset', ' ', lambda x: hexfn(x.fctx.node()), formathex), | |
332 |
('date', ' ', lambda x: x |
|
332 | ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)), | |
333 |
('file', ' ', lambda x: x |
|
333 | ('file', ' ', lambda x: x.fctx.path(), str), | |
334 |
('line_number', ':', lambda x: x |
|
334 | ('line_number', ':', lambda x: x.lineno, str), | |
335 | ] |
|
335 | ] | |
336 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} |
|
336 | fieldnamemap = {'number': 'rev', 'changeset': 'node'} | |
337 |
|
337 | |||
338 | if (not opts.get('user') and not opts.get('changeset') |
|
338 | if (not opts.get('user') and not opts.get('changeset') | |
339 | and not opts.get('date') and not opts.get('file')): |
|
339 | and not opts.get('date') and not opts.get('file')): | |
340 | opts['number'] = True |
|
340 | opts['number'] = True | |
341 |
|
341 | |||
342 | linenumber = opts.get('line_number') is not None |
|
342 | linenumber = opts.get('line_number') is not None | |
343 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
343 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): | |
344 | raise error.Abort(_('at least one of -n/-c is required for -l')) |
|
344 | raise error.Abort(_('at least one of -n/-c is required for -l')) | |
345 |
|
345 | |||
346 | ui.pager('annotate') |
|
346 | ui.pager('annotate') | |
347 |
|
347 | |||
348 | if rootfm.isplain(): |
|
348 | if rootfm.isplain(): | |
349 | def makefunc(get, fmt): |
|
349 | def makefunc(get, fmt): | |
350 | return lambda x: fmt(get(x)) |
|
350 | return lambda x: fmt(get(x)) | |
351 | else: |
|
351 | else: | |
352 | def makefunc(get, fmt): |
|
352 | def makefunc(get, fmt): | |
353 | return get |
|
353 | return get | |
354 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap |
|
354 | funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap | |
355 | if opts.get(op)] |
|
355 | if opts.get(op)] | |
356 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
356 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column | |
357 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap |
|
357 | fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap | |
358 | if opts.get(op)) |
|
358 | if opts.get(op)) | |
359 |
|
359 | |||
360 | def bad(x, y): |
|
360 | def bad(x, y): | |
361 | raise error.Abort("%s: %s" % (x, y)) |
|
361 | raise error.Abort("%s: %s" % (x, y)) | |
362 |
|
362 | |||
363 | m = scmutil.match(ctx, pats, opts, badfn=bad) |
|
363 | m = scmutil.match(ctx, pats, opts, badfn=bad) | |
364 |
|
364 | |||
365 | follow = not opts.get('no_follow') |
|
365 | follow = not opts.get('no_follow') | |
366 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', |
|
366 | diffopts = patch.difffeatureopts(ui, opts, section='annotate', | |
367 | whitespace=True) |
|
367 | whitespace=True) | |
368 | skiprevs = opts.get('skip') |
|
368 | skiprevs = opts.get('skip') | |
369 | if skiprevs: |
|
369 | if skiprevs: | |
370 | skiprevs = scmutil.revrange(repo, skiprevs) |
|
370 | skiprevs = scmutil.revrange(repo, skiprevs) | |
371 |
|
371 | |||
372 | for abs in ctx.walk(m): |
|
372 | for abs in ctx.walk(m): | |
373 | fctx = ctx[abs] |
|
373 | fctx = ctx[abs] | |
374 | rootfm.startitem() |
|
374 | rootfm.startitem() | |
375 | rootfm.data(abspath=abs, path=m.rel(abs)) |
|
375 | rootfm.data(abspath=abs, path=m.rel(abs)) | |
376 | if not opts.get('text') and fctx.isbinary(): |
|
376 | if not opts.get('text') and fctx.isbinary(): | |
377 | rootfm.plain(_("%s: binary file\n") |
|
377 | rootfm.plain(_("%s: binary file\n") | |
378 | % ((pats and m.rel(abs)) or abs)) |
|
378 | % ((pats and m.rel(abs)) or abs)) | |
379 | continue |
|
379 | continue | |
380 |
|
380 | |||
381 | fm = rootfm.nested('lines') |
|
381 | fm = rootfm.nested('lines') | |
382 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
382 | lines = fctx.annotate(follow=follow, linenumber=linenumber, | |
383 | skiprevs=skiprevs, diffopts=diffopts) |
|
383 | skiprevs=skiprevs, diffopts=diffopts) | |
384 | if not lines: |
|
384 | if not lines: | |
385 | fm.end() |
|
385 | fm.end() | |
386 | continue |
|
386 | continue | |
387 | formats = [] |
|
387 | formats = [] | |
388 | pieces = [] |
|
388 | pieces = [] | |
389 |
|
389 | |||
390 | for f, sep in funcmap: |
|
390 | for f, sep in funcmap: | |
391 | l = [f(n) for n, dummy in lines] |
|
391 | l = [f(n) for n, dummy in lines] | |
392 | if fm.isplain(): |
|
392 | if fm.isplain(): | |
393 | sizes = [encoding.colwidth(x) for x in l] |
|
393 | sizes = [encoding.colwidth(x) for x in l] | |
394 | ml = max(sizes) |
|
394 | ml = max(sizes) | |
395 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) |
|
395 | formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes]) | |
396 | else: |
|
396 | else: | |
397 | formats.append(['%s' for x in l]) |
|
397 | formats.append(['%s' for x in l]) | |
398 | pieces.append(l) |
|
398 | pieces.append(l) | |
399 |
|
399 | |||
400 | for f, p, l in zip(zip(*formats), zip(*pieces), lines): |
|
400 | for f, p, l in zip(zip(*formats), zip(*pieces), lines): | |
401 | fm.startitem() |
|
401 | fm.startitem() | |
402 | fm.write(fields, "".join(f), *p) |
|
402 | fm.write(fields, "".join(f), *p) | |
403 | fm.write('line', ": %s", l[1]) |
|
403 | fm.write('line', ": %s", l[1]) | |
404 |
|
404 | |||
405 | if not lines[-1][1].endswith('\n'): |
|
405 | if not lines[-1][1].endswith('\n'): | |
406 | fm.plain('\n') |
|
406 | fm.plain('\n') | |
407 | fm.end() |
|
407 | fm.end() | |
408 |
|
408 | |||
409 | rootfm.end() |
|
409 | rootfm.end() | |
410 |
|
410 | |||
411 | @command('archive', |
|
411 | @command('archive', | |
412 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
412 | [('', 'no-decode', None, _('do not pass files through decoders')), | |
413 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
413 | ('p', 'prefix', '', _('directory prefix for files in archive'), | |
414 | _('PREFIX')), |
|
414 | _('PREFIX')), | |
415 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
415 | ('r', 'rev', '', _('revision to distribute'), _('REV')), | |
416 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
416 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), | |
417 | ] + subrepoopts + walkopts, |
|
417 | ] + subrepoopts + walkopts, | |
418 | _('[OPTION]... DEST')) |
|
418 | _('[OPTION]... DEST')) | |
419 | def archive(ui, repo, dest, **opts): |
|
419 | def archive(ui, repo, dest, **opts): | |
420 | '''create an unversioned archive of a repository revision |
|
420 | '''create an unversioned archive of a repository revision | |
421 |
|
421 | |||
422 | By default, the revision used is the parent of the working |
|
422 | By default, the revision used is the parent of the working | |
423 | directory; use -r/--rev to specify a different revision. |
|
423 | directory; use -r/--rev to specify a different revision. | |
424 |
|
424 | |||
425 | The archive type is automatically detected based on file |
|
425 | The archive type is automatically detected based on file | |
426 | extension (to override, use -t/--type). |
|
426 | extension (to override, use -t/--type). | |
427 |
|
427 | |||
428 | .. container:: verbose |
|
428 | .. container:: verbose | |
429 |
|
429 | |||
430 | Examples: |
|
430 | Examples: | |
431 |
|
431 | |||
432 | - create a zip file containing the 1.0 release:: |
|
432 | - create a zip file containing the 1.0 release:: | |
433 |
|
433 | |||
434 | hg archive -r 1.0 project-1.0.zip |
|
434 | hg archive -r 1.0 project-1.0.zip | |
435 |
|
435 | |||
436 | - create a tarball excluding .hg files:: |
|
436 | - create a tarball excluding .hg files:: | |
437 |
|
437 | |||
438 | hg archive project.tar.gz -X ".hg*" |
|
438 | hg archive project.tar.gz -X ".hg*" | |
439 |
|
439 | |||
440 | Valid types are: |
|
440 | Valid types are: | |
441 |
|
441 | |||
442 | :``files``: a directory full of files (default) |
|
442 | :``files``: a directory full of files (default) | |
443 | :``tar``: tar archive, uncompressed |
|
443 | :``tar``: tar archive, uncompressed | |
444 | :``tbz2``: tar archive, compressed using bzip2 |
|
444 | :``tbz2``: tar archive, compressed using bzip2 | |
445 | :``tgz``: tar archive, compressed using gzip |
|
445 | :``tgz``: tar archive, compressed using gzip | |
446 | :``uzip``: zip archive, uncompressed |
|
446 | :``uzip``: zip archive, uncompressed | |
447 | :``zip``: zip archive, compressed using deflate |
|
447 | :``zip``: zip archive, compressed using deflate | |
448 |
|
448 | |||
449 | The exact name of the destination archive or directory is given |
|
449 | The exact name of the destination archive or directory is given | |
450 | using a format string; see :hg:`help export` for details. |
|
450 | using a format string; see :hg:`help export` for details. | |
451 |
|
451 | |||
452 | Each member added to an archive file has a directory prefix |
|
452 | Each member added to an archive file has a directory prefix | |
453 | prepended. Use -p/--prefix to specify a format string for the |
|
453 | prepended. Use -p/--prefix to specify a format string for the | |
454 | prefix. The default is the basename of the archive, with suffixes |
|
454 | prefix. The default is the basename of the archive, with suffixes | |
455 | removed. |
|
455 | removed. | |
456 |
|
456 | |||
457 | Returns 0 on success. |
|
457 | Returns 0 on success. | |
458 | ''' |
|
458 | ''' | |
459 |
|
459 | |||
460 | opts = pycompat.byteskwargs(opts) |
|
460 | opts = pycompat.byteskwargs(opts) | |
461 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
461 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
462 | if not ctx: |
|
462 | if not ctx: | |
463 | raise error.Abort(_('no working directory: please specify a revision')) |
|
463 | raise error.Abort(_('no working directory: please specify a revision')) | |
464 | node = ctx.node() |
|
464 | node = ctx.node() | |
465 | dest = cmdutil.makefilename(repo, dest, node) |
|
465 | dest = cmdutil.makefilename(repo, dest, node) | |
466 | if os.path.realpath(dest) == repo.root: |
|
466 | if os.path.realpath(dest) == repo.root: | |
467 | raise error.Abort(_('repository root cannot be destination')) |
|
467 | raise error.Abort(_('repository root cannot be destination')) | |
468 |
|
468 | |||
469 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
469 | kind = opts.get('type') or archival.guesskind(dest) or 'files' | |
470 | prefix = opts.get('prefix') |
|
470 | prefix = opts.get('prefix') | |
471 |
|
471 | |||
472 | if dest == '-': |
|
472 | if dest == '-': | |
473 | if kind == 'files': |
|
473 | if kind == 'files': | |
474 | raise error.Abort(_('cannot archive plain files to stdout')) |
|
474 | raise error.Abort(_('cannot archive plain files to stdout')) | |
475 | dest = cmdutil.makefileobj(repo, dest) |
|
475 | dest = cmdutil.makefileobj(repo, dest) | |
476 | if not prefix: |
|
476 | if not prefix: | |
477 | prefix = os.path.basename(repo.root) + '-%h' |
|
477 | prefix = os.path.basename(repo.root) + '-%h' | |
478 |
|
478 | |||
479 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
479 | prefix = cmdutil.makefilename(repo, prefix, node) | |
480 | match = scmutil.match(ctx, [], opts) |
|
480 | match = scmutil.match(ctx, [], opts) | |
481 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
481 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | |
482 | match, prefix, subrepos=opts.get('subrepos')) |
|
482 | match, prefix, subrepos=opts.get('subrepos')) | |
483 |
|
483 | |||
484 | @command('backout', |
|
484 | @command('backout', | |
485 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
485 | [('', 'merge', None, _('merge with old dirstate parent after backout')), | |
486 | ('', 'commit', None, |
|
486 | ('', 'commit', None, | |
487 | _('commit if no conflicts were encountered (DEPRECATED)')), |
|
487 | _('commit if no conflicts were encountered (DEPRECATED)')), | |
488 | ('', 'no-commit', None, _('do not commit')), |
|
488 | ('', 'no-commit', None, _('do not commit')), | |
489 | ('', 'parent', '', |
|
489 | ('', 'parent', '', | |
490 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
490 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), | |
491 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
491 | ('r', 'rev', '', _('revision to backout'), _('REV')), | |
492 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
492 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
493 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
493 | ] + mergetoolopts + walkopts + commitopts + commitopts2, | |
494 | _('[OPTION]... [-r] REV')) |
|
494 | _('[OPTION]... [-r] REV')) | |
495 | def backout(ui, repo, node=None, rev=None, **opts): |
|
495 | def backout(ui, repo, node=None, rev=None, **opts): | |
496 | '''reverse effect of earlier changeset |
|
496 | '''reverse effect of earlier changeset | |
497 |
|
497 | |||
498 | Prepare a new changeset with the effect of REV undone in the |
|
498 | Prepare a new changeset with the effect of REV undone in the | |
499 | current working directory. If no conflicts were encountered, |
|
499 | current working directory. If no conflicts were encountered, | |
500 | it will be committed immediately. |
|
500 | it will be committed immediately. | |
501 |
|
501 | |||
502 | If REV is the parent of the working directory, then this new changeset |
|
502 | If REV is the parent of the working directory, then this new changeset | |
503 | is committed automatically (unless --no-commit is specified). |
|
503 | is committed automatically (unless --no-commit is specified). | |
504 |
|
504 | |||
505 | .. note:: |
|
505 | .. note:: | |
506 |
|
506 | |||
507 | :hg:`backout` cannot be used to fix either an unwanted or |
|
507 | :hg:`backout` cannot be used to fix either an unwanted or | |
508 | incorrect merge. |
|
508 | incorrect merge. | |
509 |
|
509 | |||
510 | .. container:: verbose |
|
510 | .. container:: verbose | |
511 |
|
511 | |||
512 | Examples: |
|
512 | Examples: | |
513 |
|
513 | |||
514 | - Reverse the effect of the parent of the working directory. |
|
514 | - Reverse the effect of the parent of the working directory. | |
515 | This backout will be committed immediately:: |
|
515 | This backout will be committed immediately:: | |
516 |
|
516 | |||
517 | hg backout -r . |
|
517 | hg backout -r . | |
518 |
|
518 | |||
519 | - Reverse the effect of previous bad revision 23:: |
|
519 | - Reverse the effect of previous bad revision 23:: | |
520 |
|
520 | |||
521 | hg backout -r 23 |
|
521 | hg backout -r 23 | |
522 |
|
522 | |||
523 | - Reverse the effect of previous bad revision 23 and |
|
523 | - Reverse the effect of previous bad revision 23 and | |
524 | leave changes uncommitted:: |
|
524 | leave changes uncommitted:: | |
525 |
|
525 | |||
526 | hg backout -r 23 --no-commit |
|
526 | hg backout -r 23 --no-commit | |
527 | hg commit -m "Backout revision 23" |
|
527 | hg commit -m "Backout revision 23" | |
528 |
|
528 | |||
529 | By default, the pending changeset will have one parent, |
|
529 | By default, the pending changeset will have one parent, | |
530 | maintaining a linear history. With --merge, the pending |
|
530 | maintaining a linear history. With --merge, the pending | |
531 | changeset will instead have two parents: the old parent of the |
|
531 | changeset will instead have two parents: the old parent of the | |
532 | working directory and a new child of REV that simply undoes REV. |
|
532 | working directory and a new child of REV that simply undoes REV. | |
533 |
|
533 | |||
534 | Before version 1.7, the behavior without --merge was equivalent |
|
534 | Before version 1.7, the behavior without --merge was equivalent | |
535 | to specifying --merge followed by :hg:`update --clean .` to |
|
535 | to specifying --merge followed by :hg:`update --clean .` to | |
536 | cancel the merge and leave the child of REV as a head to be |
|
536 | cancel the merge and leave the child of REV as a head to be | |
537 | merged separately. |
|
537 | merged separately. | |
538 |
|
538 | |||
539 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
539 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
540 |
|
540 | |||
541 | See :hg:`help revert` for a way to restore files to the state |
|
541 | See :hg:`help revert` for a way to restore files to the state | |
542 | of another revision. |
|
542 | of another revision. | |
543 |
|
543 | |||
544 | Returns 0 on success, 1 if nothing to backout or there are unresolved |
|
544 | Returns 0 on success, 1 if nothing to backout or there are unresolved | |
545 | files. |
|
545 | files. | |
546 | ''' |
|
546 | ''' | |
547 | wlock = lock = None |
|
547 | wlock = lock = None | |
548 | try: |
|
548 | try: | |
549 | wlock = repo.wlock() |
|
549 | wlock = repo.wlock() | |
550 | lock = repo.lock() |
|
550 | lock = repo.lock() | |
551 | return _dobackout(ui, repo, node, rev, **opts) |
|
551 | return _dobackout(ui, repo, node, rev, **opts) | |
552 | finally: |
|
552 | finally: | |
553 | release(lock, wlock) |
|
553 | release(lock, wlock) | |
554 |
|
554 | |||
555 | def _dobackout(ui, repo, node=None, rev=None, **opts): |
|
555 | def _dobackout(ui, repo, node=None, rev=None, **opts): | |
556 | opts = pycompat.byteskwargs(opts) |
|
556 | opts = pycompat.byteskwargs(opts) | |
557 | if opts.get('commit') and opts.get('no_commit'): |
|
557 | if opts.get('commit') and opts.get('no_commit'): | |
558 | raise error.Abort(_("cannot use --commit with --no-commit")) |
|
558 | raise error.Abort(_("cannot use --commit with --no-commit")) | |
559 | if opts.get('merge') and opts.get('no_commit'): |
|
559 | if opts.get('merge') and opts.get('no_commit'): | |
560 | raise error.Abort(_("cannot use --merge with --no-commit")) |
|
560 | raise error.Abort(_("cannot use --merge with --no-commit")) | |
561 |
|
561 | |||
562 | if rev and node: |
|
562 | if rev and node: | |
563 | raise error.Abort(_("please specify just one revision")) |
|
563 | raise error.Abort(_("please specify just one revision")) | |
564 |
|
564 | |||
565 | if not rev: |
|
565 | if not rev: | |
566 | rev = node |
|
566 | rev = node | |
567 |
|
567 | |||
568 | if not rev: |
|
568 | if not rev: | |
569 | raise error.Abort(_("please specify a revision to backout")) |
|
569 | raise error.Abort(_("please specify a revision to backout")) | |
570 |
|
570 | |||
571 | date = opts.get('date') |
|
571 | date = opts.get('date') | |
572 | if date: |
|
572 | if date: | |
573 | opts['date'] = util.parsedate(date) |
|
573 | opts['date'] = util.parsedate(date) | |
574 |
|
574 | |||
575 | cmdutil.checkunfinished(repo) |
|
575 | cmdutil.checkunfinished(repo) | |
576 | cmdutil.bailifchanged(repo) |
|
576 | cmdutil.bailifchanged(repo) | |
577 | node = scmutil.revsingle(repo, rev).node() |
|
577 | node = scmutil.revsingle(repo, rev).node() | |
578 |
|
578 | |||
579 | op1, op2 = repo.dirstate.parents() |
|
579 | op1, op2 = repo.dirstate.parents() | |
580 | if not repo.changelog.isancestor(node, op1): |
|
580 | if not repo.changelog.isancestor(node, op1): | |
581 | raise error.Abort(_('cannot backout change that is not an ancestor')) |
|
581 | raise error.Abort(_('cannot backout change that is not an ancestor')) | |
582 |
|
582 | |||
583 | p1, p2 = repo.changelog.parents(node) |
|
583 | p1, p2 = repo.changelog.parents(node) | |
584 | if p1 == nullid: |
|
584 | if p1 == nullid: | |
585 | raise error.Abort(_('cannot backout a change with no parents')) |
|
585 | raise error.Abort(_('cannot backout a change with no parents')) | |
586 | if p2 != nullid: |
|
586 | if p2 != nullid: | |
587 | if not opts.get('parent'): |
|
587 | if not opts.get('parent'): | |
588 | raise error.Abort(_('cannot backout a merge changeset')) |
|
588 | raise error.Abort(_('cannot backout a merge changeset')) | |
589 | p = repo.lookup(opts['parent']) |
|
589 | p = repo.lookup(opts['parent']) | |
590 | if p not in (p1, p2): |
|
590 | if p not in (p1, p2): | |
591 | raise error.Abort(_('%s is not a parent of %s') % |
|
591 | raise error.Abort(_('%s is not a parent of %s') % | |
592 | (short(p), short(node))) |
|
592 | (short(p), short(node))) | |
593 | parent = p |
|
593 | parent = p | |
594 | else: |
|
594 | else: | |
595 | if opts.get('parent'): |
|
595 | if opts.get('parent'): | |
596 | raise error.Abort(_('cannot use --parent on non-merge changeset')) |
|
596 | raise error.Abort(_('cannot use --parent on non-merge changeset')) | |
597 | parent = p1 |
|
597 | parent = p1 | |
598 |
|
598 | |||
599 | # the backout should appear on the same branch |
|
599 | # the backout should appear on the same branch | |
600 | branch = repo.dirstate.branch() |
|
600 | branch = repo.dirstate.branch() | |
601 | bheads = repo.branchheads(branch) |
|
601 | bheads = repo.branchheads(branch) | |
602 | rctx = scmutil.revsingle(repo, hex(parent)) |
|
602 | rctx = scmutil.revsingle(repo, hex(parent)) | |
603 | if not opts.get('merge') and op1 != node: |
|
603 | if not opts.get('merge') and op1 != node: | |
604 | dsguard = dirstateguard.dirstateguard(repo, 'backout') |
|
604 | dsguard = dirstateguard.dirstateguard(repo, 'backout') | |
605 | try: |
|
605 | try: | |
606 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
606 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |
607 | 'backout') |
|
607 | 'backout') | |
608 | stats = mergemod.update(repo, parent, True, True, node, False) |
|
608 | stats = mergemod.update(repo, parent, True, True, node, False) | |
609 | repo.setparents(op1, op2) |
|
609 | repo.setparents(op1, op2) | |
610 | dsguard.close() |
|
610 | dsguard.close() | |
611 | hg._showstats(repo, stats) |
|
611 | hg._showstats(repo, stats) | |
612 | if stats[3]: |
|
612 | if stats[3]: | |
613 | repo.ui.status(_("use 'hg resolve' to retry unresolved " |
|
613 | repo.ui.status(_("use 'hg resolve' to retry unresolved " | |
614 | "file merges\n")) |
|
614 | "file merges\n")) | |
615 | return 1 |
|
615 | return 1 | |
616 | finally: |
|
616 | finally: | |
617 | ui.setconfig('ui', 'forcemerge', '', '') |
|
617 | ui.setconfig('ui', 'forcemerge', '', '') | |
618 | lockmod.release(dsguard) |
|
618 | lockmod.release(dsguard) | |
619 | else: |
|
619 | else: | |
620 | hg.clean(repo, node, show_stats=False) |
|
620 | hg.clean(repo, node, show_stats=False) | |
621 | repo.dirstate.setbranch(branch) |
|
621 | repo.dirstate.setbranch(branch) | |
622 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) |
|
622 | cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) | |
623 |
|
623 | |||
624 | if opts.get('no_commit'): |
|
624 | if opts.get('no_commit'): | |
625 | msg = _("changeset %s backed out, " |
|
625 | msg = _("changeset %s backed out, " | |
626 | "don't forget to commit.\n") |
|
626 | "don't forget to commit.\n") | |
627 | ui.status(msg % short(node)) |
|
627 | ui.status(msg % short(node)) | |
628 | return 0 |
|
628 | return 0 | |
629 |
|
629 | |||
630 | def commitfunc(ui, repo, message, match, opts): |
|
630 | def commitfunc(ui, repo, message, match, opts): | |
631 | editform = 'backout' |
|
631 | editform = 'backout' | |
632 | e = cmdutil.getcommiteditor(editform=editform, |
|
632 | e = cmdutil.getcommiteditor(editform=editform, | |
633 | **pycompat.strkwargs(opts)) |
|
633 | **pycompat.strkwargs(opts)) | |
634 | if not message: |
|
634 | if not message: | |
635 | # we don't translate commit messages |
|
635 | # we don't translate commit messages | |
636 | message = "Backed out changeset %s" % short(node) |
|
636 | message = "Backed out changeset %s" % short(node) | |
637 | e = cmdutil.getcommiteditor(edit=True, editform=editform) |
|
637 | e = cmdutil.getcommiteditor(edit=True, editform=editform) | |
638 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
638 | return repo.commit(message, opts.get('user'), opts.get('date'), | |
639 | match, editor=e) |
|
639 | match, editor=e) | |
640 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) |
|
640 | newnode = cmdutil.commit(ui, repo, commitfunc, [], opts) | |
641 | if not newnode: |
|
641 | if not newnode: | |
642 | ui.status(_("nothing changed\n")) |
|
642 | ui.status(_("nothing changed\n")) | |
643 | return 1 |
|
643 | return 1 | |
644 | cmdutil.commitstatus(repo, newnode, branch, bheads) |
|
644 | cmdutil.commitstatus(repo, newnode, branch, bheads) | |
645 |
|
645 | |||
646 | def nice(node): |
|
646 | def nice(node): | |
647 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
647 | return '%d:%s' % (repo.changelog.rev(node), short(node)) | |
648 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
648 | ui.status(_('changeset %s backs out changeset %s\n') % | |
649 | (nice(repo.changelog.tip()), nice(node))) |
|
649 | (nice(repo.changelog.tip()), nice(node))) | |
650 | if opts.get('merge') and op1 != node: |
|
650 | if opts.get('merge') and op1 != node: | |
651 | hg.clean(repo, op1, show_stats=False) |
|
651 | hg.clean(repo, op1, show_stats=False) | |
652 | ui.status(_('merging with changeset %s\n') |
|
652 | ui.status(_('merging with changeset %s\n') | |
653 | % nice(repo.changelog.tip())) |
|
653 | % nice(repo.changelog.tip())) | |
654 | try: |
|
654 | try: | |
655 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
655 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |
656 | 'backout') |
|
656 | 'backout') | |
657 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
657 | return hg.merge(repo, hex(repo.changelog.tip())) | |
658 | finally: |
|
658 | finally: | |
659 | ui.setconfig('ui', 'forcemerge', '', '') |
|
659 | ui.setconfig('ui', 'forcemerge', '', '') | |
660 | return 0 |
|
660 | return 0 | |
661 |
|
661 | |||
662 | @command('bisect', |
|
662 | @command('bisect', | |
663 | [('r', 'reset', False, _('reset bisect state')), |
|
663 | [('r', 'reset', False, _('reset bisect state')), | |
664 | ('g', 'good', False, _('mark changeset good')), |
|
664 | ('g', 'good', False, _('mark changeset good')), | |
665 | ('b', 'bad', False, _('mark changeset bad')), |
|
665 | ('b', 'bad', False, _('mark changeset bad')), | |
666 | ('s', 'skip', False, _('skip testing changeset')), |
|
666 | ('s', 'skip', False, _('skip testing changeset')), | |
667 | ('e', 'extend', False, _('extend the bisect range')), |
|
667 | ('e', 'extend', False, _('extend the bisect range')), | |
668 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
668 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), | |
669 | ('U', 'noupdate', False, _('do not update to target'))], |
|
669 | ('U', 'noupdate', False, _('do not update to target'))], | |
670 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
670 | _("[-gbsr] [-U] [-c CMD] [REV]")) | |
671 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
671 | def bisect(ui, repo, rev=None, extra=None, command=None, | |
672 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
672 | reset=None, good=None, bad=None, skip=None, extend=None, | |
673 | noupdate=None): |
|
673 | noupdate=None): | |
674 | """subdivision search of changesets |
|
674 | """subdivision search of changesets | |
675 |
|
675 | |||
676 | This command helps to find changesets which introduce problems. To |
|
676 | This command helps to find changesets which introduce problems. To | |
677 | use, mark the earliest changeset you know exhibits the problem as |
|
677 | use, mark the earliest changeset you know exhibits the problem as | |
678 | bad, then mark the latest changeset which is free from the problem |
|
678 | bad, then mark the latest changeset which is free from the problem | |
679 | as good. Bisect will update your working directory to a revision |
|
679 | as good. Bisect will update your working directory to a revision | |
680 | for testing (unless the -U/--noupdate option is specified). Once |
|
680 | for testing (unless the -U/--noupdate option is specified). Once | |
681 | you have performed tests, mark the working directory as good or |
|
681 | you have performed tests, mark the working directory as good or | |
682 | bad, and bisect will either update to another candidate changeset |
|
682 | bad, and bisect will either update to another candidate changeset | |
683 | or announce that it has found the bad revision. |
|
683 | or announce that it has found the bad revision. | |
684 |
|
684 | |||
685 | As a shortcut, you can also use the revision argument to mark a |
|
685 | As a shortcut, you can also use the revision argument to mark a | |
686 | revision as good or bad without checking it out first. |
|
686 | revision as good or bad without checking it out first. | |
687 |
|
687 | |||
688 | If you supply a command, it will be used for automatic bisection. |
|
688 | If you supply a command, it will be used for automatic bisection. | |
689 | The environment variable HG_NODE will contain the ID of the |
|
689 | The environment variable HG_NODE will contain the ID of the | |
690 | changeset being tested. The exit status of the command will be |
|
690 | changeset being tested. The exit status of the command will be | |
691 | used to mark revisions as good or bad: status 0 means good, 125 |
|
691 | used to mark revisions as good or bad: status 0 means good, 125 | |
692 | means to skip the revision, 127 (command not found) will abort the |
|
692 | means to skip the revision, 127 (command not found) will abort the | |
693 | bisection, and any other non-zero exit status means the revision |
|
693 | bisection, and any other non-zero exit status means the revision | |
694 | is bad. |
|
694 | is bad. | |
695 |
|
695 | |||
696 | .. container:: verbose |
|
696 | .. container:: verbose | |
697 |
|
697 | |||
698 | Some examples: |
|
698 | Some examples: | |
699 |
|
699 | |||
700 | - start a bisection with known bad revision 34, and good revision 12:: |
|
700 | - start a bisection with known bad revision 34, and good revision 12:: | |
701 |
|
701 | |||
702 | hg bisect --bad 34 |
|
702 | hg bisect --bad 34 | |
703 | hg bisect --good 12 |
|
703 | hg bisect --good 12 | |
704 |
|
704 | |||
705 | - advance the current bisection by marking current revision as good or |
|
705 | - advance the current bisection by marking current revision as good or | |
706 | bad:: |
|
706 | bad:: | |
707 |
|
707 | |||
708 | hg bisect --good |
|
708 | hg bisect --good | |
709 | hg bisect --bad |
|
709 | hg bisect --bad | |
710 |
|
710 | |||
711 | - mark the current revision, or a known revision, to be skipped (e.g. if |
|
711 | - mark the current revision, or a known revision, to be skipped (e.g. if | |
712 | that revision is not usable because of another issue):: |
|
712 | that revision is not usable because of another issue):: | |
713 |
|
713 | |||
714 | hg bisect --skip |
|
714 | hg bisect --skip | |
715 | hg bisect --skip 23 |
|
715 | hg bisect --skip 23 | |
716 |
|
716 | |||
717 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: |
|
717 | - skip all revisions that do not touch directories ``foo`` or ``bar``:: | |
718 |
|
718 | |||
719 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" |
|
719 | hg bisect --skip "!( file('path:foo') & file('path:bar') )" | |
720 |
|
720 | |||
721 | - forget the current bisection:: |
|
721 | - forget the current bisection:: | |
722 |
|
722 | |||
723 | hg bisect --reset |
|
723 | hg bisect --reset | |
724 |
|
724 | |||
725 | - use 'make && make tests' to automatically find the first broken |
|
725 | - use 'make && make tests' to automatically find the first broken | |
726 | revision:: |
|
726 | revision:: | |
727 |
|
727 | |||
728 | hg bisect --reset |
|
728 | hg bisect --reset | |
729 | hg bisect --bad 34 |
|
729 | hg bisect --bad 34 | |
730 | hg bisect --good 12 |
|
730 | hg bisect --good 12 | |
731 | hg bisect --command "make && make tests" |
|
731 | hg bisect --command "make && make tests" | |
732 |
|
732 | |||
733 | - see all changesets whose states are already known in the current |
|
733 | - see all changesets whose states are already known in the current | |
734 | bisection:: |
|
734 | bisection:: | |
735 |
|
735 | |||
736 | hg log -r "bisect(pruned)" |
|
736 | hg log -r "bisect(pruned)" | |
737 |
|
737 | |||
738 | - see the changeset currently being bisected (especially useful |
|
738 | - see the changeset currently being bisected (especially useful | |
739 | if running with -U/--noupdate):: |
|
739 | if running with -U/--noupdate):: | |
740 |
|
740 | |||
741 | hg log -r "bisect(current)" |
|
741 | hg log -r "bisect(current)" | |
742 |
|
742 | |||
743 | - see all changesets that took part in the current bisection:: |
|
743 | - see all changesets that took part in the current bisection:: | |
744 |
|
744 | |||
745 | hg log -r "bisect(range)" |
|
745 | hg log -r "bisect(range)" | |
746 |
|
746 | |||
747 | - you can even get a nice graph:: |
|
747 | - you can even get a nice graph:: | |
748 |
|
748 | |||
749 | hg log --graph -r "bisect(range)" |
|
749 | hg log --graph -r "bisect(range)" | |
750 |
|
750 | |||
751 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. |
|
751 | See :hg:`help revisions.bisect` for more about the `bisect()` predicate. | |
752 |
|
752 | |||
753 | Returns 0 on success. |
|
753 | Returns 0 on success. | |
754 | """ |
|
754 | """ | |
755 | # backward compatibility |
|
755 | # backward compatibility | |
756 | if rev in "good bad reset init".split(): |
|
756 | if rev in "good bad reset init".split(): | |
757 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
757 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) | |
758 | cmd, rev, extra = rev, extra, None |
|
758 | cmd, rev, extra = rev, extra, None | |
759 | if cmd == "good": |
|
759 | if cmd == "good": | |
760 | good = True |
|
760 | good = True | |
761 | elif cmd == "bad": |
|
761 | elif cmd == "bad": | |
762 | bad = True |
|
762 | bad = True | |
763 | else: |
|
763 | else: | |
764 | reset = True |
|
764 | reset = True | |
765 | elif extra: |
|
765 | elif extra: | |
766 | raise error.Abort(_('incompatible arguments')) |
|
766 | raise error.Abort(_('incompatible arguments')) | |
767 |
|
767 | |||
768 | incompatibles = { |
|
768 | incompatibles = { | |
769 | '--bad': bad, |
|
769 | '--bad': bad, | |
770 | '--command': bool(command), |
|
770 | '--command': bool(command), | |
771 | '--extend': extend, |
|
771 | '--extend': extend, | |
772 | '--good': good, |
|
772 | '--good': good, | |
773 | '--reset': reset, |
|
773 | '--reset': reset, | |
774 | '--skip': skip, |
|
774 | '--skip': skip, | |
775 | } |
|
775 | } | |
776 |
|
776 | |||
777 | enabled = [x for x in incompatibles if incompatibles[x]] |
|
777 | enabled = [x for x in incompatibles if incompatibles[x]] | |
778 |
|
778 | |||
779 | if len(enabled) > 1: |
|
779 | if len(enabled) > 1: | |
780 | raise error.Abort(_('%s and %s are incompatible') % |
|
780 | raise error.Abort(_('%s and %s are incompatible') % | |
781 | tuple(sorted(enabled)[0:2])) |
|
781 | tuple(sorted(enabled)[0:2])) | |
782 |
|
782 | |||
783 | if reset: |
|
783 | if reset: | |
784 | hbisect.resetstate(repo) |
|
784 | hbisect.resetstate(repo) | |
785 | return |
|
785 | return | |
786 |
|
786 | |||
787 | state = hbisect.load_state(repo) |
|
787 | state = hbisect.load_state(repo) | |
788 |
|
788 | |||
789 | # update state |
|
789 | # update state | |
790 | if good or bad or skip: |
|
790 | if good or bad or skip: | |
791 | if rev: |
|
791 | if rev: | |
792 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
792 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] | |
793 | else: |
|
793 | else: | |
794 | nodes = [repo.lookup('.')] |
|
794 | nodes = [repo.lookup('.')] | |
795 | if good: |
|
795 | if good: | |
796 | state['good'] += nodes |
|
796 | state['good'] += nodes | |
797 | elif bad: |
|
797 | elif bad: | |
798 | state['bad'] += nodes |
|
798 | state['bad'] += nodes | |
799 | elif skip: |
|
799 | elif skip: | |
800 | state['skip'] += nodes |
|
800 | state['skip'] += nodes | |
801 | hbisect.save_state(repo, state) |
|
801 | hbisect.save_state(repo, state) | |
802 | if not (state['good'] and state['bad']): |
|
802 | if not (state['good'] and state['bad']): | |
803 | return |
|
803 | return | |
804 |
|
804 | |||
805 | def mayupdate(repo, node, show_stats=True): |
|
805 | def mayupdate(repo, node, show_stats=True): | |
806 | """common used update sequence""" |
|
806 | """common used update sequence""" | |
807 | if noupdate: |
|
807 | if noupdate: | |
808 | return |
|
808 | return | |
809 | cmdutil.checkunfinished(repo) |
|
809 | cmdutil.checkunfinished(repo) | |
810 | cmdutil.bailifchanged(repo) |
|
810 | cmdutil.bailifchanged(repo) | |
811 | return hg.clean(repo, node, show_stats=show_stats) |
|
811 | return hg.clean(repo, node, show_stats=show_stats) | |
812 |
|
812 | |||
813 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
813 | displayer = cmdutil.show_changeset(ui, repo, {}) | |
814 |
|
814 | |||
815 | if command: |
|
815 | if command: | |
816 | changesets = 1 |
|
816 | changesets = 1 | |
817 | if noupdate: |
|
817 | if noupdate: | |
818 | try: |
|
818 | try: | |
819 | node = state['current'][0] |
|
819 | node = state['current'][0] | |
820 | except LookupError: |
|
820 | except LookupError: | |
821 | raise error.Abort(_('current bisect revision is unknown - ' |
|
821 | raise error.Abort(_('current bisect revision is unknown - ' | |
822 | 'start a new bisect to fix')) |
|
822 | 'start a new bisect to fix')) | |
823 | else: |
|
823 | else: | |
824 | node, p2 = repo.dirstate.parents() |
|
824 | node, p2 = repo.dirstate.parents() | |
825 | if p2 != nullid: |
|
825 | if p2 != nullid: | |
826 | raise error.Abort(_('current bisect revision is a merge')) |
|
826 | raise error.Abort(_('current bisect revision is a merge')) | |
827 | if rev: |
|
827 | if rev: | |
828 | node = repo[scmutil.revsingle(repo, rev, node)].node() |
|
828 | node = repo[scmutil.revsingle(repo, rev, node)].node() | |
829 | try: |
|
829 | try: | |
830 | while changesets: |
|
830 | while changesets: | |
831 | # update state |
|
831 | # update state | |
832 | state['current'] = [node] |
|
832 | state['current'] = [node] | |
833 | hbisect.save_state(repo, state) |
|
833 | hbisect.save_state(repo, state) | |
834 | status = ui.system(command, environ={'HG_NODE': hex(node)}, |
|
834 | status = ui.system(command, environ={'HG_NODE': hex(node)}, | |
835 | blockedtag='bisect_check') |
|
835 | blockedtag='bisect_check') | |
836 | if status == 125: |
|
836 | if status == 125: | |
837 | transition = "skip" |
|
837 | transition = "skip" | |
838 | elif status == 0: |
|
838 | elif status == 0: | |
839 | transition = "good" |
|
839 | transition = "good" | |
840 | # status < 0 means process was killed |
|
840 | # status < 0 means process was killed | |
841 | elif status == 127: |
|
841 | elif status == 127: | |
842 | raise error.Abort(_("failed to execute %s") % command) |
|
842 | raise error.Abort(_("failed to execute %s") % command) | |
843 | elif status < 0: |
|
843 | elif status < 0: | |
844 | raise error.Abort(_("%s killed") % command) |
|
844 | raise error.Abort(_("%s killed") % command) | |
845 | else: |
|
845 | else: | |
846 | transition = "bad" |
|
846 | transition = "bad" | |
847 | state[transition].append(node) |
|
847 | state[transition].append(node) | |
848 | ctx = repo[node] |
|
848 | ctx = repo[node] | |
849 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
849 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) | |
850 | hbisect.checkstate(state) |
|
850 | hbisect.checkstate(state) | |
851 | # bisect |
|
851 | # bisect | |
852 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) |
|
852 | nodes, changesets, bgood = hbisect.bisect(repo.changelog, state) | |
853 | # update to next check |
|
853 | # update to next check | |
854 | node = nodes[0] |
|
854 | node = nodes[0] | |
855 | mayupdate(repo, node, show_stats=False) |
|
855 | mayupdate(repo, node, show_stats=False) | |
856 | finally: |
|
856 | finally: | |
857 | state['current'] = [node] |
|
857 | state['current'] = [node] | |
858 | hbisect.save_state(repo, state) |
|
858 | hbisect.save_state(repo, state) | |
859 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) |
|
859 | hbisect.printresult(ui, repo, state, displayer, nodes, bgood) | |
860 | return |
|
860 | return | |
861 |
|
861 | |||
862 | hbisect.checkstate(state) |
|
862 | hbisect.checkstate(state) | |
863 |
|
863 | |||
864 | # actually bisect |
|
864 | # actually bisect | |
865 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
865 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) | |
866 | if extend: |
|
866 | if extend: | |
867 | if not changesets: |
|
867 | if not changesets: | |
868 | extendnode = hbisect.extendrange(repo, state, nodes, good) |
|
868 | extendnode = hbisect.extendrange(repo, state, nodes, good) | |
869 | if extendnode is not None: |
|
869 | if extendnode is not None: | |
870 | ui.write(_("Extending search to changeset %d:%s\n") |
|
870 | ui.write(_("Extending search to changeset %d:%s\n") | |
871 | % (extendnode.rev(), extendnode)) |
|
871 | % (extendnode.rev(), extendnode)) | |
872 | state['current'] = [extendnode.node()] |
|
872 | state['current'] = [extendnode.node()] | |
873 | hbisect.save_state(repo, state) |
|
873 | hbisect.save_state(repo, state) | |
874 | return mayupdate(repo, extendnode.node()) |
|
874 | return mayupdate(repo, extendnode.node()) | |
875 | raise error.Abort(_("nothing to extend")) |
|
875 | raise error.Abort(_("nothing to extend")) | |
876 |
|
876 | |||
877 | if changesets == 0: |
|
877 | if changesets == 0: | |
878 | hbisect.printresult(ui, repo, state, displayer, nodes, good) |
|
878 | hbisect.printresult(ui, repo, state, displayer, nodes, good) | |
879 | else: |
|
879 | else: | |
880 | assert len(nodes) == 1 # only a single node can be tested next |
|
880 | assert len(nodes) == 1 # only a single node can be tested next | |
881 | node = nodes[0] |
|
881 | node = nodes[0] | |
882 | # compute the approximate number of remaining tests |
|
882 | # compute the approximate number of remaining tests | |
883 | tests, size = 0, 2 |
|
883 | tests, size = 0, 2 | |
884 | while size <= changesets: |
|
884 | while size <= changesets: | |
885 | tests, size = tests + 1, size * 2 |
|
885 | tests, size = tests + 1, size * 2 | |
886 | rev = repo.changelog.rev(node) |
|
886 | rev = repo.changelog.rev(node) | |
887 | ui.write(_("Testing changeset %d:%s " |
|
887 | ui.write(_("Testing changeset %d:%s " | |
888 | "(%d changesets remaining, ~%d tests)\n") |
|
888 | "(%d changesets remaining, ~%d tests)\n") | |
889 | % (rev, short(node), changesets, tests)) |
|
889 | % (rev, short(node), changesets, tests)) | |
890 | state['current'] = [node] |
|
890 | state['current'] = [node] | |
891 | hbisect.save_state(repo, state) |
|
891 | hbisect.save_state(repo, state) | |
892 | return mayupdate(repo, node) |
|
892 | return mayupdate(repo, node) | |
893 |
|
893 | |||
894 | @command('bookmarks|bookmark', |
|
894 | @command('bookmarks|bookmark', | |
895 | [('f', 'force', False, _('force')), |
|
895 | [('f', 'force', False, _('force')), | |
896 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), |
|
896 | ('r', 'rev', '', _('revision for bookmark action'), _('REV')), | |
897 | ('d', 'delete', False, _('delete a given bookmark')), |
|
897 | ('d', 'delete', False, _('delete a given bookmark')), | |
898 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), |
|
898 | ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), | |
899 | ('i', 'inactive', False, _('mark a bookmark inactive')), |
|
899 | ('i', 'inactive', False, _('mark a bookmark inactive')), | |
900 | ] + formatteropts, |
|
900 | ] + formatteropts, | |
901 | _('hg bookmarks [OPTIONS]... [NAME]...')) |
|
901 | _('hg bookmarks [OPTIONS]... [NAME]...')) | |
902 | def bookmark(ui, repo, *names, **opts): |
|
902 | def bookmark(ui, repo, *names, **opts): | |
903 | '''create a new bookmark or list existing bookmarks |
|
903 | '''create a new bookmark or list existing bookmarks | |
904 |
|
904 | |||
905 | Bookmarks are labels on changesets to help track lines of development. |
|
905 | Bookmarks are labels on changesets to help track lines of development. | |
906 | Bookmarks are unversioned and can be moved, renamed and deleted. |
|
906 | Bookmarks are unversioned and can be moved, renamed and deleted. | |
907 | Deleting or moving a bookmark has no effect on the associated changesets. |
|
907 | Deleting or moving a bookmark has no effect on the associated changesets. | |
908 |
|
908 | |||
909 | Creating or updating to a bookmark causes it to be marked as 'active'. |
|
909 | Creating or updating to a bookmark causes it to be marked as 'active'. | |
910 | The active bookmark is indicated with a '*'. |
|
910 | The active bookmark is indicated with a '*'. | |
911 | When a commit is made, the active bookmark will advance to the new commit. |
|
911 | When a commit is made, the active bookmark will advance to the new commit. | |
912 | A plain :hg:`update` will also advance an active bookmark, if possible. |
|
912 | A plain :hg:`update` will also advance an active bookmark, if possible. | |
913 | Updating away from a bookmark will cause it to be deactivated. |
|
913 | Updating away from a bookmark will cause it to be deactivated. | |
914 |
|
914 | |||
915 | Bookmarks can be pushed and pulled between repositories (see |
|
915 | Bookmarks can be pushed and pulled between repositories (see | |
916 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has |
|
916 | :hg:`help push` and :hg:`help pull`). If a shared bookmark has | |
917 | diverged, a new 'divergent bookmark' of the form 'name@path' will |
|
917 | diverged, a new 'divergent bookmark' of the form 'name@path' will | |
918 | be created. Using :hg:`merge` will resolve the divergence. |
|
918 | be created. Using :hg:`merge` will resolve the divergence. | |
919 |
|
919 | |||
920 | Specifying bookmark as '.' to -m or -d options is equivalent to specifying |
|
920 | Specifying bookmark as '.' to -m or -d options is equivalent to specifying | |
921 | the active bookmark's name. |
|
921 | the active bookmark's name. | |
922 |
|
922 | |||
923 | A bookmark named '@' has the special property that :hg:`clone` will |
|
923 | A bookmark named '@' has the special property that :hg:`clone` will | |
924 | check it out by default if it exists. |
|
924 | check it out by default if it exists. | |
925 |
|
925 | |||
926 | .. container:: verbose |
|
926 | .. container:: verbose | |
927 |
|
927 | |||
928 | Examples: |
|
928 | Examples: | |
929 |
|
929 | |||
930 | - create an active bookmark for a new line of development:: |
|
930 | - create an active bookmark for a new line of development:: | |
931 |
|
931 | |||
932 | hg book new-feature |
|
932 | hg book new-feature | |
933 |
|
933 | |||
934 | - create an inactive bookmark as a place marker:: |
|
934 | - create an inactive bookmark as a place marker:: | |
935 |
|
935 | |||
936 | hg book -i reviewed |
|
936 | hg book -i reviewed | |
937 |
|
937 | |||
938 | - create an inactive bookmark on another changeset:: |
|
938 | - create an inactive bookmark on another changeset:: | |
939 |
|
939 | |||
940 | hg book -r .^ tested |
|
940 | hg book -r .^ tested | |
941 |
|
941 | |||
942 | - rename bookmark turkey to dinner:: |
|
942 | - rename bookmark turkey to dinner:: | |
943 |
|
943 | |||
944 | hg book -m turkey dinner |
|
944 | hg book -m turkey dinner | |
945 |
|
945 | |||
946 | - move the '@' bookmark from another branch:: |
|
946 | - move the '@' bookmark from another branch:: | |
947 |
|
947 | |||
948 | hg book -f @ |
|
948 | hg book -f @ | |
949 | ''' |
|
949 | ''' | |
950 | force = opts.get(r'force') |
|
950 | force = opts.get(r'force') | |
951 | rev = opts.get(r'rev') |
|
951 | rev = opts.get(r'rev') | |
952 | delete = opts.get(r'delete') |
|
952 | delete = opts.get(r'delete') | |
953 | rename = opts.get(r'rename') |
|
953 | rename = opts.get(r'rename') | |
954 | inactive = opts.get(r'inactive') |
|
954 | inactive = opts.get(r'inactive') | |
955 |
|
955 | |||
956 | if delete and rename: |
|
956 | if delete and rename: | |
957 | raise error.Abort(_("--delete and --rename are incompatible")) |
|
957 | raise error.Abort(_("--delete and --rename are incompatible")) | |
958 | if delete and rev: |
|
958 | if delete and rev: | |
959 | raise error.Abort(_("--rev is incompatible with --delete")) |
|
959 | raise error.Abort(_("--rev is incompatible with --delete")) | |
960 | if rename and rev: |
|
960 | if rename and rev: | |
961 | raise error.Abort(_("--rev is incompatible with --rename")) |
|
961 | raise error.Abort(_("--rev is incompatible with --rename")) | |
962 | if not names and (delete or rev): |
|
962 | if not names and (delete or rev): | |
963 | raise error.Abort(_("bookmark name required")) |
|
963 | raise error.Abort(_("bookmark name required")) | |
964 |
|
964 | |||
965 | if delete or rename or names or inactive: |
|
965 | if delete or rename or names or inactive: | |
966 | with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: |
|
966 | with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: | |
967 | if delete: |
|
967 | if delete: | |
968 | names = pycompat.maplist(repo._bookmarks.expandname, names) |
|
968 | names = pycompat.maplist(repo._bookmarks.expandname, names) | |
969 | bookmarks.delete(repo, tr, names) |
|
969 | bookmarks.delete(repo, tr, names) | |
970 | elif rename: |
|
970 | elif rename: | |
971 | if not names: |
|
971 | if not names: | |
972 | raise error.Abort(_("new bookmark name required")) |
|
972 | raise error.Abort(_("new bookmark name required")) | |
973 | elif len(names) > 1: |
|
973 | elif len(names) > 1: | |
974 | raise error.Abort(_("only one new bookmark name allowed")) |
|
974 | raise error.Abort(_("only one new bookmark name allowed")) | |
975 | rename = repo._bookmarks.expandname(rename) |
|
975 | rename = repo._bookmarks.expandname(rename) | |
976 | bookmarks.rename(repo, tr, rename, names[0], force, inactive) |
|
976 | bookmarks.rename(repo, tr, rename, names[0], force, inactive) | |
977 | elif names: |
|
977 | elif names: | |
978 | bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) |
|
978 | bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) | |
979 | elif inactive: |
|
979 | elif inactive: | |
980 | if len(repo._bookmarks) == 0: |
|
980 | if len(repo._bookmarks) == 0: | |
981 | ui.status(_("no bookmarks set\n")) |
|
981 | ui.status(_("no bookmarks set\n")) | |
982 | elif not repo._activebookmark: |
|
982 | elif not repo._activebookmark: | |
983 | ui.status(_("no active bookmark\n")) |
|
983 | ui.status(_("no active bookmark\n")) | |
984 | else: |
|
984 | else: | |
985 | bookmarks.deactivate(repo) |
|
985 | bookmarks.deactivate(repo) | |
986 | else: # show bookmarks |
|
986 | else: # show bookmarks | |
987 | bookmarks.printbookmarks(ui, repo, **opts) |
|
987 | bookmarks.printbookmarks(ui, repo, **opts) | |
988 |
|
988 | |||
989 | @command('branch', |
|
989 | @command('branch', | |
990 | [('f', 'force', None, |
|
990 | [('f', 'force', None, | |
991 | _('set branch name even if it shadows an existing branch')), |
|
991 | _('set branch name even if it shadows an existing branch')), | |
992 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
992 | ('C', 'clean', None, _('reset branch name to parent branch name'))], | |
993 | _('[-fC] [NAME]')) |
|
993 | _('[-fC] [NAME]')) | |
994 | def branch(ui, repo, label=None, **opts): |
|
994 | def branch(ui, repo, label=None, **opts): | |
995 | """set or show the current branch name |
|
995 | """set or show the current branch name | |
996 |
|
996 | |||
997 | .. note:: |
|
997 | .. note:: | |
998 |
|
998 | |||
999 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
999 | Branch names are permanent and global. Use :hg:`bookmark` to create a | |
1000 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
1000 | light-weight bookmark instead. See :hg:`help glossary` for more | |
1001 | information about named branches and bookmarks. |
|
1001 | information about named branches and bookmarks. | |
1002 |
|
1002 | |||
1003 | With no argument, show the current branch name. With one argument, |
|
1003 | With no argument, show the current branch name. With one argument, | |
1004 | set the working directory branch name (the branch will not exist |
|
1004 | set the working directory branch name (the branch will not exist | |
1005 | in the repository until the next commit). Standard practice |
|
1005 | in the repository until the next commit). Standard practice | |
1006 | recommends that primary development take place on the 'default' |
|
1006 | recommends that primary development take place on the 'default' | |
1007 | branch. |
|
1007 | branch. | |
1008 |
|
1008 | |||
1009 | Unless -f/--force is specified, branch will not let you set a |
|
1009 | Unless -f/--force is specified, branch will not let you set a | |
1010 | branch name that already exists. |
|
1010 | branch name that already exists. | |
1011 |
|
1011 | |||
1012 | Use -C/--clean to reset the working directory branch to that of |
|
1012 | Use -C/--clean to reset the working directory branch to that of | |
1013 | the parent of the working directory, negating a previous branch |
|
1013 | the parent of the working directory, negating a previous branch | |
1014 | change. |
|
1014 | change. | |
1015 |
|
1015 | |||
1016 | Use the command :hg:`update` to switch to an existing branch. Use |
|
1016 | Use the command :hg:`update` to switch to an existing branch. Use | |
1017 | :hg:`commit --close-branch` to mark this branch head as closed. |
|
1017 | :hg:`commit --close-branch` to mark this branch head as closed. | |
1018 | When all heads of a branch are closed, the branch will be |
|
1018 | When all heads of a branch are closed, the branch will be | |
1019 | considered closed. |
|
1019 | considered closed. | |
1020 |
|
1020 | |||
1021 | Returns 0 on success. |
|
1021 | Returns 0 on success. | |
1022 | """ |
|
1022 | """ | |
1023 | opts = pycompat.byteskwargs(opts) |
|
1023 | opts = pycompat.byteskwargs(opts) | |
1024 | if label: |
|
1024 | if label: | |
1025 | label = label.strip() |
|
1025 | label = label.strip() | |
1026 |
|
1026 | |||
1027 | if not opts.get('clean') and not label: |
|
1027 | if not opts.get('clean') and not label: | |
1028 | ui.write("%s\n" % repo.dirstate.branch()) |
|
1028 | ui.write("%s\n" % repo.dirstate.branch()) | |
1029 | return |
|
1029 | return | |
1030 |
|
1030 | |||
1031 | with repo.wlock(): |
|
1031 | with repo.wlock(): | |
1032 | if opts.get('clean'): |
|
1032 | if opts.get('clean'): | |
1033 | label = repo[None].p1().branch() |
|
1033 | label = repo[None].p1().branch() | |
1034 | repo.dirstate.setbranch(label) |
|
1034 | repo.dirstate.setbranch(label) | |
1035 | ui.status(_('reset working directory to branch %s\n') % label) |
|
1035 | ui.status(_('reset working directory to branch %s\n') % label) | |
1036 | elif label: |
|
1036 | elif label: | |
1037 | if not opts.get('force') and label in repo.branchmap(): |
|
1037 | if not opts.get('force') and label in repo.branchmap(): | |
1038 | if label not in [p.branch() for p in repo[None].parents()]: |
|
1038 | if label not in [p.branch() for p in repo[None].parents()]: | |
1039 | raise error.Abort(_('a branch of the same name already' |
|
1039 | raise error.Abort(_('a branch of the same name already' | |
1040 | ' exists'), |
|
1040 | ' exists'), | |
1041 | # i18n: "it" refers to an existing branch |
|
1041 | # i18n: "it" refers to an existing branch | |
1042 | hint=_("use 'hg update' to switch to it")) |
|
1042 | hint=_("use 'hg update' to switch to it")) | |
1043 | scmutil.checknewlabel(repo, label, 'branch') |
|
1043 | scmutil.checknewlabel(repo, label, 'branch') | |
1044 | repo.dirstate.setbranch(label) |
|
1044 | repo.dirstate.setbranch(label) | |
1045 | ui.status(_('marked working directory as branch %s\n') % label) |
|
1045 | ui.status(_('marked working directory as branch %s\n') % label) | |
1046 |
|
1046 | |||
1047 | # find any open named branches aside from default |
|
1047 | # find any open named branches aside from default | |
1048 | others = [n for n, h, t, c in repo.branchmap().iterbranches() |
|
1048 | others = [n for n, h, t, c in repo.branchmap().iterbranches() | |
1049 | if n != "default" and not c] |
|
1049 | if n != "default" and not c] | |
1050 | if not others: |
|
1050 | if not others: | |
1051 | ui.status(_('(branches are permanent and global, ' |
|
1051 | ui.status(_('(branches are permanent and global, ' | |
1052 | 'did you want a bookmark?)\n')) |
|
1052 | 'did you want a bookmark?)\n')) | |
1053 |
|
1053 | |||
1054 | @command('branches', |
|
1054 | @command('branches', | |
1055 | [('a', 'active', False, |
|
1055 | [('a', 'active', False, | |
1056 | _('show only branches that have unmerged heads (DEPRECATED)')), |
|
1056 | _('show only branches that have unmerged heads (DEPRECATED)')), | |
1057 | ('c', 'closed', False, _('show normal and closed branches')), |
|
1057 | ('c', 'closed', False, _('show normal and closed branches')), | |
1058 | ] + formatteropts, |
|
1058 | ] + formatteropts, | |
1059 | _('[-c]')) |
|
1059 | _('[-c]')) | |
1060 | def branches(ui, repo, active=False, closed=False, **opts): |
|
1060 | def branches(ui, repo, active=False, closed=False, **opts): | |
1061 | """list repository named branches |
|
1061 | """list repository named branches | |
1062 |
|
1062 | |||
1063 | List the repository's named branches, indicating which ones are |
|
1063 | List the repository's named branches, indicating which ones are | |
1064 | inactive. If -c/--closed is specified, also list branches which have |
|
1064 | inactive. If -c/--closed is specified, also list branches which have | |
1065 | been marked closed (see :hg:`commit --close-branch`). |
|
1065 | been marked closed (see :hg:`commit --close-branch`). | |
1066 |
|
1066 | |||
1067 | Use the command :hg:`update` to switch to an existing branch. |
|
1067 | Use the command :hg:`update` to switch to an existing branch. | |
1068 |
|
1068 | |||
1069 | Returns 0. |
|
1069 | Returns 0. | |
1070 | """ |
|
1070 | """ | |
1071 |
|
1071 | |||
1072 | opts = pycompat.byteskwargs(opts) |
|
1072 | opts = pycompat.byteskwargs(opts) | |
1073 | ui.pager('branches') |
|
1073 | ui.pager('branches') | |
1074 | fm = ui.formatter('branches', opts) |
|
1074 | fm = ui.formatter('branches', opts) | |
1075 | hexfunc = fm.hexfunc |
|
1075 | hexfunc = fm.hexfunc | |
1076 |
|
1076 | |||
1077 | allheads = set(repo.heads()) |
|
1077 | allheads = set(repo.heads()) | |
1078 | branches = [] |
|
1078 | branches = [] | |
1079 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): |
|
1079 | for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): | |
1080 | isactive = False |
|
1080 | isactive = False | |
1081 | if not isclosed: |
|
1081 | if not isclosed: | |
1082 | openheads = set(repo.branchmap().iteropen(heads)) |
|
1082 | openheads = set(repo.branchmap().iteropen(heads)) | |
1083 | isactive = bool(openheads & allheads) |
|
1083 | isactive = bool(openheads & allheads) | |
1084 | branches.append((tag, repo[tip], isactive, not isclosed)) |
|
1084 | branches.append((tag, repo[tip], isactive, not isclosed)) | |
1085 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), |
|
1085 | branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), | |
1086 | reverse=True) |
|
1086 | reverse=True) | |
1087 |
|
1087 | |||
1088 | for tag, ctx, isactive, isopen in branches: |
|
1088 | for tag, ctx, isactive, isopen in branches: | |
1089 | if active and not isactive: |
|
1089 | if active and not isactive: | |
1090 | continue |
|
1090 | continue | |
1091 | if isactive: |
|
1091 | if isactive: | |
1092 | label = 'branches.active' |
|
1092 | label = 'branches.active' | |
1093 | notice = '' |
|
1093 | notice = '' | |
1094 | elif not isopen: |
|
1094 | elif not isopen: | |
1095 | if not closed: |
|
1095 | if not closed: | |
1096 | continue |
|
1096 | continue | |
1097 | label = 'branches.closed' |
|
1097 | label = 'branches.closed' | |
1098 | notice = _(' (closed)') |
|
1098 | notice = _(' (closed)') | |
1099 | else: |
|
1099 | else: | |
1100 | label = 'branches.inactive' |
|
1100 | label = 'branches.inactive' | |
1101 | notice = _(' (inactive)') |
|
1101 | notice = _(' (inactive)') | |
1102 | current = (tag == repo.dirstate.branch()) |
|
1102 | current = (tag == repo.dirstate.branch()) | |
1103 | if current: |
|
1103 | if current: | |
1104 | label = 'branches.current' |
|
1104 | label = 'branches.current' | |
1105 |
|
1105 | |||
1106 | fm.startitem() |
|
1106 | fm.startitem() | |
1107 | fm.write('branch', '%s', tag, label=label) |
|
1107 | fm.write('branch', '%s', tag, label=label) | |
1108 | rev = ctx.rev() |
|
1108 | rev = ctx.rev() | |
1109 | padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) |
|
1109 | padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) | |
1110 | fmt = ' ' * padsize + ' %d:%s' |
|
1110 | fmt = ' ' * padsize + ' %d:%s' | |
1111 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), |
|
1111 | fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()), | |
1112 | label='log.changeset changeset.%s' % ctx.phasestr()) |
|
1112 | label='log.changeset changeset.%s' % ctx.phasestr()) | |
1113 | fm.context(ctx=ctx) |
|
1113 | fm.context(ctx=ctx) | |
1114 | fm.data(active=isactive, closed=not isopen, current=current) |
|
1114 | fm.data(active=isactive, closed=not isopen, current=current) | |
1115 | if not ui.quiet: |
|
1115 | if not ui.quiet: | |
1116 | fm.plain(notice) |
|
1116 | fm.plain(notice) | |
1117 | fm.plain('\n') |
|
1117 | fm.plain('\n') | |
1118 | fm.end() |
|
1118 | fm.end() | |
1119 |
|
1119 | |||
1120 | @command('bundle', |
|
1120 | @command('bundle', | |
1121 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
1121 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
1122 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
1122 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), | |
1123 | _('REV')), |
|
1123 | _('REV')), | |
1124 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
1124 | ('b', 'branch', [], _('a specific branch you would like to bundle'), | |
1125 | _('BRANCH')), |
|
1125 | _('BRANCH')), | |
1126 | ('', 'base', [], |
|
1126 | ('', 'base', [], | |
1127 | _('a base changeset assumed to be available at the destination'), |
|
1127 | _('a base changeset assumed to be available at the destination'), | |
1128 | _('REV')), |
|
1128 | _('REV')), | |
1129 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
1129 | ('a', 'all', None, _('bundle all changesets in the repository')), | |
1130 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
1130 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), | |
1131 | ] + remoteopts, |
|
1131 | ] + remoteopts, | |
1132 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
1132 | _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]')) | |
1133 | def bundle(ui, repo, fname, dest=None, **opts): |
|
1133 | def bundle(ui, repo, fname, dest=None, **opts): | |
1134 | """create a bundle file |
|
1134 | """create a bundle file | |
1135 |
|
1135 | |||
1136 | Generate a bundle file containing data to be added to a repository. |
|
1136 | Generate a bundle file containing data to be added to a repository. | |
1137 |
|
1137 | |||
1138 | To create a bundle containing all changesets, use -a/--all |
|
1138 | To create a bundle containing all changesets, use -a/--all | |
1139 | (or --base null). Otherwise, hg assumes the destination will have |
|
1139 | (or --base null). Otherwise, hg assumes the destination will have | |
1140 | all the nodes you specify with --base parameters. Otherwise, hg |
|
1140 | all the nodes you specify with --base parameters. Otherwise, hg | |
1141 | will assume the repository has all the nodes in destination, or |
|
1141 | will assume the repository has all the nodes in destination, or | |
1142 | default-push/default if no destination is specified. |
|
1142 | default-push/default if no destination is specified. | |
1143 |
|
1143 | |||
1144 | You can change bundle format with the -t/--type option. See |
|
1144 | You can change bundle format with the -t/--type option. See | |
1145 | :hg:`help bundlespec` for documentation on this format. By default, |
|
1145 | :hg:`help bundlespec` for documentation on this format. By default, | |
1146 | the most appropriate format is used and compression defaults to |
|
1146 | the most appropriate format is used and compression defaults to | |
1147 | bzip2. |
|
1147 | bzip2. | |
1148 |
|
1148 | |||
1149 | The bundle file can then be transferred using conventional means |
|
1149 | The bundle file can then be transferred using conventional means | |
1150 | and applied to another repository with the unbundle or pull |
|
1150 | and applied to another repository with the unbundle or pull | |
1151 | command. This is useful when direct push and pull are not |
|
1151 | command. This is useful when direct push and pull are not | |
1152 | available or when exporting an entire repository is undesirable. |
|
1152 | available or when exporting an entire repository is undesirable. | |
1153 |
|
1153 | |||
1154 | Applying bundles preserves all changeset contents including |
|
1154 | Applying bundles preserves all changeset contents including | |
1155 | permissions, copy/rename information, and revision history. |
|
1155 | permissions, copy/rename information, and revision history. | |
1156 |
|
1156 | |||
1157 | Returns 0 on success, 1 if no changes found. |
|
1157 | Returns 0 on success, 1 if no changes found. | |
1158 | """ |
|
1158 | """ | |
1159 | opts = pycompat.byteskwargs(opts) |
|
1159 | opts = pycompat.byteskwargs(opts) | |
1160 | revs = None |
|
1160 | revs = None | |
1161 | if 'rev' in opts: |
|
1161 | if 'rev' in opts: | |
1162 | revstrings = opts['rev'] |
|
1162 | revstrings = opts['rev'] | |
1163 | revs = scmutil.revrange(repo, revstrings) |
|
1163 | revs = scmutil.revrange(repo, revstrings) | |
1164 | if revstrings and not revs: |
|
1164 | if revstrings and not revs: | |
1165 | raise error.Abort(_('no commits to bundle')) |
|
1165 | raise error.Abort(_('no commits to bundle')) | |
1166 |
|
1166 | |||
1167 | bundletype = opts.get('type', 'bzip2').lower() |
|
1167 | bundletype = opts.get('type', 'bzip2').lower() | |
1168 | try: |
|
1168 | try: | |
1169 | bcompression, cgversion, params = exchange.parsebundlespec( |
|
1169 | bcompression, cgversion, params = exchange.parsebundlespec( | |
1170 | repo, bundletype, strict=False) |
|
1170 | repo, bundletype, strict=False) | |
1171 | except error.UnsupportedBundleSpecification as e: |
|
1171 | except error.UnsupportedBundleSpecification as e: | |
1172 | raise error.Abort(str(e), |
|
1172 | raise error.Abort(str(e), | |
1173 | hint=_("see 'hg help bundlespec' for supported " |
|
1173 | hint=_("see 'hg help bundlespec' for supported " | |
1174 | "values for --type")) |
|
1174 | "values for --type")) | |
1175 |
|
1175 | |||
1176 | # Packed bundles are a pseudo bundle format for now. |
|
1176 | # Packed bundles are a pseudo bundle format for now. | |
1177 | if cgversion == 's1': |
|
1177 | if cgversion == 's1': | |
1178 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), |
|
1178 | raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'), | |
1179 | hint=_("use 'hg debugcreatestreamclonebundle'")) |
|
1179 | hint=_("use 'hg debugcreatestreamclonebundle'")) | |
1180 |
|
1180 | |||
1181 | if opts.get('all'): |
|
1181 | if opts.get('all'): | |
1182 | if dest: |
|
1182 | if dest: | |
1183 | raise error.Abort(_("--all is incompatible with specifying " |
|
1183 | raise error.Abort(_("--all is incompatible with specifying " | |
1184 | "a destination")) |
|
1184 | "a destination")) | |
1185 | if opts.get('base'): |
|
1185 | if opts.get('base'): | |
1186 | ui.warn(_("ignoring --base because --all was specified\n")) |
|
1186 | ui.warn(_("ignoring --base because --all was specified\n")) | |
1187 | base = ['null'] |
|
1187 | base = ['null'] | |
1188 | else: |
|
1188 | else: | |
1189 | base = scmutil.revrange(repo, opts.get('base')) |
|
1189 | base = scmutil.revrange(repo, opts.get('base')) | |
1190 | if cgversion not in changegroup.supportedoutgoingversions(repo): |
|
1190 | if cgversion not in changegroup.supportedoutgoingversions(repo): | |
1191 | raise error.Abort(_("repository does not support bundle version %s") % |
|
1191 | raise error.Abort(_("repository does not support bundle version %s") % | |
1192 | cgversion) |
|
1192 | cgversion) | |
1193 |
|
1193 | |||
1194 | if base: |
|
1194 | if base: | |
1195 | if dest: |
|
1195 | if dest: | |
1196 | raise error.Abort(_("--base is incompatible with specifying " |
|
1196 | raise error.Abort(_("--base is incompatible with specifying " | |
1197 | "a destination")) |
|
1197 | "a destination")) | |
1198 | common = [repo.lookup(rev) for rev in base] |
|
1198 | common = [repo.lookup(rev) for rev in base] | |
1199 | heads = revs and map(repo.lookup, revs) or None |
|
1199 | heads = revs and map(repo.lookup, revs) or None | |
1200 | outgoing = discovery.outgoing(repo, common, heads) |
|
1200 | outgoing = discovery.outgoing(repo, common, heads) | |
1201 | else: |
|
1201 | else: | |
1202 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1202 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
1203 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1203 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
1204 | other = hg.peer(repo, opts, dest) |
|
1204 | other = hg.peer(repo, opts, dest) | |
1205 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) |
|
1205 | revs, checkout = hg.addbranchrevs(repo, repo, branches, revs) | |
1206 | heads = revs and map(repo.lookup, revs) or revs |
|
1206 | heads = revs and map(repo.lookup, revs) or revs | |
1207 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1207 | outgoing = discovery.findcommonoutgoing(repo, other, | |
1208 | onlyheads=heads, |
|
1208 | onlyheads=heads, | |
1209 | force=opts.get('force'), |
|
1209 | force=opts.get('force'), | |
1210 | portable=True) |
|
1210 | portable=True) | |
1211 |
|
1211 | |||
1212 | if not outgoing.missing: |
|
1212 | if not outgoing.missing: | |
1213 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) |
|
1213 | scmutil.nochangesfound(ui, repo, not base and outgoing.excluded) | |
1214 | return 1 |
|
1214 | return 1 | |
1215 |
|
1215 | |||
1216 | if cgversion == '01': #bundle1 |
|
1216 | if cgversion == '01': #bundle1 | |
1217 | if bcompression is None: |
|
1217 | if bcompression is None: | |
1218 | bcompression = 'UN' |
|
1218 | bcompression = 'UN' | |
1219 | bversion = 'HG10' + bcompression |
|
1219 | bversion = 'HG10' + bcompression | |
1220 | bcompression = None |
|
1220 | bcompression = None | |
1221 | elif cgversion in ('02', '03'): |
|
1221 | elif cgversion in ('02', '03'): | |
1222 | bversion = 'HG20' |
|
1222 | bversion = 'HG20' | |
1223 | else: |
|
1223 | else: | |
1224 | raise error.ProgrammingError( |
|
1224 | raise error.ProgrammingError( | |
1225 | 'bundle: unexpected changegroup version %s' % cgversion) |
|
1225 | 'bundle: unexpected changegroup version %s' % cgversion) | |
1226 |
|
1226 | |||
1227 | # TODO compression options should be derived from bundlespec parsing. |
|
1227 | # TODO compression options should be derived from bundlespec parsing. | |
1228 | # This is a temporary hack to allow adjusting bundle compression |
|
1228 | # This is a temporary hack to allow adjusting bundle compression | |
1229 | # level without a) formalizing the bundlespec changes to declare it |
|
1229 | # level without a) formalizing the bundlespec changes to declare it | |
1230 | # b) introducing a command flag. |
|
1230 | # b) introducing a command flag. | |
1231 | compopts = {} |
|
1231 | compopts = {} | |
1232 | complevel = ui.configint('experimental', 'bundlecomplevel') |
|
1232 | complevel = ui.configint('experimental', 'bundlecomplevel') | |
1233 | if complevel is not None: |
|
1233 | if complevel is not None: | |
1234 | compopts['level'] = complevel |
|
1234 | compopts['level'] = complevel | |
1235 |
|
1235 | |||
1236 |
|
1236 | |||
1237 | contentopts = {'cg.version': cgversion} |
|
1237 | contentopts = {'cg.version': cgversion} | |
1238 | if repo.ui.configbool('experimental', 'stabilization.bundle-obsmarker'): |
|
1238 | if repo.ui.configbool('experimental', 'stabilization.bundle-obsmarker'): | |
1239 | contentopts['obsolescence'] = True |
|
1239 | contentopts['obsolescence'] = True | |
1240 | if repo.ui.configbool('experimental', 'bundle-phases'): |
|
1240 | if repo.ui.configbool('experimental', 'bundle-phases'): | |
1241 | contentopts['phases'] = True |
|
1241 | contentopts['phases'] = True | |
1242 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, |
|
1242 | bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing, | |
1243 | contentopts, compression=bcompression, |
|
1243 | contentopts, compression=bcompression, | |
1244 | compopts=compopts) |
|
1244 | compopts=compopts) | |
1245 |
|
1245 | |||
1246 | @command('cat', |
|
1246 | @command('cat', | |
1247 | [('o', 'output', '', |
|
1247 | [('o', 'output', '', | |
1248 | _('print output to file with formatted name'), _('FORMAT')), |
|
1248 | _('print output to file with formatted name'), _('FORMAT')), | |
1249 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1249 | ('r', 'rev', '', _('print the given revision'), _('REV')), | |
1250 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1250 | ('', 'decode', None, _('apply any matching decode filter')), | |
1251 | ] + walkopts + formatteropts, |
|
1251 | ] + walkopts + formatteropts, | |
1252 | _('[OPTION]... FILE...'), |
|
1252 | _('[OPTION]... FILE...'), | |
1253 | inferrepo=True) |
|
1253 | inferrepo=True) | |
1254 | def cat(ui, repo, file1, *pats, **opts): |
|
1254 | def cat(ui, repo, file1, *pats, **opts): | |
1255 | """output the current or given revision of files |
|
1255 | """output the current or given revision of files | |
1256 |
|
1256 | |||
1257 | Print the specified files as they were at the given revision. If |
|
1257 | Print the specified files as they were at the given revision. If | |
1258 | no revision is given, the parent of the working directory is used. |
|
1258 | no revision is given, the parent of the working directory is used. | |
1259 |
|
1259 | |||
1260 | Output may be to a file, in which case the name of the file is |
|
1260 | Output may be to a file, in which case the name of the file is | |
1261 | given using a format string. The formatting rules as follows: |
|
1261 | given using a format string. The formatting rules as follows: | |
1262 |
|
1262 | |||
1263 | :``%%``: literal "%" character |
|
1263 | :``%%``: literal "%" character | |
1264 | :``%s``: basename of file being printed |
|
1264 | :``%s``: basename of file being printed | |
1265 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1265 | :``%d``: dirname of file being printed, or '.' if in repository root | |
1266 | :``%p``: root-relative path name of file being printed |
|
1266 | :``%p``: root-relative path name of file being printed | |
1267 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1267 | :``%H``: changeset hash (40 hexadecimal digits) | |
1268 | :``%R``: changeset revision number |
|
1268 | :``%R``: changeset revision number | |
1269 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1269 | :``%h``: short-form changeset hash (12 hexadecimal digits) | |
1270 | :``%r``: zero-padded changeset revision number |
|
1270 | :``%r``: zero-padded changeset revision number | |
1271 | :``%b``: basename of the exporting repository |
|
1271 | :``%b``: basename of the exporting repository | |
1272 |
|
1272 | |||
1273 | Returns 0 on success. |
|
1273 | Returns 0 on success. | |
1274 | """ |
|
1274 | """ | |
1275 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1275 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
1276 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1276 | m = scmutil.match(ctx, (file1,) + pats, opts) | |
1277 | fntemplate = opts.pop('output', '') |
|
1277 | fntemplate = opts.pop('output', '') | |
1278 | if cmdutil.isstdiofilename(fntemplate): |
|
1278 | if cmdutil.isstdiofilename(fntemplate): | |
1279 | fntemplate = '' |
|
1279 | fntemplate = '' | |
1280 |
|
1280 | |||
1281 | if fntemplate: |
|
1281 | if fntemplate: | |
1282 | fm = formatter.nullformatter(ui, 'cat') |
|
1282 | fm = formatter.nullformatter(ui, 'cat') | |
1283 | else: |
|
1283 | else: | |
1284 | ui.pager('cat') |
|
1284 | ui.pager('cat') | |
1285 | fm = ui.formatter('cat', opts) |
|
1285 | fm = ui.formatter('cat', opts) | |
1286 | with fm: |
|
1286 | with fm: | |
1287 | return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', **opts) |
|
1287 | return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', **opts) | |
1288 |
|
1288 | |||
1289 | @command('^clone', |
|
1289 | @command('^clone', | |
1290 | [('U', 'noupdate', None, _('the clone will include an empty working ' |
|
1290 | [('U', 'noupdate', None, _('the clone will include an empty working ' | |
1291 | 'directory (only a repository)')), |
|
1291 | 'directory (only a repository)')), | |
1292 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), |
|
1292 | ('u', 'updaterev', '', _('revision, tag, or branch to check out'), | |
1293 | _('REV')), |
|
1293 | _('REV')), | |
1294 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1294 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), | |
1295 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1295 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), | |
1296 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1296 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
1297 | ('', 'uncompressed', None, |
|
1297 | ('', 'uncompressed', None, | |
1298 | _('an alias to --stream (DEPRECATED)')), |
|
1298 | _('an alias to --stream (DEPRECATED)')), | |
1299 | ('', 'stream', None, |
|
1299 | ('', 'stream', None, | |
1300 | _('clone with minimal data processing')), |
|
1300 | _('clone with minimal data processing')), | |
1301 | ] + remoteopts, |
|
1301 | ] + remoteopts, | |
1302 | _('[OPTION]... SOURCE [DEST]'), |
|
1302 | _('[OPTION]... SOURCE [DEST]'), | |
1303 | norepo=True) |
|
1303 | norepo=True) | |
1304 | def clone(ui, source, dest=None, **opts): |
|
1304 | def clone(ui, source, dest=None, **opts): | |
1305 | """make a copy of an existing repository |
|
1305 | """make a copy of an existing repository | |
1306 |
|
1306 | |||
1307 | Create a copy of an existing repository in a new directory. |
|
1307 | Create a copy of an existing repository in a new directory. | |
1308 |
|
1308 | |||
1309 | If no destination directory name is specified, it defaults to the |
|
1309 | If no destination directory name is specified, it defaults to the | |
1310 | basename of the source. |
|
1310 | basename of the source. | |
1311 |
|
1311 | |||
1312 | The location of the source is added to the new repository's |
|
1312 | The location of the source is added to the new repository's | |
1313 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1313 | ``.hg/hgrc`` file, as the default to be used for future pulls. | |
1314 |
|
1314 | |||
1315 | Only local paths and ``ssh://`` URLs are supported as |
|
1315 | Only local paths and ``ssh://`` URLs are supported as | |
1316 | destinations. For ``ssh://`` destinations, no working directory or |
|
1316 | destinations. For ``ssh://`` destinations, no working directory or | |
1317 | ``.hg/hgrc`` will be created on the remote side. |
|
1317 | ``.hg/hgrc`` will be created on the remote side. | |
1318 |
|
1318 | |||
1319 | If the source repository has a bookmark called '@' set, that |
|
1319 | If the source repository has a bookmark called '@' set, that | |
1320 | revision will be checked out in the new repository by default. |
|
1320 | revision will be checked out in the new repository by default. | |
1321 |
|
1321 | |||
1322 | To check out a particular version, use -u/--update, or |
|
1322 | To check out a particular version, use -u/--update, or | |
1323 | -U/--noupdate to create a clone with no working directory. |
|
1323 | -U/--noupdate to create a clone with no working directory. | |
1324 |
|
1324 | |||
1325 | To pull only a subset of changesets, specify one or more revisions |
|
1325 | To pull only a subset of changesets, specify one or more revisions | |
1326 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1326 | identifiers with -r/--rev or branches with -b/--branch. The | |
1327 | resulting clone will contain only the specified changesets and |
|
1327 | resulting clone will contain only the specified changesets and | |
1328 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1328 | their ancestors. These options (or 'clone src#rev dest') imply | |
1329 | --pull, even for local source repositories. |
|
1329 | --pull, even for local source repositories. | |
1330 |
|
1330 | |||
1331 | In normal clone mode, the remote normalizes repository data into a common |
|
1331 | In normal clone mode, the remote normalizes repository data into a common | |
1332 | exchange format and the receiving end translates this data into its local |
|
1332 | exchange format and the receiving end translates this data into its local | |
1333 | storage format. --stream activates a different clone mode that essentially |
|
1333 | storage format. --stream activates a different clone mode that essentially | |
1334 | copies repository files from the remote with minimal data processing. This |
|
1334 | copies repository files from the remote with minimal data processing. This | |
1335 | significantly reduces the CPU cost of a clone both remotely and locally. |
|
1335 | significantly reduces the CPU cost of a clone both remotely and locally. | |
1336 | However, it often increases the transferred data size by 30-40%. This can |
|
1336 | However, it often increases the transferred data size by 30-40%. This can | |
1337 | result in substantially faster clones where I/O throughput is plentiful, |
|
1337 | result in substantially faster clones where I/O throughput is plentiful, | |
1338 | especially for larger repositories. A side-effect of --stream clones is |
|
1338 | especially for larger repositories. A side-effect of --stream clones is | |
1339 | that storage settings and requirements on the remote are applied locally: |
|
1339 | that storage settings and requirements on the remote are applied locally: | |
1340 | a modern client may inherit legacy or inefficient storage used by the |
|
1340 | a modern client may inherit legacy or inefficient storage used by the | |
1341 | remote or a legacy Mercurial client may not be able to clone from a |
|
1341 | remote or a legacy Mercurial client may not be able to clone from a | |
1342 | modern Mercurial remote. |
|
1342 | modern Mercurial remote. | |
1343 |
|
1343 | |||
1344 | .. note:: |
|
1344 | .. note:: | |
1345 |
|
1345 | |||
1346 | Specifying a tag will include the tagged changeset but not the |
|
1346 | Specifying a tag will include the tagged changeset but not the | |
1347 | changeset containing the tag. |
|
1347 | changeset containing the tag. | |
1348 |
|
1348 | |||
1349 | .. container:: verbose |
|
1349 | .. container:: verbose | |
1350 |
|
1350 | |||
1351 | For efficiency, hardlinks are used for cloning whenever the |
|
1351 | For efficiency, hardlinks are used for cloning whenever the | |
1352 | source and destination are on the same filesystem (note this |
|
1352 | source and destination are on the same filesystem (note this | |
1353 | applies only to the repository data, not to the working |
|
1353 | applies only to the repository data, not to the working | |
1354 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1354 | directory). Some filesystems, such as AFS, implement hardlinking | |
1355 | incorrectly, but do not report errors. In these cases, use the |
|
1355 | incorrectly, but do not report errors. In these cases, use the | |
1356 | --pull option to avoid hardlinking. |
|
1356 | --pull option to avoid hardlinking. | |
1357 |
|
1357 | |||
1358 | Mercurial will update the working directory to the first applicable |
|
1358 | Mercurial will update the working directory to the first applicable | |
1359 | revision from this list: |
|
1359 | revision from this list: | |
1360 |
|
1360 | |||
1361 | a) null if -U or the source repository has no changesets |
|
1361 | a) null if -U or the source repository has no changesets | |
1362 | b) if -u . and the source repository is local, the first parent of |
|
1362 | b) if -u . and the source repository is local, the first parent of | |
1363 | the source repository's working directory |
|
1363 | the source repository's working directory | |
1364 | c) the changeset specified with -u (if a branch name, this means the |
|
1364 | c) the changeset specified with -u (if a branch name, this means the | |
1365 | latest head of that branch) |
|
1365 | latest head of that branch) | |
1366 | d) the changeset specified with -r |
|
1366 | d) the changeset specified with -r | |
1367 | e) the tipmost head specified with -b |
|
1367 | e) the tipmost head specified with -b | |
1368 | f) the tipmost head specified with the url#branch source syntax |
|
1368 | f) the tipmost head specified with the url#branch source syntax | |
1369 | g) the revision marked with the '@' bookmark, if present |
|
1369 | g) the revision marked with the '@' bookmark, if present | |
1370 | h) the tipmost head of the default branch |
|
1370 | h) the tipmost head of the default branch | |
1371 | i) tip |
|
1371 | i) tip | |
1372 |
|
1372 | |||
1373 | When cloning from servers that support it, Mercurial may fetch |
|
1373 | When cloning from servers that support it, Mercurial may fetch | |
1374 | pre-generated data from a server-advertised URL. When this is done, |
|
1374 | pre-generated data from a server-advertised URL. When this is done, | |
1375 | hooks operating on incoming changesets and changegroups may fire twice, |
|
1375 | hooks operating on incoming changesets and changegroups may fire twice, | |
1376 | once for the bundle fetched from the URL and another for any additional |
|
1376 | once for the bundle fetched from the URL and another for any additional | |
1377 | data not fetched from this URL. In addition, if an error occurs, the |
|
1377 | data not fetched from this URL. In addition, if an error occurs, the | |
1378 | repository may be rolled back to a partial clone. This behavior may |
|
1378 | repository may be rolled back to a partial clone. This behavior may | |
1379 | change in future releases. See :hg:`help -e clonebundles` for more. |
|
1379 | change in future releases. See :hg:`help -e clonebundles` for more. | |
1380 |
|
1380 | |||
1381 | Examples: |
|
1381 | Examples: | |
1382 |
|
1382 | |||
1383 | - clone a remote repository to a new directory named hg/:: |
|
1383 | - clone a remote repository to a new directory named hg/:: | |
1384 |
|
1384 | |||
1385 | hg clone https://www.mercurial-scm.org/repo/hg/ |
|
1385 | hg clone https://www.mercurial-scm.org/repo/hg/ | |
1386 |
|
1386 | |||
1387 | - create a lightweight local clone:: |
|
1387 | - create a lightweight local clone:: | |
1388 |
|
1388 | |||
1389 | hg clone project/ project-feature/ |
|
1389 | hg clone project/ project-feature/ | |
1390 |
|
1390 | |||
1391 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1391 | - clone from an absolute path on an ssh server (note double-slash):: | |
1392 |
|
1392 | |||
1393 | hg clone ssh://user@server//home/projects/alpha/ |
|
1393 | hg clone ssh://user@server//home/projects/alpha/ | |
1394 |
|
1394 | |||
1395 | - do a streaming clone while checking out a specified version:: |
|
1395 | - do a streaming clone while checking out a specified version:: | |
1396 |
|
1396 | |||
1397 | hg clone --stream http://server/repo -u 1.5 |
|
1397 | hg clone --stream http://server/repo -u 1.5 | |
1398 |
|
1398 | |||
1399 | - create a repository without changesets after a particular revision:: |
|
1399 | - create a repository without changesets after a particular revision:: | |
1400 |
|
1400 | |||
1401 | hg clone -r 04e544 experimental/ good/ |
|
1401 | hg clone -r 04e544 experimental/ good/ | |
1402 |
|
1402 | |||
1403 | - clone (and track) a particular named branch:: |
|
1403 | - clone (and track) a particular named branch:: | |
1404 |
|
1404 | |||
1405 | hg clone https://www.mercurial-scm.org/repo/hg/#stable |
|
1405 | hg clone https://www.mercurial-scm.org/repo/hg/#stable | |
1406 |
|
1406 | |||
1407 | See :hg:`help urls` for details on specifying URLs. |
|
1407 | See :hg:`help urls` for details on specifying URLs. | |
1408 |
|
1408 | |||
1409 | Returns 0 on success. |
|
1409 | Returns 0 on success. | |
1410 | """ |
|
1410 | """ | |
1411 | opts = pycompat.byteskwargs(opts) |
|
1411 | opts = pycompat.byteskwargs(opts) | |
1412 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1412 | if opts.get('noupdate') and opts.get('updaterev'): | |
1413 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1413 | raise error.Abort(_("cannot specify both --noupdate and --updaterev")) | |
1414 |
|
1414 | |||
1415 | r = hg.clone(ui, opts, source, dest, |
|
1415 | r = hg.clone(ui, opts, source, dest, | |
1416 | pull=opts.get('pull'), |
|
1416 | pull=opts.get('pull'), | |
1417 | stream=opts.get('stream') or opts.get('uncompressed'), |
|
1417 | stream=opts.get('stream') or opts.get('uncompressed'), | |
1418 | rev=opts.get('rev'), |
|
1418 | rev=opts.get('rev'), | |
1419 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1419 | update=opts.get('updaterev') or not opts.get('noupdate'), | |
1420 | branch=opts.get('branch'), |
|
1420 | branch=opts.get('branch'), | |
1421 | shareopts=opts.get('shareopts')) |
|
1421 | shareopts=opts.get('shareopts')) | |
1422 |
|
1422 | |||
1423 | return r is None |
|
1423 | return r is None | |
1424 |
|
1424 | |||
1425 | @command('^commit|ci', |
|
1425 | @command('^commit|ci', | |
1426 | [('A', 'addremove', None, |
|
1426 | [('A', 'addremove', None, | |
1427 | _('mark new/missing files as added/removed before committing')), |
|
1427 | _('mark new/missing files as added/removed before committing')), | |
1428 | ('', 'close-branch', None, |
|
1428 | ('', 'close-branch', None, | |
1429 | _('mark a branch head as closed')), |
|
1429 | _('mark a branch head as closed')), | |
1430 | ('', 'amend', None, _('amend the parent of the working directory')), |
|
1430 | ('', 'amend', None, _('amend the parent of the working directory')), | |
1431 | ('s', 'secret', None, _('use the secret phase for committing')), |
|
1431 | ('s', 'secret', None, _('use the secret phase for committing')), | |
1432 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
1432 | ('e', 'edit', None, _('invoke editor on commit messages')), | |
1433 | ('i', 'interactive', None, _('use interactive mode')), |
|
1433 | ('i', 'interactive', None, _('use interactive mode')), | |
1434 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1434 | ] + walkopts + commitopts + commitopts2 + subrepoopts, | |
1435 | _('[OPTION]... [FILE]...'), |
|
1435 | _('[OPTION]... [FILE]...'), | |
1436 | inferrepo=True) |
|
1436 | inferrepo=True) | |
1437 | def commit(ui, repo, *pats, **opts): |
|
1437 | def commit(ui, repo, *pats, **opts): | |
1438 | """commit the specified files or all outstanding changes |
|
1438 | """commit the specified files or all outstanding changes | |
1439 |
|
1439 | |||
1440 | Commit changes to the given files into the repository. Unlike a |
|
1440 | Commit changes to the given files into the repository. Unlike a | |
1441 | centralized SCM, this operation is a local operation. See |
|
1441 | centralized SCM, this operation is a local operation. See | |
1442 | :hg:`push` for a way to actively distribute your changes. |
|
1442 | :hg:`push` for a way to actively distribute your changes. | |
1443 |
|
1443 | |||
1444 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1444 | If a list of files is omitted, all changes reported by :hg:`status` | |
1445 | will be committed. |
|
1445 | will be committed. | |
1446 |
|
1446 | |||
1447 | If you are committing the result of a merge, do not provide any |
|
1447 | If you are committing the result of a merge, do not provide any | |
1448 | filenames or -I/-X filters. |
|
1448 | filenames or -I/-X filters. | |
1449 |
|
1449 | |||
1450 | If no commit message is specified, Mercurial starts your |
|
1450 | If no commit message is specified, Mercurial starts your | |
1451 | configured editor where you can enter a message. In case your |
|
1451 | configured editor where you can enter a message. In case your | |
1452 | commit fails, you will find a backup of your message in |
|
1452 | commit fails, you will find a backup of your message in | |
1453 | ``.hg/last-message.txt``. |
|
1453 | ``.hg/last-message.txt``. | |
1454 |
|
1454 | |||
1455 | The --close-branch flag can be used to mark the current branch |
|
1455 | The --close-branch flag can be used to mark the current branch | |
1456 | head closed. When all heads of a branch are closed, the branch |
|
1456 | head closed. When all heads of a branch are closed, the branch | |
1457 | will be considered closed and no longer listed. |
|
1457 | will be considered closed and no longer listed. | |
1458 |
|
1458 | |||
1459 | The --amend flag can be used to amend the parent of the |
|
1459 | The --amend flag can be used to amend the parent of the | |
1460 | working directory with a new commit that contains the changes |
|
1460 | working directory with a new commit that contains the changes | |
1461 | in the parent in addition to those currently reported by :hg:`status`, |
|
1461 | in the parent in addition to those currently reported by :hg:`status`, | |
1462 | if there are any. The old commit is stored in a backup bundle in |
|
1462 | if there are any. The old commit is stored in a backup bundle in | |
1463 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1463 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` | |
1464 | on how to restore it). |
|
1464 | on how to restore it). | |
1465 |
|
1465 | |||
1466 | Message, user and date are taken from the amended commit unless |
|
1466 | Message, user and date are taken from the amended commit unless | |
1467 | specified. When a message isn't specified on the command line, |
|
1467 | specified. When a message isn't specified on the command line, | |
1468 | the editor will open with the message of the amended commit. |
|
1468 | the editor will open with the message of the amended commit. | |
1469 |
|
1469 | |||
1470 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1470 | It is not possible to amend public changesets (see :hg:`help phases`) | |
1471 | or changesets that have children. |
|
1471 | or changesets that have children. | |
1472 |
|
1472 | |||
1473 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1473 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
1474 |
|
1474 | |||
1475 | Returns 0 on success, 1 if nothing changed. |
|
1475 | Returns 0 on success, 1 if nothing changed. | |
1476 |
|
1476 | |||
1477 | .. container:: verbose |
|
1477 | .. container:: verbose | |
1478 |
|
1478 | |||
1479 | Examples: |
|
1479 | Examples: | |
1480 |
|
1480 | |||
1481 | - commit all files ending in .py:: |
|
1481 | - commit all files ending in .py:: | |
1482 |
|
1482 | |||
1483 | hg commit --include "set:**.py" |
|
1483 | hg commit --include "set:**.py" | |
1484 |
|
1484 | |||
1485 | - commit all non-binary files:: |
|
1485 | - commit all non-binary files:: | |
1486 |
|
1486 | |||
1487 | hg commit --exclude "set:binary()" |
|
1487 | hg commit --exclude "set:binary()" | |
1488 |
|
1488 | |||
1489 | - amend the current commit and set the date to now:: |
|
1489 | - amend the current commit and set the date to now:: | |
1490 |
|
1490 | |||
1491 | hg commit --amend --date now |
|
1491 | hg commit --amend --date now | |
1492 | """ |
|
1492 | """ | |
1493 | wlock = lock = None |
|
1493 | wlock = lock = None | |
1494 | try: |
|
1494 | try: | |
1495 | wlock = repo.wlock() |
|
1495 | wlock = repo.wlock() | |
1496 | lock = repo.lock() |
|
1496 | lock = repo.lock() | |
1497 | return _docommit(ui, repo, *pats, **opts) |
|
1497 | return _docommit(ui, repo, *pats, **opts) | |
1498 | finally: |
|
1498 | finally: | |
1499 | release(lock, wlock) |
|
1499 | release(lock, wlock) | |
1500 |
|
1500 | |||
1501 | def _docommit(ui, repo, *pats, **opts): |
|
1501 | def _docommit(ui, repo, *pats, **opts): | |
1502 | if opts.get(r'interactive'): |
|
1502 | if opts.get(r'interactive'): | |
1503 | opts.pop(r'interactive') |
|
1503 | opts.pop(r'interactive') | |
1504 | ret = cmdutil.dorecord(ui, repo, commit, None, False, |
|
1504 | ret = cmdutil.dorecord(ui, repo, commit, None, False, | |
1505 | cmdutil.recordfilter, *pats, |
|
1505 | cmdutil.recordfilter, *pats, | |
1506 | **opts) |
|
1506 | **opts) | |
1507 | # ret can be 0 (no changes to record) or the value returned by |
|
1507 | # ret can be 0 (no changes to record) or the value returned by | |
1508 | # commit(), 1 if nothing changed or None on success. |
|
1508 | # commit(), 1 if nothing changed or None on success. | |
1509 | return 1 if ret == 0 else ret |
|
1509 | return 1 if ret == 0 else ret | |
1510 |
|
1510 | |||
1511 | opts = pycompat.byteskwargs(opts) |
|
1511 | opts = pycompat.byteskwargs(opts) | |
1512 | if opts.get('subrepos'): |
|
1512 | if opts.get('subrepos'): | |
1513 | if opts.get('amend'): |
|
1513 | if opts.get('amend'): | |
1514 | raise error.Abort(_('cannot amend with --subrepos')) |
|
1514 | raise error.Abort(_('cannot amend with --subrepos')) | |
1515 | # Let --subrepos on the command line override config setting. |
|
1515 | # Let --subrepos on the command line override config setting. | |
1516 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') |
|
1516 | ui.setconfig('ui', 'commitsubrepos', True, 'commit') | |
1517 |
|
1517 | |||
1518 | cmdutil.checkunfinished(repo, commit=True) |
|
1518 | cmdutil.checkunfinished(repo, commit=True) | |
1519 |
|
1519 | |||
1520 | branch = repo[None].branch() |
|
1520 | branch = repo[None].branch() | |
1521 | bheads = repo.branchheads(branch) |
|
1521 | bheads = repo.branchheads(branch) | |
1522 |
|
1522 | |||
1523 | extra = {} |
|
1523 | extra = {} | |
1524 | if opts.get('close_branch'): |
|
1524 | if opts.get('close_branch'): | |
1525 | extra['close'] = 1 |
|
1525 | extra['close'] = 1 | |
1526 |
|
1526 | |||
1527 | if not bheads: |
|
1527 | if not bheads: | |
1528 | raise error.Abort(_('can only close branch heads')) |
|
1528 | raise error.Abort(_('can only close branch heads')) | |
1529 | elif opts.get('amend'): |
|
1529 | elif opts.get('amend'): | |
1530 | if repo[None].parents()[0].p1().branch() != branch and \ |
|
1530 | if repo[None].parents()[0].p1().branch() != branch and \ | |
1531 | repo[None].parents()[0].p2().branch() != branch: |
|
1531 | repo[None].parents()[0].p2().branch() != branch: | |
1532 | raise error.Abort(_('can only close branch heads')) |
|
1532 | raise error.Abort(_('can only close branch heads')) | |
1533 |
|
1533 | |||
1534 | if opts.get('amend'): |
|
1534 | if opts.get('amend'): | |
1535 | if ui.configbool('ui', 'commitsubrepos'): |
|
1535 | if ui.configbool('ui', 'commitsubrepos'): | |
1536 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) |
|
1536 | raise error.Abort(_('cannot amend with ui.commitsubrepos enabled')) | |
1537 |
|
1537 | |||
1538 | old = repo['.'] |
|
1538 | old = repo['.'] | |
1539 | if not old.mutable(): |
|
1539 | if not old.mutable(): | |
1540 | raise error.Abort(_('cannot amend public changesets')) |
|
1540 | raise error.Abort(_('cannot amend public changesets')) | |
1541 | if len(repo[None].parents()) > 1: |
|
1541 | if len(repo[None].parents()) > 1: | |
1542 | raise error.Abort(_('cannot amend while merging')) |
|
1542 | raise error.Abort(_('cannot amend while merging')) | |
1543 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
1543 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) | |
1544 | if not allowunstable and old.children(): |
|
1544 | if not allowunstable and old.children(): | |
1545 | raise error.Abort(_('cannot amend changeset with children')) |
|
1545 | raise error.Abort(_('cannot amend changeset with children')) | |
1546 |
|
1546 | |||
1547 | # Currently histedit gets confused if an amend happens while histedit |
|
1547 | # Currently histedit gets confused if an amend happens while histedit | |
1548 | # is in progress. Since we have a checkunfinished command, we are |
|
1548 | # is in progress. Since we have a checkunfinished command, we are | |
1549 | # temporarily honoring it. |
|
1549 | # temporarily honoring it. | |
1550 | # |
|
1550 | # | |
1551 | # Note: eventually this guard will be removed. Please do not expect |
|
1551 | # Note: eventually this guard will be removed. Please do not expect | |
1552 | # this behavior to remain. |
|
1552 | # this behavior to remain. | |
1553 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
1553 | if not obsolete.isenabled(repo, obsolete.createmarkersopt): | |
1554 | cmdutil.checkunfinished(repo) |
|
1554 | cmdutil.checkunfinished(repo) | |
1555 |
|
1555 | |||
1556 | node = cmdutil.amend(ui, repo, old, extra, pats, opts) |
|
1556 | node = cmdutil.amend(ui, repo, old, extra, pats, opts) | |
1557 | if node == old.node(): |
|
1557 | if node == old.node(): | |
1558 | ui.status(_("nothing changed\n")) |
|
1558 | ui.status(_("nothing changed\n")) | |
1559 | return 1 |
|
1559 | return 1 | |
1560 | else: |
|
1560 | else: | |
1561 | def commitfunc(ui, repo, message, match, opts): |
|
1561 | def commitfunc(ui, repo, message, match, opts): | |
1562 | overrides = {} |
|
1562 | overrides = {} | |
1563 | if opts.get('secret'): |
|
1563 | if opts.get('secret'): | |
1564 | overrides[('phases', 'new-commit')] = 'secret' |
|
1564 | overrides[('phases', 'new-commit')] = 'secret' | |
1565 |
|
1565 | |||
1566 | baseui = repo.baseui |
|
1566 | baseui = repo.baseui | |
1567 | with baseui.configoverride(overrides, 'commit'): |
|
1567 | with baseui.configoverride(overrides, 'commit'): | |
1568 | with ui.configoverride(overrides, 'commit'): |
|
1568 | with ui.configoverride(overrides, 'commit'): | |
1569 | editform = cmdutil.mergeeditform(repo[None], |
|
1569 | editform = cmdutil.mergeeditform(repo[None], | |
1570 | 'commit.normal') |
|
1570 | 'commit.normal') | |
1571 | editor = cmdutil.getcommiteditor( |
|
1571 | editor = cmdutil.getcommiteditor( | |
1572 | editform=editform, **pycompat.strkwargs(opts)) |
|
1572 | editform=editform, **pycompat.strkwargs(opts)) | |
1573 | return repo.commit(message, |
|
1573 | return repo.commit(message, | |
1574 | opts.get('user'), |
|
1574 | opts.get('user'), | |
1575 | opts.get('date'), |
|
1575 | opts.get('date'), | |
1576 | match, |
|
1576 | match, | |
1577 | editor=editor, |
|
1577 | editor=editor, | |
1578 | extra=extra) |
|
1578 | extra=extra) | |
1579 |
|
1579 | |||
1580 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1580 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | |
1581 |
|
1581 | |||
1582 | if not node: |
|
1582 | if not node: | |
1583 | stat = cmdutil.postcommitstatus(repo, pats, opts) |
|
1583 | stat = cmdutil.postcommitstatus(repo, pats, opts) | |
1584 | if stat[3]: |
|
1584 | if stat[3]: | |
1585 | ui.status(_("nothing changed (%d missing files, see " |
|
1585 | ui.status(_("nothing changed (%d missing files, see " | |
1586 | "'hg status')\n") % len(stat[3])) |
|
1586 | "'hg status')\n") % len(stat[3])) | |
1587 | else: |
|
1587 | else: | |
1588 | ui.status(_("nothing changed\n")) |
|
1588 | ui.status(_("nothing changed\n")) | |
1589 | return 1 |
|
1589 | return 1 | |
1590 |
|
1590 | |||
1591 | cmdutil.commitstatus(repo, node, branch, bheads, opts) |
|
1591 | cmdutil.commitstatus(repo, node, branch, bheads, opts) | |
1592 |
|
1592 | |||
1593 | @command('config|showconfig|debugconfig', |
|
1593 | @command('config|showconfig|debugconfig', | |
1594 | [('u', 'untrusted', None, _('show untrusted configuration options')), |
|
1594 | [('u', 'untrusted', None, _('show untrusted configuration options')), | |
1595 | ('e', 'edit', None, _('edit user config')), |
|
1595 | ('e', 'edit', None, _('edit user config')), | |
1596 | ('l', 'local', None, _('edit repository config')), |
|
1596 | ('l', 'local', None, _('edit repository config')), | |
1597 | ('g', 'global', None, _('edit global config'))] + formatteropts, |
|
1597 | ('g', 'global', None, _('edit global config'))] + formatteropts, | |
1598 | _('[-u] [NAME]...'), |
|
1598 | _('[-u] [NAME]...'), | |
1599 | optionalrepo=True) |
|
1599 | optionalrepo=True) | |
1600 | def config(ui, repo, *values, **opts): |
|
1600 | def config(ui, repo, *values, **opts): | |
1601 | """show combined config settings from all hgrc files |
|
1601 | """show combined config settings from all hgrc files | |
1602 |
|
1602 | |||
1603 | With no arguments, print names and values of all config items. |
|
1603 | With no arguments, print names and values of all config items. | |
1604 |
|
1604 | |||
1605 | With one argument of the form section.name, print just the value |
|
1605 | With one argument of the form section.name, print just the value | |
1606 | of that config item. |
|
1606 | of that config item. | |
1607 |
|
1607 | |||
1608 | With multiple arguments, print names and values of all config |
|
1608 | With multiple arguments, print names and values of all config | |
1609 | items with matching section names. |
|
1609 | items with matching section names. | |
1610 |
|
1610 | |||
1611 | With --edit, start an editor on the user-level config file. With |
|
1611 | With --edit, start an editor on the user-level config file. With | |
1612 | --global, edit the system-wide config file. With --local, edit the |
|
1612 | --global, edit the system-wide config file. With --local, edit the | |
1613 | repository-level config file. |
|
1613 | repository-level config file. | |
1614 |
|
1614 | |||
1615 | With --debug, the source (filename and line number) is printed |
|
1615 | With --debug, the source (filename and line number) is printed | |
1616 | for each config item. |
|
1616 | for each config item. | |
1617 |
|
1617 | |||
1618 | See :hg:`help config` for more information about config files. |
|
1618 | See :hg:`help config` for more information about config files. | |
1619 |
|
1619 | |||
1620 | Returns 0 on success, 1 if NAME does not exist. |
|
1620 | Returns 0 on success, 1 if NAME does not exist. | |
1621 |
|
1621 | |||
1622 | """ |
|
1622 | """ | |
1623 |
|
1623 | |||
1624 | opts = pycompat.byteskwargs(opts) |
|
1624 | opts = pycompat.byteskwargs(opts) | |
1625 | if opts.get('edit') or opts.get('local') or opts.get('global'): |
|
1625 | if opts.get('edit') or opts.get('local') or opts.get('global'): | |
1626 | if opts.get('local') and opts.get('global'): |
|
1626 | if opts.get('local') and opts.get('global'): | |
1627 | raise error.Abort(_("can't use --local and --global together")) |
|
1627 | raise error.Abort(_("can't use --local and --global together")) | |
1628 |
|
1628 | |||
1629 | if opts.get('local'): |
|
1629 | if opts.get('local'): | |
1630 | if not repo: |
|
1630 | if not repo: | |
1631 | raise error.Abort(_("can't use --local outside a repository")) |
|
1631 | raise error.Abort(_("can't use --local outside a repository")) | |
1632 | paths = [repo.vfs.join('hgrc')] |
|
1632 | paths = [repo.vfs.join('hgrc')] | |
1633 | elif opts.get('global'): |
|
1633 | elif opts.get('global'): | |
1634 | paths = rcutil.systemrcpath() |
|
1634 | paths = rcutil.systemrcpath() | |
1635 | else: |
|
1635 | else: | |
1636 | paths = rcutil.userrcpath() |
|
1636 | paths = rcutil.userrcpath() | |
1637 |
|
1637 | |||
1638 | for f in paths: |
|
1638 | for f in paths: | |
1639 | if os.path.exists(f): |
|
1639 | if os.path.exists(f): | |
1640 | break |
|
1640 | break | |
1641 | else: |
|
1641 | else: | |
1642 | if opts.get('global'): |
|
1642 | if opts.get('global'): | |
1643 | samplehgrc = uimod.samplehgrcs['global'] |
|
1643 | samplehgrc = uimod.samplehgrcs['global'] | |
1644 | elif opts.get('local'): |
|
1644 | elif opts.get('local'): | |
1645 | samplehgrc = uimod.samplehgrcs['local'] |
|
1645 | samplehgrc = uimod.samplehgrcs['local'] | |
1646 | else: |
|
1646 | else: | |
1647 | samplehgrc = uimod.samplehgrcs['user'] |
|
1647 | samplehgrc = uimod.samplehgrcs['user'] | |
1648 |
|
1648 | |||
1649 | f = paths[0] |
|
1649 | f = paths[0] | |
1650 | fp = open(f, "wb") |
|
1650 | fp = open(f, "wb") | |
1651 | fp.write(util.tonativeeol(samplehgrc)) |
|
1651 | fp.write(util.tonativeeol(samplehgrc)) | |
1652 | fp.close() |
|
1652 | fp.close() | |
1653 |
|
1653 | |||
1654 | editor = ui.geteditor() |
|
1654 | editor = ui.geteditor() | |
1655 | ui.system("%s \"%s\"" % (editor, f), |
|
1655 | ui.system("%s \"%s\"" % (editor, f), | |
1656 | onerr=error.Abort, errprefix=_("edit failed"), |
|
1656 | onerr=error.Abort, errprefix=_("edit failed"), | |
1657 | blockedtag='config_edit') |
|
1657 | blockedtag='config_edit') | |
1658 | return |
|
1658 | return | |
1659 | ui.pager('config') |
|
1659 | ui.pager('config') | |
1660 | fm = ui.formatter('config', opts) |
|
1660 | fm = ui.formatter('config', opts) | |
1661 | for t, f in rcutil.rccomponents(): |
|
1661 | for t, f in rcutil.rccomponents(): | |
1662 | if t == 'path': |
|
1662 | if t == 'path': | |
1663 | ui.debug('read config from: %s\n' % f) |
|
1663 | ui.debug('read config from: %s\n' % f) | |
1664 | elif t == 'items': |
|
1664 | elif t == 'items': | |
1665 | for section, name, value, source in f: |
|
1665 | for section, name, value, source in f: | |
1666 | ui.debug('set config by: %s\n' % source) |
|
1666 | ui.debug('set config by: %s\n' % source) | |
1667 | else: |
|
1667 | else: | |
1668 | raise error.ProgrammingError('unknown rctype: %s' % t) |
|
1668 | raise error.ProgrammingError('unknown rctype: %s' % t) | |
1669 | untrusted = bool(opts.get('untrusted')) |
|
1669 | untrusted = bool(opts.get('untrusted')) | |
1670 | if values: |
|
1670 | if values: | |
1671 | sections = [v for v in values if '.' not in v] |
|
1671 | sections = [v for v in values if '.' not in v] | |
1672 | items = [v for v in values if '.' in v] |
|
1672 | items = [v for v in values if '.' in v] | |
1673 | if len(items) > 1 or items and sections: |
|
1673 | if len(items) > 1 or items and sections: | |
1674 | raise error.Abort(_('only one config item permitted')) |
|
1674 | raise error.Abort(_('only one config item permitted')) | |
1675 | matched = False |
|
1675 | matched = False | |
1676 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
1676 | for section, name, value in ui.walkconfig(untrusted=untrusted): | |
1677 | source = ui.configsource(section, name, untrusted) |
|
1677 | source = ui.configsource(section, name, untrusted) | |
1678 | value = pycompat.bytestr(value) |
|
1678 | value = pycompat.bytestr(value) | |
1679 | if fm.isplain(): |
|
1679 | if fm.isplain(): | |
1680 | source = source or 'none' |
|
1680 | source = source or 'none' | |
1681 | value = value.replace('\n', '\\n') |
|
1681 | value = value.replace('\n', '\\n') | |
1682 | entryname = section + '.' + name |
|
1682 | entryname = section + '.' + name | |
1683 | if values: |
|
1683 | if values: | |
1684 | for v in values: |
|
1684 | for v in values: | |
1685 | if v == section: |
|
1685 | if v == section: | |
1686 | fm.startitem() |
|
1686 | fm.startitem() | |
1687 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1687 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | |
1688 | fm.write('name value', '%s=%s\n', entryname, value) |
|
1688 | fm.write('name value', '%s=%s\n', entryname, value) | |
1689 | matched = True |
|
1689 | matched = True | |
1690 | elif v == entryname: |
|
1690 | elif v == entryname: | |
1691 | fm.startitem() |
|
1691 | fm.startitem() | |
1692 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1692 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | |
1693 | fm.write('value', '%s\n', value) |
|
1693 | fm.write('value', '%s\n', value) | |
1694 | fm.data(name=entryname) |
|
1694 | fm.data(name=entryname) | |
1695 | matched = True |
|
1695 | matched = True | |
1696 | else: |
|
1696 | else: | |
1697 | fm.startitem() |
|
1697 | fm.startitem() | |
1698 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) |
|
1698 | fm.condwrite(ui.debugflag, 'source', '%s: ', source) | |
1699 | fm.write('name value', '%s=%s\n', entryname, value) |
|
1699 | fm.write('name value', '%s=%s\n', entryname, value) | |
1700 | matched = True |
|
1700 | matched = True | |
1701 | fm.end() |
|
1701 | fm.end() | |
1702 | if matched: |
|
1702 | if matched: | |
1703 | return 0 |
|
1703 | return 0 | |
1704 | return 1 |
|
1704 | return 1 | |
1705 |
|
1705 | |||
1706 | @command('copy|cp', |
|
1706 | @command('copy|cp', | |
1707 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1707 | [('A', 'after', None, _('record a copy that has already occurred')), | |
1708 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1708 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
1709 | ] + walkopts + dryrunopts, |
|
1709 | ] + walkopts + dryrunopts, | |
1710 | _('[OPTION]... [SOURCE]... DEST')) |
|
1710 | _('[OPTION]... [SOURCE]... DEST')) | |
1711 | def copy(ui, repo, *pats, **opts): |
|
1711 | def copy(ui, repo, *pats, **opts): | |
1712 | """mark files as copied for the next commit |
|
1712 | """mark files as copied for the next commit | |
1713 |
|
1713 | |||
1714 | Mark dest as having copies of source files. If dest is a |
|
1714 | Mark dest as having copies of source files. If dest is a | |
1715 | directory, copies are put in that directory. If dest is a file, |
|
1715 | directory, copies are put in that directory. If dest is a file, | |
1716 | the source must be a single file. |
|
1716 | the source must be a single file. | |
1717 |
|
1717 | |||
1718 | By default, this command copies the contents of files as they |
|
1718 | By default, this command copies the contents of files as they | |
1719 | exist in the working directory. If invoked with -A/--after, the |
|
1719 | exist in the working directory. If invoked with -A/--after, the | |
1720 | operation is recorded, but no copying is performed. |
|
1720 | operation is recorded, but no copying is performed. | |
1721 |
|
1721 | |||
1722 | This command takes effect with the next commit. To undo a copy |
|
1722 | This command takes effect with the next commit. To undo a copy | |
1723 | before that, see :hg:`revert`. |
|
1723 | before that, see :hg:`revert`. | |
1724 |
|
1724 | |||
1725 | Returns 0 on success, 1 if errors are encountered. |
|
1725 | Returns 0 on success, 1 if errors are encountered. | |
1726 | """ |
|
1726 | """ | |
1727 | opts = pycompat.byteskwargs(opts) |
|
1727 | opts = pycompat.byteskwargs(opts) | |
1728 | with repo.wlock(False): |
|
1728 | with repo.wlock(False): | |
1729 | return cmdutil.copy(ui, repo, pats, opts) |
|
1729 | return cmdutil.copy(ui, repo, pats, opts) | |
1730 |
|
1730 | |||
1731 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) |
|
1731 | @command('debugcommands', [], _('[COMMAND]'), norepo=True) | |
1732 | def debugcommands(ui, cmd='', *args): |
|
1732 | def debugcommands(ui, cmd='', *args): | |
1733 | """list all available commands and options""" |
|
1733 | """list all available commands and options""" | |
1734 | for cmd, vals in sorted(table.iteritems()): |
|
1734 | for cmd, vals in sorted(table.iteritems()): | |
1735 | cmd = cmd.split('|')[0].strip('^') |
|
1735 | cmd = cmd.split('|')[0].strip('^') | |
1736 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1736 | opts = ', '.join([i[1] for i in vals[1]]) | |
1737 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1737 | ui.write('%s: %s\n' % (cmd, opts)) | |
1738 |
|
1738 | |||
1739 | @command('debugcomplete', |
|
1739 | @command('debugcomplete', | |
1740 | [('o', 'options', None, _('show the command options'))], |
|
1740 | [('o', 'options', None, _('show the command options'))], | |
1741 | _('[-o] CMD'), |
|
1741 | _('[-o] CMD'), | |
1742 | norepo=True) |
|
1742 | norepo=True) | |
1743 | def debugcomplete(ui, cmd='', **opts): |
|
1743 | def debugcomplete(ui, cmd='', **opts): | |
1744 | """returns the completion list associated with the given command""" |
|
1744 | """returns the completion list associated with the given command""" | |
1745 |
|
1745 | |||
1746 | if opts.get('options'): |
|
1746 | if opts.get('options'): | |
1747 | options = [] |
|
1747 | options = [] | |
1748 | otables = [globalopts] |
|
1748 | otables = [globalopts] | |
1749 | if cmd: |
|
1749 | if cmd: | |
1750 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1750 | aliases, entry = cmdutil.findcmd(cmd, table, False) | |
1751 | otables.append(entry[1]) |
|
1751 | otables.append(entry[1]) | |
1752 | for t in otables: |
|
1752 | for t in otables: | |
1753 | for o in t: |
|
1753 | for o in t: | |
1754 | if "(DEPRECATED)" in o[3]: |
|
1754 | if "(DEPRECATED)" in o[3]: | |
1755 | continue |
|
1755 | continue | |
1756 | if o[0]: |
|
1756 | if o[0]: | |
1757 | options.append('-%s' % o[0]) |
|
1757 | options.append('-%s' % o[0]) | |
1758 | options.append('--%s' % o[1]) |
|
1758 | options.append('--%s' % o[1]) | |
1759 | ui.write("%s\n" % "\n".join(options)) |
|
1759 | ui.write("%s\n" % "\n".join(options)) | |
1760 | return |
|
1760 | return | |
1761 |
|
1761 | |||
1762 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) |
|
1762 | cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table) | |
1763 | if ui.verbose: |
|
1763 | if ui.verbose: | |
1764 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1764 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | |
1765 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1765 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) | |
1766 |
|
1766 | |||
1767 | @command('^diff', |
|
1767 | @command('^diff', | |
1768 | [('r', 'rev', [], _('revision'), _('REV')), |
|
1768 | [('r', 'rev', [], _('revision'), _('REV')), | |
1769 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
1769 | ('c', 'change', '', _('change made by revision'), _('REV')) | |
1770 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
1770 | ] + diffopts + diffopts2 + walkopts + subrepoopts, | |
1771 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), |
|
1771 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'), | |
1772 | inferrepo=True) |
|
1772 | inferrepo=True) | |
1773 | def diff(ui, repo, *pats, **opts): |
|
1773 | def diff(ui, repo, *pats, **opts): | |
1774 | """diff repository (or selected files) |
|
1774 | """diff repository (or selected files) | |
1775 |
|
1775 | |||
1776 | Show differences between revisions for the specified files. |
|
1776 | Show differences between revisions for the specified files. | |
1777 |
|
1777 | |||
1778 | Differences between files are shown using the unified diff format. |
|
1778 | Differences between files are shown using the unified diff format. | |
1779 |
|
1779 | |||
1780 | .. note:: |
|
1780 | .. note:: | |
1781 |
|
1781 | |||
1782 | :hg:`diff` may generate unexpected results for merges, as it will |
|
1782 | :hg:`diff` may generate unexpected results for merges, as it will | |
1783 | default to comparing against the working directory's first |
|
1783 | default to comparing against the working directory's first | |
1784 | parent changeset if no revisions are specified. |
|
1784 | parent changeset if no revisions are specified. | |
1785 |
|
1785 | |||
1786 | When two revision arguments are given, then changes are shown |
|
1786 | When two revision arguments are given, then changes are shown | |
1787 | between those revisions. If only one revision is specified then |
|
1787 | between those revisions. If only one revision is specified then | |
1788 | that revision is compared to the working directory, and, when no |
|
1788 | that revision is compared to the working directory, and, when no | |
1789 | revisions are specified, the working directory files are compared |
|
1789 | revisions are specified, the working directory files are compared | |
1790 | to its first parent. |
|
1790 | to its first parent. | |
1791 |
|
1791 | |||
1792 | Alternatively you can specify -c/--change with a revision to see |
|
1792 | Alternatively you can specify -c/--change with a revision to see | |
1793 | the changes in that changeset relative to its first parent. |
|
1793 | the changes in that changeset relative to its first parent. | |
1794 |
|
1794 | |||
1795 | Without the -a/--text option, diff will avoid generating diffs of |
|
1795 | Without the -a/--text option, diff will avoid generating diffs of | |
1796 | files it detects as binary. With -a, diff will generate a diff |
|
1796 | files it detects as binary. With -a, diff will generate a diff | |
1797 | anyway, probably with undesirable results. |
|
1797 | anyway, probably with undesirable results. | |
1798 |
|
1798 | |||
1799 | Use the -g/--git option to generate diffs in the git extended diff |
|
1799 | Use the -g/--git option to generate diffs in the git extended diff | |
1800 | format. For more information, read :hg:`help diffs`. |
|
1800 | format. For more information, read :hg:`help diffs`. | |
1801 |
|
1801 | |||
1802 | .. container:: verbose |
|
1802 | .. container:: verbose | |
1803 |
|
1803 | |||
1804 | Examples: |
|
1804 | Examples: | |
1805 |
|
1805 | |||
1806 | - compare a file in the current working directory to its parent:: |
|
1806 | - compare a file in the current working directory to its parent:: | |
1807 |
|
1807 | |||
1808 | hg diff foo.c |
|
1808 | hg diff foo.c | |
1809 |
|
1809 | |||
1810 | - compare two historical versions of a directory, with rename info:: |
|
1810 | - compare two historical versions of a directory, with rename info:: | |
1811 |
|
1811 | |||
1812 | hg diff --git -r 1.0:1.2 lib/ |
|
1812 | hg diff --git -r 1.0:1.2 lib/ | |
1813 |
|
1813 | |||
1814 | - get change stats relative to the last change on some date:: |
|
1814 | - get change stats relative to the last change on some date:: | |
1815 |
|
1815 | |||
1816 | hg diff --stat -r "date('may 2')" |
|
1816 | hg diff --stat -r "date('may 2')" | |
1817 |
|
1817 | |||
1818 | - diff all newly-added files that contain a keyword:: |
|
1818 | - diff all newly-added files that contain a keyword:: | |
1819 |
|
1819 | |||
1820 | hg diff "set:added() and grep(GNU)" |
|
1820 | hg diff "set:added() and grep(GNU)" | |
1821 |
|
1821 | |||
1822 | - compare a revision and its parents:: |
|
1822 | - compare a revision and its parents:: | |
1823 |
|
1823 | |||
1824 | hg diff -c 9353 # compare against first parent |
|
1824 | hg diff -c 9353 # compare against first parent | |
1825 | hg diff -r 9353^:9353 # same using revset syntax |
|
1825 | hg diff -r 9353^:9353 # same using revset syntax | |
1826 | hg diff -r 9353^2:9353 # compare against the second parent |
|
1826 | hg diff -r 9353^2:9353 # compare against the second parent | |
1827 |
|
1827 | |||
1828 | Returns 0 on success. |
|
1828 | Returns 0 on success. | |
1829 | """ |
|
1829 | """ | |
1830 |
|
1830 | |||
1831 | opts = pycompat.byteskwargs(opts) |
|
1831 | opts = pycompat.byteskwargs(opts) | |
1832 | revs = opts.get('rev') |
|
1832 | revs = opts.get('rev') | |
1833 | change = opts.get('change') |
|
1833 | change = opts.get('change') | |
1834 | stat = opts.get('stat') |
|
1834 | stat = opts.get('stat') | |
1835 | reverse = opts.get('reverse') |
|
1835 | reverse = opts.get('reverse') | |
1836 |
|
1836 | |||
1837 | if revs and change: |
|
1837 | if revs and change: | |
1838 | msg = _('cannot specify --rev and --change at the same time') |
|
1838 | msg = _('cannot specify --rev and --change at the same time') | |
1839 | raise error.Abort(msg) |
|
1839 | raise error.Abort(msg) | |
1840 | elif change: |
|
1840 | elif change: | |
1841 | node2 = scmutil.revsingle(repo, change, None).node() |
|
1841 | node2 = scmutil.revsingle(repo, change, None).node() | |
1842 | node1 = repo[node2].p1().node() |
|
1842 | node1 = repo[node2].p1().node() | |
1843 | else: |
|
1843 | else: | |
1844 | node1, node2 = scmutil.revpair(repo, revs) |
|
1844 | node1, node2 = scmutil.revpair(repo, revs) | |
1845 |
|
1845 | |||
1846 | if reverse: |
|
1846 | if reverse: | |
1847 | node1, node2 = node2, node1 |
|
1847 | node1, node2 = node2, node1 | |
1848 |
|
1848 | |||
1849 | diffopts = patch.diffallopts(ui, opts) |
|
1849 | diffopts = patch.diffallopts(ui, opts) | |
1850 | m = scmutil.match(repo[node2], pats, opts) |
|
1850 | m = scmutil.match(repo[node2], pats, opts) | |
1851 | ui.pager('diff') |
|
1851 | ui.pager('diff') | |
1852 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
1852 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | |
1853 | listsubrepos=opts.get('subrepos'), |
|
1853 | listsubrepos=opts.get('subrepos'), | |
1854 | root=opts.get('root')) |
|
1854 | root=opts.get('root')) | |
1855 |
|
1855 | |||
1856 | @command('^export', |
|
1856 | @command('^export', | |
1857 | [('o', 'output', '', |
|
1857 | [('o', 'output', '', | |
1858 | _('print output to file with formatted name'), _('FORMAT')), |
|
1858 | _('print output to file with formatted name'), _('FORMAT')), | |
1859 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
1859 | ('', 'switch-parent', None, _('diff against the second parent')), | |
1860 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
1860 | ('r', 'rev', [], _('revisions to export'), _('REV')), | |
1861 | ] + diffopts, |
|
1861 | ] + diffopts, | |
1862 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) |
|
1862 | _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...')) | |
1863 | def export(ui, repo, *changesets, **opts): |
|
1863 | def export(ui, repo, *changesets, **opts): | |
1864 | """dump the header and diffs for one or more changesets |
|
1864 | """dump the header and diffs for one or more changesets | |
1865 |
|
1865 | |||
1866 | Print the changeset header and diffs for one or more revisions. |
|
1866 | Print the changeset header and diffs for one or more revisions. | |
1867 | If no revision is given, the parent of the working directory is used. |
|
1867 | If no revision is given, the parent of the working directory is used. | |
1868 |
|
1868 | |||
1869 | The information shown in the changeset header is: author, date, |
|
1869 | The information shown in the changeset header is: author, date, | |
1870 | branch name (if non-default), changeset hash, parent(s) and commit |
|
1870 | branch name (if non-default), changeset hash, parent(s) and commit | |
1871 | comment. |
|
1871 | comment. | |
1872 |
|
1872 | |||
1873 | .. note:: |
|
1873 | .. note:: | |
1874 |
|
1874 | |||
1875 | :hg:`export` may generate unexpected diff output for merge |
|
1875 | :hg:`export` may generate unexpected diff output for merge | |
1876 | changesets, as it will compare the merge changeset against its |
|
1876 | changesets, as it will compare the merge changeset against its | |
1877 | first parent only. |
|
1877 | first parent only. | |
1878 |
|
1878 | |||
1879 | Output may be to a file, in which case the name of the file is |
|
1879 | Output may be to a file, in which case the name of the file is | |
1880 | given using a format string. The formatting rules are as follows: |
|
1880 | given using a format string. The formatting rules are as follows: | |
1881 |
|
1881 | |||
1882 | :``%%``: literal "%" character |
|
1882 | :``%%``: literal "%" character | |
1883 | :``%H``: changeset hash (40 hexadecimal digits) |
|
1883 | :``%H``: changeset hash (40 hexadecimal digits) | |
1884 | :``%N``: number of patches being generated |
|
1884 | :``%N``: number of patches being generated | |
1885 | :``%R``: changeset revision number |
|
1885 | :``%R``: changeset revision number | |
1886 | :``%b``: basename of the exporting repository |
|
1886 | :``%b``: basename of the exporting repository | |
1887 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
1887 | :``%h``: short-form changeset hash (12 hexadecimal digits) | |
1888 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
1888 | :``%m``: first line of the commit message (only alphanumeric characters) | |
1889 | :``%n``: zero-padded sequence number, starting at 1 |
|
1889 | :``%n``: zero-padded sequence number, starting at 1 | |
1890 | :``%r``: zero-padded changeset revision number |
|
1890 | :``%r``: zero-padded changeset revision number | |
1891 |
|
1891 | |||
1892 | Without the -a/--text option, export will avoid generating diffs |
|
1892 | Without the -a/--text option, export will avoid generating diffs | |
1893 | of files it detects as binary. With -a, export will generate a |
|
1893 | of files it detects as binary. With -a, export will generate a | |
1894 | diff anyway, probably with undesirable results. |
|
1894 | diff anyway, probably with undesirable results. | |
1895 |
|
1895 | |||
1896 | Use the -g/--git option to generate diffs in the git extended diff |
|
1896 | Use the -g/--git option to generate diffs in the git extended diff | |
1897 | format. See :hg:`help diffs` for more information. |
|
1897 | format. See :hg:`help diffs` for more information. | |
1898 |
|
1898 | |||
1899 | With the --switch-parent option, the diff will be against the |
|
1899 | With the --switch-parent option, the diff will be against the | |
1900 | second parent. It can be useful to review a merge. |
|
1900 | second parent. It can be useful to review a merge. | |
1901 |
|
1901 | |||
1902 | .. container:: verbose |
|
1902 | .. container:: verbose | |
1903 |
|
1903 | |||
1904 | Examples: |
|
1904 | Examples: | |
1905 |
|
1905 | |||
1906 | - use export and import to transplant a bugfix to the current |
|
1906 | - use export and import to transplant a bugfix to the current | |
1907 | branch:: |
|
1907 | branch:: | |
1908 |
|
1908 | |||
1909 | hg export -r 9353 | hg import - |
|
1909 | hg export -r 9353 | hg import - | |
1910 |
|
1910 | |||
1911 | - export all the changesets between two revisions to a file with |
|
1911 | - export all the changesets between two revisions to a file with | |
1912 | rename information:: |
|
1912 | rename information:: | |
1913 |
|
1913 | |||
1914 | hg export --git -r 123:150 > changes.txt |
|
1914 | hg export --git -r 123:150 > changes.txt | |
1915 |
|
1915 | |||
1916 | - split outgoing changes into a series of patches with |
|
1916 | - split outgoing changes into a series of patches with | |
1917 | descriptive names:: |
|
1917 | descriptive names:: | |
1918 |
|
1918 | |||
1919 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
1919 | hg export -r "outgoing()" -o "%n-%m.patch" | |
1920 |
|
1920 | |||
1921 | Returns 0 on success. |
|
1921 | Returns 0 on success. | |
1922 | """ |
|
1922 | """ | |
1923 | opts = pycompat.byteskwargs(opts) |
|
1923 | opts = pycompat.byteskwargs(opts) | |
1924 | changesets += tuple(opts.get('rev', [])) |
|
1924 | changesets += tuple(opts.get('rev', [])) | |
1925 | if not changesets: |
|
1925 | if not changesets: | |
1926 | changesets = ['.'] |
|
1926 | changesets = ['.'] | |
1927 | revs = scmutil.revrange(repo, changesets) |
|
1927 | revs = scmutil.revrange(repo, changesets) | |
1928 | if not revs: |
|
1928 | if not revs: | |
1929 | raise error.Abort(_("export requires at least one changeset")) |
|
1929 | raise error.Abort(_("export requires at least one changeset")) | |
1930 | if len(revs) > 1: |
|
1930 | if len(revs) > 1: | |
1931 | ui.note(_('exporting patches:\n')) |
|
1931 | ui.note(_('exporting patches:\n')) | |
1932 | else: |
|
1932 | else: | |
1933 | ui.note(_('exporting patch:\n')) |
|
1933 | ui.note(_('exporting patch:\n')) | |
1934 | ui.pager('export') |
|
1934 | ui.pager('export') | |
1935 | cmdutil.export(repo, revs, fntemplate=opts.get('output'), |
|
1935 | cmdutil.export(repo, revs, fntemplate=opts.get('output'), | |
1936 | switch_parent=opts.get('switch_parent'), |
|
1936 | switch_parent=opts.get('switch_parent'), | |
1937 | opts=patch.diffallopts(ui, opts)) |
|
1937 | opts=patch.diffallopts(ui, opts)) | |
1938 |
|
1938 | |||
1939 | @command('files', |
|
1939 | @command('files', | |
1940 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
1940 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | |
1941 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
1941 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
1942 | ] + walkopts + formatteropts + subrepoopts, |
|
1942 | ] + walkopts + formatteropts + subrepoopts, | |
1943 | _('[OPTION]... [FILE]...')) |
|
1943 | _('[OPTION]... [FILE]...')) | |
1944 | def files(ui, repo, *pats, **opts): |
|
1944 | def files(ui, repo, *pats, **opts): | |
1945 | """list tracked files |
|
1945 | """list tracked files | |
1946 |
|
1946 | |||
1947 | Print files under Mercurial control in the working directory or |
|
1947 | Print files under Mercurial control in the working directory or | |
1948 | specified revision for given files (excluding removed files). |
|
1948 | specified revision for given files (excluding removed files). | |
1949 | Files can be specified as filenames or filesets. |
|
1949 | Files can be specified as filenames or filesets. | |
1950 |
|
1950 | |||
1951 | If no files are given to match, this command prints the names |
|
1951 | If no files are given to match, this command prints the names | |
1952 | of all files under Mercurial control. |
|
1952 | of all files under Mercurial control. | |
1953 |
|
1953 | |||
1954 | .. container:: verbose |
|
1954 | .. container:: verbose | |
1955 |
|
1955 | |||
1956 | Examples: |
|
1956 | Examples: | |
1957 |
|
1957 | |||
1958 | - list all files under the current directory:: |
|
1958 | - list all files under the current directory:: | |
1959 |
|
1959 | |||
1960 | hg files . |
|
1960 | hg files . | |
1961 |
|
1961 | |||
1962 | - shows sizes and flags for current revision:: |
|
1962 | - shows sizes and flags for current revision:: | |
1963 |
|
1963 | |||
1964 | hg files -vr . |
|
1964 | hg files -vr . | |
1965 |
|
1965 | |||
1966 | - list all files named README:: |
|
1966 | - list all files named README:: | |
1967 |
|
1967 | |||
1968 | hg files -I "**/README" |
|
1968 | hg files -I "**/README" | |
1969 |
|
1969 | |||
1970 | - list all binary files:: |
|
1970 | - list all binary files:: | |
1971 |
|
1971 | |||
1972 | hg files "set:binary()" |
|
1972 | hg files "set:binary()" | |
1973 |
|
1973 | |||
1974 | - find files containing a regular expression:: |
|
1974 | - find files containing a regular expression:: | |
1975 |
|
1975 | |||
1976 | hg files "set:grep('bob')" |
|
1976 | hg files "set:grep('bob')" | |
1977 |
|
1977 | |||
1978 | - search tracked file contents with xargs and grep:: |
|
1978 | - search tracked file contents with xargs and grep:: | |
1979 |
|
1979 | |||
1980 | hg files -0 | xargs -0 grep foo |
|
1980 | hg files -0 | xargs -0 grep foo | |
1981 |
|
1981 | |||
1982 | See :hg:`help patterns` and :hg:`help filesets` for more information |
|
1982 | See :hg:`help patterns` and :hg:`help filesets` for more information | |
1983 | on specifying file patterns. |
|
1983 | on specifying file patterns. | |
1984 |
|
1984 | |||
1985 | Returns 0 if a match is found, 1 otherwise. |
|
1985 | Returns 0 if a match is found, 1 otherwise. | |
1986 |
|
1986 | |||
1987 | """ |
|
1987 | """ | |
1988 |
|
1988 | |||
1989 | opts = pycompat.byteskwargs(opts) |
|
1989 | opts = pycompat.byteskwargs(opts) | |
1990 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
1990 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | |
1991 |
|
1991 | |||
1992 | end = '\n' |
|
1992 | end = '\n' | |
1993 | if opts.get('print0'): |
|
1993 | if opts.get('print0'): | |
1994 | end = '\0' |
|
1994 | end = '\0' | |
1995 | fmt = '%s' + end |
|
1995 | fmt = '%s' + end | |
1996 |
|
1996 | |||
1997 | m = scmutil.match(ctx, pats, opts) |
|
1997 | m = scmutil.match(ctx, pats, opts) | |
1998 | ui.pager('files') |
|
1998 | ui.pager('files') | |
1999 | with ui.formatter('files', opts) as fm: |
|
1999 | with ui.formatter('files', opts) as fm: | |
2000 | return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) |
|
2000 | return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos')) | |
2001 |
|
2001 | |||
2002 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) |
|
2002 | @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True) | |
2003 | def forget(ui, repo, *pats, **opts): |
|
2003 | def forget(ui, repo, *pats, **opts): | |
2004 | """forget the specified files on the next commit |
|
2004 | """forget the specified files on the next commit | |
2005 |
|
2005 | |||
2006 | Mark the specified files so they will no longer be tracked |
|
2006 | Mark the specified files so they will no longer be tracked | |
2007 | after the next commit. |
|
2007 | after the next commit. | |
2008 |
|
2008 | |||
2009 | This only removes files from the current branch, not from the |
|
2009 | This only removes files from the current branch, not from the | |
2010 | entire project history, and it does not delete them from the |
|
2010 | entire project history, and it does not delete them from the | |
2011 | working directory. |
|
2011 | working directory. | |
2012 |
|
2012 | |||
2013 | To delete the file from the working directory, see :hg:`remove`. |
|
2013 | To delete the file from the working directory, see :hg:`remove`. | |
2014 |
|
2014 | |||
2015 | To undo a forget before the next commit, see :hg:`add`. |
|
2015 | To undo a forget before the next commit, see :hg:`add`. | |
2016 |
|
2016 | |||
2017 | .. container:: verbose |
|
2017 | .. container:: verbose | |
2018 |
|
2018 | |||
2019 | Examples: |
|
2019 | Examples: | |
2020 |
|
2020 | |||
2021 | - forget newly-added binary files:: |
|
2021 | - forget newly-added binary files:: | |
2022 |
|
2022 | |||
2023 | hg forget "set:added() and binary()" |
|
2023 | hg forget "set:added() and binary()" | |
2024 |
|
2024 | |||
2025 | - forget files that would be excluded by .hgignore:: |
|
2025 | - forget files that would be excluded by .hgignore:: | |
2026 |
|
2026 | |||
2027 | hg forget "set:hgignore()" |
|
2027 | hg forget "set:hgignore()" | |
2028 |
|
2028 | |||
2029 | Returns 0 on success. |
|
2029 | Returns 0 on success. | |
2030 | """ |
|
2030 | """ | |
2031 |
|
2031 | |||
2032 | opts = pycompat.byteskwargs(opts) |
|
2032 | opts = pycompat.byteskwargs(opts) | |
2033 | if not pats: |
|
2033 | if not pats: | |
2034 | raise error.Abort(_('no files specified')) |
|
2034 | raise error.Abort(_('no files specified')) | |
2035 |
|
2035 | |||
2036 | m = scmutil.match(repo[None], pats, opts) |
|
2036 | m = scmutil.match(repo[None], pats, opts) | |
2037 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
2037 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] | |
2038 | return rejected and 1 or 0 |
|
2038 | return rejected and 1 or 0 | |
2039 |
|
2039 | |||
2040 | @command( |
|
2040 | @command( | |
2041 | 'graft', |
|
2041 | 'graft', | |
2042 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
2042 | [('r', 'rev', [], _('revisions to graft'), _('REV')), | |
2043 | ('c', 'continue', False, _('resume interrupted graft')), |
|
2043 | ('c', 'continue', False, _('resume interrupted graft')), | |
2044 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2044 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
2045 | ('', 'log', None, _('append graft info to log message')), |
|
2045 | ('', 'log', None, _('append graft info to log message')), | |
2046 | ('f', 'force', False, _('force graft')), |
|
2046 | ('f', 'force', False, _('force graft')), | |
2047 | ('D', 'currentdate', False, |
|
2047 | ('D', 'currentdate', False, | |
2048 | _('record the current date as commit date')), |
|
2048 | _('record the current date as commit date')), | |
2049 | ('U', 'currentuser', False, |
|
2049 | ('U', 'currentuser', False, | |
2050 | _('record the current user as committer'), _('DATE'))] |
|
2050 | _('record the current user as committer'), _('DATE'))] | |
2051 | + commitopts2 + mergetoolopts + dryrunopts, |
|
2051 | + commitopts2 + mergetoolopts + dryrunopts, | |
2052 | _('[OPTION]... [-r REV]... REV...')) |
|
2052 | _('[OPTION]... [-r REV]... REV...')) | |
2053 | def graft(ui, repo, *revs, **opts): |
|
2053 | def graft(ui, repo, *revs, **opts): | |
2054 | '''copy changes from other branches onto the current branch |
|
2054 | '''copy changes from other branches onto the current branch | |
2055 |
|
2055 | |||
2056 | This command uses Mercurial's merge logic to copy individual |
|
2056 | This command uses Mercurial's merge logic to copy individual | |
2057 | changes from other branches without merging branches in the |
|
2057 | changes from other branches without merging branches in the | |
2058 | history graph. This is sometimes known as 'backporting' or |
|
2058 | history graph. This is sometimes known as 'backporting' or | |
2059 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2059 | 'cherry-picking'. By default, graft will copy user, date, and | |
2060 | description from the source changesets. |
|
2060 | description from the source changesets. | |
2061 |
|
2061 | |||
2062 | Changesets that are ancestors of the current revision, that have |
|
2062 | Changesets that are ancestors of the current revision, that have | |
2063 | already been grafted, or that are merges will be skipped. |
|
2063 | already been grafted, or that are merges will be skipped. | |
2064 |
|
2064 | |||
2065 | If --log is specified, log messages will have a comment appended |
|
2065 | If --log is specified, log messages will have a comment appended | |
2066 | of the form:: |
|
2066 | of the form:: | |
2067 |
|
2067 | |||
2068 | (grafted from CHANGESETHASH) |
|
2068 | (grafted from CHANGESETHASH) | |
2069 |
|
2069 | |||
2070 | If --force is specified, revisions will be grafted even if they |
|
2070 | If --force is specified, revisions will be grafted even if they | |
2071 | are already ancestors of or have been grafted to the destination. |
|
2071 | are already ancestors of or have been grafted to the destination. | |
2072 | This is useful when the revisions have since been backed out. |
|
2072 | This is useful when the revisions have since been backed out. | |
2073 |
|
2073 | |||
2074 | If a graft merge results in conflicts, the graft process is |
|
2074 | If a graft merge results in conflicts, the graft process is | |
2075 | interrupted so that the current merge can be manually resolved. |
|
2075 | interrupted so that the current merge can be manually resolved. | |
2076 | Once all conflicts are addressed, the graft process can be |
|
2076 | Once all conflicts are addressed, the graft process can be | |
2077 | continued with the -c/--continue option. |
|
2077 | continued with the -c/--continue option. | |
2078 |
|
2078 | |||
2079 | .. note:: |
|
2079 | .. note:: | |
2080 |
|
2080 | |||
2081 | The -c/--continue option does not reapply earlier options, except |
|
2081 | The -c/--continue option does not reapply earlier options, except | |
2082 | for --force. |
|
2082 | for --force. | |
2083 |
|
2083 | |||
2084 | .. container:: verbose |
|
2084 | .. container:: verbose | |
2085 |
|
2085 | |||
2086 | Examples: |
|
2086 | Examples: | |
2087 |
|
2087 | |||
2088 | - copy a single change to the stable branch and edit its description:: |
|
2088 | - copy a single change to the stable branch and edit its description:: | |
2089 |
|
2089 | |||
2090 | hg update stable |
|
2090 | hg update stable | |
2091 | hg graft --edit 9393 |
|
2091 | hg graft --edit 9393 | |
2092 |
|
2092 | |||
2093 | - graft a range of changesets with one exception, updating dates:: |
|
2093 | - graft a range of changesets with one exception, updating dates:: | |
2094 |
|
2094 | |||
2095 | hg graft -D "2085::2093 and not 2091" |
|
2095 | hg graft -D "2085::2093 and not 2091" | |
2096 |
|
2096 | |||
2097 | - continue a graft after resolving conflicts:: |
|
2097 | - continue a graft after resolving conflicts:: | |
2098 |
|
2098 | |||
2099 | hg graft -c |
|
2099 | hg graft -c | |
2100 |
|
2100 | |||
2101 | - show the source of a grafted changeset:: |
|
2101 | - show the source of a grafted changeset:: | |
2102 |
|
2102 | |||
2103 | hg log --debug -r . |
|
2103 | hg log --debug -r . | |
2104 |
|
2104 | |||
2105 | - show revisions sorted by date:: |
|
2105 | - show revisions sorted by date:: | |
2106 |
|
2106 | |||
2107 | hg log -r "sort(all(), date)" |
|
2107 | hg log -r "sort(all(), date)" | |
2108 |
|
2108 | |||
2109 | See :hg:`help revisions` for more about specifying revisions. |
|
2109 | See :hg:`help revisions` for more about specifying revisions. | |
2110 |
|
2110 | |||
2111 | Returns 0 on successful completion. |
|
2111 | Returns 0 on successful completion. | |
2112 | ''' |
|
2112 | ''' | |
2113 | with repo.wlock(): |
|
2113 | with repo.wlock(): | |
2114 | return _dograft(ui, repo, *revs, **opts) |
|
2114 | return _dograft(ui, repo, *revs, **opts) | |
2115 |
|
2115 | |||
2116 | def _dograft(ui, repo, *revs, **opts): |
|
2116 | def _dograft(ui, repo, *revs, **opts): | |
2117 | opts = pycompat.byteskwargs(opts) |
|
2117 | opts = pycompat.byteskwargs(opts) | |
2118 | if revs and opts.get('rev'): |
|
2118 | if revs and opts.get('rev'): | |
2119 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' |
|
2119 | ui.warn(_('warning: inconsistent use of --rev might give unexpected ' | |
2120 | 'revision ordering!\n')) |
|
2120 | 'revision ordering!\n')) | |
2121 |
|
2121 | |||
2122 | revs = list(revs) |
|
2122 | revs = list(revs) | |
2123 | revs.extend(opts.get('rev')) |
|
2123 | revs.extend(opts.get('rev')) | |
2124 |
|
2124 | |||
2125 | if not opts.get('user') and opts.get('currentuser'): |
|
2125 | if not opts.get('user') and opts.get('currentuser'): | |
2126 | opts['user'] = ui.username() |
|
2126 | opts['user'] = ui.username() | |
2127 | if not opts.get('date') and opts.get('currentdate'): |
|
2127 | if not opts.get('date') and opts.get('currentdate'): | |
2128 | opts['date'] = "%d %d" % util.makedate() |
|
2128 | opts['date'] = "%d %d" % util.makedate() | |
2129 |
|
2129 | |||
2130 | editor = cmdutil.getcommiteditor(editform='graft', |
|
2130 | editor = cmdutil.getcommiteditor(editform='graft', | |
2131 | **pycompat.strkwargs(opts)) |
|
2131 | **pycompat.strkwargs(opts)) | |
2132 |
|
2132 | |||
2133 | cont = False |
|
2133 | cont = False | |
2134 | if opts.get('continue'): |
|
2134 | if opts.get('continue'): | |
2135 | cont = True |
|
2135 | cont = True | |
2136 | if revs: |
|
2136 | if revs: | |
2137 | raise error.Abort(_("can't specify --continue and revisions")) |
|
2137 | raise error.Abort(_("can't specify --continue and revisions")) | |
2138 | # read in unfinished revisions |
|
2138 | # read in unfinished revisions | |
2139 | try: |
|
2139 | try: | |
2140 | nodes = repo.vfs.read('graftstate').splitlines() |
|
2140 | nodes = repo.vfs.read('graftstate').splitlines() | |
2141 | revs = [repo[node].rev() for node in nodes] |
|
2141 | revs = [repo[node].rev() for node in nodes] | |
2142 | except IOError as inst: |
|
2142 | except IOError as inst: | |
2143 | if inst.errno != errno.ENOENT: |
|
2143 | if inst.errno != errno.ENOENT: | |
2144 | raise |
|
2144 | raise | |
2145 | cmdutil.wrongtooltocontinue(repo, _('graft')) |
|
2145 | cmdutil.wrongtooltocontinue(repo, _('graft')) | |
2146 | else: |
|
2146 | else: | |
2147 | cmdutil.checkunfinished(repo) |
|
2147 | cmdutil.checkunfinished(repo) | |
2148 | cmdutil.bailifchanged(repo) |
|
2148 | cmdutil.bailifchanged(repo) | |
2149 | if not revs: |
|
2149 | if not revs: | |
2150 | raise error.Abort(_('no revisions specified')) |
|
2150 | raise error.Abort(_('no revisions specified')) | |
2151 | revs = scmutil.revrange(repo, revs) |
|
2151 | revs = scmutil.revrange(repo, revs) | |
2152 |
|
2152 | |||
2153 | skipped = set() |
|
2153 | skipped = set() | |
2154 | # check for merges |
|
2154 | # check for merges | |
2155 | for rev in repo.revs('%ld and merge()', revs): |
|
2155 | for rev in repo.revs('%ld and merge()', revs): | |
2156 | ui.warn(_('skipping ungraftable merge revision %d\n') % rev) |
|
2156 | ui.warn(_('skipping ungraftable merge revision %d\n') % rev) | |
2157 | skipped.add(rev) |
|
2157 | skipped.add(rev) | |
2158 | revs = [r for r in revs if r not in skipped] |
|
2158 | revs = [r for r in revs if r not in skipped] | |
2159 | if not revs: |
|
2159 | if not revs: | |
2160 | return -1 |
|
2160 | return -1 | |
2161 |
|
2161 | |||
2162 | # Don't check in the --continue case, in effect retaining --force across |
|
2162 | # Don't check in the --continue case, in effect retaining --force across | |
2163 | # --continues. That's because without --force, any revisions we decided to |
|
2163 | # --continues. That's because without --force, any revisions we decided to | |
2164 | # skip would have been filtered out here, so they wouldn't have made their |
|
2164 | # skip would have been filtered out here, so they wouldn't have made their | |
2165 | # way to the graftstate. With --force, any revisions we would have otherwise |
|
2165 | # way to the graftstate. With --force, any revisions we would have otherwise | |
2166 | # skipped would not have been filtered out, and if they hadn't been applied |
|
2166 | # skipped would not have been filtered out, and if they hadn't been applied | |
2167 | # already, they'd have been in the graftstate. |
|
2167 | # already, they'd have been in the graftstate. | |
2168 | if not (cont or opts.get('force')): |
|
2168 | if not (cont or opts.get('force')): | |
2169 | # check for ancestors of dest branch |
|
2169 | # check for ancestors of dest branch | |
2170 | crev = repo['.'].rev() |
|
2170 | crev = repo['.'].rev() | |
2171 | ancestors = repo.changelog.ancestors([crev], inclusive=True) |
|
2171 | ancestors = repo.changelog.ancestors([crev], inclusive=True) | |
2172 | # XXX make this lazy in the future |
|
2172 | # XXX make this lazy in the future | |
2173 | # don't mutate while iterating, create a copy |
|
2173 | # don't mutate while iterating, create a copy | |
2174 | for rev in list(revs): |
|
2174 | for rev in list(revs): | |
2175 | if rev in ancestors: |
|
2175 | if rev in ancestors: | |
2176 | ui.warn(_('skipping ancestor revision %d:%s\n') % |
|
2176 | ui.warn(_('skipping ancestor revision %d:%s\n') % | |
2177 | (rev, repo[rev])) |
|
2177 | (rev, repo[rev])) | |
2178 | # XXX remove on list is slow |
|
2178 | # XXX remove on list is slow | |
2179 | revs.remove(rev) |
|
2179 | revs.remove(rev) | |
2180 | if not revs: |
|
2180 | if not revs: | |
2181 | return -1 |
|
2181 | return -1 | |
2182 |
|
2182 | |||
2183 | # analyze revs for earlier grafts |
|
2183 | # analyze revs for earlier grafts | |
2184 | ids = {} |
|
2184 | ids = {} | |
2185 | for ctx in repo.set("%ld", revs): |
|
2185 | for ctx in repo.set("%ld", revs): | |
2186 | ids[ctx.hex()] = ctx.rev() |
|
2186 | ids[ctx.hex()] = ctx.rev() | |
2187 | n = ctx.extra().get('source') |
|
2187 | n = ctx.extra().get('source') | |
2188 | if n: |
|
2188 | if n: | |
2189 | ids[n] = ctx.rev() |
|
2189 | ids[n] = ctx.rev() | |
2190 |
|
2190 | |||
2191 | # check ancestors for earlier grafts |
|
2191 | # check ancestors for earlier grafts | |
2192 | ui.debug('scanning for duplicate grafts\n') |
|
2192 | ui.debug('scanning for duplicate grafts\n') | |
2193 |
|
2193 | |||
2194 | # The only changesets we can be sure doesn't contain grafts of any |
|
2194 | # The only changesets we can be sure doesn't contain grafts of any | |
2195 | # revs, are the ones that are common ancestors of *all* revs: |
|
2195 | # revs, are the ones that are common ancestors of *all* revs: | |
2196 | for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): |
|
2196 | for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs): | |
2197 | ctx = repo[rev] |
|
2197 | ctx = repo[rev] | |
2198 | n = ctx.extra().get('source') |
|
2198 | n = ctx.extra().get('source') | |
2199 | if n in ids: |
|
2199 | if n in ids: | |
2200 | try: |
|
2200 | try: | |
2201 | r = repo[n].rev() |
|
2201 | r = repo[n].rev() | |
2202 | except error.RepoLookupError: |
|
2202 | except error.RepoLookupError: | |
2203 | r = None |
|
2203 | r = None | |
2204 | if r in revs: |
|
2204 | if r in revs: | |
2205 | ui.warn(_('skipping revision %d:%s ' |
|
2205 | ui.warn(_('skipping revision %d:%s ' | |
2206 | '(already grafted to %d:%s)\n') |
|
2206 | '(already grafted to %d:%s)\n') | |
2207 | % (r, repo[r], rev, ctx)) |
|
2207 | % (r, repo[r], rev, ctx)) | |
2208 | revs.remove(r) |
|
2208 | revs.remove(r) | |
2209 | elif ids[n] in revs: |
|
2209 | elif ids[n] in revs: | |
2210 | if r is None: |
|
2210 | if r is None: | |
2211 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2211 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2212 | '(%d:%s also has unknown origin %s)\n') |
|
2212 | '(%d:%s also has unknown origin %s)\n') | |
2213 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) |
|
2213 | % (ids[n], repo[ids[n]], rev, ctx, n[:12])) | |
2214 | else: |
|
2214 | else: | |
2215 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2215 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2216 | '(%d:%s also has origin %d:%s)\n') |
|
2216 | '(%d:%s also has origin %d:%s)\n') | |
2217 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) |
|
2217 | % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])) | |
2218 | revs.remove(ids[n]) |
|
2218 | revs.remove(ids[n]) | |
2219 | elif ctx.hex() in ids: |
|
2219 | elif ctx.hex() in ids: | |
2220 | r = ids[ctx.hex()] |
|
2220 | r = ids[ctx.hex()] | |
2221 | ui.warn(_('skipping already grafted revision %d:%s ' |
|
2221 | ui.warn(_('skipping already grafted revision %d:%s ' | |
2222 | '(was grafted from %d:%s)\n') % |
|
2222 | '(was grafted from %d:%s)\n') % | |
2223 | (r, repo[r], rev, ctx)) |
|
2223 | (r, repo[r], rev, ctx)) | |
2224 | revs.remove(r) |
|
2224 | revs.remove(r) | |
2225 | if not revs: |
|
2225 | if not revs: | |
2226 | return -1 |
|
2226 | return -1 | |
2227 |
|
2227 | |||
2228 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
2228 | for pos, ctx in enumerate(repo.set("%ld", revs)): | |
2229 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
|
2229 | desc = '%d:%s "%s"' % (ctx.rev(), ctx, | |
2230 | ctx.description().split('\n', 1)[0]) |
|
2230 | ctx.description().split('\n', 1)[0]) | |
2231 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
|
2231 | names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) | |
2232 | if names: |
|
2232 | if names: | |
2233 | desc += ' (%s)' % ' '.join(names) |
|
2233 | desc += ' (%s)' % ' '.join(names) | |
2234 | ui.status(_('grafting %s\n') % desc) |
|
2234 | ui.status(_('grafting %s\n') % desc) | |
2235 | if opts.get('dry_run'): |
|
2235 | if opts.get('dry_run'): | |
2236 | continue |
|
2236 | continue | |
2237 |
|
2237 | |||
2238 | source = ctx.extra().get('source') |
|
2238 | source = ctx.extra().get('source') | |
2239 | extra = {} |
|
2239 | extra = {} | |
2240 | if source: |
|
2240 | if source: | |
2241 | extra['source'] = source |
|
2241 | extra['source'] = source | |
2242 | extra['intermediate-source'] = ctx.hex() |
|
2242 | extra['intermediate-source'] = ctx.hex() | |
2243 | else: |
|
2243 | else: | |
2244 | extra['source'] = ctx.hex() |
|
2244 | extra['source'] = ctx.hex() | |
2245 | user = ctx.user() |
|
2245 | user = ctx.user() | |
2246 | if opts.get('user'): |
|
2246 | if opts.get('user'): | |
2247 | user = opts['user'] |
|
2247 | user = opts['user'] | |
2248 | date = ctx.date() |
|
2248 | date = ctx.date() | |
2249 | if opts.get('date'): |
|
2249 | if opts.get('date'): | |
2250 | date = opts['date'] |
|
2250 | date = opts['date'] | |
2251 | message = ctx.description() |
|
2251 | message = ctx.description() | |
2252 | if opts.get('log'): |
|
2252 | if opts.get('log'): | |
2253 | message += '\n(grafted from %s)' % ctx.hex() |
|
2253 | message += '\n(grafted from %s)' % ctx.hex() | |
2254 |
|
2254 | |||
2255 | # we don't merge the first commit when continuing |
|
2255 | # we don't merge the first commit when continuing | |
2256 | if not cont: |
|
2256 | if not cont: | |
2257 | # perform the graft merge with p1(rev) as 'ancestor' |
|
2257 | # perform the graft merge with p1(rev) as 'ancestor' | |
2258 | try: |
|
2258 | try: | |
2259 | # ui.forcemerge is an internal variable, do not document |
|
2259 | # ui.forcemerge is an internal variable, do not document | |
2260 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
2260 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |
2261 | 'graft') |
|
2261 | 'graft') | |
2262 | stats = mergemod.graft(repo, ctx, ctx.p1(), |
|
2262 | stats = mergemod.graft(repo, ctx, ctx.p1(), | |
2263 | ['local', 'graft']) |
|
2263 | ['local', 'graft']) | |
2264 | finally: |
|
2264 | finally: | |
2265 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') |
|
2265 | repo.ui.setconfig('ui', 'forcemerge', '', 'graft') | |
2266 | # report any conflicts |
|
2266 | # report any conflicts | |
2267 | if stats and stats[3] > 0: |
|
2267 | if stats and stats[3] > 0: | |
2268 | # write out state for --continue |
|
2268 | # write out state for --continue | |
2269 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
2269 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] | |
2270 | repo.vfs.write('graftstate', ''.join(nodelines)) |
|
2270 | repo.vfs.write('graftstate', ''.join(nodelines)) | |
2271 | extra = '' |
|
2271 | extra = '' | |
2272 | if opts.get('user'): |
|
2272 | if opts.get('user'): | |
2273 | extra += ' --user %s' % util.shellquote(opts['user']) |
|
2273 | extra += ' --user %s' % util.shellquote(opts['user']) | |
2274 | if opts.get('date'): |
|
2274 | if opts.get('date'): | |
2275 | extra += ' --date %s' % util.shellquote(opts['date']) |
|
2275 | extra += ' --date %s' % util.shellquote(opts['date']) | |
2276 | if opts.get('log'): |
|
2276 | if opts.get('log'): | |
2277 | extra += ' --log' |
|
2277 | extra += ' --log' | |
2278 | hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra |
|
2278 | hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra | |
2279 | raise error.Abort( |
|
2279 | raise error.Abort( | |
2280 | _("unresolved conflicts, can't continue"), |
|
2280 | _("unresolved conflicts, can't continue"), | |
2281 | hint=hint) |
|
2281 | hint=hint) | |
2282 | else: |
|
2282 | else: | |
2283 | cont = False |
|
2283 | cont = False | |
2284 |
|
2284 | |||
2285 | # commit |
|
2285 | # commit | |
2286 | node = repo.commit(text=message, user=user, |
|
2286 | node = repo.commit(text=message, user=user, | |
2287 | date=date, extra=extra, editor=editor) |
|
2287 | date=date, extra=extra, editor=editor) | |
2288 | if node is None: |
|
2288 | if node is None: | |
2289 | ui.warn( |
|
2289 | ui.warn( | |
2290 | _('note: graft of %d:%s created no changes to commit\n') % |
|
2290 | _('note: graft of %d:%s created no changes to commit\n') % | |
2291 | (ctx.rev(), ctx)) |
|
2291 | (ctx.rev(), ctx)) | |
2292 |
|
2292 | |||
2293 | # remove state when we complete successfully |
|
2293 | # remove state when we complete successfully | |
2294 | if not opts.get('dry_run'): |
|
2294 | if not opts.get('dry_run'): | |
2295 | repo.vfs.unlinkpath('graftstate', ignoremissing=True) |
|
2295 | repo.vfs.unlinkpath('graftstate', ignoremissing=True) | |
2296 |
|
2296 | |||
2297 | return 0 |
|
2297 | return 0 | |
2298 |
|
2298 | |||
2299 | @command('grep', |
|
2299 | @command('grep', | |
2300 | [('0', 'print0', None, _('end fields with NUL')), |
|
2300 | [('0', 'print0', None, _('end fields with NUL')), | |
2301 | ('', 'all', None, _('print all revisions that match')), |
|
2301 | ('', 'all', None, _('print all revisions that match')), | |
2302 | ('a', 'text', None, _('treat all files as text')), |
|
2302 | ('a', 'text', None, _('treat all files as text')), | |
2303 | ('f', 'follow', None, |
|
2303 | ('f', 'follow', None, | |
2304 | _('follow changeset history,' |
|
2304 | _('follow changeset history,' | |
2305 | ' or file history across copies and renames')), |
|
2305 | ' or file history across copies and renames')), | |
2306 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2306 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2307 | ('l', 'files-with-matches', None, |
|
2307 | ('l', 'files-with-matches', None, | |
2308 | _('print only filenames and revisions that match')), |
|
2308 | _('print only filenames and revisions that match')), | |
2309 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2309 | ('n', 'line-number', None, _('print matching line numbers')), | |
2310 | ('r', 'rev', [], |
|
2310 | ('r', 'rev', [], | |
2311 | _('only search files changed within revision range'), _('REV')), |
|
2311 | _('only search files changed within revision range'), _('REV')), | |
2312 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2312 | ('u', 'user', None, _('list the author (long with -v)')), | |
2313 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2313 | ('d', 'date', None, _('list the date (short with -q)')), | |
2314 | ] + formatteropts + walkopts, |
|
2314 | ] + formatteropts + walkopts, | |
2315 | _('[OPTION]... PATTERN [FILE]...'), |
|
2315 | _('[OPTION]... PATTERN [FILE]...'), | |
2316 | inferrepo=True) |
|
2316 | inferrepo=True) | |
2317 | def grep(ui, repo, pattern, *pats, **opts): |
|
2317 | def grep(ui, repo, pattern, *pats, **opts): | |
2318 | """search revision history for a pattern in specified files |
|
2318 | """search revision history for a pattern in specified files | |
2319 |
|
2319 | |||
2320 | Search revision history for a regular expression in the specified |
|
2320 | Search revision history for a regular expression in the specified | |
2321 | files or the entire project. |
|
2321 | files or the entire project. | |
2322 |
|
2322 | |||
2323 | By default, grep prints the most recent revision number for each |
|
2323 | By default, grep prints the most recent revision number for each | |
2324 | file in which it finds a match. To get it to print every revision |
|
2324 | file in which it finds a match. To get it to print every revision | |
2325 | that contains a change in match status ("-" for a match that becomes |
|
2325 | that contains a change in match status ("-" for a match that becomes | |
2326 | a non-match, or "+" for a non-match that becomes a match), use the |
|
2326 | a non-match, or "+" for a non-match that becomes a match), use the | |
2327 | --all flag. |
|
2327 | --all flag. | |
2328 |
|
2328 | |||
2329 | PATTERN can be any Python (roughly Perl-compatible) regular |
|
2329 | PATTERN can be any Python (roughly Perl-compatible) regular | |
2330 | expression. |
|
2330 | expression. | |
2331 |
|
2331 | |||
2332 | If no FILEs are specified (and -f/--follow isn't set), all files in |
|
2332 | If no FILEs are specified (and -f/--follow isn't set), all files in | |
2333 | the repository are searched, including those that don't exist in the |
|
2333 | the repository are searched, including those that don't exist in the | |
2334 | current branch or have been deleted in a prior changeset. |
|
2334 | current branch or have been deleted in a prior changeset. | |
2335 |
|
2335 | |||
2336 | Returns 0 if a match is found, 1 otherwise. |
|
2336 | Returns 0 if a match is found, 1 otherwise. | |
2337 | """ |
|
2337 | """ | |
2338 | opts = pycompat.byteskwargs(opts) |
|
2338 | opts = pycompat.byteskwargs(opts) | |
2339 | reflags = re.M |
|
2339 | reflags = re.M | |
2340 | if opts.get('ignore_case'): |
|
2340 | if opts.get('ignore_case'): | |
2341 | reflags |= re.I |
|
2341 | reflags |= re.I | |
2342 | try: |
|
2342 | try: | |
2343 | regexp = util.re.compile(pattern, reflags) |
|
2343 | regexp = util.re.compile(pattern, reflags) | |
2344 | except re.error as inst: |
|
2344 | except re.error as inst: | |
2345 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
2345 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) | |
2346 | return 1 |
|
2346 | return 1 | |
2347 | sep, eol = ':', '\n' |
|
2347 | sep, eol = ':', '\n' | |
2348 | if opts.get('print0'): |
|
2348 | if opts.get('print0'): | |
2349 | sep = eol = '\0' |
|
2349 | sep = eol = '\0' | |
2350 |
|
2350 | |||
2351 | getfile = util.lrucachefunc(repo.file) |
|
2351 | getfile = util.lrucachefunc(repo.file) | |
2352 |
|
2352 | |||
2353 | def matchlines(body): |
|
2353 | def matchlines(body): | |
2354 | begin = 0 |
|
2354 | begin = 0 | |
2355 | linenum = 0 |
|
2355 | linenum = 0 | |
2356 | while begin < len(body): |
|
2356 | while begin < len(body): | |
2357 | match = regexp.search(body, begin) |
|
2357 | match = regexp.search(body, begin) | |
2358 | if not match: |
|
2358 | if not match: | |
2359 | break |
|
2359 | break | |
2360 | mstart, mend = match.span() |
|
2360 | mstart, mend = match.span() | |
2361 | linenum += body.count('\n', begin, mstart) + 1 |
|
2361 | linenum += body.count('\n', begin, mstart) + 1 | |
2362 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2362 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
2363 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
2363 | begin = body.find('\n', mend) + 1 or len(body) + 1 | |
2364 | lend = begin - 1 |
|
2364 | lend = begin - 1 | |
2365 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2365 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
2366 |
|
2366 | |||
2367 | class linestate(object): |
|
2367 | class linestate(object): | |
2368 | def __init__(self, line, linenum, colstart, colend): |
|
2368 | def __init__(self, line, linenum, colstart, colend): | |
2369 | self.line = line |
|
2369 | self.line = line | |
2370 | self.linenum = linenum |
|
2370 | self.linenum = linenum | |
2371 | self.colstart = colstart |
|
2371 | self.colstart = colstart | |
2372 | self.colend = colend |
|
2372 | self.colend = colend | |
2373 |
|
2373 | |||
2374 | def __hash__(self): |
|
2374 | def __hash__(self): | |
2375 | return hash((self.linenum, self.line)) |
|
2375 | return hash((self.linenum, self.line)) | |
2376 |
|
2376 | |||
2377 | def __eq__(self, other): |
|
2377 | def __eq__(self, other): | |
2378 | return self.line == other.line |
|
2378 | return self.line == other.line | |
2379 |
|
2379 | |||
2380 | def findpos(self): |
|
2380 | def findpos(self): | |
2381 | """Iterate all (start, end) indices of matches""" |
|
2381 | """Iterate all (start, end) indices of matches""" | |
2382 | yield self.colstart, self.colend |
|
2382 | yield self.colstart, self.colend | |
2383 | p = self.colend |
|
2383 | p = self.colend | |
2384 | while p < len(self.line): |
|
2384 | while p < len(self.line): | |
2385 | m = regexp.search(self.line, p) |
|
2385 | m = regexp.search(self.line, p) | |
2386 | if not m: |
|
2386 | if not m: | |
2387 | break |
|
2387 | break | |
2388 | yield m.span() |
|
2388 | yield m.span() | |
2389 | p = m.end() |
|
2389 | p = m.end() | |
2390 |
|
2390 | |||
2391 | matches = {} |
|
2391 | matches = {} | |
2392 | copies = {} |
|
2392 | copies = {} | |
2393 | def grepbody(fn, rev, body): |
|
2393 | def grepbody(fn, rev, body): | |
2394 | matches[rev].setdefault(fn, []) |
|
2394 | matches[rev].setdefault(fn, []) | |
2395 | m = matches[rev][fn] |
|
2395 | m = matches[rev][fn] | |
2396 | for lnum, cstart, cend, line in matchlines(body): |
|
2396 | for lnum, cstart, cend, line in matchlines(body): | |
2397 | s = linestate(line, lnum, cstart, cend) |
|
2397 | s = linestate(line, lnum, cstart, cend) | |
2398 | m.append(s) |
|
2398 | m.append(s) | |
2399 |
|
2399 | |||
2400 | def difflinestates(a, b): |
|
2400 | def difflinestates(a, b): | |
2401 | sm = difflib.SequenceMatcher(None, a, b) |
|
2401 | sm = difflib.SequenceMatcher(None, a, b) | |
2402 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2402 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | |
2403 | if tag == 'insert': |
|
2403 | if tag == 'insert': | |
2404 | for i in xrange(blo, bhi): |
|
2404 | for i in xrange(blo, bhi): | |
2405 | yield ('+', b[i]) |
|
2405 | yield ('+', b[i]) | |
2406 | elif tag == 'delete': |
|
2406 | elif tag == 'delete': | |
2407 | for i in xrange(alo, ahi): |
|
2407 | for i in xrange(alo, ahi): | |
2408 | yield ('-', a[i]) |
|
2408 | yield ('-', a[i]) | |
2409 | elif tag == 'replace': |
|
2409 | elif tag == 'replace': | |
2410 | for i in xrange(alo, ahi): |
|
2410 | for i in xrange(alo, ahi): | |
2411 | yield ('-', a[i]) |
|
2411 | yield ('-', a[i]) | |
2412 | for i in xrange(blo, bhi): |
|
2412 | for i in xrange(blo, bhi): | |
2413 | yield ('+', b[i]) |
|
2413 | yield ('+', b[i]) | |
2414 |
|
2414 | |||
2415 | def display(fm, fn, ctx, pstates, states): |
|
2415 | def display(fm, fn, ctx, pstates, states): | |
2416 | rev = ctx.rev() |
|
2416 | rev = ctx.rev() | |
2417 | if fm.isplain(): |
|
2417 | if fm.isplain(): | |
2418 | formatuser = ui.shortuser |
|
2418 | formatuser = ui.shortuser | |
2419 | else: |
|
2419 | else: | |
2420 | formatuser = str |
|
2420 | formatuser = str | |
2421 | if ui.quiet: |
|
2421 | if ui.quiet: | |
2422 | datefmt = '%Y-%m-%d' |
|
2422 | datefmt = '%Y-%m-%d' | |
2423 | else: |
|
2423 | else: | |
2424 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' |
|
2424 | datefmt = '%a %b %d %H:%M:%S %Y %1%2' | |
2425 | found = False |
|
2425 | found = False | |
2426 | @util.cachefunc |
|
2426 | @util.cachefunc | |
2427 | def binary(): |
|
2427 | def binary(): | |
2428 | flog = getfile(fn) |
|
2428 | flog = getfile(fn) | |
2429 | return util.binary(flog.read(ctx.filenode(fn))) |
|
2429 | return util.binary(flog.read(ctx.filenode(fn))) | |
2430 |
|
2430 | |||
2431 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} |
|
2431 | fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'} | |
2432 | if opts.get('all'): |
|
2432 | if opts.get('all'): | |
2433 | iter = difflinestates(pstates, states) |
|
2433 | iter = difflinestates(pstates, states) | |
2434 | else: |
|
2434 | else: | |
2435 | iter = [('', l) for l in states] |
|
2435 | iter = [('', l) for l in states] | |
2436 | for change, l in iter: |
|
2436 | for change, l in iter: | |
2437 | fm.startitem() |
|
2437 | fm.startitem() | |
2438 | fm.data(node=fm.hexfunc(ctx.node())) |
|
2438 | fm.data(node=fm.hexfunc(ctx.node())) | |
2439 | cols = [ |
|
2439 | cols = [ | |
2440 | ('filename', fn, True), |
|
2440 | ('filename', fn, True), | |
2441 | ('rev', rev, True), |
|
2441 | ('rev', rev, True), | |
2442 | ('linenumber', l.linenum, opts.get('line_number')), |
|
2442 | ('linenumber', l.linenum, opts.get('line_number')), | |
2443 | ] |
|
2443 | ] | |
2444 | if opts.get('all'): |
|
2444 | if opts.get('all'): | |
2445 | cols.append(('change', change, True)) |
|
2445 | cols.append(('change', change, True)) | |
2446 | cols.extend([ |
|
2446 | cols.extend([ | |
2447 | ('user', formatuser(ctx.user()), opts.get('user')), |
|
2447 | ('user', formatuser(ctx.user()), opts.get('user')), | |
2448 | ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), |
|
2448 | ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')), | |
2449 | ]) |
|
2449 | ]) | |
2450 | lastcol = next(name for name, data, cond in reversed(cols) if cond) |
|
2450 | lastcol = next(name for name, data, cond in reversed(cols) if cond) | |
2451 | for name, data, cond in cols: |
|
2451 | for name, data, cond in cols: | |
2452 | field = fieldnamemap.get(name, name) |
|
2452 | field = fieldnamemap.get(name, name) | |
2453 | fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) |
|
2453 | fm.condwrite(cond, field, '%s', data, label='grep.%s' % name) | |
2454 | if cond and name != lastcol: |
|
2454 | if cond and name != lastcol: | |
2455 | fm.plain(sep, label='grep.sep') |
|
2455 | fm.plain(sep, label='grep.sep') | |
2456 | if not opts.get('files_with_matches'): |
|
2456 | if not opts.get('files_with_matches'): | |
2457 | fm.plain(sep, label='grep.sep') |
|
2457 | fm.plain(sep, label='grep.sep') | |
2458 | if not opts.get('text') and binary(): |
|
2458 | if not opts.get('text') and binary(): | |
2459 | fm.plain(_(" Binary file matches")) |
|
2459 | fm.plain(_(" Binary file matches")) | |
2460 | else: |
|
2460 | else: | |
2461 | displaymatches(fm.nested('texts'), l) |
|
2461 | displaymatches(fm.nested('texts'), l) | |
2462 | fm.plain(eol) |
|
2462 | fm.plain(eol) | |
2463 | found = True |
|
2463 | found = True | |
2464 | if opts.get('files_with_matches'): |
|
2464 | if opts.get('files_with_matches'): | |
2465 | break |
|
2465 | break | |
2466 | return found |
|
2466 | return found | |
2467 |
|
2467 | |||
2468 | def displaymatches(fm, l): |
|
2468 | def displaymatches(fm, l): | |
2469 | p = 0 |
|
2469 | p = 0 | |
2470 | for s, e in l.findpos(): |
|
2470 | for s, e in l.findpos(): | |
2471 | if p < s: |
|
2471 | if p < s: | |
2472 | fm.startitem() |
|
2472 | fm.startitem() | |
2473 | fm.write('text', '%s', l.line[p:s]) |
|
2473 | fm.write('text', '%s', l.line[p:s]) | |
2474 | fm.data(matched=False) |
|
2474 | fm.data(matched=False) | |
2475 | fm.startitem() |
|
2475 | fm.startitem() | |
2476 | fm.write('text', '%s', l.line[s:e], label='grep.match') |
|
2476 | fm.write('text', '%s', l.line[s:e], label='grep.match') | |
2477 | fm.data(matched=True) |
|
2477 | fm.data(matched=True) | |
2478 | p = e |
|
2478 | p = e | |
2479 | if p < len(l.line): |
|
2479 | if p < len(l.line): | |
2480 | fm.startitem() |
|
2480 | fm.startitem() | |
2481 | fm.write('text', '%s', l.line[p:]) |
|
2481 | fm.write('text', '%s', l.line[p:]) | |
2482 | fm.data(matched=False) |
|
2482 | fm.data(matched=False) | |
2483 | fm.end() |
|
2483 | fm.end() | |
2484 |
|
2484 | |||
2485 | skip = {} |
|
2485 | skip = {} | |
2486 | revfiles = {} |
|
2486 | revfiles = {} | |
2487 | match = scmutil.match(repo[None], pats, opts) |
|
2487 | match = scmutil.match(repo[None], pats, opts) | |
2488 | found = False |
|
2488 | found = False | |
2489 | follow = opts.get('follow') |
|
2489 | follow = opts.get('follow') | |
2490 |
|
2490 | |||
2491 | def prep(ctx, fns): |
|
2491 | def prep(ctx, fns): | |
2492 | rev = ctx.rev() |
|
2492 | rev = ctx.rev() | |
2493 | pctx = ctx.p1() |
|
2493 | pctx = ctx.p1() | |
2494 | parent = pctx.rev() |
|
2494 | parent = pctx.rev() | |
2495 | matches.setdefault(rev, {}) |
|
2495 | matches.setdefault(rev, {}) | |
2496 | matches.setdefault(parent, {}) |
|
2496 | matches.setdefault(parent, {}) | |
2497 | files = revfiles.setdefault(rev, []) |
|
2497 | files = revfiles.setdefault(rev, []) | |
2498 | for fn in fns: |
|
2498 | for fn in fns: | |
2499 | flog = getfile(fn) |
|
2499 | flog = getfile(fn) | |
2500 | try: |
|
2500 | try: | |
2501 | fnode = ctx.filenode(fn) |
|
2501 | fnode = ctx.filenode(fn) | |
2502 | except error.LookupError: |
|
2502 | except error.LookupError: | |
2503 | continue |
|
2503 | continue | |
2504 |
|
2504 | |||
2505 | copied = flog.renamed(fnode) |
|
2505 | copied = flog.renamed(fnode) | |
2506 | copy = follow and copied and copied[0] |
|
2506 | copy = follow and copied and copied[0] | |
2507 | if copy: |
|
2507 | if copy: | |
2508 | copies.setdefault(rev, {})[fn] = copy |
|
2508 | copies.setdefault(rev, {})[fn] = copy | |
2509 | if fn in skip: |
|
2509 | if fn in skip: | |
2510 | if copy: |
|
2510 | if copy: | |
2511 | skip[copy] = True |
|
2511 | skip[copy] = True | |
2512 | continue |
|
2512 | continue | |
2513 | files.append(fn) |
|
2513 | files.append(fn) | |
2514 |
|
2514 | |||
2515 | if fn not in matches[rev]: |
|
2515 | if fn not in matches[rev]: | |
2516 | grepbody(fn, rev, flog.read(fnode)) |
|
2516 | grepbody(fn, rev, flog.read(fnode)) | |
2517 |
|
2517 | |||
2518 | pfn = copy or fn |
|
2518 | pfn = copy or fn | |
2519 | if pfn not in matches[parent]: |
|
2519 | if pfn not in matches[parent]: | |
2520 | try: |
|
2520 | try: | |
2521 | fnode = pctx.filenode(pfn) |
|
2521 | fnode = pctx.filenode(pfn) | |
2522 | grepbody(pfn, parent, flog.read(fnode)) |
|
2522 | grepbody(pfn, parent, flog.read(fnode)) | |
2523 | except error.LookupError: |
|
2523 | except error.LookupError: | |
2524 | pass |
|
2524 | pass | |
2525 |
|
2525 | |||
2526 | ui.pager('grep') |
|
2526 | ui.pager('grep') | |
2527 | fm = ui.formatter('grep', opts) |
|
2527 | fm = ui.formatter('grep', opts) | |
2528 | for ctx in cmdutil.walkchangerevs(repo, match, opts, prep): |
|
2528 | for ctx in cmdutil.walkchangerevs(repo, match, opts, prep): | |
2529 | rev = ctx.rev() |
|
2529 | rev = ctx.rev() | |
2530 | parent = ctx.p1().rev() |
|
2530 | parent = ctx.p1().rev() | |
2531 | for fn in sorted(revfiles.get(rev, [])): |
|
2531 | for fn in sorted(revfiles.get(rev, [])): | |
2532 | states = matches[rev][fn] |
|
2532 | states = matches[rev][fn] | |
2533 | copy = copies.get(rev, {}).get(fn) |
|
2533 | copy = copies.get(rev, {}).get(fn) | |
2534 | if fn in skip: |
|
2534 | if fn in skip: | |
2535 | if copy: |
|
2535 | if copy: | |
2536 | skip[copy] = True |
|
2536 | skip[copy] = True | |
2537 | continue |
|
2537 | continue | |
2538 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
2538 | pstates = matches.get(parent, {}).get(copy or fn, []) | |
2539 | if pstates or states: |
|
2539 | if pstates or states: | |
2540 | r = display(fm, fn, ctx, pstates, states) |
|
2540 | r = display(fm, fn, ctx, pstates, states) | |
2541 | found = found or r |
|
2541 | found = found or r | |
2542 | if r and not opts.get('all'): |
|
2542 | if r and not opts.get('all'): | |
2543 | skip[fn] = True |
|
2543 | skip[fn] = True | |
2544 | if copy: |
|
2544 | if copy: | |
2545 | skip[copy] = True |
|
2545 | skip[copy] = True | |
2546 | del matches[rev] |
|
2546 | del matches[rev] | |
2547 | del revfiles[rev] |
|
2547 | del revfiles[rev] | |
2548 | fm.end() |
|
2548 | fm.end() | |
2549 |
|
2549 | |||
2550 | return not found |
|
2550 | return not found | |
2551 |
|
2551 | |||
2552 | @command('heads', |
|
2552 | @command('heads', | |
2553 | [('r', 'rev', '', |
|
2553 | [('r', 'rev', '', | |
2554 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
2554 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), | |
2555 | ('t', 'topo', False, _('show topological heads only')), |
|
2555 | ('t', 'topo', False, _('show topological heads only')), | |
2556 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
2556 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), | |
2557 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
2557 | ('c', 'closed', False, _('show normal and closed branch heads')), | |
2558 | ] + templateopts, |
|
2558 | ] + templateopts, | |
2559 | _('[-ct] [-r STARTREV] [REV]...')) |
|
2559 | _('[-ct] [-r STARTREV] [REV]...')) | |
2560 | def heads(ui, repo, *branchrevs, **opts): |
|
2560 | def heads(ui, repo, *branchrevs, **opts): | |
2561 | """show branch heads |
|
2561 | """show branch heads | |
2562 |
|
2562 | |||
2563 | With no arguments, show all open branch heads in the repository. |
|
2563 | With no arguments, show all open branch heads in the repository. | |
2564 | Branch heads are changesets that have no descendants on the |
|
2564 | Branch heads are changesets that have no descendants on the | |
2565 | same branch. They are where development generally takes place and |
|
2565 | same branch. They are where development generally takes place and | |
2566 | are the usual targets for update and merge operations. |
|
2566 | are the usual targets for update and merge operations. | |
2567 |
|
2567 | |||
2568 | If one or more REVs are given, only open branch heads on the |
|
2568 | If one or more REVs are given, only open branch heads on the | |
2569 | branches associated with the specified changesets are shown. This |
|
2569 | branches associated with the specified changesets are shown. This | |
2570 | means that you can use :hg:`heads .` to see the heads on the |
|
2570 | means that you can use :hg:`heads .` to see the heads on the | |
2571 | currently checked-out branch. |
|
2571 | currently checked-out branch. | |
2572 |
|
2572 | |||
2573 | If -c/--closed is specified, also show branch heads marked closed |
|
2573 | If -c/--closed is specified, also show branch heads marked closed | |
2574 | (see :hg:`commit --close-branch`). |
|
2574 | (see :hg:`commit --close-branch`). | |
2575 |
|
2575 | |||
2576 | If STARTREV is specified, only those heads that are descendants of |
|
2576 | If STARTREV is specified, only those heads that are descendants of | |
2577 | STARTREV will be displayed. |
|
2577 | STARTREV will be displayed. | |
2578 |
|
2578 | |||
2579 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
2579 | If -t/--topo is specified, named branch mechanics will be ignored and only | |
2580 | topological heads (changesets with no children) will be shown. |
|
2580 | topological heads (changesets with no children) will be shown. | |
2581 |
|
2581 | |||
2582 | Returns 0 if matching heads are found, 1 if not. |
|
2582 | Returns 0 if matching heads are found, 1 if not. | |
2583 | """ |
|
2583 | """ | |
2584 |
|
2584 | |||
2585 | opts = pycompat.byteskwargs(opts) |
|
2585 | opts = pycompat.byteskwargs(opts) | |
2586 | start = None |
|
2586 | start = None | |
2587 | if 'rev' in opts: |
|
2587 | if 'rev' in opts: | |
2588 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
2588 | start = scmutil.revsingle(repo, opts['rev'], None).node() | |
2589 |
|
2589 | |||
2590 | if opts.get('topo'): |
|
2590 | if opts.get('topo'): | |
2591 | heads = [repo[h] for h in repo.heads(start)] |
|
2591 | heads = [repo[h] for h in repo.heads(start)] | |
2592 | else: |
|
2592 | else: | |
2593 | heads = [] |
|
2593 | heads = [] | |
2594 | for branch in repo.branchmap(): |
|
2594 | for branch in repo.branchmap(): | |
2595 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
2595 | heads += repo.branchheads(branch, start, opts.get('closed')) | |
2596 | heads = [repo[h] for h in heads] |
|
2596 | heads = [repo[h] for h in heads] | |
2597 |
|
2597 | |||
2598 | if branchrevs: |
|
2598 | if branchrevs: | |
2599 | branches = set(repo[br].branch() for br in branchrevs) |
|
2599 | branches = set(repo[br].branch() for br in branchrevs) | |
2600 | heads = [h for h in heads if h.branch() in branches] |
|
2600 | heads = [h for h in heads if h.branch() in branches] | |
2601 |
|
2601 | |||
2602 | if opts.get('active') and branchrevs: |
|
2602 | if opts.get('active') and branchrevs: | |
2603 | dagheads = repo.heads(start) |
|
2603 | dagheads = repo.heads(start) | |
2604 | heads = [h for h in heads if h.node() in dagheads] |
|
2604 | heads = [h for h in heads if h.node() in dagheads] | |
2605 |
|
2605 | |||
2606 | if branchrevs: |
|
2606 | if branchrevs: | |
2607 | haveheads = set(h.branch() for h in heads) |
|
2607 | haveheads = set(h.branch() for h in heads) | |
2608 | if branches - haveheads: |
|
2608 | if branches - haveheads: | |
2609 | headless = ', '.join(b for b in branches - haveheads) |
|
2609 | headless = ', '.join(b for b in branches - haveheads) | |
2610 | msg = _('no open branch heads found on branches %s') |
|
2610 | msg = _('no open branch heads found on branches %s') | |
2611 | if opts.get('rev'): |
|
2611 | if opts.get('rev'): | |
2612 | msg += _(' (started at %s)') % opts['rev'] |
|
2612 | msg += _(' (started at %s)') % opts['rev'] | |
2613 | ui.warn((msg + '\n') % headless) |
|
2613 | ui.warn((msg + '\n') % headless) | |
2614 |
|
2614 | |||
2615 | if not heads: |
|
2615 | if not heads: | |
2616 | return 1 |
|
2616 | return 1 | |
2617 |
|
2617 | |||
2618 | ui.pager('heads') |
|
2618 | ui.pager('heads') | |
2619 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
2619 | heads = sorted(heads, key=lambda x: -x.rev()) | |
2620 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2620 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
2621 | for ctx in heads: |
|
2621 | for ctx in heads: | |
2622 | displayer.show(ctx) |
|
2622 | displayer.show(ctx) | |
2623 | displayer.close() |
|
2623 | displayer.close() | |
2624 |
|
2624 | |||
2625 | @command('help', |
|
2625 | @command('help', | |
2626 | [('e', 'extension', None, _('show only help for extensions')), |
|
2626 | [('e', 'extension', None, _('show only help for extensions')), | |
2627 | ('c', 'command', None, _('show only help for commands')), |
|
2627 | ('c', 'command', None, _('show only help for commands')), | |
2628 | ('k', 'keyword', None, _('show topics matching keyword')), |
|
2628 | ('k', 'keyword', None, _('show topics matching keyword')), | |
2629 | ('s', 'system', [], _('show help for specific platform(s)')), |
|
2629 | ('s', 'system', [], _('show help for specific platform(s)')), | |
2630 | ], |
|
2630 | ], | |
2631 | _('[-ecks] [TOPIC]'), |
|
2631 | _('[-ecks] [TOPIC]'), | |
2632 | norepo=True) |
|
2632 | norepo=True) | |
2633 | def help_(ui, name=None, **opts): |
|
2633 | def help_(ui, name=None, **opts): | |
2634 | """show help for a given topic or a help overview |
|
2634 | """show help for a given topic or a help overview | |
2635 |
|
2635 | |||
2636 | With no arguments, print a list of commands with short help messages. |
|
2636 | With no arguments, print a list of commands with short help messages. | |
2637 |
|
2637 | |||
2638 | Given a topic, extension, or command name, print help for that |
|
2638 | Given a topic, extension, or command name, print help for that | |
2639 | topic. |
|
2639 | topic. | |
2640 |
|
2640 | |||
2641 | Returns 0 if successful. |
|
2641 | Returns 0 if successful. | |
2642 | """ |
|
2642 | """ | |
2643 |
|
2643 | |||
2644 | keep = opts.get(r'system') or [] |
|
2644 | keep = opts.get(r'system') or [] | |
2645 | if len(keep) == 0: |
|
2645 | if len(keep) == 0: | |
2646 | if pycompat.sysplatform.startswith('win'): |
|
2646 | if pycompat.sysplatform.startswith('win'): | |
2647 | keep.append('windows') |
|
2647 | keep.append('windows') | |
2648 | elif pycompat.sysplatform == 'OpenVMS': |
|
2648 | elif pycompat.sysplatform == 'OpenVMS': | |
2649 | keep.append('vms') |
|
2649 | keep.append('vms') | |
2650 | elif pycompat.sysplatform == 'plan9': |
|
2650 | elif pycompat.sysplatform == 'plan9': | |
2651 | keep.append('plan9') |
|
2651 | keep.append('plan9') | |
2652 | else: |
|
2652 | else: | |
2653 | keep.append('unix') |
|
2653 | keep.append('unix') | |
2654 | keep.append(pycompat.sysplatform.lower()) |
|
2654 | keep.append(pycompat.sysplatform.lower()) | |
2655 | if ui.verbose: |
|
2655 | if ui.verbose: | |
2656 | keep.append('verbose') |
|
2656 | keep.append('verbose') | |
2657 |
|
2657 | |||
2658 | commands = sys.modules[__name__] |
|
2658 | commands = sys.modules[__name__] | |
2659 | formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) |
|
2659 | formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts) | |
2660 | ui.pager('help') |
|
2660 | ui.pager('help') | |
2661 | ui.write(formatted) |
|
2661 | ui.write(formatted) | |
2662 |
|
2662 | |||
2663 |
|
2663 | |||
2664 | @command('identify|id', |
|
2664 | @command('identify|id', | |
2665 | [('r', 'rev', '', |
|
2665 | [('r', 'rev', '', | |
2666 | _('identify the specified revision'), _('REV')), |
|
2666 | _('identify the specified revision'), _('REV')), | |
2667 | ('n', 'num', None, _('show local revision number')), |
|
2667 | ('n', 'num', None, _('show local revision number')), | |
2668 | ('i', 'id', None, _('show global revision id')), |
|
2668 | ('i', 'id', None, _('show global revision id')), | |
2669 | ('b', 'branch', None, _('show branch')), |
|
2669 | ('b', 'branch', None, _('show branch')), | |
2670 | ('t', 'tags', None, _('show tags')), |
|
2670 | ('t', 'tags', None, _('show tags')), | |
2671 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
2671 | ('B', 'bookmarks', None, _('show bookmarks')), | |
2672 | ] + remoteopts + formatteropts, |
|
2672 | ] + remoteopts + formatteropts, | |
2673 | _('[-nibtB] [-r REV] [SOURCE]'), |
|
2673 | _('[-nibtB] [-r REV] [SOURCE]'), | |
2674 | optionalrepo=True) |
|
2674 | optionalrepo=True) | |
2675 | def identify(ui, repo, source=None, rev=None, |
|
2675 | def identify(ui, repo, source=None, rev=None, | |
2676 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
2676 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): | |
2677 | """identify the working directory or specified revision |
|
2677 | """identify the working directory or specified revision | |
2678 |
|
2678 | |||
2679 | Print a summary identifying the repository state at REV using one or |
|
2679 | Print a summary identifying the repository state at REV using one or | |
2680 | two parent hash identifiers, followed by a "+" if the working |
|
2680 | two parent hash identifiers, followed by a "+" if the working | |
2681 | directory has uncommitted changes, the branch name (if not default), |
|
2681 | directory has uncommitted changes, the branch name (if not default), | |
2682 | a list of tags, and a list of bookmarks. |
|
2682 | a list of tags, and a list of bookmarks. | |
2683 |
|
2683 | |||
2684 | When REV is not given, print a summary of the current state of the |
|
2684 | When REV is not given, print a summary of the current state of the | |
2685 | repository. |
|
2685 | repository. | |
2686 |
|
2686 | |||
2687 | Specifying a path to a repository root or Mercurial bundle will |
|
2687 | Specifying a path to a repository root or Mercurial bundle will | |
2688 | cause lookup to operate on that repository/bundle. |
|
2688 | cause lookup to operate on that repository/bundle. | |
2689 |
|
2689 | |||
2690 | .. container:: verbose |
|
2690 | .. container:: verbose | |
2691 |
|
2691 | |||
2692 | Examples: |
|
2692 | Examples: | |
2693 |
|
2693 | |||
2694 | - generate a build identifier for the working directory:: |
|
2694 | - generate a build identifier for the working directory:: | |
2695 |
|
2695 | |||
2696 | hg id --id > build-id.dat |
|
2696 | hg id --id > build-id.dat | |
2697 |
|
2697 | |||
2698 | - find the revision corresponding to a tag:: |
|
2698 | - find the revision corresponding to a tag:: | |
2699 |
|
2699 | |||
2700 | hg id -n -r 1.3 |
|
2700 | hg id -n -r 1.3 | |
2701 |
|
2701 | |||
2702 | - check the most recent revision of a remote repository:: |
|
2702 | - check the most recent revision of a remote repository:: | |
2703 |
|
2703 | |||
2704 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ |
|
2704 | hg id -r tip https://www.mercurial-scm.org/repo/hg/ | |
2705 |
|
2705 | |||
2706 | See :hg:`log` for generating more information about specific revisions, |
|
2706 | See :hg:`log` for generating more information about specific revisions, | |
2707 | including full hash identifiers. |
|
2707 | including full hash identifiers. | |
2708 |
|
2708 | |||
2709 | Returns 0 if successful. |
|
2709 | Returns 0 if successful. | |
2710 | """ |
|
2710 | """ | |
2711 |
|
2711 | |||
2712 | opts = pycompat.byteskwargs(opts) |
|
2712 | opts = pycompat.byteskwargs(opts) | |
2713 | if not repo and not source: |
|
2713 | if not repo and not source: | |
2714 | raise error.Abort(_("there is no Mercurial repository here " |
|
2714 | raise error.Abort(_("there is no Mercurial repository here " | |
2715 | "(.hg not found)")) |
|
2715 | "(.hg not found)")) | |
2716 |
|
2716 | |||
2717 | if ui.debugflag: |
|
2717 | if ui.debugflag: | |
2718 | hexfunc = hex |
|
2718 | hexfunc = hex | |
2719 | else: |
|
2719 | else: | |
2720 | hexfunc = short |
|
2720 | hexfunc = short | |
2721 | default = not (num or id or branch or tags or bookmarks) |
|
2721 | default = not (num or id or branch or tags or bookmarks) | |
2722 | output = [] |
|
2722 | output = [] | |
2723 | revs = [] |
|
2723 | revs = [] | |
2724 |
|
2724 | |||
2725 | if source: |
|
2725 | if source: | |
2726 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
2726 | source, branches = hg.parseurl(ui.expandpath(source)) | |
2727 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo |
|
2727 | peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo | |
2728 | repo = peer.local() |
|
2728 | repo = peer.local() | |
2729 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) |
|
2729 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) | |
2730 |
|
2730 | |||
2731 | fm = ui.formatter('identify', opts) |
|
2731 | fm = ui.formatter('identify', opts) | |
2732 | fm.startitem() |
|
2732 | fm.startitem() | |
2733 |
|
2733 | |||
2734 | if not repo: |
|
2734 | if not repo: | |
2735 | if num or branch or tags: |
|
2735 | if num or branch or tags: | |
2736 | raise error.Abort( |
|
2736 | raise error.Abort( | |
2737 | _("can't query remote revision number, branch, or tags")) |
|
2737 | _("can't query remote revision number, branch, or tags")) | |
2738 | if not rev and revs: |
|
2738 | if not rev and revs: | |
2739 | rev = revs[0] |
|
2739 | rev = revs[0] | |
2740 | if not rev: |
|
2740 | if not rev: | |
2741 | rev = "tip" |
|
2741 | rev = "tip" | |
2742 |
|
2742 | |||
2743 | remoterev = peer.lookup(rev) |
|
2743 | remoterev = peer.lookup(rev) | |
2744 | hexrev = hexfunc(remoterev) |
|
2744 | hexrev = hexfunc(remoterev) | |
2745 | if default or id: |
|
2745 | if default or id: | |
2746 | output = [hexrev] |
|
2746 | output = [hexrev] | |
2747 | fm.data(id=hexrev) |
|
2747 | fm.data(id=hexrev) | |
2748 |
|
2748 | |||
2749 | def getbms(): |
|
2749 | def getbms(): | |
2750 | bms = [] |
|
2750 | bms = [] | |
2751 |
|
2751 | |||
2752 | if 'bookmarks' in peer.listkeys('namespaces'): |
|
2752 | if 'bookmarks' in peer.listkeys('namespaces'): | |
2753 | hexremoterev = hex(remoterev) |
|
2753 | hexremoterev = hex(remoterev) | |
2754 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() |
|
2754 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() | |
2755 | if bmr == hexremoterev] |
|
2755 | if bmr == hexremoterev] | |
2756 |
|
2756 | |||
2757 | return sorted(bms) |
|
2757 | return sorted(bms) | |
2758 |
|
2758 | |||
2759 | bms = getbms() |
|
2759 | bms = getbms() | |
2760 | if bookmarks: |
|
2760 | if bookmarks: | |
2761 | output.extend(bms) |
|
2761 | output.extend(bms) | |
2762 | elif default and not ui.quiet: |
|
2762 | elif default and not ui.quiet: | |
2763 | # multiple bookmarks for a single parent separated by '/' |
|
2763 | # multiple bookmarks for a single parent separated by '/' | |
2764 | bm = '/'.join(bms) |
|
2764 | bm = '/'.join(bms) | |
2765 | if bm: |
|
2765 | if bm: | |
2766 | output.append(bm) |
|
2766 | output.append(bm) | |
2767 |
|
2767 | |||
2768 | fm.data(node=hex(remoterev)) |
|
2768 | fm.data(node=hex(remoterev)) | |
2769 | fm.data(bookmarks=fm.formatlist(bms, name='bookmark')) |
|
2769 | fm.data(bookmarks=fm.formatlist(bms, name='bookmark')) | |
2770 | else: |
|
2770 | else: | |
2771 | ctx = scmutil.revsingle(repo, rev, None) |
|
2771 | ctx = scmutil.revsingle(repo, rev, None) | |
2772 |
|
2772 | |||
2773 | if ctx.rev() is None: |
|
2773 | if ctx.rev() is None: | |
2774 | ctx = repo[None] |
|
2774 | ctx = repo[None] | |
2775 | parents = ctx.parents() |
|
2775 | parents = ctx.parents() | |
2776 | taglist = [] |
|
2776 | taglist = [] | |
2777 | for p in parents: |
|
2777 | for p in parents: | |
2778 | taglist.extend(p.tags()) |
|
2778 | taglist.extend(p.tags()) | |
2779 |
|
2779 | |||
2780 | dirty = "" |
|
2780 | dirty = "" | |
2781 | if ctx.dirty(missing=True, merge=False, branch=False): |
|
2781 | if ctx.dirty(missing=True, merge=False, branch=False): | |
2782 | dirty = '+' |
|
2782 | dirty = '+' | |
2783 | fm.data(dirty=dirty) |
|
2783 | fm.data(dirty=dirty) | |
2784 |
|
2784 | |||
2785 | hexoutput = [hexfunc(p.node()) for p in parents] |
|
2785 | hexoutput = [hexfunc(p.node()) for p in parents] | |
2786 | if default or id: |
|
2786 | if default or id: | |
2787 | output = ["%s%s" % ('+'.join(hexoutput), dirty)] |
|
2787 | output = ["%s%s" % ('+'.join(hexoutput), dirty)] | |
2788 | fm.data(id="%s%s" % ('+'.join(hexoutput), dirty)) |
|
2788 | fm.data(id="%s%s" % ('+'.join(hexoutput), dirty)) | |
2789 |
|
2789 | |||
2790 | if num: |
|
2790 | if num: | |
2791 | numoutput = ["%d" % p.rev() for p in parents] |
|
2791 | numoutput = ["%d" % p.rev() for p in parents] | |
2792 | output.append("%s%s" % ('+'.join(numoutput), dirty)) |
|
2792 | output.append("%s%s" % ('+'.join(numoutput), dirty)) | |
2793 |
|
2793 | |||
2794 | fn = fm.nested('parents') |
|
2794 | fn = fm.nested('parents') | |
2795 | for p in parents: |
|
2795 | for p in parents: | |
2796 | fn.startitem() |
|
2796 | fn.startitem() | |
2797 | fn.data(rev=p.rev()) |
|
2797 | fn.data(rev=p.rev()) | |
2798 | fn.data(node=p.hex()) |
|
2798 | fn.data(node=p.hex()) | |
2799 | fn.context(ctx=p) |
|
2799 | fn.context(ctx=p) | |
2800 | fn.end() |
|
2800 | fn.end() | |
2801 | else: |
|
2801 | else: | |
2802 | hexoutput = hexfunc(ctx.node()) |
|
2802 | hexoutput = hexfunc(ctx.node()) | |
2803 | if default or id: |
|
2803 | if default or id: | |
2804 | output = [hexoutput] |
|
2804 | output = [hexoutput] | |
2805 | fm.data(id=hexoutput) |
|
2805 | fm.data(id=hexoutput) | |
2806 |
|
2806 | |||
2807 | if num: |
|
2807 | if num: | |
2808 | output.append(pycompat.bytestr(ctx.rev())) |
|
2808 | output.append(pycompat.bytestr(ctx.rev())) | |
2809 | taglist = ctx.tags() |
|
2809 | taglist = ctx.tags() | |
2810 |
|
2810 | |||
2811 | if default and not ui.quiet: |
|
2811 | if default and not ui.quiet: | |
2812 | b = ctx.branch() |
|
2812 | b = ctx.branch() | |
2813 | if b != 'default': |
|
2813 | if b != 'default': | |
2814 | output.append("(%s)" % b) |
|
2814 | output.append("(%s)" % b) | |
2815 |
|
2815 | |||
2816 | # multiple tags for a single parent separated by '/' |
|
2816 | # multiple tags for a single parent separated by '/' | |
2817 | t = '/'.join(taglist) |
|
2817 | t = '/'.join(taglist) | |
2818 | if t: |
|
2818 | if t: | |
2819 | output.append(t) |
|
2819 | output.append(t) | |
2820 |
|
2820 | |||
2821 | # multiple bookmarks for a single parent separated by '/' |
|
2821 | # multiple bookmarks for a single parent separated by '/' | |
2822 | bm = '/'.join(ctx.bookmarks()) |
|
2822 | bm = '/'.join(ctx.bookmarks()) | |
2823 | if bm: |
|
2823 | if bm: | |
2824 | output.append(bm) |
|
2824 | output.append(bm) | |
2825 | else: |
|
2825 | else: | |
2826 | if branch: |
|
2826 | if branch: | |
2827 | output.append(ctx.branch()) |
|
2827 | output.append(ctx.branch()) | |
2828 |
|
2828 | |||
2829 | if tags: |
|
2829 | if tags: | |
2830 | output.extend(taglist) |
|
2830 | output.extend(taglist) | |
2831 |
|
2831 | |||
2832 | if bookmarks: |
|
2832 | if bookmarks: | |
2833 | output.extend(ctx.bookmarks()) |
|
2833 | output.extend(ctx.bookmarks()) | |
2834 |
|
2834 | |||
2835 | fm.data(node=ctx.hex()) |
|
2835 | fm.data(node=ctx.hex()) | |
2836 | fm.data(branch=ctx.branch()) |
|
2836 | fm.data(branch=ctx.branch()) | |
2837 | fm.data(tags=fm.formatlist(taglist, name='tag', sep=':')) |
|
2837 | fm.data(tags=fm.formatlist(taglist, name='tag', sep=':')) | |
2838 | fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark')) |
|
2838 | fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark')) | |
2839 | fm.context(ctx=ctx) |
|
2839 | fm.context(ctx=ctx) | |
2840 |
|
2840 | |||
2841 | fm.plain("%s\n" % ' '.join(output)) |
|
2841 | fm.plain("%s\n" % ' '.join(output)) | |
2842 | fm.end() |
|
2842 | fm.end() | |
2843 |
|
2843 | |||
2844 | @command('import|patch', |
|
2844 | @command('import|patch', | |
2845 | [('p', 'strip', 1, |
|
2845 | [('p', 'strip', 1, | |
2846 | _('directory strip option for patch. This has the same ' |
|
2846 | _('directory strip option for patch. This has the same ' | |
2847 | 'meaning as the corresponding patch option'), _('NUM')), |
|
2847 | 'meaning as the corresponding patch option'), _('NUM')), | |
2848 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
2848 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), | |
2849 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2849 | ('e', 'edit', False, _('invoke editor on commit messages')), | |
2850 | ('f', 'force', None, |
|
2850 | ('f', 'force', None, | |
2851 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), |
|
2851 | _('skip check for outstanding uncommitted changes (DEPRECATED)')), | |
2852 | ('', 'no-commit', None, |
|
2852 | ('', 'no-commit', None, | |
2853 | _("don't commit, just update the working directory")), |
|
2853 | _("don't commit, just update the working directory")), | |
2854 | ('', 'bypass', None, |
|
2854 | ('', 'bypass', None, | |
2855 | _("apply patch without touching the working directory")), |
|
2855 | _("apply patch without touching the working directory")), | |
2856 | ('', 'partial', None, |
|
2856 | ('', 'partial', None, | |
2857 | _('commit even if some hunks fail')), |
|
2857 | _('commit even if some hunks fail')), | |
2858 | ('', 'exact', None, |
|
2858 | ('', 'exact', None, | |
2859 | _('abort if patch would apply lossily')), |
|
2859 | _('abort if patch would apply lossily')), | |
2860 | ('', 'prefix', '', |
|
2860 | ('', 'prefix', '', | |
2861 | _('apply patch to subdirectory'), _('DIR')), |
|
2861 | _('apply patch to subdirectory'), _('DIR')), | |
2862 | ('', 'import-branch', None, |
|
2862 | ('', 'import-branch', None, | |
2863 | _('use any branch information in patch (implied by --exact)'))] + |
|
2863 | _('use any branch information in patch (implied by --exact)'))] + | |
2864 | commitopts + commitopts2 + similarityopts, |
|
2864 | commitopts + commitopts2 + similarityopts, | |
2865 | _('[OPTION]... PATCH...')) |
|
2865 | _('[OPTION]... PATCH...')) | |
2866 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
2866 | def import_(ui, repo, patch1=None, *patches, **opts): | |
2867 | """import an ordered set of patches |
|
2867 | """import an ordered set of patches | |
2868 |
|
2868 | |||
2869 | Import a list of patches and commit them individually (unless |
|
2869 | Import a list of patches and commit them individually (unless | |
2870 | --no-commit is specified). |
|
2870 | --no-commit is specified). | |
2871 |
|
2871 | |||
2872 | To read a patch from standard input (stdin), use "-" as the patch |
|
2872 | To read a patch from standard input (stdin), use "-" as the patch | |
2873 | name. If a URL is specified, the patch will be downloaded from |
|
2873 | name. If a URL is specified, the patch will be downloaded from | |
2874 | there. |
|
2874 | there. | |
2875 |
|
2875 | |||
2876 | Import first applies changes to the working directory (unless |
|
2876 | Import first applies changes to the working directory (unless | |
2877 | --bypass is specified), import will abort if there are outstanding |
|
2877 | --bypass is specified), import will abort if there are outstanding | |
2878 | changes. |
|
2878 | changes. | |
2879 |
|
2879 | |||
2880 | Use --bypass to apply and commit patches directly to the |
|
2880 | Use --bypass to apply and commit patches directly to the | |
2881 | repository, without affecting the working directory. Without |
|
2881 | repository, without affecting the working directory. Without | |
2882 | --exact, patches will be applied on top of the working directory |
|
2882 | --exact, patches will be applied on top of the working directory | |
2883 | parent revision. |
|
2883 | parent revision. | |
2884 |
|
2884 | |||
2885 | You can import a patch straight from a mail message. Even patches |
|
2885 | You can import a patch straight from a mail message. Even patches | |
2886 | as attachments work (to use the body part, it must have type |
|
2886 | as attachments work (to use the body part, it must have type | |
2887 | text/plain or text/x-patch). From and Subject headers of email |
|
2887 | text/plain or text/x-patch). From and Subject headers of email | |
2888 | message are used as default committer and commit message. All |
|
2888 | message are used as default committer and commit message. All | |
2889 | text/plain body parts before first diff are added to the commit |
|
2889 | text/plain body parts before first diff are added to the commit | |
2890 | message. |
|
2890 | message. | |
2891 |
|
2891 | |||
2892 | If the imported patch was generated by :hg:`export`, user and |
|
2892 | If the imported patch was generated by :hg:`export`, user and | |
2893 | description from patch override values from message headers and |
|
2893 | description from patch override values from message headers and | |
2894 | body. Values given on command line with -m/--message and -u/--user |
|
2894 | body. Values given on command line with -m/--message and -u/--user | |
2895 | override these. |
|
2895 | override these. | |
2896 |
|
2896 | |||
2897 | If --exact is specified, import will set the working directory to |
|
2897 | If --exact is specified, import will set the working directory to | |
2898 | the parent of each patch before applying it, and will abort if the |
|
2898 | the parent of each patch before applying it, and will abort if the | |
2899 | resulting changeset has a different ID than the one recorded in |
|
2899 | resulting changeset has a different ID than the one recorded in | |
2900 | the patch. This will guard against various ways that portable |
|
2900 | the patch. This will guard against various ways that portable | |
2901 | patch formats and mail systems might fail to transfer Mercurial |
|
2901 | patch formats and mail systems might fail to transfer Mercurial | |
2902 | data or metadata. See :hg:`bundle` for lossless transmission. |
|
2902 | data or metadata. See :hg:`bundle` for lossless transmission. | |
2903 |
|
2903 | |||
2904 | Use --partial to ensure a changeset will be created from the patch |
|
2904 | Use --partial to ensure a changeset will be created from the patch | |
2905 | even if some hunks fail to apply. Hunks that fail to apply will be |
|
2905 | even if some hunks fail to apply. Hunks that fail to apply will be | |
2906 | written to a <target-file>.rej file. Conflicts can then be resolved |
|
2906 | written to a <target-file>.rej file. Conflicts can then be resolved | |
2907 | by hand before :hg:`commit --amend` is run to update the created |
|
2907 | by hand before :hg:`commit --amend` is run to update the created | |
2908 | changeset. This flag exists to let people import patches that |
|
2908 | changeset. This flag exists to let people import patches that | |
2909 | partially apply without losing the associated metadata (author, |
|
2909 | partially apply without losing the associated metadata (author, | |
2910 | date, description, ...). |
|
2910 | date, description, ...). | |
2911 |
|
2911 | |||
2912 | .. note:: |
|
2912 | .. note:: | |
2913 |
|
2913 | |||
2914 | When no hunks apply cleanly, :hg:`import --partial` will create |
|
2914 | When no hunks apply cleanly, :hg:`import --partial` will create | |
2915 | an empty changeset, importing only the patch metadata. |
|
2915 | an empty changeset, importing only the patch metadata. | |
2916 |
|
2916 | |||
2917 | With -s/--similarity, hg will attempt to discover renames and |
|
2917 | With -s/--similarity, hg will attempt to discover renames and | |
2918 | copies in the patch in the same way as :hg:`addremove`. |
|
2918 | copies in the patch in the same way as :hg:`addremove`. | |
2919 |
|
2919 | |||
2920 | It is possible to use external patch programs to perform the patch |
|
2920 | It is possible to use external patch programs to perform the patch | |
2921 | by setting the ``ui.patch`` configuration option. For the default |
|
2921 | by setting the ``ui.patch`` configuration option. For the default | |
2922 | internal tool, the fuzz can also be configured via ``patch.fuzz``. |
|
2922 | internal tool, the fuzz can also be configured via ``patch.fuzz``. | |
2923 | See :hg:`help config` for more information about configuration |
|
2923 | See :hg:`help config` for more information about configuration | |
2924 | files and how to use these options. |
|
2924 | files and how to use these options. | |
2925 |
|
2925 | |||
2926 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
2926 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
2927 |
|
2927 | |||
2928 | .. container:: verbose |
|
2928 | .. container:: verbose | |
2929 |
|
2929 | |||
2930 | Examples: |
|
2930 | Examples: | |
2931 |
|
2931 | |||
2932 | - import a traditional patch from a website and detect renames:: |
|
2932 | - import a traditional patch from a website and detect renames:: | |
2933 |
|
2933 | |||
2934 | hg import -s 80 http://example.com/bugfix.patch |
|
2934 | hg import -s 80 http://example.com/bugfix.patch | |
2935 |
|
2935 | |||
2936 | - import a changeset from an hgweb server:: |
|
2936 | - import a changeset from an hgweb server:: | |
2937 |
|
2937 | |||
2938 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa |
|
2938 | hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa | |
2939 |
|
2939 | |||
2940 | - import all the patches in an Unix-style mbox:: |
|
2940 | - import all the patches in an Unix-style mbox:: | |
2941 |
|
2941 | |||
2942 | hg import incoming-patches.mbox |
|
2942 | hg import incoming-patches.mbox | |
2943 |
|
2943 | |||
2944 | - import patches from stdin:: |
|
2944 | - import patches from stdin:: | |
2945 |
|
2945 | |||
2946 | hg import - |
|
2946 | hg import - | |
2947 |
|
2947 | |||
2948 | - attempt to exactly restore an exported changeset (not always |
|
2948 | - attempt to exactly restore an exported changeset (not always | |
2949 | possible):: |
|
2949 | possible):: | |
2950 |
|
2950 | |||
2951 | hg import --exact proposed-fix.patch |
|
2951 | hg import --exact proposed-fix.patch | |
2952 |
|
2952 | |||
2953 | - use an external tool to apply a patch which is too fuzzy for |
|
2953 | - use an external tool to apply a patch which is too fuzzy for | |
2954 | the default internal tool. |
|
2954 | the default internal tool. | |
2955 |
|
2955 | |||
2956 | hg import --config ui.patch="patch --merge" fuzzy.patch |
|
2956 | hg import --config ui.patch="patch --merge" fuzzy.patch | |
2957 |
|
2957 | |||
2958 | - change the default fuzzing from 2 to a less strict 7 |
|
2958 | - change the default fuzzing from 2 to a less strict 7 | |
2959 |
|
2959 | |||
2960 | hg import --config ui.fuzz=7 fuzz.patch |
|
2960 | hg import --config ui.fuzz=7 fuzz.patch | |
2961 |
|
2961 | |||
2962 | Returns 0 on success, 1 on partial success (see --partial). |
|
2962 | Returns 0 on success, 1 on partial success (see --partial). | |
2963 | """ |
|
2963 | """ | |
2964 |
|
2964 | |||
2965 | opts = pycompat.byteskwargs(opts) |
|
2965 | opts = pycompat.byteskwargs(opts) | |
2966 | if not patch1: |
|
2966 | if not patch1: | |
2967 | raise error.Abort(_('need at least one patch to import')) |
|
2967 | raise error.Abort(_('need at least one patch to import')) | |
2968 |
|
2968 | |||
2969 | patches = (patch1,) + patches |
|
2969 | patches = (patch1,) + patches | |
2970 |
|
2970 | |||
2971 | date = opts.get('date') |
|
2971 | date = opts.get('date') | |
2972 | if date: |
|
2972 | if date: | |
2973 | opts['date'] = util.parsedate(date) |
|
2973 | opts['date'] = util.parsedate(date) | |
2974 |
|
2974 | |||
2975 | exact = opts.get('exact') |
|
2975 | exact = opts.get('exact') | |
2976 | update = not opts.get('bypass') |
|
2976 | update = not opts.get('bypass') | |
2977 | if not update and opts.get('no_commit'): |
|
2977 | if not update and opts.get('no_commit'): | |
2978 | raise error.Abort(_('cannot use --no-commit with --bypass')) |
|
2978 | raise error.Abort(_('cannot use --no-commit with --bypass')) | |
2979 | try: |
|
2979 | try: | |
2980 | sim = float(opts.get('similarity') or 0) |
|
2980 | sim = float(opts.get('similarity') or 0) | |
2981 | except ValueError: |
|
2981 | except ValueError: | |
2982 | raise error.Abort(_('similarity must be a number')) |
|
2982 | raise error.Abort(_('similarity must be a number')) | |
2983 | if sim < 0 or sim > 100: |
|
2983 | if sim < 0 or sim > 100: | |
2984 | raise error.Abort(_('similarity must be between 0 and 100')) |
|
2984 | raise error.Abort(_('similarity must be between 0 and 100')) | |
2985 | if sim and not update: |
|
2985 | if sim and not update: | |
2986 | raise error.Abort(_('cannot use --similarity with --bypass')) |
|
2986 | raise error.Abort(_('cannot use --similarity with --bypass')) | |
2987 | if exact: |
|
2987 | if exact: | |
2988 | if opts.get('edit'): |
|
2988 | if opts.get('edit'): | |
2989 | raise error.Abort(_('cannot use --exact with --edit')) |
|
2989 | raise error.Abort(_('cannot use --exact with --edit')) | |
2990 | if opts.get('prefix'): |
|
2990 | if opts.get('prefix'): | |
2991 | raise error.Abort(_('cannot use --exact with --prefix')) |
|
2991 | raise error.Abort(_('cannot use --exact with --prefix')) | |
2992 |
|
2992 | |||
2993 | base = opts["base"] |
|
2993 | base = opts["base"] | |
2994 | wlock = dsguard = lock = tr = None |
|
2994 | wlock = dsguard = lock = tr = None | |
2995 | msgs = [] |
|
2995 | msgs = [] | |
2996 | ret = 0 |
|
2996 | ret = 0 | |
2997 |
|
2997 | |||
2998 |
|
2998 | |||
2999 | try: |
|
2999 | try: | |
3000 | wlock = repo.wlock() |
|
3000 | wlock = repo.wlock() | |
3001 |
|
3001 | |||
3002 | if update: |
|
3002 | if update: | |
3003 | cmdutil.checkunfinished(repo) |
|
3003 | cmdutil.checkunfinished(repo) | |
3004 | if (exact or not opts.get('force')): |
|
3004 | if (exact or not opts.get('force')): | |
3005 | cmdutil.bailifchanged(repo) |
|
3005 | cmdutil.bailifchanged(repo) | |
3006 |
|
3006 | |||
3007 | if not opts.get('no_commit'): |
|
3007 | if not opts.get('no_commit'): | |
3008 | lock = repo.lock() |
|
3008 | lock = repo.lock() | |
3009 | tr = repo.transaction('import') |
|
3009 | tr = repo.transaction('import') | |
3010 | else: |
|
3010 | else: | |
3011 | dsguard = dirstateguard.dirstateguard(repo, 'import') |
|
3011 | dsguard = dirstateguard.dirstateguard(repo, 'import') | |
3012 | parents = repo[None].parents() |
|
3012 | parents = repo[None].parents() | |
3013 | for patchurl in patches: |
|
3013 | for patchurl in patches: | |
3014 | if patchurl == '-': |
|
3014 | if patchurl == '-': | |
3015 | ui.status(_('applying patch from stdin\n')) |
|
3015 | ui.status(_('applying patch from stdin\n')) | |
3016 | patchfile = ui.fin |
|
3016 | patchfile = ui.fin | |
3017 | patchurl = 'stdin' # for error message |
|
3017 | patchurl = 'stdin' # for error message | |
3018 | else: |
|
3018 | else: | |
3019 | patchurl = os.path.join(base, patchurl) |
|
3019 | patchurl = os.path.join(base, patchurl) | |
3020 | ui.status(_('applying %s\n') % patchurl) |
|
3020 | ui.status(_('applying %s\n') % patchurl) | |
3021 | patchfile = hg.openpath(ui, patchurl) |
|
3021 | patchfile = hg.openpath(ui, patchurl) | |
3022 |
|
3022 | |||
3023 | haspatch = False |
|
3023 | haspatch = False | |
3024 | for hunk in patch.split(patchfile): |
|
3024 | for hunk in patch.split(patchfile): | |
3025 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, |
|
3025 | (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk, | |
3026 | parents, opts, |
|
3026 | parents, opts, | |
3027 | msgs, hg.clean) |
|
3027 | msgs, hg.clean) | |
3028 | if msg: |
|
3028 | if msg: | |
3029 | haspatch = True |
|
3029 | haspatch = True | |
3030 | ui.note(msg + '\n') |
|
3030 | ui.note(msg + '\n') | |
3031 | if update or exact: |
|
3031 | if update or exact: | |
3032 | parents = repo[None].parents() |
|
3032 | parents = repo[None].parents() | |
3033 | else: |
|
3033 | else: | |
3034 | parents = [repo[node]] |
|
3034 | parents = [repo[node]] | |
3035 | if rej: |
|
3035 | if rej: | |
3036 | ui.write_err(_("patch applied partially\n")) |
|
3036 | ui.write_err(_("patch applied partially\n")) | |
3037 | ui.write_err(_("(fix the .rej files and run " |
|
3037 | ui.write_err(_("(fix the .rej files and run " | |
3038 | "`hg commit --amend`)\n")) |
|
3038 | "`hg commit --amend`)\n")) | |
3039 | ret = 1 |
|
3039 | ret = 1 | |
3040 | break |
|
3040 | break | |
3041 |
|
3041 | |||
3042 | if not haspatch: |
|
3042 | if not haspatch: | |
3043 | raise error.Abort(_('%s: no diffs found') % patchurl) |
|
3043 | raise error.Abort(_('%s: no diffs found') % patchurl) | |
3044 |
|
3044 | |||
3045 | if tr: |
|
3045 | if tr: | |
3046 | tr.close() |
|
3046 | tr.close() | |
3047 | if msgs: |
|
3047 | if msgs: | |
3048 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3048 | repo.savecommitmessage('\n* * *\n'.join(msgs)) | |
3049 | if dsguard: |
|
3049 | if dsguard: | |
3050 | dsguard.close() |
|
3050 | dsguard.close() | |
3051 | return ret |
|
3051 | return ret | |
3052 | finally: |
|
3052 | finally: | |
3053 | if tr: |
|
3053 | if tr: | |
3054 | tr.release() |
|
3054 | tr.release() | |
3055 | release(lock, dsguard, wlock) |
|
3055 | release(lock, dsguard, wlock) | |
3056 |
|
3056 | |||
3057 | @command('incoming|in', |
|
3057 | @command('incoming|in', | |
3058 | [('f', 'force', None, |
|
3058 | [('f', 'force', None, | |
3059 | _('run even if remote repository is unrelated')), |
|
3059 | _('run even if remote repository is unrelated')), | |
3060 | ('n', 'newest-first', None, _('show newest record first')), |
|
3060 | ('n', 'newest-first', None, _('show newest record first')), | |
3061 | ('', 'bundle', '', |
|
3061 | ('', 'bundle', '', | |
3062 | _('file to store the bundles into'), _('FILE')), |
|
3062 | _('file to store the bundles into'), _('FILE')), | |
3063 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3063 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
3064 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3064 | ('B', 'bookmarks', False, _("compare bookmarks")), | |
3065 | ('b', 'branch', [], |
|
3065 | ('b', 'branch', [], | |
3066 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3066 | _('a specific branch you would like to pull'), _('BRANCH')), | |
3067 | ] + logopts + remoteopts + subrepoopts, |
|
3067 | ] + logopts + remoteopts + subrepoopts, | |
3068 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3068 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) | |
3069 | def incoming(ui, repo, source="default", **opts): |
|
3069 | def incoming(ui, repo, source="default", **opts): | |
3070 | """show new changesets found in source |
|
3070 | """show new changesets found in source | |
3071 |
|
3071 | |||
3072 | Show new changesets found in the specified path/URL or the default |
|
3072 | Show new changesets found in the specified path/URL or the default | |
3073 | pull location. These are the changesets that would have been pulled |
|
3073 | pull location. These are the changesets that would have been pulled | |
3074 | if a pull at the time you issued this command. |
|
3074 | if a pull at the time you issued this command. | |
3075 |
|
3075 | |||
3076 | See pull for valid source format details. |
|
3076 | See pull for valid source format details. | |
3077 |
|
3077 | |||
3078 | .. container:: verbose |
|
3078 | .. container:: verbose | |
3079 |
|
3079 | |||
3080 | With -B/--bookmarks, the result of bookmark comparison between |
|
3080 | With -B/--bookmarks, the result of bookmark comparison between | |
3081 | local and remote repositories is displayed. With -v/--verbose, |
|
3081 | local and remote repositories is displayed. With -v/--verbose, | |
3082 | status is also displayed for each bookmark like below:: |
|
3082 | status is also displayed for each bookmark like below:: | |
3083 |
|
3083 | |||
3084 | BM1 01234567890a added |
|
3084 | BM1 01234567890a added | |
3085 | BM2 1234567890ab advanced |
|
3085 | BM2 1234567890ab advanced | |
3086 | BM3 234567890abc diverged |
|
3086 | BM3 234567890abc diverged | |
3087 | BM4 34567890abcd changed |
|
3087 | BM4 34567890abcd changed | |
3088 |
|
3088 | |||
3089 | The action taken locally when pulling depends on the |
|
3089 | The action taken locally when pulling depends on the | |
3090 | status of each bookmark: |
|
3090 | status of each bookmark: | |
3091 |
|
3091 | |||
3092 | :``added``: pull will create it |
|
3092 | :``added``: pull will create it | |
3093 | :``advanced``: pull will update it |
|
3093 | :``advanced``: pull will update it | |
3094 | :``diverged``: pull will create a divergent bookmark |
|
3094 | :``diverged``: pull will create a divergent bookmark | |
3095 | :``changed``: result depends on remote changesets |
|
3095 | :``changed``: result depends on remote changesets | |
3096 |
|
3096 | |||
3097 | From the point of view of pulling behavior, bookmark |
|
3097 | From the point of view of pulling behavior, bookmark | |
3098 | existing only in the remote repository are treated as ``added``, |
|
3098 | existing only in the remote repository are treated as ``added``, | |
3099 | even if it is in fact locally deleted. |
|
3099 | even if it is in fact locally deleted. | |
3100 |
|
3100 | |||
3101 | .. container:: verbose |
|
3101 | .. container:: verbose | |
3102 |
|
3102 | |||
3103 | For remote repository, using --bundle avoids downloading the |
|
3103 | For remote repository, using --bundle avoids downloading the | |
3104 | changesets twice if the incoming is followed by a pull. |
|
3104 | changesets twice if the incoming is followed by a pull. | |
3105 |
|
3105 | |||
3106 | Examples: |
|
3106 | Examples: | |
3107 |
|
3107 | |||
3108 | - show incoming changes with patches and full description:: |
|
3108 | - show incoming changes with patches and full description:: | |
3109 |
|
3109 | |||
3110 | hg incoming -vp |
|
3110 | hg incoming -vp | |
3111 |
|
3111 | |||
3112 | - show incoming changes excluding merges, store a bundle:: |
|
3112 | - show incoming changes excluding merges, store a bundle:: | |
3113 |
|
3113 | |||
3114 | hg in -vpM --bundle incoming.hg |
|
3114 | hg in -vpM --bundle incoming.hg | |
3115 | hg pull incoming.hg |
|
3115 | hg pull incoming.hg | |
3116 |
|
3116 | |||
3117 | - briefly list changes inside a bundle:: |
|
3117 | - briefly list changes inside a bundle:: | |
3118 |
|
3118 | |||
3119 | hg in changes.hg -T "{desc|firstline}\\n" |
|
3119 | hg in changes.hg -T "{desc|firstline}\\n" | |
3120 |
|
3120 | |||
3121 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3121 | Returns 0 if there are incoming changes, 1 otherwise. | |
3122 | """ |
|
3122 | """ | |
3123 | opts = pycompat.byteskwargs(opts) |
|
3123 | opts = pycompat.byteskwargs(opts) | |
3124 | if opts.get('graph'): |
|
3124 | if opts.get('graph'): | |
3125 | cmdutil.checkunsupportedgraphflags([], opts) |
|
3125 | cmdutil.checkunsupportedgraphflags([], opts) | |
3126 | def display(other, chlist, displayer): |
|
3126 | def display(other, chlist, displayer): | |
3127 | revdag = cmdutil.graphrevs(other, chlist, opts) |
|
3127 | revdag = cmdutil.graphrevs(other, chlist, opts) | |
3128 | cmdutil.displaygraph(ui, repo, revdag, displayer, |
|
3128 | cmdutil.displaygraph(ui, repo, revdag, displayer, | |
3129 | graphmod.asciiedges) |
|
3129 | graphmod.asciiedges) | |
3130 |
|
3130 | |||
3131 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
3131 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) | |
3132 | return 0 |
|
3132 | return 0 | |
3133 |
|
3133 | |||
3134 | if opts.get('bundle') and opts.get('subrepos'): |
|
3134 | if opts.get('bundle') and opts.get('subrepos'): | |
3135 | raise error.Abort(_('cannot combine --bundle and --subrepos')) |
|
3135 | raise error.Abort(_('cannot combine --bundle and --subrepos')) | |
3136 |
|
3136 | |||
3137 | if opts.get('bookmarks'): |
|
3137 | if opts.get('bookmarks'): | |
3138 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3138 | source, branches = hg.parseurl(ui.expandpath(source), | |
3139 | opts.get('branch')) |
|
3139 | opts.get('branch')) | |
3140 | other = hg.peer(repo, opts, source) |
|
3140 | other = hg.peer(repo, opts, source) | |
3141 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3141 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3142 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3142 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3143 | return 0 |
|
3143 | return 0 | |
3144 | ui.pager('incoming') |
|
3144 | ui.pager('incoming') | |
3145 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3145 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | |
3146 | return bookmarks.incoming(ui, repo, other) |
|
3146 | return bookmarks.incoming(ui, repo, other) | |
3147 |
|
3147 | |||
3148 | repo._subtoppath = ui.expandpath(source) |
|
3148 | repo._subtoppath = ui.expandpath(source) | |
3149 | try: |
|
3149 | try: | |
3150 | return hg.incoming(ui, repo, source, opts) |
|
3150 | return hg.incoming(ui, repo, source, opts) | |
3151 | finally: |
|
3151 | finally: | |
3152 | del repo._subtoppath |
|
3152 | del repo._subtoppath | |
3153 |
|
3153 | |||
3154 |
|
3154 | |||
3155 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), |
|
3155 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'), | |
3156 | norepo=True) |
|
3156 | norepo=True) | |
3157 | def init(ui, dest=".", **opts): |
|
3157 | def init(ui, dest=".", **opts): | |
3158 | """create a new repository in the given directory |
|
3158 | """create a new repository in the given directory | |
3159 |
|
3159 | |||
3160 | Initialize a new repository in the given directory. If the given |
|
3160 | Initialize a new repository in the given directory. If the given | |
3161 | directory does not exist, it will be created. |
|
3161 | directory does not exist, it will be created. | |
3162 |
|
3162 | |||
3163 | If no directory is given, the current directory is used. |
|
3163 | If no directory is given, the current directory is used. | |
3164 |
|
3164 | |||
3165 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3165 | It is possible to specify an ``ssh://`` URL as the destination. | |
3166 | See :hg:`help urls` for more information. |
|
3166 | See :hg:`help urls` for more information. | |
3167 |
|
3167 | |||
3168 | Returns 0 on success. |
|
3168 | Returns 0 on success. | |
3169 | """ |
|
3169 | """ | |
3170 | opts = pycompat.byteskwargs(opts) |
|
3170 | opts = pycompat.byteskwargs(opts) | |
3171 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
3171 | hg.peer(ui, opts, ui.expandpath(dest), create=True) | |
3172 |
|
3172 | |||
3173 | @command('locate', |
|
3173 | @command('locate', | |
3174 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3174 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | |
3175 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3175 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
3176 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3176 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), | |
3177 | ] + walkopts, |
|
3177 | ] + walkopts, | |
3178 | _('[OPTION]... [PATTERN]...')) |
|
3178 | _('[OPTION]... [PATTERN]...')) | |
3179 | def locate(ui, repo, *pats, **opts): |
|
3179 | def locate(ui, repo, *pats, **opts): | |
3180 | """locate files matching specific patterns (DEPRECATED) |
|
3180 | """locate files matching specific patterns (DEPRECATED) | |
3181 |
|
3181 | |||
3182 | Print files under Mercurial control in the working directory whose |
|
3182 | Print files under Mercurial control in the working directory whose | |
3183 | names match the given patterns. |
|
3183 | names match the given patterns. | |
3184 |
|
3184 | |||
3185 | By default, this command searches all directories in the working |
|
3185 | By default, this command searches all directories in the working | |
3186 | directory. To search just the current directory and its |
|
3186 | directory. To search just the current directory and its | |
3187 | subdirectories, use "--include .". |
|
3187 | subdirectories, use "--include .". | |
3188 |
|
3188 | |||
3189 | If no patterns are given to match, this command prints the names |
|
3189 | If no patterns are given to match, this command prints the names | |
3190 | of all files under Mercurial control in the working directory. |
|
3190 | of all files under Mercurial control in the working directory. | |
3191 |
|
3191 | |||
3192 | If you want to feed the output of this command into the "xargs" |
|
3192 | If you want to feed the output of this command into the "xargs" | |
3193 | command, use the -0 option to both this command and "xargs". This |
|
3193 | command, use the -0 option to both this command and "xargs". This | |
3194 | will avoid the problem of "xargs" treating single filenames that |
|
3194 | will avoid the problem of "xargs" treating single filenames that | |
3195 | contain whitespace as multiple filenames. |
|
3195 | contain whitespace as multiple filenames. | |
3196 |
|
3196 | |||
3197 | See :hg:`help files` for a more versatile command. |
|
3197 | See :hg:`help files` for a more versatile command. | |
3198 |
|
3198 | |||
3199 | Returns 0 if a match is found, 1 otherwise. |
|
3199 | Returns 0 if a match is found, 1 otherwise. | |
3200 | """ |
|
3200 | """ | |
3201 | opts = pycompat.byteskwargs(opts) |
|
3201 | opts = pycompat.byteskwargs(opts) | |
3202 | if opts.get('print0'): |
|
3202 | if opts.get('print0'): | |
3203 | end = '\0' |
|
3203 | end = '\0' | |
3204 | else: |
|
3204 | else: | |
3205 | end = '\n' |
|
3205 | end = '\n' | |
3206 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
3206 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() | |
3207 |
|
3207 | |||
3208 | ret = 1 |
|
3208 | ret = 1 | |
3209 | ctx = repo[rev] |
|
3209 | ctx = repo[rev] | |
3210 | m = scmutil.match(ctx, pats, opts, default='relglob', |
|
3210 | m = scmutil.match(ctx, pats, opts, default='relglob', | |
3211 | badfn=lambda x, y: False) |
|
3211 | badfn=lambda x, y: False) | |
3212 |
|
3212 | |||
3213 | ui.pager('locate') |
|
3213 | ui.pager('locate') | |
3214 | for abs in ctx.matches(m): |
|
3214 | for abs in ctx.matches(m): | |
3215 | if opts.get('fullpath'): |
|
3215 | if opts.get('fullpath'): | |
3216 | ui.write(repo.wjoin(abs), end) |
|
3216 | ui.write(repo.wjoin(abs), end) | |
3217 | else: |
|
3217 | else: | |
3218 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3218 | ui.write(((pats and m.rel(abs)) or abs), end) | |
3219 | ret = 0 |
|
3219 | ret = 0 | |
3220 |
|
3220 | |||
3221 | return ret |
|
3221 | return ret | |
3222 |
|
3222 | |||
3223 | @command('^log|history', |
|
3223 | @command('^log|history', | |
3224 | [('f', 'follow', None, |
|
3224 | [('f', 'follow', None, | |
3225 | _('follow changeset history, or file history across copies and renames')), |
|
3225 | _('follow changeset history, or file history across copies and renames')), | |
3226 | ('', 'follow-first', None, |
|
3226 | ('', 'follow-first', None, | |
3227 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
3227 | _('only follow the first parent of merge changesets (DEPRECATED)')), | |
3228 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3228 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), | |
3229 | ('C', 'copies', None, _('show copied files')), |
|
3229 | ('C', 'copies', None, _('show copied files')), | |
3230 | ('k', 'keyword', [], |
|
3230 | ('k', 'keyword', [], | |
3231 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3231 | _('do case-insensitive search for a given text'), _('TEXT')), | |
3232 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), |
|
3232 | ('r', 'rev', [], _('show the specified revision or revset'), _('REV')), | |
3233 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3233 | ('', 'removed', None, _('include revisions where files were removed')), | |
3234 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
3234 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), | |
3235 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3235 | ('u', 'user', [], _('revisions committed by user'), _('USER')), | |
3236 | ('', 'only-branch', [], |
|
3236 | ('', 'only-branch', [], | |
3237 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3237 | _('show only changesets within the given named branch (DEPRECATED)'), | |
3238 | _('BRANCH')), |
|
3238 | _('BRANCH')), | |
3239 | ('b', 'branch', [], |
|
3239 | ('b', 'branch', [], | |
3240 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3240 | _('show changesets within the given named branch'), _('BRANCH')), | |
3241 | ('P', 'prune', [], |
|
3241 | ('P', 'prune', [], | |
3242 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3242 | _('do not display revision or any of its ancestors'), _('REV')), | |
3243 | ] + logopts + walkopts, |
|
3243 | ] + logopts + walkopts, | |
3244 | _('[OPTION]... [FILE]'), |
|
3244 | _('[OPTION]... [FILE]'), | |
3245 | inferrepo=True) |
|
3245 | inferrepo=True) | |
3246 | def log(ui, repo, *pats, **opts): |
|
3246 | def log(ui, repo, *pats, **opts): | |
3247 | """show revision history of entire repository or files |
|
3247 | """show revision history of entire repository or files | |
3248 |
|
3248 | |||
3249 | Print the revision history of the specified files or the entire |
|
3249 | Print the revision history of the specified files or the entire | |
3250 | project. |
|
3250 | project. | |
3251 |
|
3251 | |||
3252 | If no revision range is specified, the default is ``tip:0`` unless |
|
3252 | If no revision range is specified, the default is ``tip:0`` unless | |
3253 | --follow is set, in which case the working directory parent is |
|
3253 | --follow is set, in which case the working directory parent is | |
3254 | used as the starting revision. |
|
3254 | used as the starting revision. | |
3255 |
|
3255 | |||
3256 | File history is shown without following rename or copy history of |
|
3256 | File history is shown without following rename or copy history of | |
3257 | files. Use -f/--follow with a filename to follow history across |
|
3257 | files. Use -f/--follow with a filename to follow history across | |
3258 | renames and copies. --follow without a filename will only show |
|
3258 | renames and copies. --follow without a filename will only show | |
3259 | ancestors or descendants of the starting revision. |
|
3259 | ancestors or descendants of the starting revision. | |
3260 |
|
3260 | |||
3261 | By default this command prints revision number and changeset id, |
|
3261 | By default this command prints revision number and changeset id, | |
3262 | tags, non-trivial parents, user, date and time, and a summary for |
|
3262 | tags, non-trivial parents, user, date and time, and a summary for | |
3263 | each commit. When the -v/--verbose switch is used, the list of |
|
3263 | each commit. When the -v/--verbose switch is used, the list of | |
3264 | changed files and full commit message are shown. |
|
3264 | changed files and full commit message are shown. | |
3265 |
|
3265 | |||
3266 | With --graph the revisions are shown as an ASCII art DAG with the most |
|
3266 | With --graph the revisions are shown as an ASCII art DAG with the most | |
3267 | recent changeset at the top. |
|
3267 | recent changeset at the top. | |
3268 | 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, |
|
3268 | 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, | |
3269 | and '+' represents a fork where the changeset from the lines below is a |
|
3269 | and '+' represents a fork where the changeset from the lines below is a | |
3270 | parent of the 'o' merge on the same line. |
|
3270 | parent of the 'o' merge on the same line. | |
3271 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place |
|
3271 | Paths in the DAG are represented with '|', '/' and so forth. ':' in place | |
3272 | of a '|' indicates one or more revisions in a path are omitted. |
|
3272 | of a '|' indicates one or more revisions in a path are omitted. | |
3273 |
|
3273 | |||
3274 | .. note:: |
|
3274 | .. note:: | |
3275 |
|
3275 | |||
3276 | :hg:`log --patch` may generate unexpected diff output for merge |
|
3276 | :hg:`log --patch` may generate unexpected diff output for merge | |
3277 | changesets, as it will only compare the merge changeset against |
|
3277 | changesets, as it will only compare the merge changeset against | |
3278 | its first parent. Also, only files different from BOTH parents |
|
3278 | its first parent. Also, only files different from BOTH parents | |
3279 | will appear in files:. |
|
3279 | will appear in files:. | |
3280 |
|
3280 | |||
3281 | .. note:: |
|
3281 | .. note:: | |
3282 |
|
3282 | |||
3283 | For performance reasons, :hg:`log FILE` may omit duplicate changes |
|
3283 | For performance reasons, :hg:`log FILE` may omit duplicate changes | |
3284 | made on branches and will not show removals or mode changes. To |
|
3284 | made on branches and will not show removals or mode changes. To | |
3285 | see all such changes, use the --removed switch. |
|
3285 | see all such changes, use the --removed switch. | |
3286 |
|
3286 | |||
3287 | .. container:: verbose |
|
3287 | .. container:: verbose | |
3288 |
|
3288 | |||
3289 | Some examples: |
|
3289 | Some examples: | |
3290 |
|
3290 | |||
3291 | - changesets with full descriptions and file lists:: |
|
3291 | - changesets with full descriptions and file lists:: | |
3292 |
|
3292 | |||
3293 | hg log -v |
|
3293 | hg log -v | |
3294 |
|
3294 | |||
3295 | - changesets ancestral to the working directory:: |
|
3295 | - changesets ancestral to the working directory:: | |
3296 |
|
3296 | |||
3297 | hg log -f |
|
3297 | hg log -f | |
3298 |
|
3298 | |||
3299 | - last 10 commits on the current branch:: |
|
3299 | - last 10 commits on the current branch:: | |
3300 |
|
3300 | |||
3301 | hg log -l 10 -b . |
|
3301 | hg log -l 10 -b . | |
3302 |
|
3302 | |||
3303 | - changesets showing all modifications of a file, including removals:: |
|
3303 | - changesets showing all modifications of a file, including removals:: | |
3304 |
|
3304 | |||
3305 | hg log --removed file.c |
|
3305 | hg log --removed file.c | |
3306 |
|
3306 | |||
3307 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
3307 | - all changesets that touch a directory, with diffs, excluding merges:: | |
3308 |
|
3308 | |||
3309 | hg log -Mp lib/ |
|
3309 | hg log -Mp lib/ | |
3310 |
|
3310 | |||
3311 | - all revision numbers that match a keyword:: |
|
3311 | - all revision numbers that match a keyword:: | |
3312 |
|
3312 | |||
3313 | hg log -k bug --template "{rev}\\n" |
|
3313 | hg log -k bug --template "{rev}\\n" | |
3314 |
|
3314 | |||
3315 | - the full hash identifier of the working directory parent:: |
|
3315 | - the full hash identifier of the working directory parent:: | |
3316 |
|
3316 | |||
3317 | hg log -r . --template "{node}\\n" |
|
3317 | hg log -r . --template "{node}\\n" | |
3318 |
|
3318 | |||
3319 | - list available log templates:: |
|
3319 | - list available log templates:: | |
3320 |
|
3320 | |||
3321 | hg log -T list |
|
3321 | hg log -T list | |
3322 |
|
3322 | |||
3323 | - check if a given changeset is included in a tagged release:: |
|
3323 | - check if a given changeset is included in a tagged release:: | |
3324 |
|
3324 | |||
3325 | hg log -r "a21ccf and ancestor(1.9)" |
|
3325 | hg log -r "a21ccf and ancestor(1.9)" | |
3326 |
|
3326 | |||
3327 | - find all changesets by some user in a date range:: |
|
3327 | - find all changesets by some user in a date range:: | |
3328 |
|
3328 | |||
3329 | hg log -k alice -d "may 2008 to jul 2008" |
|
3329 | hg log -k alice -d "may 2008 to jul 2008" | |
3330 |
|
3330 | |||
3331 | - summary of all changesets after the last tag:: |
|
3331 | - summary of all changesets after the last tag:: | |
3332 |
|
3332 | |||
3333 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
3333 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" | |
3334 |
|
3334 | |||
3335 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3335 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
3336 |
|
3336 | |||
3337 | See :hg:`help revisions` for more about specifying and ordering |
|
3337 | See :hg:`help revisions` for more about specifying and ordering | |
3338 | revisions. |
|
3338 | revisions. | |
3339 |
|
3339 | |||
3340 | See :hg:`help templates` for more about pre-packaged styles and |
|
3340 | See :hg:`help templates` for more about pre-packaged styles and | |
3341 | specifying custom templates. The default template used by the log |
|
3341 | specifying custom templates. The default template used by the log | |
3342 | command can be customized via the ``ui.logtemplate`` configuration |
|
3342 | command can be customized via the ``ui.logtemplate`` configuration | |
3343 | setting. |
|
3343 | setting. | |
3344 |
|
3344 | |||
3345 | Returns 0 on success. |
|
3345 | Returns 0 on success. | |
3346 |
|
3346 | |||
3347 | """ |
|
3347 | """ | |
3348 | opts = pycompat.byteskwargs(opts) |
|
3348 | opts = pycompat.byteskwargs(opts) | |
3349 | if opts.get('follow') and opts.get('rev'): |
|
3349 | if opts.get('follow') and opts.get('rev'): | |
3350 | opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))] |
|
3350 | opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))] | |
3351 | del opts['follow'] |
|
3351 | del opts['follow'] | |
3352 |
|
3352 | |||
3353 | if opts.get('graph'): |
|
3353 | if opts.get('graph'): | |
3354 | return cmdutil.graphlog(ui, repo, pats, opts) |
|
3354 | return cmdutil.graphlog(ui, repo, pats, opts) | |
3355 |
|
3355 | |||
3356 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) |
|
3356 | revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) | |
3357 | limit = cmdutil.loglimit(opts) |
|
3357 | limit = cmdutil.loglimit(opts) | |
3358 | count = 0 |
|
3358 | count = 0 | |
3359 |
|
3359 | |||
3360 | getrenamed = None |
|
3360 | getrenamed = None | |
3361 | if opts.get('copies'): |
|
3361 | if opts.get('copies'): | |
3362 | endrev = None |
|
3362 | endrev = None | |
3363 | if opts.get('rev'): |
|
3363 | if opts.get('rev'): | |
3364 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 |
|
3364 | endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1 | |
3365 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3365 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | |
3366 |
|
3366 | |||
3367 | ui.pager('log') |
|
3367 | ui.pager('log') | |
3368 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
3368 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | |
3369 | for rev in revs: |
|
3369 | for rev in revs: | |
3370 | if count == limit: |
|
3370 | if count == limit: | |
3371 | break |
|
3371 | break | |
3372 | ctx = repo[rev] |
|
3372 | ctx = repo[rev] | |
3373 | copies = None |
|
3373 | copies = None | |
3374 | if getrenamed is not None and rev: |
|
3374 | if getrenamed is not None and rev: | |
3375 | copies = [] |
|
3375 | copies = [] | |
3376 | for fn in ctx.files(): |
|
3376 | for fn in ctx.files(): | |
3377 | rename = getrenamed(fn, rev) |
|
3377 | rename = getrenamed(fn, rev) | |
3378 | if rename: |
|
3378 | if rename: | |
3379 | copies.append((fn, rename[0])) |
|
3379 | copies.append((fn, rename[0])) | |
3380 | if filematcher: |
|
3380 | if filematcher: | |
3381 | revmatchfn = filematcher(ctx.rev()) |
|
3381 | revmatchfn = filematcher(ctx.rev()) | |
3382 | else: |
|
3382 | else: | |
3383 | revmatchfn = None |
|
3383 | revmatchfn = None | |
3384 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
3384 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) | |
3385 | if displayer.flush(ctx): |
|
3385 | if displayer.flush(ctx): | |
3386 | count += 1 |
|
3386 | count += 1 | |
3387 |
|
3387 | |||
3388 | displayer.close() |
|
3388 | displayer.close() | |
3389 |
|
3389 | |||
3390 | @command('manifest', |
|
3390 | @command('manifest', | |
3391 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
3391 | [('r', 'rev', '', _('revision to display'), _('REV')), | |
3392 | ('', 'all', False, _("list files from all revisions"))] |
|
3392 | ('', 'all', False, _("list files from all revisions"))] | |
3393 | + formatteropts, |
|
3393 | + formatteropts, | |
3394 | _('[-r REV]')) |
|
3394 | _('[-r REV]')) | |
3395 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
3395 | def manifest(ui, repo, node=None, rev=None, **opts): | |
3396 | """output the current or given revision of the project manifest |
|
3396 | """output the current or given revision of the project manifest | |
3397 |
|
3397 | |||
3398 | Print a list of version controlled files for the given revision. |
|
3398 | Print a list of version controlled files for the given revision. | |
3399 | If no revision is given, the first parent of the working directory |
|
3399 | If no revision is given, the first parent of the working directory | |
3400 | is used, or the null revision if no revision is checked out. |
|
3400 | is used, or the null revision if no revision is checked out. | |
3401 |
|
3401 | |||
3402 | With -v, print file permissions, symlink and executable bits. |
|
3402 | With -v, print file permissions, symlink and executable bits. | |
3403 | With --debug, print file revision hashes. |
|
3403 | With --debug, print file revision hashes. | |
3404 |
|
3404 | |||
3405 | If option --all is specified, the list of all files from all revisions |
|
3405 | If option --all is specified, the list of all files from all revisions | |
3406 | is printed. This includes deleted and renamed files. |
|
3406 | is printed. This includes deleted and renamed files. | |
3407 |
|
3407 | |||
3408 | Returns 0 on success. |
|
3408 | Returns 0 on success. | |
3409 | """ |
|
3409 | """ | |
3410 | opts = pycompat.byteskwargs(opts) |
|
3410 | opts = pycompat.byteskwargs(opts) | |
3411 | fm = ui.formatter('manifest', opts) |
|
3411 | fm = ui.formatter('manifest', opts) | |
3412 |
|
3412 | |||
3413 | if opts.get('all'): |
|
3413 | if opts.get('all'): | |
3414 | if rev or node: |
|
3414 | if rev or node: | |
3415 | raise error.Abort(_("can't specify a revision with --all")) |
|
3415 | raise error.Abort(_("can't specify a revision with --all")) | |
3416 |
|
3416 | |||
3417 | res = [] |
|
3417 | res = [] | |
3418 | prefix = "data/" |
|
3418 | prefix = "data/" | |
3419 | suffix = ".i" |
|
3419 | suffix = ".i" | |
3420 | plen = len(prefix) |
|
3420 | plen = len(prefix) | |
3421 | slen = len(suffix) |
|
3421 | slen = len(suffix) | |
3422 | with repo.lock(): |
|
3422 | with repo.lock(): | |
3423 | for fn, b, size in repo.store.datafiles(): |
|
3423 | for fn, b, size in repo.store.datafiles(): | |
3424 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
3424 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: | |
3425 | res.append(fn[plen:-slen]) |
|
3425 | res.append(fn[plen:-slen]) | |
3426 | ui.pager('manifest') |
|
3426 | ui.pager('manifest') | |
3427 | for f in res: |
|
3427 | for f in res: | |
3428 | fm.startitem() |
|
3428 | fm.startitem() | |
3429 | fm.write("path", '%s\n', f) |
|
3429 | fm.write("path", '%s\n', f) | |
3430 | fm.end() |
|
3430 | fm.end() | |
3431 | return |
|
3431 | return | |
3432 |
|
3432 | |||
3433 | if rev and node: |
|
3433 | if rev and node: | |
3434 | raise error.Abort(_("please specify just one revision")) |
|
3434 | raise error.Abort(_("please specify just one revision")) | |
3435 |
|
3435 | |||
3436 | if not node: |
|
3436 | if not node: | |
3437 | node = rev |
|
3437 | node = rev | |
3438 |
|
3438 | |||
3439 | char = {'l': '@', 'x': '*', '': ''} |
|
3439 | char = {'l': '@', 'x': '*', '': ''} | |
3440 | mode = {'l': '644', 'x': '755', '': '644'} |
|
3440 | mode = {'l': '644', 'x': '755', '': '644'} | |
3441 | ctx = scmutil.revsingle(repo, node) |
|
3441 | ctx = scmutil.revsingle(repo, node) | |
3442 | mf = ctx.manifest() |
|
3442 | mf = ctx.manifest() | |
3443 | ui.pager('manifest') |
|
3443 | ui.pager('manifest') | |
3444 | for f in ctx: |
|
3444 | for f in ctx: | |
3445 | fm.startitem() |
|
3445 | fm.startitem() | |
3446 | fl = ctx[f].flags() |
|
3446 | fl = ctx[f].flags() | |
3447 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) |
|
3447 | fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f])) | |
3448 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) |
|
3448 | fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl]) | |
3449 | fm.write('path', '%s\n', f) |
|
3449 | fm.write('path', '%s\n', f) | |
3450 | fm.end() |
|
3450 | fm.end() | |
3451 |
|
3451 | |||
3452 | @command('^merge', |
|
3452 | @command('^merge', | |
3453 | [('f', 'force', None, |
|
3453 | [('f', 'force', None, | |
3454 | _('force a merge including outstanding changes (DEPRECATED)')), |
|
3454 | _('force a merge including outstanding changes (DEPRECATED)')), | |
3455 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
3455 | ('r', 'rev', '', _('revision to merge'), _('REV')), | |
3456 | ('P', 'preview', None, |
|
3456 | ('P', 'preview', None, | |
3457 | _('review revisions to merge (no merge is performed)')) |
|
3457 | _('review revisions to merge (no merge is performed)')) | |
3458 | ] + mergetoolopts, |
|
3458 | ] + mergetoolopts, | |
3459 | _('[-P] [[-r] REV]')) |
|
3459 | _('[-P] [[-r] REV]')) | |
3460 | def merge(ui, repo, node=None, **opts): |
|
3460 | def merge(ui, repo, node=None, **opts): | |
3461 | """merge another revision into working directory |
|
3461 | """merge another revision into working directory | |
3462 |
|
3462 | |||
3463 | The current working directory is updated with all changes made in |
|
3463 | The current working directory is updated with all changes made in | |
3464 | the requested revision since the last common predecessor revision. |
|
3464 | the requested revision since the last common predecessor revision. | |
3465 |
|
3465 | |||
3466 | Files that changed between either parent are marked as changed for |
|
3466 | Files that changed between either parent are marked as changed for | |
3467 | the next commit and a commit must be performed before any further |
|
3467 | the next commit and a commit must be performed before any further | |
3468 | updates to the repository are allowed. The next commit will have |
|
3468 | updates to the repository are allowed. The next commit will have | |
3469 | two parents. |
|
3469 | two parents. | |
3470 |
|
3470 | |||
3471 | ``--tool`` can be used to specify the merge tool used for file |
|
3471 | ``--tool`` can be used to specify the merge tool used for file | |
3472 | merges. It overrides the HGMERGE environment variable and your |
|
3472 | merges. It overrides the HGMERGE environment variable and your | |
3473 | configuration files. See :hg:`help merge-tools` for options. |
|
3473 | configuration files. See :hg:`help merge-tools` for options. | |
3474 |
|
3474 | |||
3475 | If no revision is specified, the working directory's parent is a |
|
3475 | If no revision is specified, the working directory's parent is a | |
3476 | head revision, and the current branch contains exactly one other |
|
3476 | head revision, and the current branch contains exactly one other | |
3477 | head, the other head is merged with by default. Otherwise, an |
|
3477 | head, the other head is merged with by default. Otherwise, an | |
3478 | explicit revision with which to merge with must be provided. |
|
3478 | explicit revision with which to merge with must be provided. | |
3479 |
|
3479 | |||
3480 | See :hg:`help resolve` for information on handling file conflicts. |
|
3480 | See :hg:`help resolve` for information on handling file conflicts. | |
3481 |
|
3481 | |||
3482 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
3482 | To undo an uncommitted merge, use :hg:`update --clean .` which | |
3483 | will check out a clean copy of the original merge parent, losing |
|
3483 | will check out a clean copy of the original merge parent, losing | |
3484 | all changes. |
|
3484 | all changes. | |
3485 |
|
3485 | |||
3486 | Returns 0 on success, 1 if there are unresolved files. |
|
3486 | Returns 0 on success, 1 if there are unresolved files. | |
3487 | """ |
|
3487 | """ | |
3488 |
|
3488 | |||
3489 | opts = pycompat.byteskwargs(opts) |
|
3489 | opts = pycompat.byteskwargs(opts) | |
3490 | if opts.get('rev') and node: |
|
3490 | if opts.get('rev') and node: | |
3491 | raise error.Abort(_("please specify just one revision")) |
|
3491 | raise error.Abort(_("please specify just one revision")) | |
3492 | if not node: |
|
3492 | if not node: | |
3493 | node = opts.get('rev') |
|
3493 | node = opts.get('rev') | |
3494 |
|
3494 | |||
3495 | if node: |
|
3495 | if node: | |
3496 | node = scmutil.revsingle(repo, node).node() |
|
3496 | node = scmutil.revsingle(repo, node).node() | |
3497 |
|
3497 | |||
3498 | if not node: |
|
3498 | if not node: | |
3499 | node = repo[destutil.destmerge(repo)].node() |
|
3499 | node = repo[destutil.destmerge(repo)].node() | |
3500 |
|
3500 | |||
3501 | if opts.get('preview'): |
|
3501 | if opts.get('preview'): | |
3502 | # find nodes that are ancestors of p2 but not of p1 |
|
3502 | # find nodes that are ancestors of p2 but not of p1 | |
3503 | p1 = repo.lookup('.') |
|
3503 | p1 = repo.lookup('.') | |
3504 | p2 = repo.lookup(node) |
|
3504 | p2 = repo.lookup(node) | |
3505 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
3505 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) | |
3506 |
|
3506 | |||
3507 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3507 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
3508 | for node in nodes: |
|
3508 | for node in nodes: | |
3509 | displayer.show(repo[node]) |
|
3509 | displayer.show(repo[node]) | |
3510 | displayer.close() |
|
3510 | displayer.close() | |
3511 | return 0 |
|
3511 | return 0 | |
3512 |
|
3512 | |||
3513 | try: |
|
3513 | try: | |
3514 | # ui.forcemerge is an internal variable, do not document |
|
3514 | # ui.forcemerge is an internal variable, do not document | |
3515 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') |
|
3515 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge') | |
3516 | force = opts.get('force') |
|
3516 | force = opts.get('force') | |
3517 | labels = ['working copy', 'merge rev'] |
|
3517 | labels = ['working copy', 'merge rev'] | |
3518 | return hg.merge(repo, node, force=force, mergeforce=force, |
|
3518 | return hg.merge(repo, node, force=force, mergeforce=force, | |
3519 | labels=labels) |
|
3519 | labels=labels) | |
3520 | finally: |
|
3520 | finally: | |
3521 | ui.setconfig('ui', 'forcemerge', '', 'merge') |
|
3521 | ui.setconfig('ui', 'forcemerge', '', 'merge') | |
3522 |
|
3522 | |||
3523 | @command('outgoing|out', |
|
3523 | @command('outgoing|out', | |
3524 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
3524 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
3525 | ('r', 'rev', [], |
|
3525 | ('r', 'rev', [], | |
3526 | _('a changeset intended to be included in the destination'), _('REV')), |
|
3526 | _('a changeset intended to be included in the destination'), _('REV')), | |
3527 | ('n', 'newest-first', None, _('show newest record first')), |
|
3527 | ('n', 'newest-first', None, _('show newest record first')), | |
3528 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
3528 | ('B', 'bookmarks', False, _('compare bookmarks')), | |
3529 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
3529 | ('b', 'branch', [], _('a specific branch you would like to push'), | |
3530 | _('BRANCH')), |
|
3530 | _('BRANCH')), | |
3531 | ] + logopts + remoteopts + subrepoopts, |
|
3531 | ] + logopts + remoteopts + subrepoopts, | |
3532 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
3532 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) | |
3533 | def outgoing(ui, repo, dest=None, **opts): |
|
3533 | def outgoing(ui, repo, dest=None, **opts): | |
3534 | """show changesets not found in the destination |
|
3534 | """show changesets not found in the destination | |
3535 |
|
3535 | |||
3536 | Show changesets not found in the specified destination repository |
|
3536 | Show changesets not found in the specified destination repository | |
3537 | or the default push location. These are the changesets that would |
|
3537 | or the default push location. These are the changesets that would | |
3538 | be pushed if a push was requested. |
|
3538 | be pushed if a push was requested. | |
3539 |
|
3539 | |||
3540 | See pull for details of valid destination formats. |
|
3540 | See pull for details of valid destination formats. | |
3541 |
|
3541 | |||
3542 | .. container:: verbose |
|
3542 | .. container:: verbose | |
3543 |
|
3543 | |||
3544 | With -B/--bookmarks, the result of bookmark comparison between |
|
3544 | With -B/--bookmarks, the result of bookmark comparison between | |
3545 | local and remote repositories is displayed. With -v/--verbose, |
|
3545 | local and remote repositories is displayed. With -v/--verbose, | |
3546 | status is also displayed for each bookmark like below:: |
|
3546 | status is also displayed for each bookmark like below:: | |
3547 |
|
3547 | |||
3548 | BM1 01234567890a added |
|
3548 | BM1 01234567890a added | |
3549 | BM2 deleted |
|
3549 | BM2 deleted | |
3550 | BM3 234567890abc advanced |
|
3550 | BM3 234567890abc advanced | |
3551 | BM4 34567890abcd diverged |
|
3551 | BM4 34567890abcd diverged | |
3552 | BM5 4567890abcde changed |
|
3552 | BM5 4567890abcde changed | |
3553 |
|
3553 | |||
3554 | The action taken when pushing depends on the |
|
3554 | The action taken when pushing depends on the | |
3555 | status of each bookmark: |
|
3555 | status of each bookmark: | |
3556 |
|
3556 | |||
3557 | :``added``: push with ``-B`` will create it |
|
3557 | :``added``: push with ``-B`` will create it | |
3558 | :``deleted``: push with ``-B`` will delete it |
|
3558 | :``deleted``: push with ``-B`` will delete it | |
3559 | :``advanced``: push will update it |
|
3559 | :``advanced``: push will update it | |
3560 | :``diverged``: push with ``-B`` will update it |
|
3560 | :``diverged``: push with ``-B`` will update it | |
3561 | :``changed``: push with ``-B`` will update it |
|
3561 | :``changed``: push with ``-B`` will update it | |
3562 |
|
3562 | |||
3563 | From the point of view of pushing behavior, bookmarks |
|
3563 | From the point of view of pushing behavior, bookmarks | |
3564 | existing only in the remote repository are treated as |
|
3564 | existing only in the remote repository are treated as | |
3565 | ``deleted``, even if it is in fact added remotely. |
|
3565 | ``deleted``, even if it is in fact added remotely. | |
3566 |
|
3566 | |||
3567 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
3567 | Returns 0 if there are outgoing changes, 1 otherwise. | |
3568 | """ |
|
3568 | """ | |
3569 | opts = pycompat.byteskwargs(opts) |
|
3569 | opts = pycompat.byteskwargs(opts) | |
3570 | if opts.get('graph'): |
|
3570 | if opts.get('graph'): | |
3571 | cmdutil.checkunsupportedgraphflags([], opts) |
|
3571 | cmdutil.checkunsupportedgraphflags([], opts) | |
3572 | o, other = hg._outgoing(ui, repo, dest, opts) |
|
3572 | o, other = hg._outgoing(ui, repo, dest, opts) | |
3573 | if not o: |
|
3573 | if not o: | |
3574 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3574 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | |
3575 | return |
|
3575 | return | |
3576 |
|
3576 | |||
3577 | revdag = cmdutil.graphrevs(repo, o, opts) |
|
3577 | revdag = cmdutil.graphrevs(repo, o, opts) | |
3578 | ui.pager('outgoing') |
|
3578 | ui.pager('outgoing') | |
3579 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
3579 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) | |
3580 | cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) |
|
3580 | cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges) | |
3581 | cmdutil.outgoinghooks(ui, repo, other, opts, o) |
|
3581 | cmdutil.outgoinghooks(ui, repo, other, opts, o) | |
3582 | return 0 |
|
3582 | return 0 | |
3583 |
|
3583 | |||
3584 | if opts.get('bookmarks'): |
|
3584 | if opts.get('bookmarks'): | |
3585 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3585 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
3586 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
3586 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
3587 | other = hg.peer(repo, opts, dest) |
|
3587 | other = hg.peer(repo, opts, dest) | |
3588 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3588 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3589 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3589 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3590 | return 0 |
|
3590 | return 0 | |
3591 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
3591 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | |
3592 | ui.pager('outgoing') |
|
3592 | ui.pager('outgoing') | |
3593 | return bookmarks.outgoing(ui, repo, other) |
|
3593 | return bookmarks.outgoing(ui, repo, other) | |
3594 |
|
3594 | |||
3595 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3595 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') | |
3596 | try: |
|
3596 | try: | |
3597 | return hg.outgoing(ui, repo, dest, opts) |
|
3597 | return hg.outgoing(ui, repo, dest, opts) | |
3598 | finally: |
|
3598 | finally: | |
3599 | del repo._subtoppath |
|
3599 | del repo._subtoppath | |
3600 |
|
3600 | |||
3601 | @command('parents', |
|
3601 | @command('parents', | |
3602 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
3602 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), | |
3603 | ] + templateopts, |
|
3603 | ] + templateopts, | |
3604 | _('[-r REV] [FILE]'), |
|
3604 | _('[-r REV] [FILE]'), | |
3605 | inferrepo=True) |
|
3605 | inferrepo=True) | |
3606 | def parents(ui, repo, file_=None, **opts): |
|
3606 | def parents(ui, repo, file_=None, **opts): | |
3607 | """show the parents of the working directory or revision (DEPRECATED) |
|
3607 | """show the parents of the working directory or revision (DEPRECATED) | |
3608 |
|
3608 | |||
3609 | Print the working directory's parent revisions. If a revision is |
|
3609 | Print the working directory's parent revisions. If a revision is | |
3610 | given via -r/--rev, the parent of that revision will be printed. |
|
3610 | given via -r/--rev, the parent of that revision will be printed. | |
3611 | If a file argument is given, the revision in which the file was |
|
3611 | If a file argument is given, the revision in which the file was | |
3612 | last changed (before the working directory revision or the |
|
3612 | last changed (before the working directory revision or the | |
3613 | argument to --rev if given) is printed. |
|
3613 | argument to --rev if given) is printed. | |
3614 |
|
3614 | |||
3615 | This command is equivalent to:: |
|
3615 | This command is equivalent to:: | |
3616 |
|
3616 | |||
3617 | hg log -r "p1()+p2()" or |
|
3617 | hg log -r "p1()+p2()" or | |
3618 | hg log -r "p1(REV)+p2(REV)" or |
|
3618 | hg log -r "p1(REV)+p2(REV)" or | |
3619 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or |
|
3619 | hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or | |
3620 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" |
|
3620 | hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))" | |
3621 |
|
3621 | |||
3622 | See :hg:`summary` and :hg:`help revsets` for related information. |
|
3622 | See :hg:`summary` and :hg:`help revsets` for related information. | |
3623 |
|
3623 | |||
3624 | Returns 0 on success. |
|
3624 | Returns 0 on success. | |
3625 | """ |
|
3625 | """ | |
3626 |
|
3626 | |||
3627 | opts = pycompat.byteskwargs(opts) |
|
3627 | opts = pycompat.byteskwargs(opts) | |
3628 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3628 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | |
3629 |
|
3629 | |||
3630 | if file_: |
|
3630 | if file_: | |
3631 | m = scmutil.match(ctx, (file_,), opts) |
|
3631 | m = scmutil.match(ctx, (file_,), opts) | |
3632 | if m.anypats() or len(m.files()) != 1: |
|
3632 | if m.anypats() or len(m.files()) != 1: | |
3633 | raise error.Abort(_('can only specify an explicit filename')) |
|
3633 | raise error.Abort(_('can only specify an explicit filename')) | |
3634 | file_ = m.files()[0] |
|
3634 | file_ = m.files()[0] | |
3635 | filenodes = [] |
|
3635 | filenodes = [] | |
3636 | for cp in ctx.parents(): |
|
3636 | for cp in ctx.parents(): | |
3637 | if not cp: |
|
3637 | if not cp: | |
3638 | continue |
|
3638 | continue | |
3639 | try: |
|
3639 | try: | |
3640 | filenodes.append(cp.filenode(file_)) |
|
3640 | filenodes.append(cp.filenode(file_)) | |
3641 | except error.LookupError: |
|
3641 | except error.LookupError: | |
3642 | pass |
|
3642 | pass | |
3643 | if not filenodes: |
|
3643 | if not filenodes: | |
3644 | raise error.Abort(_("'%s' not found in manifest!") % file_) |
|
3644 | raise error.Abort(_("'%s' not found in manifest!") % file_) | |
3645 | p = [] |
|
3645 | p = [] | |
3646 | for fn in filenodes: |
|
3646 | for fn in filenodes: | |
3647 | fctx = repo.filectx(file_, fileid=fn) |
|
3647 | fctx = repo.filectx(file_, fileid=fn) | |
3648 | p.append(fctx.node()) |
|
3648 | p.append(fctx.node()) | |
3649 | else: |
|
3649 | else: | |
3650 | p = [cp.node() for cp in ctx.parents()] |
|
3650 | p = [cp.node() for cp in ctx.parents()] | |
3651 |
|
3651 | |||
3652 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3652 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
3653 | for n in p: |
|
3653 | for n in p: | |
3654 | if n != nullid: |
|
3654 | if n != nullid: | |
3655 | displayer.show(repo[n]) |
|
3655 | displayer.show(repo[n]) | |
3656 | displayer.close() |
|
3656 | displayer.close() | |
3657 |
|
3657 | |||
3658 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True) |
|
3658 | @command('paths', formatteropts, _('[NAME]'), optionalrepo=True) | |
3659 | def paths(ui, repo, search=None, **opts): |
|
3659 | def paths(ui, repo, search=None, **opts): | |
3660 | """show aliases for remote repositories |
|
3660 | """show aliases for remote repositories | |
3661 |
|
3661 | |||
3662 | Show definition of symbolic path name NAME. If no name is given, |
|
3662 | Show definition of symbolic path name NAME. If no name is given, | |
3663 | show definition of all available names. |
|
3663 | show definition of all available names. | |
3664 |
|
3664 | |||
3665 | Option -q/--quiet suppresses all output when searching for NAME |
|
3665 | Option -q/--quiet suppresses all output when searching for NAME | |
3666 | and shows only the path names when listing all definitions. |
|
3666 | and shows only the path names when listing all definitions. | |
3667 |
|
3667 | |||
3668 | Path names are defined in the [paths] section of your |
|
3668 | Path names are defined in the [paths] section of your | |
3669 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
3669 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a | |
3670 | repository, ``.hg/hgrc`` is used, too. |
|
3670 | repository, ``.hg/hgrc`` is used, too. | |
3671 |
|
3671 | |||
3672 | The path names ``default`` and ``default-push`` have a special |
|
3672 | The path names ``default`` and ``default-push`` have a special | |
3673 | meaning. When performing a push or pull operation, they are used |
|
3673 | meaning. When performing a push or pull operation, they are used | |
3674 | as fallbacks if no location is specified on the command-line. |
|
3674 | as fallbacks if no location is specified on the command-line. | |
3675 | When ``default-push`` is set, it will be used for push and |
|
3675 | When ``default-push`` is set, it will be used for push and | |
3676 | ``default`` will be used for pull; otherwise ``default`` is used |
|
3676 | ``default`` will be used for pull; otherwise ``default`` is used | |
3677 | as the fallback for both. When cloning a repository, the clone |
|
3677 | as the fallback for both. When cloning a repository, the clone | |
3678 | source is written as ``default`` in ``.hg/hgrc``. |
|
3678 | source is written as ``default`` in ``.hg/hgrc``. | |
3679 |
|
3679 | |||
3680 | .. note:: |
|
3680 | .. note:: | |
3681 |
|
3681 | |||
3682 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
3682 | ``default`` and ``default-push`` apply to all inbound (e.g. | |
3683 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` |
|
3683 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` | |
3684 | and :hg:`bundle`) operations. |
|
3684 | and :hg:`bundle`) operations. | |
3685 |
|
3685 | |||
3686 | See :hg:`help urls` for more information. |
|
3686 | See :hg:`help urls` for more information. | |
3687 |
|
3687 | |||
3688 | Returns 0 on success. |
|
3688 | Returns 0 on success. | |
3689 | """ |
|
3689 | """ | |
3690 |
|
3690 | |||
3691 | opts = pycompat.byteskwargs(opts) |
|
3691 | opts = pycompat.byteskwargs(opts) | |
3692 | ui.pager('paths') |
|
3692 | ui.pager('paths') | |
3693 | if search: |
|
3693 | if search: | |
3694 | pathitems = [(name, path) for name, path in ui.paths.iteritems() |
|
3694 | pathitems = [(name, path) for name, path in ui.paths.iteritems() | |
3695 | if name == search] |
|
3695 | if name == search] | |
3696 | else: |
|
3696 | else: | |
3697 | pathitems = sorted(ui.paths.iteritems()) |
|
3697 | pathitems = sorted(ui.paths.iteritems()) | |
3698 |
|
3698 | |||
3699 | fm = ui.formatter('paths', opts) |
|
3699 | fm = ui.formatter('paths', opts) | |
3700 | if fm.isplain(): |
|
3700 | if fm.isplain(): | |
3701 | hidepassword = util.hidepassword |
|
3701 | hidepassword = util.hidepassword | |
3702 | else: |
|
3702 | else: | |
3703 | hidepassword = str |
|
3703 | hidepassword = str | |
3704 | if ui.quiet: |
|
3704 | if ui.quiet: | |
3705 | namefmt = '%s\n' |
|
3705 | namefmt = '%s\n' | |
3706 | else: |
|
3706 | else: | |
3707 | namefmt = '%s = ' |
|
3707 | namefmt = '%s = ' | |
3708 | showsubopts = not search and not ui.quiet |
|
3708 | showsubopts = not search and not ui.quiet | |
3709 |
|
3709 | |||
3710 | for name, path in pathitems: |
|
3710 | for name, path in pathitems: | |
3711 | fm.startitem() |
|
3711 | fm.startitem() | |
3712 | fm.condwrite(not search, 'name', namefmt, name) |
|
3712 | fm.condwrite(not search, 'name', namefmt, name) | |
3713 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) |
|
3713 | fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc)) | |
3714 | for subopt, value in sorted(path.suboptions.items()): |
|
3714 | for subopt, value in sorted(path.suboptions.items()): | |
3715 | assert subopt not in ('name', 'url') |
|
3715 | assert subopt not in ('name', 'url') | |
3716 | if showsubopts: |
|
3716 | if showsubopts: | |
3717 | fm.plain('%s:%s = ' % (name, subopt)) |
|
3717 | fm.plain('%s:%s = ' % (name, subopt)) | |
3718 | fm.condwrite(showsubopts, subopt, '%s\n', value) |
|
3718 | fm.condwrite(showsubopts, subopt, '%s\n', value) | |
3719 |
|
3719 | |||
3720 | fm.end() |
|
3720 | fm.end() | |
3721 |
|
3721 | |||
3722 | if search and not pathitems: |
|
3722 | if search and not pathitems: | |
3723 | if not ui.quiet: |
|
3723 | if not ui.quiet: | |
3724 | ui.warn(_("not found!\n")) |
|
3724 | ui.warn(_("not found!\n")) | |
3725 | return 1 |
|
3725 | return 1 | |
3726 | else: |
|
3726 | else: | |
3727 | return 0 |
|
3727 | return 0 | |
3728 |
|
3728 | |||
3729 | @command('phase', |
|
3729 | @command('phase', | |
3730 | [('p', 'public', False, _('set changeset phase to public')), |
|
3730 | [('p', 'public', False, _('set changeset phase to public')), | |
3731 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
3731 | ('d', 'draft', False, _('set changeset phase to draft')), | |
3732 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
3732 | ('s', 'secret', False, _('set changeset phase to secret')), | |
3733 | ('f', 'force', False, _('allow to move boundary backward')), |
|
3733 | ('f', 'force', False, _('allow to move boundary backward')), | |
3734 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
3734 | ('r', 'rev', [], _('target revision'), _('REV')), | |
3735 | ], |
|
3735 | ], | |
3736 | _('[-p|-d|-s] [-f] [-r] [REV...]')) |
|
3736 | _('[-p|-d|-s] [-f] [-r] [REV...]')) | |
3737 | def phase(ui, repo, *revs, **opts): |
|
3737 | def phase(ui, repo, *revs, **opts): | |
3738 | """set or show the current phase name |
|
3738 | """set or show the current phase name | |
3739 |
|
3739 | |||
3740 | With no argument, show the phase name of the current revision(s). |
|
3740 | With no argument, show the phase name of the current revision(s). | |
3741 |
|
3741 | |||
3742 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
3742 | With one of -p/--public, -d/--draft or -s/--secret, change the | |
3743 | phase value of the specified revisions. |
|
3743 | phase value of the specified revisions. | |
3744 |
|
3744 | |||
3745 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
3745 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a | |
3746 | lower phase to an higher phase. Phases are ordered as follows:: |
|
3746 | lower phase to an higher phase. Phases are ordered as follows:: | |
3747 |
|
3747 | |||
3748 | public < draft < secret |
|
3748 | public < draft < secret | |
3749 |
|
3749 | |||
3750 | Returns 0 on success, 1 if some phases could not be changed. |
|
3750 | Returns 0 on success, 1 if some phases could not be changed. | |
3751 |
|
3751 | |||
3752 | (For more information about the phases concept, see :hg:`help phases`.) |
|
3752 | (For more information about the phases concept, see :hg:`help phases`.) | |
3753 | """ |
|
3753 | """ | |
3754 | opts = pycompat.byteskwargs(opts) |
|
3754 | opts = pycompat.byteskwargs(opts) | |
3755 | # search for a unique phase argument |
|
3755 | # search for a unique phase argument | |
3756 | targetphase = None |
|
3756 | targetphase = None | |
3757 | for idx, name in enumerate(phases.phasenames): |
|
3757 | for idx, name in enumerate(phases.phasenames): | |
3758 | if opts[name]: |
|
3758 | if opts[name]: | |
3759 | if targetphase is not None: |
|
3759 | if targetphase is not None: | |
3760 | raise error.Abort(_('only one phase can be specified')) |
|
3760 | raise error.Abort(_('only one phase can be specified')) | |
3761 | targetphase = idx |
|
3761 | targetphase = idx | |
3762 |
|
3762 | |||
3763 | # look for specified revision |
|
3763 | # look for specified revision | |
3764 | revs = list(revs) |
|
3764 | revs = list(revs) | |
3765 | revs.extend(opts['rev']) |
|
3765 | revs.extend(opts['rev']) | |
3766 | if not revs: |
|
3766 | if not revs: | |
3767 | # display both parents as the second parent phase can influence |
|
3767 | # display both parents as the second parent phase can influence | |
3768 | # the phase of a merge commit |
|
3768 | # the phase of a merge commit | |
3769 | revs = [c.rev() for c in repo[None].parents()] |
|
3769 | revs = [c.rev() for c in repo[None].parents()] | |
3770 |
|
3770 | |||
3771 | revs = scmutil.revrange(repo, revs) |
|
3771 | revs = scmutil.revrange(repo, revs) | |
3772 |
|
3772 | |||
3773 | lock = None |
|
3773 | lock = None | |
3774 | ret = 0 |
|
3774 | ret = 0 | |
3775 | if targetphase is None: |
|
3775 | if targetphase is None: | |
3776 | # display |
|
3776 | # display | |
3777 | for r in revs: |
|
3777 | for r in revs: | |
3778 | ctx = repo[r] |
|
3778 | ctx = repo[r] | |
3779 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
3779 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | |
3780 | else: |
|
3780 | else: | |
3781 | tr = None |
|
3781 | tr = None | |
3782 | lock = repo.lock() |
|
3782 | lock = repo.lock() | |
3783 | try: |
|
3783 | try: | |
3784 | tr = repo.transaction("phase") |
|
3784 | tr = repo.transaction("phase") | |
3785 | # set phase |
|
3785 | # set phase | |
3786 | if not revs: |
|
3786 | if not revs: | |
3787 | raise error.Abort(_('empty revision set')) |
|
3787 | raise error.Abort(_('empty revision set')) | |
3788 | nodes = [repo[r].node() for r in revs] |
|
3788 | nodes = [repo[r].node() for r in revs] | |
3789 | # moving revision from public to draft may hide them |
|
3789 | # moving revision from public to draft may hide them | |
3790 | # We have to check result on an unfiltered repository |
|
3790 | # We have to check result on an unfiltered repository | |
3791 | unfi = repo.unfiltered() |
|
3791 | unfi = repo.unfiltered() | |
3792 | getphase = unfi._phasecache.phase |
|
3792 | getphase = unfi._phasecache.phase | |
3793 | olddata = [getphase(unfi, r) for r in unfi] |
|
3793 | olddata = [getphase(unfi, r) for r in unfi] | |
3794 | phases.advanceboundary(repo, tr, targetphase, nodes) |
|
3794 | phases.advanceboundary(repo, tr, targetphase, nodes) | |
3795 | if opts['force']: |
|
3795 | if opts['force']: | |
3796 | phases.retractboundary(repo, tr, targetphase, nodes) |
|
3796 | phases.retractboundary(repo, tr, targetphase, nodes) | |
3797 | tr.close() |
|
3797 | tr.close() | |
3798 | finally: |
|
3798 | finally: | |
3799 | if tr is not None: |
|
3799 | if tr is not None: | |
3800 | tr.release() |
|
3800 | tr.release() | |
3801 | lock.release() |
|
3801 | lock.release() | |
3802 | getphase = unfi._phasecache.phase |
|
3802 | getphase = unfi._phasecache.phase | |
3803 | newdata = [getphase(unfi, r) for r in unfi] |
|
3803 | newdata = [getphase(unfi, r) for r in unfi] | |
3804 | changes = sum(newdata[r] != olddata[r] for r in unfi) |
|
3804 | changes = sum(newdata[r] != olddata[r] for r in unfi) | |
3805 | cl = unfi.changelog |
|
3805 | cl = unfi.changelog | |
3806 | rejected = [n for n in nodes |
|
3806 | rejected = [n for n in nodes | |
3807 | if newdata[cl.rev(n)] < targetphase] |
|
3807 | if newdata[cl.rev(n)] < targetphase] | |
3808 | if rejected: |
|
3808 | if rejected: | |
3809 | ui.warn(_('cannot move %i changesets to a higher ' |
|
3809 | ui.warn(_('cannot move %i changesets to a higher ' | |
3810 | 'phase, use --force\n') % len(rejected)) |
|
3810 | 'phase, use --force\n') % len(rejected)) | |
3811 | ret = 1 |
|
3811 | ret = 1 | |
3812 | if changes: |
|
3812 | if changes: | |
3813 | msg = _('phase changed for %i changesets\n') % changes |
|
3813 | msg = _('phase changed for %i changesets\n') % changes | |
3814 | if ret: |
|
3814 | if ret: | |
3815 | ui.status(msg) |
|
3815 | ui.status(msg) | |
3816 | else: |
|
3816 | else: | |
3817 | ui.note(msg) |
|
3817 | ui.note(msg) | |
3818 | else: |
|
3818 | else: | |
3819 | ui.warn(_('no phases changed\n')) |
|
3819 | ui.warn(_('no phases changed\n')) | |
3820 | return ret |
|
3820 | return ret | |
3821 |
|
3821 | |||
3822 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): |
|
3822 | def postincoming(ui, repo, modheads, optupdate, checkout, brev): | |
3823 | """Run after a changegroup has been added via pull/unbundle |
|
3823 | """Run after a changegroup has been added via pull/unbundle | |
3824 |
|
3824 | |||
3825 | This takes arguments below: |
|
3825 | This takes arguments below: | |
3826 |
|
3826 | |||
3827 | :modheads: change of heads by pull/unbundle |
|
3827 | :modheads: change of heads by pull/unbundle | |
3828 | :optupdate: updating working directory is needed or not |
|
3828 | :optupdate: updating working directory is needed or not | |
3829 | :checkout: update destination revision (or None to default destination) |
|
3829 | :checkout: update destination revision (or None to default destination) | |
3830 | :brev: a name, which might be a bookmark to be activated after updating |
|
3830 | :brev: a name, which might be a bookmark to be activated after updating | |
3831 | """ |
|
3831 | """ | |
3832 | if modheads == 0: |
|
3832 | if modheads == 0: | |
3833 | return |
|
3833 | return | |
3834 | if optupdate: |
|
3834 | if optupdate: | |
3835 | try: |
|
3835 | try: | |
3836 | return hg.updatetotally(ui, repo, checkout, brev) |
|
3836 | return hg.updatetotally(ui, repo, checkout, brev) | |
3837 | except error.UpdateAbort as inst: |
|
3837 | except error.UpdateAbort as inst: | |
3838 | msg = _("not updating: %s") % str(inst) |
|
3838 | msg = _("not updating: %s") % str(inst) | |
3839 | hint = inst.hint |
|
3839 | hint = inst.hint | |
3840 | raise error.UpdateAbort(msg, hint=hint) |
|
3840 | raise error.UpdateAbort(msg, hint=hint) | |
3841 | if modheads > 1: |
|
3841 | if modheads > 1: | |
3842 | currentbranchheads = len(repo.branchheads()) |
|
3842 | currentbranchheads = len(repo.branchheads()) | |
3843 | if currentbranchheads == modheads: |
|
3843 | if currentbranchheads == modheads: | |
3844 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
3844 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
3845 | elif currentbranchheads > 1: |
|
3845 | elif currentbranchheads > 1: | |
3846 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
3846 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " | |
3847 | "merge)\n")) |
|
3847 | "merge)\n")) | |
3848 | else: |
|
3848 | else: | |
3849 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
3849 | ui.status(_("(run 'hg heads' to see heads)\n")) | |
3850 | elif not ui.configbool('commands', 'update.requiredest'): |
|
3850 | elif not ui.configbool('commands', 'update.requiredest'): | |
3851 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
3851 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
3852 |
|
3852 | |||
3853 | @command('^pull', |
|
3853 | @command('^pull', | |
3854 | [('u', 'update', None, |
|
3854 | [('u', 'update', None, | |
3855 | _('update to new branch head if changesets were pulled')), |
|
3855 | _('update to new branch head if changesets were pulled')), | |
3856 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
3856 | ('f', 'force', None, _('run even when remote repository is unrelated')), | |
3857 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3857 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
3858 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
3858 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), | |
3859 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
3859 | ('b', 'branch', [], _('a specific branch you would like to pull'), | |
3860 | _('BRANCH')), |
|
3860 | _('BRANCH')), | |
3861 | ] + remoteopts, |
|
3861 | ] + remoteopts, | |
3862 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
3862 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) | |
3863 | def pull(ui, repo, source="default", **opts): |
|
3863 | def pull(ui, repo, source="default", **opts): | |
3864 | """pull changes from the specified source |
|
3864 | """pull changes from the specified source | |
3865 |
|
3865 | |||
3866 | Pull changes from a remote repository to a local one. |
|
3866 | Pull changes from a remote repository to a local one. | |
3867 |
|
3867 | |||
3868 | This finds all changes from the repository at the specified path |
|
3868 | This finds all changes from the repository at the specified path | |
3869 | or URL and adds them to a local repository (the current one unless |
|
3869 | or URL and adds them to a local repository (the current one unless | |
3870 | -R is specified). By default, this does not update the copy of the |
|
3870 | -R is specified). By default, this does not update the copy of the | |
3871 | project in the working directory. |
|
3871 | project in the working directory. | |
3872 |
|
3872 | |||
3873 | Use :hg:`incoming` if you want to see what would have been added |
|
3873 | Use :hg:`incoming` if you want to see what would have been added | |
3874 | by a pull at the time you issued this command. If you then decide |
|
3874 | by a pull at the time you issued this command. If you then decide | |
3875 | to add those changes to the repository, you should use :hg:`pull |
|
3875 | to add those changes to the repository, you should use :hg:`pull | |
3876 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
3876 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. | |
3877 |
|
3877 | |||
3878 | If SOURCE is omitted, the 'default' path will be used. |
|
3878 | If SOURCE is omitted, the 'default' path will be used. | |
3879 | See :hg:`help urls` for more information. |
|
3879 | See :hg:`help urls` for more information. | |
3880 |
|
3880 | |||
3881 | Specifying bookmark as ``.`` is equivalent to specifying the active |
|
3881 | Specifying bookmark as ``.`` is equivalent to specifying the active | |
3882 | bookmark's name. |
|
3882 | bookmark's name. | |
3883 |
|
3883 | |||
3884 | Returns 0 on success, 1 if an update had unresolved files. |
|
3884 | Returns 0 on success, 1 if an update had unresolved files. | |
3885 | """ |
|
3885 | """ | |
3886 |
|
3886 | |||
3887 | opts = pycompat.byteskwargs(opts) |
|
3887 | opts = pycompat.byteskwargs(opts) | |
3888 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): |
|
3888 | if ui.configbool('commands', 'update.requiredest') and opts.get('update'): | |
3889 | msg = _('update destination required by configuration') |
|
3889 | msg = _('update destination required by configuration') | |
3890 | hint = _('use hg pull followed by hg update DEST') |
|
3890 | hint = _('use hg pull followed by hg update DEST') | |
3891 | raise error.Abort(msg, hint=hint) |
|
3891 | raise error.Abort(msg, hint=hint) | |
3892 |
|
3892 | |||
3893 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
3893 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | |
3894 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
3894 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) | |
3895 | other = hg.peer(repo, opts, source) |
|
3895 | other = hg.peer(repo, opts, source) | |
3896 | try: |
|
3896 | try: | |
3897 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
3897 | revs, checkout = hg.addbranchrevs(repo, other, branches, | |
3898 | opts.get('rev')) |
|
3898 | opts.get('rev')) | |
3899 |
|
3899 | |||
3900 |
|
3900 | |||
3901 | pullopargs = {} |
|
3901 | pullopargs = {} | |
3902 | if opts.get('bookmark'): |
|
3902 | if opts.get('bookmark'): | |
3903 | if not revs: |
|
3903 | if not revs: | |
3904 | revs = [] |
|
3904 | revs = [] | |
3905 | # The list of bookmark used here is not the one used to actually |
|
3905 | # The list of bookmark used here is not the one used to actually | |
3906 | # update the bookmark name. This can result in the revision pulled |
|
3906 | # update the bookmark name. This can result in the revision pulled | |
3907 | # not ending up with the name of the bookmark because of a race |
|
3907 | # not ending up with the name of the bookmark because of a race | |
3908 | # condition on the server. (See issue 4689 for details) |
|
3908 | # condition on the server. (See issue 4689 for details) | |
3909 | remotebookmarks = other.listkeys('bookmarks') |
|
3909 | remotebookmarks = other.listkeys('bookmarks') | |
3910 | pullopargs['remotebookmarks'] = remotebookmarks |
|
3910 | pullopargs['remotebookmarks'] = remotebookmarks | |
3911 | for b in opts['bookmark']: |
|
3911 | for b in opts['bookmark']: | |
3912 | b = repo._bookmarks.expandname(b) |
|
3912 | b = repo._bookmarks.expandname(b) | |
3913 | if b not in remotebookmarks: |
|
3913 | if b not in remotebookmarks: | |
3914 | raise error.Abort(_('remote bookmark %s not found!') % b) |
|
3914 | raise error.Abort(_('remote bookmark %s not found!') % b) | |
3915 | revs.append(remotebookmarks[b]) |
|
3915 | revs.append(remotebookmarks[b]) | |
3916 |
|
3916 | |||
3917 | if revs: |
|
3917 | if revs: | |
3918 | try: |
|
3918 | try: | |
3919 | # When 'rev' is a bookmark name, we cannot guarantee that it |
|
3919 | # When 'rev' is a bookmark name, we cannot guarantee that it | |
3920 | # will be updated with that name because of a race condition |
|
3920 | # will be updated with that name because of a race condition | |
3921 | # server side. (See issue 4689 for details) |
|
3921 | # server side. (See issue 4689 for details) | |
3922 | oldrevs = revs |
|
3922 | oldrevs = revs | |
3923 | revs = [] # actually, nodes |
|
3923 | revs = [] # actually, nodes | |
3924 | for r in oldrevs: |
|
3924 | for r in oldrevs: | |
3925 | node = other.lookup(r) |
|
3925 | node = other.lookup(r) | |
3926 | revs.append(node) |
|
3926 | revs.append(node) | |
3927 | if r == checkout: |
|
3927 | if r == checkout: | |
3928 | checkout = node |
|
3928 | checkout = node | |
3929 | except error.CapabilityError: |
|
3929 | except error.CapabilityError: | |
3930 | err = _("other repository doesn't support revision lookup, " |
|
3930 | err = _("other repository doesn't support revision lookup, " | |
3931 | "so a rev cannot be specified.") |
|
3931 | "so a rev cannot be specified.") | |
3932 | raise error.Abort(err) |
|
3932 | raise error.Abort(err) | |
3933 |
|
3933 | |||
3934 | pullopargs.update(opts.get('opargs', {})) |
|
3934 | pullopargs.update(opts.get('opargs', {})) | |
3935 | modheads = exchange.pull(repo, other, heads=revs, |
|
3935 | modheads = exchange.pull(repo, other, heads=revs, | |
3936 | force=opts.get('force'), |
|
3936 | force=opts.get('force'), | |
3937 | bookmarks=opts.get('bookmark', ()), |
|
3937 | bookmarks=opts.get('bookmark', ()), | |
3938 | opargs=pullopargs).cgresult |
|
3938 | opargs=pullopargs).cgresult | |
3939 |
|
3939 | |||
3940 | # brev is a name, which might be a bookmark to be activated at |
|
3940 | # brev is a name, which might be a bookmark to be activated at | |
3941 | # the end of the update. In other words, it is an explicit |
|
3941 | # the end of the update. In other words, it is an explicit | |
3942 | # destination of the update |
|
3942 | # destination of the update | |
3943 | brev = None |
|
3943 | brev = None | |
3944 |
|
3944 | |||
3945 | if checkout: |
|
3945 | if checkout: | |
3946 | checkout = str(repo.changelog.rev(checkout)) |
|
3946 | checkout = str(repo.changelog.rev(checkout)) | |
3947 |
|
3947 | |||
3948 | # order below depends on implementation of |
|
3948 | # order below depends on implementation of | |
3949 | # hg.addbranchrevs(). opts['bookmark'] is ignored, |
|
3949 | # hg.addbranchrevs(). opts['bookmark'] is ignored, | |
3950 | # because 'checkout' is determined without it. |
|
3950 | # because 'checkout' is determined without it. | |
3951 | if opts.get('rev'): |
|
3951 | if opts.get('rev'): | |
3952 | brev = opts['rev'][0] |
|
3952 | brev = opts['rev'][0] | |
3953 | elif opts.get('branch'): |
|
3953 | elif opts.get('branch'): | |
3954 | brev = opts['branch'][0] |
|
3954 | brev = opts['branch'][0] | |
3955 | else: |
|
3955 | else: | |
3956 | brev = branches[0] |
|
3956 | brev = branches[0] | |
3957 | repo._subtoppath = source |
|
3957 | repo._subtoppath = source | |
3958 | try: |
|
3958 | try: | |
3959 | ret = postincoming(ui, repo, modheads, opts.get('update'), |
|
3959 | ret = postincoming(ui, repo, modheads, opts.get('update'), | |
3960 | checkout, brev) |
|
3960 | checkout, brev) | |
3961 |
|
3961 | |||
3962 | finally: |
|
3962 | finally: | |
3963 | del repo._subtoppath |
|
3963 | del repo._subtoppath | |
3964 |
|
3964 | |||
3965 | finally: |
|
3965 | finally: | |
3966 | other.close() |
|
3966 | other.close() | |
3967 | return ret |
|
3967 | return ret | |
3968 |
|
3968 | |||
3969 | @command('^push', |
|
3969 | @command('^push', | |
3970 | [('f', 'force', None, _('force push')), |
|
3970 | [('f', 'force', None, _('force push')), | |
3971 | ('r', 'rev', [], |
|
3971 | ('r', 'rev', [], | |
3972 | _('a changeset intended to be included in the destination'), |
|
3972 | _('a changeset intended to be included in the destination'), | |
3973 | _('REV')), |
|
3973 | _('REV')), | |
3974 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
3974 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), | |
3975 | ('b', 'branch', [], |
|
3975 | ('b', 'branch', [], | |
3976 | _('a specific branch you would like to push'), _('BRANCH')), |
|
3976 | _('a specific branch you would like to push'), _('BRANCH')), | |
3977 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
3977 | ('', 'new-branch', False, _('allow pushing a new branch')), | |
3978 | ('', 'pushvars', [], _('variables that can be sent to server (ADVANCED)')), |
|
3978 | ('', 'pushvars', [], _('variables that can be sent to server (ADVANCED)')), | |
3979 | ] + remoteopts, |
|
3979 | ] + remoteopts, | |
3980 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
3980 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) | |
3981 | def push(ui, repo, dest=None, **opts): |
|
3981 | def push(ui, repo, dest=None, **opts): | |
3982 | """push changes to the specified destination |
|
3982 | """push changes to the specified destination | |
3983 |
|
3983 | |||
3984 | Push changesets from the local repository to the specified |
|
3984 | Push changesets from the local repository to the specified | |
3985 | destination. |
|
3985 | destination. | |
3986 |
|
3986 | |||
3987 | This operation is symmetrical to pull: it is identical to a pull |
|
3987 | This operation is symmetrical to pull: it is identical to a pull | |
3988 | in the destination repository from the current one. |
|
3988 | in the destination repository from the current one. | |
3989 |
|
3989 | |||
3990 | By default, push will not allow creation of new heads at the |
|
3990 | By default, push will not allow creation of new heads at the | |
3991 | destination, since multiple heads would make it unclear which head |
|
3991 | destination, since multiple heads would make it unclear which head | |
3992 | to use. In this situation, it is recommended to pull and merge |
|
3992 | to use. In this situation, it is recommended to pull and merge | |
3993 | before pushing. |
|
3993 | before pushing. | |
3994 |
|
3994 | |||
3995 | Use --new-branch if you want to allow push to create a new named |
|
3995 | Use --new-branch if you want to allow push to create a new named | |
3996 | branch that is not present at the destination. This allows you to |
|
3996 | branch that is not present at the destination. This allows you to | |
3997 | only create a new branch without forcing other changes. |
|
3997 | only create a new branch without forcing other changes. | |
3998 |
|
3998 | |||
3999 | .. note:: |
|
3999 | .. note:: | |
4000 |
|
4000 | |||
4001 | Extra care should be taken with the -f/--force option, |
|
4001 | Extra care should be taken with the -f/--force option, | |
4002 | which will push all new heads on all branches, an action which will |
|
4002 | which will push all new heads on all branches, an action which will | |
4003 | almost always cause confusion for collaborators. |
|
4003 | almost always cause confusion for collaborators. | |
4004 |
|
4004 | |||
4005 | If -r/--rev is used, the specified revision and all its ancestors |
|
4005 | If -r/--rev is used, the specified revision and all its ancestors | |
4006 | will be pushed to the remote repository. |
|
4006 | will be pushed to the remote repository. | |
4007 |
|
4007 | |||
4008 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
4008 | If -B/--bookmark is used, the specified bookmarked revision, its | |
4009 | ancestors, and the bookmark will be pushed to the remote |
|
4009 | ancestors, and the bookmark will be pushed to the remote | |
4010 | repository. Specifying ``.`` is equivalent to specifying the active |
|
4010 | repository. Specifying ``.`` is equivalent to specifying the active | |
4011 | bookmark's name. |
|
4011 | bookmark's name. | |
4012 |
|
4012 | |||
4013 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
4013 | Please see :hg:`help urls` for important details about ``ssh://`` | |
4014 | URLs. If DESTINATION is omitted, a default path will be used. |
|
4014 | URLs. If DESTINATION is omitted, a default path will be used. | |
4015 |
|
4015 | |||
4016 | .. container:: verbose |
|
4016 | .. container:: verbose | |
4017 |
|
4017 | |||
4018 | The --pushvars option sends strings to the server that become |
|
4018 | The --pushvars option sends strings to the server that become | |
4019 | environment variables prepended with ``HG_USERVAR_``. For example, |
|
4019 | environment variables prepended with ``HG_USERVAR_``. For example, | |
4020 | ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with |
|
4020 | ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with | |
4021 | ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment. |
|
4021 | ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment. | |
4022 |
|
4022 | |||
4023 | pushvars can provide for user-overridable hooks as well as set debug |
|
4023 | pushvars can provide for user-overridable hooks as well as set debug | |
4024 | levels. One example is having a hook that blocks commits containing |
|
4024 | levels. One example is having a hook that blocks commits containing | |
4025 | conflict markers, but enables the user to override the hook if the file |
|
4025 | conflict markers, but enables the user to override the hook if the file | |
4026 | is using conflict markers for testing purposes or the file format has |
|
4026 | is using conflict markers for testing purposes or the file format has | |
4027 | strings that look like conflict markers. |
|
4027 | strings that look like conflict markers. | |
4028 |
|
4028 | |||
4029 | By default, servers will ignore `--pushvars`. To enable it add the |
|
4029 | By default, servers will ignore `--pushvars`. To enable it add the | |
4030 | following to your configuration file:: |
|
4030 | following to your configuration file:: | |
4031 |
|
4031 | |||
4032 | [push] |
|
4032 | [push] | |
4033 | pushvars.server = true |
|
4033 | pushvars.server = true | |
4034 |
|
4034 | |||
4035 | Returns 0 if push was successful, 1 if nothing to push. |
|
4035 | Returns 0 if push was successful, 1 if nothing to push. | |
4036 | """ |
|
4036 | """ | |
4037 |
|
4037 | |||
4038 | opts = pycompat.byteskwargs(opts) |
|
4038 | opts = pycompat.byteskwargs(opts) | |
4039 | if opts.get('bookmark'): |
|
4039 | if opts.get('bookmark'): | |
4040 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') |
|
4040 | ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push') | |
4041 | for b in opts['bookmark']: |
|
4041 | for b in opts['bookmark']: | |
4042 | # translate -B options to -r so changesets get pushed |
|
4042 | # translate -B options to -r so changesets get pushed | |
4043 | b = repo._bookmarks.expandname(b) |
|
4043 | b = repo._bookmarks.expandname(b) | |
4044 | if b in repo._bookmarks: |
|
4044 | if b in repo._bookmarks: | |
4045 | opts.setdefault('rev', []).append(b) |
|
4045 | opts.setdefault('rev', []).append(b) | |
4046 | else: |
|
4046 | else: | |
4047 | # if we try to push a deleted bookmark, translate it to null |
|
4047 | # if we try to push a deleted bookmark, translate it to null | |
4048 | # this lets simultaneous -r, -b options continue working |
|
4048 | # this lets simultaneous -r, -b options continue working | |
4049 | opts.setdefault('rev', []).append("null") |
|
4049 | opts.setdefault('rev', []).append("null") | |
4050 |
|
4050 | |||
4051 | path = ui.paths.getpath(dest, default=('default-push', 'default')) |
|
4051 | path = ui.paths.getpath(dest, default=('default-push', 'default')) | |
4052 | if not path: |
|
4052 | if not path: | |
4053 | raise error.Abort(_('default repository not configured!'), |
|
4053 | raise error.Abort(_('default repository not configured!'), | |
4054 | hint=_("see 'hg help config.paths'")) |
|
4054 | hint=_("see 'hg help config.paths'")) | |
4055 | dest = path.pushloc or path.loc |
|
4055 | dest = path.pushloc or path.loc | |
4056 | branches = (path.branch, opts.get('branch') or []) |
|
4056 | branches = (path.branch, opts.get('branch') or []) | |
4057 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
4057 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) | |
4058 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
4058 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) | |
4059 | other = hg.peer(repo, opts, dest) |
|
4059 | other = hg.peer(repo, opts, dest) | |
4060 |
|
4060 | |||
4061 | if revs: |
|
4061 | if revs: | |
4062 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] |
|
4062 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] | |
4063 | if not revs: |
|
4063 | if not revs: | |
4064 | raise error.Abort(_("specified revisions evaluate to an empty set"), |
|
4064 | raise error.Abort(_("specified revisions evaluate to an empty set"), | |
4065 | hint=_("use different revision arguments")) |
|
4065 | hint=_("use different revision arguments")) | |
4066 | elif path.pushrev: |
|
4066 | elif path.pushrev: | |
4067 | # It doesn't make any sense to specify ancestor revisions. So limit |
|
4067 | # It doesn't make any sense to specify ancestor revisions. So limit | |
4068 | # to DAG heads to make discovery simpler. |
|
4068 | # to DAG heads to make discovery simpler. | |
4069 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) |
|
4069 | expr = revsetlang.formatspec('heads(%r)', path.pushrev) | |
4070 | revs = scmutil.revrange(repo, [expr]) |
|
4070 | revs = scmutil.revrange(repo, [expr]) | |
4071 | revs = [repo[rev].node() for rev in revs] |
|
4071 | revs = [repo[rev].node() for rev in revs] | |
4072 | if not revs: |
|
4072 | if not revs: | |
4073 | raise error.Abort(_('default push revset for path evaluates to an ' |
|
4073 | raise error.Abort(_('default push revset for path evaluates to an ' | |
4074 | 'empty set')) |
|
4074 | 'empty set')) | |
4075 |
|
4075 | |||
4076 | repo._subtoppath = dest |
|
4076 | repo._subtoppath = dest | |
4077 | try: |
|
4077 | try: | |
4078 | # push subrepos depth-first for coherent ordering |
|
4078 | # push subrepos depth-first for coherent ordering | |
4079 | c = repo[''] |
|
4079 | c = repo[''] | |
4080 | subs = c.substate # only repos that are committed |
|
4080 | subs = c.substate # only repos that are committed | |
4081 | for s in sorted(subs): |
|
4081 | for s in sorted(subs): | |
4082 | result = c.sub(s).push(opts) |
|
4082 | result = c.sub(s).push(opts) | |
4083 | if result == 0: |
|
4083 | if result == 0: | |
4084 | return not result |
|
4084 | return not result | |
4085 | finally: |
|
4085 | finally: | |
4086 | del repo._subtoppath |
|
4086 | del repo._subtoppath | |
4087 |
|
4087 | |||
4088 | opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it |
|
4088 | opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it | |
4089 | opargs.setdefault('pushvars', []).extend(opts.get('pushvars', [])) |
|
4089 | opargs.setdefault('pushvars', []).extend(opts.get('pushvars', [])) | |
4090 |
|
4090 | |||
4091 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, |
|
4091 | pushop = exchange.push(repo, other, opts.get('force'), revs=revs, | |
4092 | newbranch=opts.get('new_branch'), |
|
4092 | newbranch=opts.get('new_branch'), | |
4093 | bookmarks=opts.get('bookmark', ()), |
|
4093 | bookmarks=opts.get('bookmark', ()), | |
4094 | opargs=opargs) |
|
4094 | opargs=opargs) | |
4095 |
|
4095 | |||
4096 | result = not pushop.cgresult |
|
4096 | result = not pushop.cgresult | |
4097 |
|
4097 | |||
4098 | if pushop.bkresult is not None: |
|
4098 | if pushop.bkresult is not None: | |
4099 | if pushop.bkresult == 2: |
|
4099 | if pushop.bkresult == 2: | |
4100 | result = 2 |
|
4100 | result = 2 | |
4101 | elif not result and pushop.bkresult: |
|
4101 | elif not result and pushop.bkresult: | |
4102 | result = 2 |
|
4102 | result = 2 | |
4103 |
|
4103 | |||
4104 | return result |
|
4104 | return result | |
4105 |
|
4105 | |||
4106 | @command('recover', []) |
|
4106 | @command('recover', []) | |
4107 | def recover(ui, repo): |
|
4107 | def recover(ui, repo): | |
4108 | """roll back an interrupted transaction |
|
4108 | """roll back an interrupted transaction | |
4109 |
|
4109 | |||
4110 | Recover from an interrupted commit or pull. |
|
4110 | Recover from an interrupted commit or pull. | |
4111 |
|
4111 | |||
4112 | This command tries to fix the repository status after an |
|
4112 | This command tries to fix the repository status after an | |
4113 | interrupted operation. It should only be necessary when Mercurial |
|
4113 | interrupted operation. It should only be necessary when Mercurial | |
4114 | suggests it. |
|
4114 | suggests it. | |
4115 |
|
4115 | |||
4116 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
4116 | Returns 0 if successful, 1 if nothing to recover or verify fails. | |
4117 | """ |
|
4117 | """ | |
4118 | if repo.recover(): |
|
4118 | if repo.recover(): | |
4119 | return hg.verify(repo) |
|
4119 | return hg.verify(repo) | |
4120 | return 1 |
|
4120 | return 1 | |
4121 |
|
4121 | |||
4122 | @command('^remove|rm', |
|
4122 | @command('^remove|rm', | |
4123 | [('A', 'after', None, _('record delete for missing files')), |
|
4123 | [('A', 'after', None, _('record delete for missing files')), | |
4124 | ('f', 'force', None, |
|
4124 | ('f', 'force', None, | |
4125 | _('forget added files, delete modified files')), |
|
4125 | _('forget added files, delete modified files')), | |
4126 | ] + subrepoopts + walkopts, |
|
4126 | ] + subrepoopts + walkopts, | |
4127 | _('[OPTION]... FILE...'), |
|
4127 | _('[OPTION]... FILE...'), | |
4128 | inferrepo=True) |
|
4128 | inferrepo=True) | |
4129 | def remove(ui, repo, *pats, **opts): |
|
4129 | def remove(ui, repo, *pats, **opts): | |
4130 | """remove the specified files on the next commit |
|
4130 | """remove the specified files on the next commit | |
4131 |
|
4131 | |||
4132 | Schedule the indicated files for removal from the current branch. |
|
4132 | Schedule the indicated files for removal from the current branch. | |
4133 |
|
4133 | |||
4134 | This command schedules the files to be removed at the next commit. |
|
4134 | This command schedules the files to be removed at the next commit. | |
4135 | To undo a remove before that, see :hg:`revert`. To undo added |
|
4135 | To undo a remove before that, see :hg:`revert`. To undo added | |
4136 | files, see :hg:`forget`. |
|
4136 | files, see :hg:`forget`. | |
4137 |
|
4137 | |||
4138 | .. container:: verbose |
|
4138 | .. container:: verbose | |
4139 |
|
4139 | |||
4140 | -A/--after can be used to remove only files that have already |
|
4140 | -A/--after can be used to remove only files that have already | |
4141 | been deleted, -f/--force can be used to force deletion, and -Af |
|
4141 | been deleted, -f/--force can be used to force deletion, and -Af | |
4142 | can be used to remove files from the next revision without |
|
4142 | can be used to remove files from the next revision without | |
4143 | deleting them from the working directory. |
|
4143 | deleting them from the working directory. | |
4144 |
|
4144 | |||
4145 | The following table details the behavior of remove for different |
|
4145 | The following table details the behavior of remove for different | |
4146 | file states (columns) and option combinations (rows). The file |
|
4146 | file states (columns) and option combinations (rows). The file | |
4147 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
4147 | states are Added [A], Clean [C], Modified [M] and Missing [!] | |
4148 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
4148 | (as reported by :hg:`status`). The actions are Warn, Remove | |
4149 | (from branch) and Delete (from disk): |
|
4149 | (from branch) and Delete (from disk): | |
4150 |
|
4150 | |||
4151 | ========= == == == == |
|
4151 | ========= == == == == | |
4152 | opt/state A C M ! |
|
4152 | opt/state A C M ! | |
4153 | ========= == == == == |
|
4153 | ========= == == == == | |
4154 | none W RD W R |
|
4154 | none W RD W R | |
4155 | -f R RD RD R |
|
4155 | -f R RD RD R | |
4156 | -A W W W R |
|
4156 | -A W W W R | |
4157 | -Af R R R R |
|
4157 | -Af R R R R | |
4158 | ========= == == == == |
|
4158 | ========= == == == == | |
4159 |
|
4159 | |||
4160 | .. note:: |
|
4160 | .. note:: | |
4161 |
|
4161 | |||
4162 | :hg:`remove` never deletes files in Added [A] state from the |
|
4162 | :hg:`remove` never deletes files in Added [A] state from the | |
4163 | working directory, not even if ``--force`` is specified. |
|
4163 | working directory, not even if ``--force`` is specified. | |
4164 |
|
4164 | |||
4165 | Returns 0 on success, 1 if any warnings encountered. |
|
4165 | Returns 0 on success, 1 if any warnings encountered. | |
4166 | """ |
|
4166 | """ | |
4167 |
|
4167 | |||
4168 | opts = pycompat.byteskwargs(opts) |
|
4168 | opts = pycompat.byteskwargs(opts) | |
4169 | after, force = opts.get('after'), opts.get('force') |
|
4169 | after, force = opts.get('after'), opts.get('force') | |
4170 | if not pats and not after: |
|
4170 | if not pats and not after: | |
4171 | raise error.Abort(_('no files specified')) |
|
4171 | raise error.Abort(_('no files specified')) | |
4172 |
|
4172 | |||
4173 | m = scmutil.match(repo[None], pats, opts) |
|
4173 | m = scmutil.match(repo[None], pats, opts) | |
4174 | subrepos = opts.get('subrepos') |
|
4174 | subrepos = opts.get('subrepos') | |
4175 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos) |
|
4175 | return cmdutil.remove(ui, repo, m, "", after, force, subrepos) | |
4176 |
|
4176 | |||
4177 | @command('rename|move|mv', |
|
4177 | @command('rename|move|mv', | |
4178 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
4178 | [('A', 'after', None, _('record a rename that has already occurred')), | |
4179 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
4179 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
4180 | ] + walkopts + dryrunopts, |
|
4180 | ] + walkopts + dryrunopts, | |
4181 | _('[OPTION]... SOURCE... DEST')) |
|
4181 | _('[OPTION]... SOURCE... DEST')) | |
4182 | def rename(ui, repo, *pats, **opts): |
|
4182 | def rename(ui, repo, *pats, **opts): | |
4183 | """rename files; equivalent of copy + remove |
|
4183 | """rename files; equivalent of copy + remove | |
4184 |
|
4184 | |||
4185 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
4185 | Mark dest as copies of sources; mark sources for deletion. If dest | |
4186 | is a directory, copies are put in that directory. If dest is a |
|
4186 | is a directory, copies are put in that directory. If dest is a | |
4187 | file, there can only be one source. |
|
4187 | file, there can only be one source. | |
4188 |
|
4188 | |||
4189 | By default, this command copies the contents of files as they |
|
4189 | By default, this command copies the contents of files as they | |
4190 | exist in the working directory. If invoked with -A/--after, the |
|
4190 | exist in the working directory. If invoked with -A/--after, the | |
4191 | operation is recorded, but no copying is performed. |
|
4191 | operation is recorded, but no copying is performed. | |
4192 |
|
4192 | |||
4193 | This command takes effect at the next commit. To undo a rename |
|
4193 | This command takes effect at the next commit. To undo a rename | |
4194 | before that, see :hg:`revert`. |
|
4194 | before that, see :hg:`revert`. | |
4195 |
|
4195 | |||
4196 | Returns 0 on success, 1 if errors are encountered. |
|
4196 | Returns 0 on success, 1 if errors are encountered. | |
4197 | """ |
|
4197 | """ | |
4198 | opts = pycompat.byteskwargs(opts) |
|
4198 | opts = pycompat.byteskwargs(opts) | |
4199 | with repo.wlock(False): |
|
4199 | with repo.wlock(False): | |
4200 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
4200 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | |
4201 |
|
4201 | |||
4202 | @command('resolve', |
|
4202 | @command('resolve', | |
4203 | [('a', 'all', None, _('select all unresolved files')), |
|
4203 | [('a', 'all', None, _('select all unresolved files')), | |
4204 | ('l', 'list', None, _('list state of files needing merge')), |
|
4204 | ('l', 'list', None, _('list state of files needing merge')), | |
4205 | ('m', 'mark', None, _('mark files as resolved')), |
|
4205 | ('m', 'mark', None, _('mark files as resolved')), | |
4206 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
4206 | ('u', 'unmark', None, _('mark files as unresolved')), | |
4207 | ('n', 'no-status', None, _('hide status prefix'))] |
|
4207 | ('n', 'no-status', None, _('hide status prefix'))] | |
4208 | + mergetoolopts + walkopts + formatteropts, |
|
4208 | + mergetoolopts + walkopts + formatteropts, | |
4209 | _('[OPTION]... [FILE]...'), |
|
4209 | _('[OPTION]... [FILE]...'), | |
4210 | inferrepo=True) |
|
4210 | inferrepo=True) | |
4211 | def resolve(ui, repo, *pats, **opts): |
|
4211 | def resolve(ui, repo, *pats, **opts): | |
4212 | """redo merges or set/view the merge status of files |
|
4212 | """redo merges or set/view the merge status of files | |
4213 |
|
4213 | |||
4214 | Merges with unresolved conflicts are often the result of |
|
4214 | Merges with unresolved conflicts are often the result of | |
4215 | non-interactive merging using the ``internal:merge`` configuration |
|
4215 | non-interactive merging using the ``internal:merge`` configuration | |
4216 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
4216 | setting, or a command-line merge tool like ``diff3``. The resolve | |
4217 | command is used to manage the files involved in a merge, after |
|
4217 | command is used to manage the files involved in a merge, after | |
4218 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
4218 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | |
4219 | working directory must have two parents). See :hg:`help |
|
4219 | working directory must have two parents). See :hg:`help | |
4220 | merge-tools` for information on configuring merge tools. |
|
4220 | merge-tools` for information on configuring merge tools. | |
4221 |
|
4221 | |||
4222 | The resolve command can be used in the following ways: |
|
4222 | The resolve command can be used in the following ways: | |
4223 |
|
4223 | |||
4224 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
4224 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | |
4225 | files, discarding any previous merge attempts. Re-merging is not |
|
4225 | files, discarding any previous merge attempts. Re-merging is not | |
4226 | performed for files already marked as resolved. Use ``--all/-a`` |
|
4226 | performed for files already marked as resolved. Use ``--all/-a`` | |
4227 | to select all unresolved files. ``--tool`` can be used to specify |
|
4227 | to select all unresolved files. ``--tool`` can be used to specify | |
4228 | the merge tool used for the given files. It overrides the HGMERGE |
|
4228 | the merge tool used for the given files. It overrides the HGMERGE | |
4229 | environment variable and your configuration files. Previous file |
|
4229 | environment variable and your configuration files. Previous file | |
4230 | contents are saved with a ``.orig`` suffix. |
|
4230 | contents are saved with a ``.orig`` suffix. | |
4231 |
|
4231 | |||
4232 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
4232 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved | |
4233 | (e.g. after having manually fixed-up the files). The default is |
|
4233 | (e.g. after having manually fixed-up the files). The default is | |
4234 | to mark all unresolved files. |
|
4234 | to mark all unresolved files. | |
4235 |
|
4235 | |||
4236 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
4236 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The | |
4237 | default is to mark all resolved files. |
|
4237 | default is to mark all resolved files. | |
4238 |
|
4238 | |||
4239 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
4239 | - :hg:`resolve -l`: list files which had or still have conflicts. | |
4240 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
4240 | In the printed list, ``U`` = unresolved and ``R`` = resolved. | |
4241 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter |
|
4241 | You can use ``set:unresolved()`` or ``set:resolved()`` to filter | |
4242 | the list. See :hg:`help filesets` for details. |
|
4242 | the list. See :hg:`help filesets` for details. | |
4243 |
|
4243 | |||
4244 | .. note:: |
|
4244 | .. note:: | |
4245 |
|
4245 | |||
4246 | Mercurial will not let you commit files with unresolved merge |
|
4246 | Mercurial will not let you commit files with unresolved merge | |
4247 | conflicts. You must use :hg:`resolve -m ...` before you can |
|
4247 | conflicts. You must use :hg:`resolve -m ...` before you can | |
4248 | commit after a conflicting merge. |
|
4248 | commit after a conflicting merge. | |
4249 |
|
4249 | |||
4250 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
4250 | Returns 0 on success, 1 if any files fail a resolve attempt. | |
4251 | """ |
|
4251 | """ | |
4252 |
|
4252 | |||
4253 | opts = pycompat.byteskwargs(opts) |
|
4253 | opts = pycompat.byteskwargs(opts) | |
4254 | flaglist = 'all mark unmark list no_status'.split() |
|
4254 | flaglist = 'all mark unmark list no_status'.split() | |
4255 | all, mark, unmark, show, nostatus = \ |
|
4255 | all, mark, unmark, show, nostatus = \ | |
4256 | [opts.get(o) for o in flaglist] |
|
4256 | [opts.get(o) for o in flaglist] | |
4257 |
|
4257 | |||
4258 | if (show and (mark or unmark)) or (mark and unmark): |
|
4258 | if (show and (mark or unmark)) or (mark and unmark): | |
4259 | raise error.Abort(_("too many options specified")) |
|
4259 | raise error.Abort(_("too many options specified")) | |
4260 | if pats and all: |
|
4260 | if pats and all: | |
4261 | raise error.Abort(_("can't specify --all and patterns")) |
|
4261 | raise error.Abort(_("can't specify --all and patterns")) | |
4262 | if not (all or pats or show or mark or unmark): |
|
4262 | if not (all or pats or show or mark or unmark): | |
4263 | raise error.Abort(_('no files or directories specified'), |
|
4263 | raise error.Abort(_('no files or directories specified'), | |
4264 | hint=('use --all to re-merge all unresolved files')) |
|
4264 | hint=('use --all to re-merge all unresolved files')) | |
4265 |
|
4265 | |||
4266 | if show: |
|
4266 | if show: | |
4267 | ui.pager('resolve') |
|
4267 | ui.pager('resolve') | |
4268 | fm = ui.formatter('resolve', opts) |
|
4268 | fm = ui.formatter('resolve', opts) | |
4269 | ms = mergemod.mergestate.read(repo) |
|
4269 | ms = mergemod.mergestate.read(repo) | |
4270 | m = scmutil.match(repo[None], pats, opts) |
|
4270 | m = scmutil.match(repo[None], pats, opts) | |
4271 | for f in ms: |
|
4271 | for f in ms: | |
4272 | if not m(f): |
|
4272 | if not m(f): | |
4273 | continue |
|
4273 | continue | |
4274 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved', |
|
4274 | l = 'resolve.' + {'u': 'unresolved', 'r': 'resolved', | |
4275 | 'd': 'driverresolved'}[ms[f]] |
|
4275 | 'd': 'driverresolved'}[ms[f]] | |
4276 | fm.startitem() |
|
4276 | fm.startitem() | |
4277 | fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) |
|
4277 | fm.condwrite(not nostatus, 'status', '%s ', ms[f].upper(), label=l) | |
4278 | fm.write('path', '%s\n', f, label=l) |
|
4278 | fm.write('path', '%s\n', f, label=l) | |
4279 | fm.end() |
|
4279 | fm.end() | |
4280 | return 0 |
|
4280 | return 0 | |
4281 |
|
4281 | |||
4282 | with repo.wlock(): |
|
4282 | with repo.wlock(): | |
4283 | ms = mergemod.mergestate.read(repo) |
|
4283 | ms = mergemod.mergestate.read(repo) | |
4284 |
|
4284 | |||
4285 | if not (ms.active() or repo.dirstate.p2() != nullid): |
|
4285 | if not (ms.active() or repo.dirstate.p2() != nullid): | |
4286 | raise error.Abort( |
|
4286 | raise error.Abort( | |
4287 | _('resolve command not applicable when not merging')) |
|
4287 | _('resolve command not applicable when not merging')) | |
4288 |
|
4288 | |||
4289 | wctx = repo[None] |
|
4289 | wctx = repo[None] | |
4290 |
|
4290 | |||
4291 | if ms.mergedriver and ms.mdstate() == 'u': |
|
4291 | if ms.mergedriver and ms.mdstate() == 'u': | |
4292 | proceed = mergemod.driverpreprocess(repo, ms, wctx) |
|
4292 | proceed = mergemod.driverpreprocess(repo, ms, wctx) | |
4293 | ms.commit() |
|
4293 | ms.commit() | |
4294 | # allow mark and unmark to go through |
|
4294 | # allow mark and unmark to go through | |
4295 | if not mark and not unmark and not proceed: |
|
4295 | if not mark and not unmark and not proceed: | |
4296 | return 1 |
|
4296 | return 1 | |
4297 |
|
4297 | |||
4298 | m = scmutil.match(wctx, pats, opts) |
|
4298 | m = scmutil.match(wctx, pats, opts) | |
4299 | ret = 0 |
|
4299 | ret = 0 | |
4300 | didwork = False |
|
4300 | didwork = False | |
4301 | runconclude = False |
|
4301 | runconclude = False | |
4302 |
|
4302 | |||
4303 | tocomplete = [] |
|
4303 | tocomplete = [] | |
4304 | for f in ms: |
|
4304 | for f in ms: | |
4305 | if not m(f): |
|
4305 | if not m(f): | |
4306 | continue |
|
4306 | continue | |
4307 |
|
4307 | |||
4308 | didwork = True |
|
4308 | didwork = True | |
4309 |
|
4309 | |||
4310 | # don't let driver-resolved files be marked, and run the conclude |
|
4310 | # don't let driver-resolved files be marked, and run the conclude | |
4311 | # step if asked to resolve |
|
4311 | # step if asked to resolve | |
4312 | if ms[f] == "d": |
|
4312 | if ms[f] == "d": | |
4313 | exact = m.exact(f) |
|
4313 | exact = m.exact(f) | |
4314 | if mark: |
|
4314 | if mark: | |
4315 | if exact: |
|
4315 | if exact: | |
4316 | ui.warn(_('not marking %s as it is driver-resolved\n') |
|
4316 | ui.warn(_('not marking %s as it is driver-resolved\n') | |
4317 | % f) |
|
4317 | % f) | |
4318 | elif unmark: |
|
4318 | elif unmark: | |
4319 | if exact: |
|
4319 | if exact: | |
4320 | ui.warn(_('not unmarking %s as it is driver-resolved\n') |
|
4320 | ui.warn(_('not unmarking %s as it is driver-resolved\n') | |
4321 | % f) |
|
4321 | % f) | |
4322 | else: |
|
4322 | else: | |
4323 | runconclude = True |
|
4323 | runconclude = True | |
4324 | continue |
|
4324 | continue | |
4325 |
|
4325 | |||
4326 | if mark: |
|
4326 | if mark: | |
4327 | ms.mark(f, "r") |
|
4327 | ms.mark(f, "r") | |
4328 | elif unmark: |
|
4328 | elif unmark: | |
4329 | ms.mark(f, "u") |
|
4329 | ms.mark(f, "u") | |
4330 | else: |
|
4330 | else: | |
4331 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
4331 | # backup pre-resolve (merge uses .orig for its own purposes) | |
4332 | a = repo.wjoin(f) |
|
4332 | a = repo.wjoin(f) | |
4333 | try: |
|
4333 | try: | |
4334 | util.copyfile(a, a + ".resolve") |
|
4334 | util.copyfile(a, a + ".resolve") | |
4335 | except (IOError, OSError) as inst: |
|
4335 | except (IOError, OSError) as inst: | |
4336 | if inst.errno != errno.ENOENT: |
|
4336 | if inst.errno != errno.ENOENT: | |
4337 | raise |
|
4337 | raise | |
4338 |
|
4338 | |||
4339 | try: |
|
4339 | try: | |
4340 | # preresolve file |
|
4340 | # preresolve file | |
4341 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
4341 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |
4342 | 'resolve') |
|
4342 | 'resolve') | |
4343 | complete, r = ms.preresolve(f, wctx) |
|
4343 | complete, r = ms.preresolve(f, wctx) | |
4344 | if not complete: |
|
4344 | if not complete: | |
4345 | tocomplete.append(f) |
|
4345 | tocomplete.append(f) | |
4346 | elif r: |
|
4346 | elif r: | |
4347 | ret = 1 |
|
4347 | ret = 1 | |
4348 | finally: |
|
4348 | finally: | |
4349 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
4349 | ui.setconfig('ui', 'forcemerge', '', 'resolve') | |
4350 | ms.commit() |
|
4350 | ms.commit() | |
4351 |
|
4351 | |||
4352 | # replace filemerge's .orig file with our resolve file, but only |
|
4352 | # replace filemerge's .orig file with our resolve file, but only | |
4353 | # for merges that are complete |
|
4353 | # for merges that are complete | |
4354 | if complete: |
|
4354 | if complete: | |
4355 | try: |
|
4355 | try: | |
4356 | util.rename(a + ".resolve", |
|
4356 | util.rename(a + ".resolve", | |
4357 | scmutil.origpath(ui, repo, a)) |
|
4357 | scmutil.origpath(ui, repo, a)) | |
4358 | except OSError as inst: |
|
4358 | except OSError as inst: | |
4359 | if inst.errno != errno.ENOENT: |
|
4359 | if inst.errno != errno.ENOENT: | |
4360 | raise |
|
4360 | raise | |
4361 |
|
4361 | |||
4362 | for f in tocomplete: |
|
4362 | for f in tocomplete: | |
4363 | try: |
|
4363 | try: | |
4364 | # resolve file |
|
4364 | # resolve file | |
4365 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), |
|
4365 | ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), | |
4366 | 'resolve') |
|
4366 | 'resolve') | |
4367 | r = ms.resolve(f, wctx) |
|
4367 | r = ms.resolve(f, wctx) | |
4368 | if r: |
|
4368 | if r: | |
4369 | ret = 1 |
|
4369 | ret = 1 | |
4370 | finally: |
|
4370 | finally: | |
4371 | ui.setconfig('ui', 'forcemerge', '', 'resolve') |
|
4371 | ui.setconfig('ui', 'forcemerge', '', 'resolve') | |
4372 | ms.commit() |
|
4372 | ms.commit() | |
4373 |
|
4373 | |||
4374 | # replace filemerge's .orig file with our resolve file |
|
4374 | # replace filemerge's .orig file with our resolve file | |
4375 | a = repo.wjoin(f) |
|
4375 | a = repo.wjoin(f) | |
4376 | try: |
|
4376 | try: | |
4377 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) |
|
4377 | util.rename(a + ".resolve", scmutil.origpath(ui, repo, a)) | |
4378 | except OSError as inst: |
|
4378 | except OSError as inst: | |
4379 | if inst.errno != errno.ENOENT: |
|
4379 | if inst.errno != errno.ENOENT: | |
4380 | raise |
|
4380 | raise | |
4381 |
|
4381 | |||
4382 | ms.commit() |
|
4382 | ms.commit() | |
4383 | ms.recordactions() |
|
4383 | ms.recordactions() | |
4384 |
|
4384 | |||
4385 | if not didwork and pats: |
|
4385 | if not didwork and pats: | |
4386 | hint = None |
|
4386 | hint = None | |
4387 | if not any([p for p in pats if p.find(':') >= 0]): |
|
4387 | if not any([p for p in pats if p.find(':') >= 0]): | |
4388 | pats = ['path:%s' % p for p in pats] |
|
4388 | pats = ['path:%s' % p for p in pats] | |
4389 | m = scmutil.match(wctx, pats, opts) |
|
4389 | m = scmutil.match(wctx, pats, opts) | |
4390 | for f in ms: |
|
4390 | for f in ms: | |
4391 | if not m(f): |
|
4391 | if not m(f): | |
4392 | continue |
|
4392 | continue | |
4393 | flags = ''.join(['-%s ' % o[0] for o in flaglist |
|
4393 | flags = ''.join(['-%s ' % o[0] for o in flaglist | |
4394 | if opts.get(o)]) |
|
4394 | if opts.get(o)]) | |
4395 | hint = _("(try: hg resolve %s%s)\n") % ( |
|
4395 | hint = _("(try: hg resolve %s%s)\n") % ( | |
4396 | flags, |
|
4396 | flags, | |
4397 | ' '.join(pats)) |
|
4397 | ' '.join(pats)) | |
4398 | break |
|
4398 | break | |
4399 | ui.warn(_("arguments do not match paths that need resolving\n")) |
|
4399 | ui.warn(_("arguments do not match paths that need resolving\n")) | |
4400 | if hint: |
|
4400 | if hint: | |
4401 | ui.warn(hint) |
|
4401 | ui.warn(hint) | |
4402 | elif ms.mergedriver and ms.mdstate() != 's': |
|
4402 | elif ms.mergedriver and ms.mdstate() != 's': | |
4403 | # run conclude step when either a driver-resolved file is requested |
|
4403 | # run conclude step when either a driver-resolved file is requested | |
4404 | # or there are no driver-resolved files |
|
4404 | # or there are no driver-resolved files | |
4405 | # we can't use 'ret' to determine whether any files are unresolved |
|
4405 | # we can't use 'ret' to determine whether any files are unresolved | |
4406 | # because we might not have tried to resolve some |
|
4406 | # because we might not have tried to resolve some | |
4407 | if ((runconclude or not list(ms.driverresolved())) |
|
4407 | if ((runconclude or not list(ms.driverresolved())) | |
4408 | and not list(ms.unresolved())): |
|
4408 | and not list(ms.unresolved())): | |
4409 | proceed = mergemod.driverconclude(repo, ms, wctx) |
|
4409 | proceed = mergemod.driverconclude(repo, ms, wctx) | |
4410 | ms.commit() |
|
4410 | ms.commit() | |
4411 | if not proceed: |
|
4411 | if not proceed: | |
4412 | return 1 |
|
4412 | return 1 | |
4413 |
|
4413 | |||
4414 | # Nudge users into finishing an unfinished operation |
|
4414 | # Nudge users into finishing an unfinished operation | |
4415 | unresolvedf = list(ms.unresolved()) |
|
4415 | unresolvedf = list(ms.unresolved()) | |
4416 | driverresolvedf = list(ms.driverresolved()) |
|
4416 | driverresolvedf = list(ms.driverresolved()) | |
4417 | if not unresolvedf and not driverresolvedf: |
|
4417 | if not unresolvedf and not driverresolvedf: | |
4418 | ui.status(_('(no more unresolved files)\n')) |
|
4418 | ui.status(_('(no more unresolved files)\n')) | |
4419 | cmdutil.checkafterresolved(repo) |
|
4419 | cmdutil.checkafterresolved(repo) | |
4420 | elif not unresolvedf: |
|
4420 | elif not unresolvedf: | |
4421 | ui.status(_('(no more unresolved files -- ' |
|
4421 | ui.status(_('(no more unresolved files -- ' | |
4422 | 'run "hg resolve --all" to conclude)\n')) |
|
4422 | 'run "hg resolve --all" to conclude)\n')) | |
4423 |
|
4423 | |||
4424 | return ret |
|
4424 | return ret | |
4425 |
|
4425 | |||
4426 | @command('revert', |
|
4426 | @command('revert', | |
4427 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4427 | [('a', 'all', None, _('revert all changes when no arguments given')), | |
4428 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4428 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
4429 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4429 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), | |
4430 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
4430 | ('C', 'no-backup', None, _('do not save backup copies of files')), | |
4431 | ('i', 'interactive', None, |
|
4431 | ('i', 'interactive', None, | |
4432 | _('interactively select the changes (EXPERIMENTAL)')), |
|
4432 | _('interactively select the changes (EXPERIMENTAL)')), | |
4433 | ] + walkopts + dryrunopts, |
|
4433 | ] + walkopts + dryrunopts, | |
4434 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4434 | _('[OPTION]... [-r REV] [NAME]...')) | |
4435 | def revert(ui, repo, *pats, **opts): |
|
4435 | def revert(ui, repo, *pats, **opts): | |
4436 | """restore files to their checkout state |
|
4436 | """restore files to their checkout state | |
4437 |
|
4437 | |||
4438 | .. note:: |
|
4438 | .. note:: | |
4439 |
|
4439 | |||
4440 | To check out earlier revisions, you should use :hg:`update REV`. |
|
4440 | To check out earlier revisions, you should use :hg:`update REV`. | |
4441 | To cancel an uncommitted merge (and lose your changes), |
|
4441 | To cancel an uncommitted merge (and lose your changes), | |
4442 | use :hg:`update --clean .`. |
|
4442 | use :hg:`update --clean .`. | |
4443 |
|
4443 | |||
4444 | With no revision specified, revert the specified files or directories |
|
4444 | With no revision specified, revert the specified files or directories | |
4445 | to the contents they had in the parent of the working directory. |
|
4445 | to the contents they had in the parent of the working directory. | |
4446 | This restores the contents of files to an unmodified |
|
4446 | This restores the contents of files to an unmodified | |
4447 | state and unschedules adds, removes, copies, and renames. If the |
|
4447 | state and unschedules adds, removes, copies, and renames. If the | |
4448 | working directory has two parents, you must explicitly specify a |
|
4448 | working directory has two parents, you must explicitly specify a | |
4449 | revision. |
|
4449 | revision. | |
4450 |
|
4450 | |||
4451 | Using the -r/--rev or -d/--date options, revert the given files or |
|
4451 | Using the -r/--rev or -d/--date options, revert the given files or | |
4452 | directories to their states as of a specific revision. Because |
|
4452 | directories to their states as of a specific revision. Because | |
4453 | revert does not change the working directory parents, this will |
|
4453 | revert does not change the working directory parents, this will | |
4454 | cause these files to appear modified. This can be helpful to "back |
|
4454 | cause these files to appear modified. This can be helpful to "back | |
4455 | out" some or all of an earlier change. See :hg:`backout` for a |
|
4455 | out" some or all of an earlier change. See :hg:`backout` for a | |
4456 | related method. |
|
4456 | related method. | |
4457 |
|
4457 | |||
4458 | Modified files are saved with a .orig suffix before reverting. |
|
4458 | Modified files are saved with a .orig suffix before reverting. | |
4459 | To disable these backups, use --no-backup. It is possible to store |
|
4459 | To disable these backups, use --no-backup. It is possible to store | |
4460 | the backup files in a custom directory relative to the root of the |
|
4460 | the backup files in a custom directory relative to the root of the | |
4461 | repository by setting the ``ui.origbackuppath`` configuration |
|
4461 | repository by setting the ``ui.origbackuppath`` configuration | |
4462 | option. |
|
4462 | option. | |
4463 |
|
4463 | |||
4464 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4464 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
4465 |
|
4465 | |||
4466 | See :hg:`help backout` for a way to reverse the effect of an |
|
4466 | See :hg:`help backout` for a way to reverse the effect of an | |
4467 | earlier changeset. |
|
4467 | earlier changeset. | |
4468 |
|
4468 | |||
4469 | Returns 0 on success. |
|
4469 | Returns 0 on success. | |
4470 | """ |
|
4470 | """ | |
4471 |
|
4471 | |||
4472 | if opts.get("date"): |
|
4472 | if opts.get("date"): | |
4473 | if opts.get("rev"): |
|
4473 | if opts.get("rev"): | |
4474 | raise error.Abort(_("you can't specify a revision and a date")) |
|
4474 | raise error.Abort(_("you can't specify a revision and a date")) | |
4475 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4475 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | |
4476 |
|
4476 | |||
4477 | parent, p2 = repo.dirstate.parents() |
|
4477 | parent, p2 = repo.dirstate.parents() | |
4478 | if not opts.get('rev') and p2 != nullid: |
|
4478 | if not opts.get('rev') and p2 != nullid: | |
4479 | # revert after merge is a trap for new users (issue2915) |
|
4479 | # revert after merge is a trap for new users (issue2915) | |
4480 | raise error.Abort(_('uncommitted merge with no revision specified'), |
|
4480 | raise error.Abort(_('uncommitted merge with no revision specified'), | |
4481 | hint=_("use 'hg update' or see 'hg help revert'")) |
|
4481 | hint=_("use 'hg update' or see 'hg help revert'")) | |
4482 |
|
4482 | |||
4483 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
4483 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
4484 |
|
4484 | |||
4485 | if (not (pats or opts.get('include') or opts.get('exclude') or |
|
4485 | if (not (pats or opts.get('include') or opts.get('exclude') or | |
4486 | opts.get('all') or opts.get('interactive'))): |
|
4486 | opts.get('all') or opts.get('interactive'))): | |
4487 | msg = _("no files or directories specified") |
|
4487 | msg = _("no files or directories specified") | |
4488 | if p2 != nullid: |
|
4488 | if p2 != nullid: | |
4489 | hint = _("uncommitted merge, use --all to discard all changes," |
|
4489 | hint = _("uncommitted merge, use --all to discard all changes," | |
4490 | " or 'hg update -C .' to abort the merge") |
|
4490 | " or 'hg update -C .' to abort the merge") | |
4491 | raise error.Abort(msg, hint=hint) |
|
4491 | raise error.Abort(msg, hint=hint) | |
4492 | dirty = any(repo.status()) |
|
4492 | dirty = any(repo.status()) | |
4493 | node = ctx.node() |
|
4493 | node = ctx.node() | |
4494 | if node != parent: |
|
4494 | if node != parent: | |
4495 | if dirty: |
|
4495 | if dirty: | |
4496 | hint = _("uncommitted changes, use --all to discard all" |
|
4496 | hint = _("uncommitted changes, use --all to discard all" | |
4497 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
4497 | " changes, or 'hg update %s' to update") % ctx.rev() | |
4498 | else: |
|
4498 | else: | |
4499 | hint = _("use --all to revert all files," |
|
4499 | hint = _("use --all to revert all files," | |
4500 | " or 'hg update %s' to update") % ctx.rev() |
|
4500 | " or 'hg update %s' to update") % ctx.rev() | |
4501 | elif dirty: |
|
4501 | elif dirty: | |
4502 | hint = _("uncommitted changes, use --all to discard all changes") |
|
4502 | hint = _("uncommitted changes, use --all to discard all changes") | |
4503 | else: |
|
4503 | else: | |
4504 | hint = _("use --all to revert all files") |
|
4504 | hint = _("use --all to revert all files") | |
4505 | raise error.Abort(msg, hint=hint) |
|
4505 | raise error.Abort(msg, hint=hint) | |
4506 |
|
4506 | |||
4507 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
4507 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) | |
4508 |
|
4508 | |||
4509 | @command('rollback', dryrunopts + |
|
4509 | @command('rollback', dryrunopts + | |
4510 | [('f', 'force', False, _('ignore safety measures'))]) |
|
4510 | [('f', 'force', False, _('ignore safety measures'))]) | |
4511 | def rollback(ui, repo, **opts): |
|
4511 | def rollback(ui, repo, **opts): | |
4512 | """roll back the last transaction (DANGEROUS) (DEPRECATED) |
|
4512 | """roll back the last transaction (DANGEROUS) (DEPRECATED) | |
4513 |
|
4513 | |||
4514 | Please use :hg:`commit --amend` instead of rollback to correct |
|
4514 | Please use :hg:`commit --amend` instead of rollback to correct | |
4515 | mistakes in the last commit. |
|
4515 | mistakes in the last commit. | |
4516 |
|
4516 | |||
4517 | This command should be used with care. There is only one level of |
|
4517 | This command should be used with care. There is only one level of | |
4518 | rollback, and there is no way to undo a rollback. It will also |
|
4518 | rollback, and there is no way to undo a rollback. It will also | |
4519 | restore the dirstate at the time of the last transaction, losing |
|
4519 | restore the dirstate at the time of the last transaction, losing | |
4520 | any dirstate changes since that time. This command does not alter |
|
4520 | any dirstate changes since that time. This command does not alter | |
4521 | the working directory. |
|
4521 | the working directory. | |
4522 |
|
4522 | |||
4523 | Transactions are used to encapsulate the effects of all commands |
|
4523 | Transactions are used to encapsulate the effects of all commands | |
4524 | that create new changesets or propagate existing changesets into a |
|
4524 | that create new changesets or propagate existing changesets into a | |
4525 | repository. |
|
4525 | repository. | |
4526 |
|
4526 | |||
4527 | .. container:: verbose |
|
4527 | .. container:: verbose | |
4528 |
|
4528 | |||
4529 | For example, the following commands are transactional, and their |
|
4529 | For example, the following commands are transactional, and their | |
4530 | effects can be rolled back: |
|
4530 | effects can be rolled back: | |
4531 |
|
4531 | |||
4532 | - commit |
|
4532 | - commit | |
4533 | - import |
|
4533 | - import | |
4534 | - pull |
|
4534 | - pull | |
4535 | - push (with this repository as the destination) |
|
4535 | - push (with this repository as the destination) | |
4536 | - unbundle |
|
4536 | - unbundle | |
4537 |
|
4537 | |||
4538 | To avoid permanent data loss, rollback will refuse to rollback a |
|
4538 | To avoid permanent data loss, rollback will refuse to rollback a | |
4539 | commit transaction if it isn't checked out. Use --force to |
|
4539 | commit transaction if it isn't checked out. Use --force to | |
4540 | override this protection. |
|
4540 | override this protection. | |
4541 |
|
4541 | |||
4542 | The rollback command can be entirely disabled by setting the |
|
4542 | The rollback command can be entirely disabled by setting the | |
4543 | ``ui.rollback`` configuration setting to false. If you're here |
|
4543 | ``ui.rollback`` configuration setting to false. If you're here | |
4544 | because you want to use rollback and it's disabled, you can |
|
4544 | because you want to use rollback and it's disabled, you can | |
4545 | re-enable the command by setting ``ui.rollback`` to true. |
|
4545 | re-enable the command by setting ``ui.rollback`` to true. | |
4546 |
|
4546 | |||
4547 | This command is not intended for use on public repositories. Once |
|
4547 | This command is not intended for use on public repositories. Once | |
4548 | changes are visible for pull by other users, rolling a transaction |
|
4548 | changes are visible for pull by other users, rolling a transaction | |
4549 | back locally is ineffective (someone else may already have pulled |
|
4549 | back locally is ineffective (someone else may already have pulled | |
4550 | the changes). Furthermore, a race is possible with readers of the |
|
4550 | the changes). Furthermore, a race is possible with readers of the | |
4551 | repository; for example an in-progress pull from the repository |
|
4551 | repository; for example an in-progress pull from the repository | |
4552 | may fail if a rollback is performed. |
|
4552 | may fail if a rollback is performed. | |
4553 |
|
4553 | |||
4554 | Returns 0 on success, 1 if no rollback data is available. |
|
4554 | Returns 0 on success, 1 if no rollback data is available. | |
4555 | """ |
|
4555 | """ | |
4556 | if not ui.configbool('ui', 'rollback'): |
|
4556 | if not ui.configbool('ui', 'rollback'): | |
4557 | raise error.Abort(_('rollback is disabled because it is unsafe'), |
|
4557 | raise error.Abort(_('rollback is disabled because it is unsafe'), | |
4558 | hint=('see `hg help -v rollback` for information')) |
|
4558 | hint=('see `hg help -v rollback` for information')) | |
4559 | return repo.rollback(dryrun=opts.get(r'dry_run'), |
|
4559 | return repo.rollback(dryrun=opts.get(r'dry_run'), | |
4560 | force=opts.get(r'force')) |
|
4560 | force=opts.get(r'force')) | |
4561 |
|
4561 | |||
4562 | @command('root', []) |
|
4562 | @command('root', []) | |
4563 | def root(ui, repo): |
|
4563 | def root(ui, repo): | |
4564 | """print the root (top) of the current working directory |
|
4564 | """print the root (top) of the current working directory | |
4565 |
|
4565 | |||
4566 | Print the root directory of the current repository. |
|
4566 | Print the root directory of the current repository. | |
4567 |
|
4567 | |||
4568 | Returns 0 on success. |
|
4568 | Returns 0 on success. | |
4569 | """ |
|
4569 | """ | |
4570 | ui.write(repo.root + "\n") |
|
4570 | ui.write(repo.root + "\n") | |
4571 |
|
4571 | |||
4572 | @command('^serve', |
|
4572 | @command('^serve', | |
4573 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
4573 | [('A', 'accesslog', '', _('name of access log file to write to'), | |
4574 | _('FILE')), |
|
4574 | _('FILE')), | |
4575 | ('d', 'daemon', None, _('run server in background')), |
|
4575 | ('d', 'daemon', None, _('run server in background')), | |
4576 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), |
|
4576 | ('', 'daemon-postexec', [], _('used internally by daemon mode')), | |
4577 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
4577 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), | |
4578 | # use string type, then we can check if something was passed |
|
4578 | # use string type, then we can check if something was passed | |
4579 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
4579 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), | |
4580 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
4580 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), | |
4581 | _('ADDR')), |
|
4581 | _('ADDR')), | |
4582 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
4582 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), | |
4583 | _('PREFIX')), |
|
4583 | _('PREFIX')), | |
4584 | ('n', 'name', '', |
|
4584 | ('n', 'name', '', | |
4585 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
4585 | _('name to show in web pages (default: working directory)'), _('NAME')), | |
4586 | ('', 'web-conf', '', |
|
4586 | ('', 'web-conf', '', | |
4587 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), |
|
4587 | _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')), | |
4588 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
4588 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), | |
4589 | _('FILE')), |
|
4589 | _('FILE')), | |
4590 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
4590 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), | |
4591 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), |
|
4591 | ('', 'stdio', None, _('for remote clients (ADVANCED)')), | |
4592 | ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')), |
|
4592 | ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')), | |
4593 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
4593 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), | |
4594 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
4594 | ('', 'style', '', _('template style to use'), _('STYLE')), | |
4595 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
4595 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), | |
4596 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))] |
|
4596 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))] | |
4597 | + subrepoopts, |
|
4597 | + subrepoopts, | |
4598 | _('[OPTION]...'), |
|
4598 | _('[OPTION]...'), | |
4599 | optionalrepo=True) |
|
4599 | optionalrepo=True) | |
4600 | def serve(ui, repo, **opts): |
|
4600 | def serve(ui, repo, **opts): | |
4601 | """start stand-alone webserver |
|
4601 | """start stand-alone webserver | |
4602 |
|
4602 | |||
4603 | Start a local HTTP repository browser and pull server. You can use |
|
4603 | Start a local HTTP repository browser and pull server. You can use | |
4604 | this for ad-hoc sharing and browsing of repositories. It is |
|
4604 | this for ad-hoc sharing and browsing of repositories. It is | |
4605 | recommended to use a real web server to serve a repository for |
|
4605 | recommended to use a real web server to serve a repository for | |
4606 | longer periods of time. |
|
4606 | longer periods of time. | |
4607 |
|
4607 | |||
4608 | Please note that the server does not implement access control. |
|
4608 | Please note that the server does not implement access control. | |
4609 | This means that, by default, anybody can read from the server and |
|
4609 | This means that, by default, anybody can read from the server and | |
4610 | nobody can write to it by default. Set the ``web.allow_push`` |
|
4610 | nobody can write to it by default. Set the ``web.allow_push`` | |
4611 | option to ``*`` to allow everybody to push to the server. You |
|
4611 | option to ``*`` to allow everybody to push to the server. You | |
4612 | should use a real web server if you need to authenticate users. |
|
4612 | should use a real web server if you need to authenticate users. | |
4613 |
|
4613 | |||
4614 | By default, the server logs accesses to stdout and errors to |
|
4614 | By default, the server logs accesses to stdout and errors to | |
4615 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
4615 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to | |
4616 | files. |
|
4616 | files. | |
4617 |
|
4617 | |||
4618 | To have the server choose a free port number to listen on, specify |
|
4618 | To have the server choose a free port number to listen on, specify | |
4619 | a port number of 0; in this case, the server will print the port |
|
4619 | a port number of 0; in this case, the server will print the port | |
4620 | number it uses. |
|
4620 | number it uses. | |
4621 |
|
4621 | |||
4622 | Returns 0 on success. |
|
4622 | Returns 0 on success. | |
4623 | """ |
|
4623 | """ | |
4624 |
|
4624 | |||
4625 | opts = pycompat.byteskwargs(opts) |
|
4625 | opts = pycompat.byteskwargs(opts) | |
4626 | if opts["stdio"] and opts["cmdserver"]: |
|
4626 | if opts["stdio"] and opts["cmdserver"]: | |
4627 | raise error.Abort(_("cannot use --stdio with --cmdserver")) |
|
4627 | raise error.Abort(_("cannot use --stdio with --cmdserver")) | |
4628 |
|
4628 | |||
4629 | if opts["stdio"]: |
|
4629 | if opts["stdio"]: | |
4630 | if repo is None: |
|
4630 | if repo is None: | |
4631 | raise error.RepoError(_("there is no Mercurial repository here" |
|
4631 | raise error.RepoError(_("there is no Mercurial repository here" | |
4632 | " (.hg not found)")) |
|
4632 | " (.hg not found)")) | |
4633 | s = sshserver.sshserver(ui, repo) |
|
4633 | s = sshserver.sshserver(ui, repo) | |
4634 | s.serve_forever() |
|
4634 | s.serve_forever() | |
4635 |
|
4635 | |||
4636 | service = server.createservice(ui, repo, opts) |
|
4636 | service = server.createservice(ui, repo, opts) | |
4637 | return server.runservice(opts, initfn=service.init, runfn=service.run) |
|
4637 | return server.runservice(opts, initfn=service.init, runfn=service.run) | |
4638 |
|
4638 | |||
4639 | @command('^status|st', |
|
4639 | @command('^status|st', | |
4640 | [('A', 'all', None, _('show status of all files')), |
|
4640 | [('A', 'all', None, _('show status of all files')), | |
4641 | ('m', 'modified', None, _('show only modified files')), |
|
4641 | ('m', 'modified', None, _('show only modified files')), | |
4642 | ('a', 'added', None, _('show only added files')), |
|
4642 | ('a', 'added', None, _('show only added files')), | |
4643 | ('r', 'removed', None, _('show only removed files')), |
|
4643 | ('r', 'removed', None, _('show only removed files')), | |
4644 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
4644 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
4645 | ('c', 'clean', None, _('show only files without changes')), |
|
4645 | ('c', 'clean', None, _('show only files without changes')), | |
4646 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
4646 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
4647 | ('i', 'ignored', None, _('show only ignored files')), |
|
4647 | ('i', 'ignored', None, _('show only ignored files')), | |
4648 | ('n', 'no-status', None, _('hide status prefix')), |
|
4648 | ('n', 'no-status', None, _('hide status prefix')), | |
4649 | ('t', 'terse', '', _('show the terse output (EXPERIMENTAL)')), |
|
4649 | ('t', 'terse', '', _('show the terse output (EXPERIMENTAL)')), | |
4650 | ('C', 'copies', None, _('show source of copied files')), |
|
4650 | ('C', 'copies', None, _('show source of copied files')), | |
4651 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4651 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
4652 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
4652 | ('', 'rev', [], _('show difference from revision'), _('REV')), | |
4653 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
4653 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), | |
4654 | ] + walkopts + subrepoopts + formatteropts, |
|
4654 | ] + walkopts + subrepoopts + formatteropts, | |
4655 | _('[OPTION]... [FILE]...'), |
|
4655 | _('[OPTION]... [FILE]...'), | |
4656 | inferrepo=True) |
|
4656 | inferrepo=True) | |
4657 | def status(ui, repo, *pats, **opts): |
|
4657 | def status(ui, repo, *pats, **opts): | |
4658 | """show changed files in the working directory |
|
4658 | """show changed files in the working directory | |
4659 |
|
4659 | |||
4660 | Show status of files in the repository. If names are given, only |
|
4660 | Show status of files in the repository. If names are given, only | |
4661 | files that match are shown. Files that are clean or ignored or |
|
4661 | files that match are shown. Files that are clean or ignored or | |
4662 | the source of a copy/move operation, are not listed unless |
|
4662 | the source of a copy/move operation, are not listed unless | |
4663 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
4663 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. | |
4664 | Unless options described with "show only ..." are given, the |
|
4664 | Unless options described with "show only ..." are given, the | |
4665 | options -mardu are used. |
|
4665 | options -mardu are used. | |
4666 |
|
4666 | |||
4667 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
4667 | Option -q/--quiet hides untracked (unknown and ignored) files | |
4668 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
4668 | unless explicitly requested with -u/--unknown or -i/--ignored. | |
4669 |
|
4669 | |||
4670 | .. note:: |
|
4670 | .. note:: | |
4671 |
|
4671 | |||
4672 | :hg:`status` may appear to disagree with diff if permissions have |
|
4672 | :hg:`status` may appear to disagree with diff if permissions have | |
4673 | changed or a merge has occurred. The standard diff format does |
|
4673 | changed or a merge has occurred. The standard diff format does | |
4674 | not report permission changes and diff only reports changes |
|
4674 | not report permission changes and diff only reports changes | |
4675 | relative to one merge parent. |
|
4675 | relative to one merge parent. | |
4676 |
|
4676 | |||
4677 | If one revision is given, it is used as the base revision. |
|
4677 | If one revision is given, it is used as the base revision. | |
4678 | If two revisions are given, the differences between them are |
|
4678 | If two revisions are given, the differences between them are | |
4679 | shown. The --change option can also be used as a shortcut to list |
|
4679 | shown. The --change option can also be used as a shortcut to list | |
4680 | the changed files of a revision from its first parent. |
|
4680 | the changed files of a revision from its first parent. | |
4681 |
|
4681 | |||
4682 | The codes used to show the status of files are:: |
|
4682 | The codes used to show the status of files are:: | |
4683 |
|
4683 | |||
4684 | M = modified |
|
4684 | M = modified | |
4685 | A = added |
|
4685 | A = added | |
4686 | R = removed |
|
4686 | R = removed | |
4687 | C = clean |
|
4687 | C = clean | |
4688 | ! = missing (deleted by non-hg command, but still tracked) |
|
4688 | ! = missing (deleted by non-hg command, but still tracked) | |
4689 | ? = not tracked |
|
4689 | ? = not tracked | |
4690 | I = ignored |
|
4690 | I = ignored | |
4691 | = origin of the previous file (with --copies) |
|
4691 | = origin of the previous file (with --copies) | |
4692 |
|
4692 | |||
4693 | .. container:: verbose |
|
4693 | .. container:: verbose | |
4694 |
|
4694 | |||
4695 | The -t/--terse option abbreviates the output by showing directory name |
|
4695 | The -t/--terse option abbreviates the output by showing directory name | |
4696 | if all the files in it share the same status. The option expects a value |
|
4696 | if all the files in it share the same status. The option expects a value | |
4697 | which can be a string formed by using 'm', 'a', 'r', 'd', 'u', 'i', 'c' |
|
4697 | which can be a string formed by using 'm', 'a', 'r', 'd', 'u', 'i', 'c' | |
4698 | where, 'm' stands for 'modified', 'a' for 'added', 'r' for 'removed', |
|
4698 | where, 'm' stands for 'modified', 'a' for 'added', 'r' for 'removed', | |
4699 | 'd' for 'deleted', 'u' for 'unknown', 'i' for 'ignored' and 'c' for clean. |
|
4699 | 'd' for 'deleted', 'u' for 'unknown', 'i' for 'ignored' and 'c' for clean. | |
4700 |
|
4700 | |||
4701 | It terses the output of only those status which are passed. The ignored |
|
4701 | It terses the output of only those status which are passed. The ignored | |
4702 | files are not considered while tersing until 'i' is there in --terse value |
|
4702 | files are not considered while tersing until 'i' is there in --terse value | |
4703 | or the --ignored option is used. |
|
4703 | or the --ignored option is used. | |
4704 |
|
4704 | |||
4705 | --verbose option shows more context about the state of the repo |
|
4705 | --verbose option shows more context about the state of the repo | |
4706 | like the repository is in unfinised merge, shelve, rebase state etc. |
|
4706 | like the repository is in unfinised merge, shelve, rebase state etc. | |
4707 | You can have this behaviour turned on by default by following config: |
|
4707 | You can have this behaviour turned on by default by following config: | |
4708 |
|
4708 | |||
4709 | [commands] |
|
4709 | [commands] | |
4710 | status.verbose = true |
|
4710 | status.verbose = true | |
4711 |
|
4711 | |||
4712 | You can also skip some states like bisect by adding following in |
|
4712 | You can also skip some states like bisect by adding following in | |
4713 | configuration file. |
|
4713 | configuration file. | |
4714 |
|
4714 | |||
4715 | [commands] |
|
4715 | [commands] | |
4716 | status.skipstates = bisect |
|
4716 | status.skipstates = bisect | |
4717 |
|
4717 | |||
4718 | Examples: |
|
4718 | Examples: | |
4719 |
|
4719 | |||
4720 | - show changes in the working directory relative to a |
|
4720 | - show changes in the working directory relative to a | |
4721 | changeset:: |
|
4721 | changeset:: | |
4722 |
|
4722 | |||
4723 | hg status --rev 9353 |
|
4723 | hg status --rev 9353 | |
4724 |
|
4724 | |||
4725 | - show changes in the working directory relative to the |
|
4725 | - show changes in the working directory relative to the | |
4726 | current directory (see :hg:`help patterns` for more information):: |
|
4726 | current directory (see :hg:`help patterns` for more information):: | |
4727 |
|
4727 | |||
4728 | hg status re: |
|
4728 | hg status re: | |
4729 |
|
4729 | |||
4730 | - show all changes including copies in an existing changeset:: |
|
4730 | - show all changes including copies in an existing changeset:: | |
4731 |
|
4731 | |||
4732 | hg status --copies --change 9353 |
|
4732 | hg status --copies --change 9353 | |
4733 |
|
4733 | |||
4734 | - get a NUL separated list of added files, suitable for xargs:: |
|
4734 | - get a NUL separated list of added files, suitable for xargs:: | |
4735 |
|
4735 | |||
4736 | hg status -an0 |
|
4736 | hg status -an0 | |
4737 |
|
4737 | |||
4738 | Returns 0 on success. |
|
4738 | Returns 0 on success. | |
4739 | """ |
|
4739 | """ | |
4740 |
|
4740 | |||
4741 | opts = pycompat.byteskwargs(opts) |
|
4741 | opts = pycompat.byteskwargs(opts) | |
4742 | revs = opts.get('rev') |
|
4742 | revs = opts.get('rev') | |
4743 | change = opts.get('change') |
|
4743 | change = opts.get('change') | |
4744 | terse = opts.get('terse') |
|
4744 | terse = opts.get('terse') | |
4745 |
|
4745 | |||
4746 | if revs and change: |
|
4746 | if revs and change: | |
4747 | msg = _('cannot specify --rev and --change at the same time') |
|
4747 | msg = _('cannot specify --rev and --change at the same time') | |
4748 | raise error.Abort(msg) |
|
4748 | raise error.Abort(msg) | |
4749 | elif revs and terse: |
|
4749 | elif revs and terse: | |
4750 | msg = _('cannot use --terse with --rev') |
|
4750 | msg = _('cannot use --terse with --rev') | |
4751 | raise error.Abort(msg) |
|
4751 | raise error.Abort(msg) | |
4752 | elif change: |
|
4752 | elif change: | |
4753 | node2 = scmutil.revsingle(repo, change, None).node() |
|
4753 | node2 = scmutil.revsingle(repo, change, None).node() | |
4754 | node1 = repo[node2].p1().node() |
|
4754 | node1 = repo[node2].p1().node() | |
4755 | else: |
|
4755 | else: | |
4756 | node1, node2 = scmutil.revpair(repo, revs) |
|
4756 | node1, node2 = scmutil.revpair(repo, revs) | |
4757 |
|
4757 | |||
4758 | if pats or ui.configbool('commands', 'status.relative'): |
|
4758 | if pats or ui.configbool('commands', 'status.relative'): | |
4759 | cwd = repo.getcwd() |
|
4759 | cwd = repo.getcwd() | |
4760 | else: |
|
4760 | else: | |
4761 | cwd = '' |
|
4761 | cwd = '' | |
4762 |
|
4762 | |||
4763 | if opts.get('print0'): |
|
4763 | if opts.get('print0'): | |
4764 | end = '\0' |
|
4764 | end = '\0' | |
4765 | else: |
|
4765 | else: | |
4766 | end = '\n' |
|
4766 | end = '\n' | |
4767 | copy = {} |
|
4767 | copy = {} | |
4768 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
4768 | states = 'modified added removed deleted unknown ignored clean'.split() | |
4769 | show = [k for k in states if opts.get(k)] |
|
4769 | show = [k for k in states if opts.get(k)] | |
4770 | if opts.get('all'): |
|
4770 | if opts.get('all'): | |
4771 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
4771 | show += ui.quiet and (states[:4] + ['clean']) or states | |
4772 |
|
4772 | |||
4773 | if not show: |
|
4773 | if not show: | |
4774 | if ui.quiet: |
|
4774 | if ui.quiet: | |
4775 | show = states[:4] |
|
4775 | show = states[:4] | |
4776 | else: |
|
4776 | else: | |
4777 | show = states[:5] |
|
4777 | show = states[:5] | |
4778 |
|
4778 | |||
4779 | m = scmutil.match(repo[node2], pats, opts) |
|
4779 | m = scmutil.match(repo[node2], pats, opts) | |
4780 | stat = repo.status(node1, node2, m, |
|
4780 | stat = repo.status(node1, node2, m, | |
4781 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
4781 | 'ignored' in show, 'clean' in show, 'unknown' in show, | |
4782 | opts.get('subrepos')) |
|
4782 | opts.get('subrepos')) | |
4783 | if terse: |
|
4783 | if terse: | |
4784 | stat = cmdutil.tersestatus(repo.root, stat, terse, |
|
4784 | stat = cmdutil.tersestatus(repo.root, stat, terse, | |
4785 | repo.dirstate._ignore, opts.get('ignored')) |
|
4785 | repo.dirstate._ignore, opts.get('ignored')) | |
4786 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) |
|
4786 | changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat) | |
4787 |
|
4787 | |||
4788 | if (opts.get('all') or opts.get('copies') |
|
4788 | if (opts.get('all') or opts.get('copies') | |
4789 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): |
|
4789 | or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'): | |
4790 | copy = copies.pathcopies(repo[node1], repo[node2], m) |
|
4790 | copy = copies.pathcopies(repo[node1], repo[node2], m) | |
4791 |
|
4791 | |||
4792 | ui.pager('status') |
|
4792 | ui.pager('status') | |
4793 | fm = ui.formatter('status', opts) |
|
4793 | fm = ui.formatter('status', opts) | |
4794 | fmt = '%s' + end |
|
4794 | fmt = '%s' + end | |
4795 | showchar = not opts.get('no_status') |
|
4795 | showchar = not opts.get('no_status') | |
4796 |
|
4796 | |||
4797 | for state, char, files in changestates: |
|
4797 | for state, char, files in changestates: | |
4798 | if state in show: |
|
4798 | if state in show: | |
4799 | label = 'status.' + state |
|
4799 | label = 'status.' + state | |
4800 | for f in files: |
|
4800 | for f in files: | |
4801 | fm.startitem() |
|
4801 | fm.startitem() | |
4802 | fm.condwrite(showchar, 'status', '%s ', char, label=label) |
|
4802 | fm.condwrite(showchar, 'status', '%s ', char, label=label) | |
4803 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) |
|
4803 | fm.write('path', fmt, repo.pathto(f, cwd), label=label) | |
4804 | if f in copy: |
|
4804 | if f in copy: | |
4805 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
4805 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), | |
4806 | label='status.copied') |
|
4806 | label='status.copied') | |
4807 |
|
4807 | |||
4808 | if ((ui.verbose or ui.configbool('commands', 'status.verbose')) |
|
4808 | if ((ui.verbose or ui.configbool('commands', 'status.verbose')) | |
4809 | and not ui.plain()): |
|
4809 | and not ui.plain()): | |
4810 | cmdutil.morestatus(repo, fm) |
|
4810 | cmdutil.morestatus(repo, fm) | |
4811 | fm.end() |
|
4811 | fm.end() | |
4812 |
|
4812 | |||
4813 | @command('^summary|sum', |
|
4813 | @command('^summary|sum', | |
4814 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
4814 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') | |
4815 | def summary(ui, repo, **opts): |
|
4815 | def summary(ui, repo, **opts): | |
4816 | """summarize working directory state |
|
4816 | """summarize working directory state | |
4817 |
|
4817 | |||
4818 | This generates a brief summary of the working directory state, |
|
4818 | This generates a brief summary of the working directory state, | |
4819 | including parents, branch, commit status, phase and available updates. |
|
4819 | including parents, branch, commit status, phase and available updates. | |
4820 |
|
4820 | |||
4821 | With the --remote option, this will check the default paths for |
|
4821 | With the --remote option, this will check the default paths for | |
4822 | incoming and outgoing changes. This can be time-consuming. |
|
4822 | incoming and outgoing changes. This can be time-consuming. | |
4823 |
|
4823 | |||
4824 | Returns 0 on success. |
|
4824 | Returns 0 on success. | |
4825 | """ |
|
4825 | """ | |
4826 |
|
4826 | |||
4827 | opts = pycompat.byteskwargs(opts) |
|
4827 | opts = pycompat.byteskwargs(opts) | |
4828 | ui.pager('summary') |
|
4828 | ui.pager('summary') | |
4829 | ctx = repo[None] |
|
4829 | ctx = repo[None] | |
4830 | parents = ctx.parents() |
|
4830 | parents = ctx.parents() | |
4831 | pnode = parents[0].node() |
|
4831 | pnode = parents[0].node() | |
4832 | marks = [] |
|
4832 | marks = [] | |
4833 |
|
4833 | |||
4834 | ms = None |
|
4834 | ms = None | |
4835 | try: |
|
4835 | try: | |
4836 | ms = mergemod.mergestate.read(repo) |
|
4836 | ms = mergemod.mergestate.read(repo) | |
4837 | except error.UnsupportedMergeRecords as e: |
|
4837 | except error.UnsupportedMergeRecords as e: | |
4838 | s = ' '.join(e.recordtypes) |
|
4838 | s = ' '.join(e.recordtypes) | |
4839 | ui.warn( |
|
4839 | ui.warn( | |
4840 | _('warning: merge state has unsupported record types: %s\n') % s) |
|
4840 | _('warning: merge state has unsupported record types: %s\n') % s) | |
4841 | unresolved = [] |
|
4841 | unresolved = [] | |
4842 | else: |
|
4842 | else: | |
4843 | unresolved = list(ms.unresolved()) |
|
4843 | unresolved = list(ms.unresolved()) | |
4844 |
|
4844 | |||
4845 | for p in parents: |
|
4845 | for p in parents: | |
4846 | # label with log.changeset (instead of log.parent) since this |
|
4846 | # label with log.changeset (instead of log.parent) since this | |
4847 | # shows a working directory parent *changeset*: |
|
4847 | # shows a working directory parent *changeset*: | |
4848 | # i18n: column positioning for "hg summary" |
|
4848 | # i18n: column positioning for "hg summary" | |
4849 | ui.write(_('parent: %d:%s ') % (p.rev(), p), |
|
4849 | ui.write(_('parent: %d:%s ') % (p.rev(), p), | |
4850 | label=cmdutil._changesetlabels(p)) |
|
4850 | label=cmdutil._changesetlabels(p)) | |
4851 | ui.write(' '.join(p.tags()), label='log.tag') |
|
4851 | ui.write(' '.join(p.tags()), label='log.tag') | |
4852 | if p.bookmarks(): |
|
4852 | if p.bookmarks(): | |
4853 | marks.extend(p.bookmarks()) |
|
4853 | marks.extend(p.bookmarks()) | |
4854 | if p.rev() == -1: |
|
4854 | if p.rev() == -1: | |
4855 | if not len(repo): |
|
4855 | if not len(repo): | |
4856 | ui.write(_(' (empty repository)')) |
|
4856 | ui.write(_(' (empty repository)')) | |
4857 | else: |
|
4857 | else: | |
4858 | ui.write(_(' (no revision checked out)')) |
|
4858 | ui.write(_(' (no revision checked out)')) | |
4859 | if p.obsolete(): |
|
4859 | if p.obsolete(): | |
4860 | ui.write(_(' (obsolete)')) |
|
4860 | ui.write(_(' (obsolete)')) | |
4861 | if p.isunstable(): |
|
4861 | if p.isunstable(): | |
4862 | instabilities = (ui.label(instability, 'trouble.%s' % instability) |
|
4862 | instabilities = (ui.label(instability, 'trouble.%s' % instability) | |
4863 | for instability in p.instabilities()) |
|
4863 | for instability in p.instabilities()) | |
4864 | ui.write(' (' |
|
4864 | ui.write(' (' | |
4865 | + ', '.join(instabilities) |
|
4865 | + ', '.join(instabilities) | |
4866 | + ')') |
|
4866 | + ')') | |
4867 | ui.write('\n') |
|
4867 | ui.write('\n') | |
4868 | if p.description(): |
|
4868 | if p.description(): | |
4869 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
4869 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', | |
4870 | label='log.summary') |
|
4870 | label='log.summary') | |
4871 |
|
4871 | |||
4872 | branch = ctx.branch() |
|
4872 | branch = ctx.branch() | |
4873 | bheads = repo.branchheads(branch) |
|
4873 | bheads = repo.branchheads(branch) | |
4874 | # i18n: column positioning for "hg summary" |
|
4874 | # i18n: column positioning for "hg summary" | |
4875 | m = _('branch: %s\n') % branch |
|
4875 | m = _('branch: %s\n') % branch | |
4876 | if branch != 'default': |
|
4876 | if branch != 'default': | |
4877 | ui.write(m, label='log.branch') |
|
4877 | ui.write(m, label='log.branch') | |
4878 | else: |
|
4878 | else: | |
4879 | ui.status(m, label='log.branch') |
|
4879 | ui.status(m, label='log.branch') | |
4880 |
|
4880 | |||
4881 | if marks: |
|
4881 | if marks: | |
4882 | active = repo._activebookmark |
|
4882 | active = repo._activebookmark | |
4883 | # i18n: column positioning for "hg summary" |
|
4883 | # i18n: column positioning for "hg summary" | |
4884 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
4884 | ui.write(_('bookmarks:'), label='log.bookmark') | |
4885 | if active is not None: |
|
4885 | if active is not None: | |
4886 | if active in marks: |
|
4886 | if active in marks: | |
4887 | ui.write(' *' + active, label=bookmarks.activebookmarklabel) |
|
4887 | ui.write(' *' + active, label=bookmarks.activebookmarklabel) | |
4888 | marks.remove(active) |
|
4888 | marks.remove(active) | |
4889 | else: |
|
4889 | else: | |
4890 | ui.write(' [%s]' % active, label=bookmarks.activebookmarklabel) |
|
4890 | ui.write(' [%s]' % active, label=bookmarks.activebookmarklabel) | |
4891 | for m in marks: |
|
4891 | for m in marks: | |
4892 | ui.write(' ' + m, label='log.bookmark') |
|
4892 | ui.write(' ' + m, label='log.bookmark') | |
4893 | ui.write('\n', label='log.bookmark') |
|
4893 | ui.write('\n', label='log.bookmark') | |
4894 |
|
4894 | |||
4895 | status = repo.status(unknown=True) |
|
4895 | status = repo.status(unknown=True) | |
4896 |
|
4896 | |||
4897 | c = repo.dirstate.copies() |
|
4897 | c = repo.dirstate.copies() | |
4898 | copied, renamed = [], [] |
|
4898 | copied, renamed = [], [] | |
4899 | for d, s in c.iteritems(): |
|
4899 | for d, s in c.iteritems(): | |
4900 | if s in status.removed: |
|
4900 | if s in status.removed: | |
4901 | status.removed.remove(s) |
|
4901 | status.removed.remove(s) | |
4902 | renamed.append(d) |
|
4902 | renamed.append(d) | |
4903 | else: |
|
4903 | else: | |
4904 | copied.append(d) |
|
4904 | copied.append(d) | |
4905 | if d in status.added: |
|
4905 | if d in status.added: | |
4906 | status.added.remove(d) |
|
4906 | status.added.remove(d) | |
4907 |
|
4907 | |||
4908 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
4908 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | |
4909 |
|
4909 | |||
4910 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
|
4910 | labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), | |
4911 | (ui.label(_('%d added'), 'status.added'), status.added), |
|
4911 | (ui.label(_('%d added'), 'status.added'), status.added), | |
4912 | (ui.label(_('%d removed'), 'status.removed'), status.removed), |
|
4912 | (ui.label(_('%d removed'), 'status.removed'), status.removed), | |
4913 | (ui.label(_('%d renamed'), 'status.copied'), renamed), |
|
4913 | (ui.label(_('%d renamed'), 'status.copied'), renamed), | |
4914 | (ui.label(_('%d copied'), 'status.copied'), copied), |
|
4914 | (ui.label(_('%d copied'), 'status.copied'), copied), | |
4915 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
|
4915 | (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), | |
4916 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
|
4916 | (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), | |
4917 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
|
4917 | (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), | |
4918 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
|
4918 | (ui.label(_('%d subrepos'), 'status.modified'), subs)] | |
4919 | t = [] |
|
4919 | t = [] | |
4920 | for l, s in labels: |
|
4920 | for l, s in labels: | |
4921 | if s: |
|
4921 | if s: | |
4922 | t.append(l % len(s)) |
|
4922 | t.append(l % len(s)) | |
4923 |
|
4923 | |||
4924 | t = ', '.join(t) |
|
4924 | t = ', '.join(t) | |
4925 | cleanworkdir = False |
|
4925 | cleanworkdir = False | |
4926 |
|
4926 | |||
4927 | if repo.vfs.exists('graftstate'): |
|
4927 | if repo.vfs.exists('graftstate'): | |
4928 | t += _(' (graft in progress)') |
|
4928 | t += _(' (graft in progress)') | |
4929 | if repo.vfs.exists('updatestate'): |
|
4929 | if repo.vfs.exists('updatestate'): | |
4930 | t += _(' (interrupted update)') |
|
4930 | t += _(' (interrupted update)') | |
4931 | elif len(parents) > 1: |
|
4931 | elif len(parents) > 1: | |
4932 | t += _(' (merge)') |
|
4932 | t += _(' (merge)') | |
4933 | elif branch != parents[0].branch(): |
|
4933 | elif branch != parents[0].branch(): | |
4934 | t += _(' (new branch)') |
|
4934 | t += _(' (new branch)') | |
4935 | elif (parents[0].closesbranch() and |
|
4935 | elif (parents[0].closesbranch() and | |
4936 | pnode in repo.branchheads(branch, closed=True)): |
|
4936 | pnode in repo.branchheads(branch, closed=True)): | |
4937 | t += _(' (head closed)') |
|
4937 | t += _(' (head closed)') | |
4938 | elif not (status.modified or status.added or status.removed or renamed or |
|
4938 | elif not (status.modified or status.added or status.removed or renamed or | |
4939 | copied or subs): |
|
4939 | copied or subs): | |
4940 | t += _(' (clean)') |
|
4940 | t += _(' (clean)') | |
4941 | cleanworkdir = True |
|
4941 | cleanworkdir = True | |
4942 | elif pnode not in bheads: |
|
4942 | elif pnode not in bheads: | |
4943 | t += _(' (new branch head)') |
|
4943 | t += _(' (new branch head)') | |
4944 |
|
4944 | |||
4945 | if parents: |
|
4945 | if parents: | |
4946 | pendingphase = max(p.phase() for p in parents) |
|
4946 | pendingphase = max(p.phase() for p in parents) | |
4947 | else: |
|
4947 | else: | |
4948 | pendingphase = phases.public |
|
4948 | pendingphase = phases.public | |
4949 |
|
4949 | |||
4950 | if pendingphase > phases.newcommitphase(ui): |
|
4950 | if pendingphase > phases.newcommitphase(ui): | |
4951 | t += ' (%s)' % phases.phasenames[pendingphase] |
|
4951 | t += ' (%s)' % phases.phasenames[pendingphase] | |
4952 |
|
4952 | |||
4953 | if cleanworkdir: |
|
4953 | if cleanworkdir: | |
4954 | # i18n: column positioning for "hg summary" |
|
4954 | # i18n: column positioning for "hg summary" | |
4955 | ui.status(_('commit: %s\n') % t.strip()) |
|
4955 | ui.status(_('commit: %s\n') % t.strip()) | |
4956 | else: |
|
4956 | else: | |
4957 | # i18n: column positioning for "hg summary" |
|
4957 | # i18n: column positioning for "hg summary" | |
4958 | ui.write(_('commit: %s\n') % t.strip()) |
|
4958 | ui.write(_('commit: %s\n') % t.strip()) | |
4959 |
|
4959 | |||
4960 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
4960 | # all ancestors of branch heads - all ancestors of parent = new csets | |
4961 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], |
|
4961 | new = len(repo.changelog.findmissing([pctx.node() for pctx in parents], | |
4962 | bheads)) |
|
4962 | bheads)) | |
4963 |
|
4963 | |||
4964 | if new == 0: |
|
4964 | if new == 0: | |
4965 | # i18n: column positioning for "hg summary" |
|
4965 | # i18n: column positioning for "hg summary" | |
4966 | ui.status(_('update: (current)\n')) |
|
4966 | ui.status(_('update: (current)\n')) | |
4967 | elif pnode not in bheads: |
|
4967 | elif pnode not in bheads: | |
4968 | # i18n: column positioning for "hg summary" |
|
4968 | # i18n: column positioning for "hg summary" | |
4969 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
4969 | ui.write(_('update: %d new changesets (update)\n') % new) | |
4970 | else: |
|
4970 | else: | |
4971 | # i18n: column positioning for "hg summary" |
|
4971 | # i18n: column positioning for "hg summary" | |
4972 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
4972 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | |
4973 | (new, len(bheads))) |
|
4973 | (new, len(bheads))) | |
4974 |
|
4974 | |||
4975 | t = [] |
|
4975 | t = [] | |
4976 | draft = len(repo.revs('draft()')) |
|
4976 | draft = len(repo.revs('draft()')) | |
4977 | if draft: |
|
4977 | if draft: | |
4978 | t.append(_('%d draft') % draft) |
|
4978 | t.append(_('%d draft') % draft) | |
4979 | secret = len(repo.revs('secret()')) |
|
4979 | secret = len(repo.revs('secret()')) | |
4980 | if secret: |
|
4980 | if secret: | |
4981 | t.append(_('%d secret') % secret) |
|
4981 | t.append(_('%d secret') % secret) | |
4982 |
|
4982 | |||
4983 | if draft or secret: |
|
4983 | if draft or secret: | |
4984 | ui.status(_('phases: %s\n') % ', '.join(t)) |
|
4984 | ui.status(_('phases: %s\n') % ', '.join(t)) | |
4985 |
|
4985 | |||
4986 | if obsolete.isenabled(repo, obsolete.createmarkersopt): |
|
4986 | if obsolete.isenabled(repo, obsolete.createmarkersopt): | |
4987 | for trouble in ("orphan", "contentdivergent", "phasedivergent"): |
|
4987 | for trouble in ("orphan", "contentdivergent", "phasedivergent"): | |
4988 | numtrouble = len(repo.revs(trouble + "()")) |
|
4988 | numtrouble = len(repo.revs(trouble + "()")) | |
4989 | # We write all the possibilities to ease translation |
|
4989 | # We write all the possibilities to ease translation | |
4990 | troublemsg = { |
|
4990 | troublemsg = { | |
4991 | "orphan": _("orphan: %d changesets"), |
|
4991 | "orphan": _("orphan: %d changesets"), | |
4992 | "contentdivergent": _("content-divergent: %d changesets"), |
|
4992 | "contentdivergent": _("content-divergent: %d changesets"), | |
4993 | "phasedivergent": _("phase-divergent: %d changesets"), |
|
4993 | "phasedivergent": _("phase-divergent: %d changesets"), | |
4994 | } |
|
4994 | } | |
4995 | if numtrouble > 0: |
|
4995 | if numtrouble > 0: | |
4996 | ui.status(troublemsg[trouble] % numtrouble + "\n") |
|
4996 | ui.status(troublemsg[trouble] % numtrouble + "\n") | |
4997 |
|
4997 | |||
4998 | cmdutil.summaryhooks(ui, repo) |
|
4998 | cmdutil.summaryhooks(ui, repo) | |
4999 |
|
4999 | |||
5000 | if opts.get('remote'): |
|
5000 | if opts.get('remote'): | |
5001 | needsincoming, needsoutgoing = True, True |
|
5001 | needsincoming, needsoutgoing = True, True | |
5002 | else: |
|
5002 | else: | |
5003 | needsincoming, needsoutgoing = False, False |
|
5003 | needsincoming, needsoutgoing = False, False | |
5004 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): |
|
5004 | for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None): | |
5005 | if i: |
|
5005 | if i: | |
5006 | needsincoming = True |
|
5006 | needsincoming = True | |
5007 | if o: |
|
5007 | if o: | |
5008 | needsoutgoing = True |
|
5008 | needsoutgoing = True | |
5009 | if not needsincoming and not needsoutgoing: |
|
5009 | if not needsincoming and not needsoutgoing: | |
5010 | return |
|
5010 | return | |
5011 |
|
5011 | |||
5012 | def getincoming(): |
|
5012 | def getincoming(): | |
5013 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
5013 | source, branches = hg.parseurl(ui.expandpath('default')) | |
5014 | sbranch = branches[0] |
|
5014 | sbranch = branches[0] | |
5015 | try: |
|
5015 | try: | |
5016 | other = hg.peer(repo, {}, source) |
|
5016 | other = hg.peer(repo, {}, source) | |
5017 | except error.RepoError: |
|
5017 | except error.RepoError: | |
5018 | if opts.get('remote'): |
|
5018 | if opts.get('remote'): | |
5019 | raise |
|
5019 | raise | |
5020 | return source, sbranch, None, None, None |
|
5020 | return source, sbranch, None, None, None | |
5021 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) |
|
5021 | revs, checkout = hg.addbranchrevs(repo, other, branches, None) | |
5022 | if revs: |
|
5022 | if revs: | |
5023 | revs = [other.lookup(rev) for rev in revs] |
|
5023 | revs = [other.lookup(rev) for rev in revs] | |
5024 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
5024 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | |
5025 | repo.ui.pushbuffer() |
|
5025 | repo.ui.pushbuffer() | |
5026 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) |
|
5026 | commoninc = discovery.findcommonincoming(repo, other, heads=revs) | |
5027 | repo.ui.popbuffer() |
|
5027 | repo.ui.popbuffer() | |
5028 | return source, sbranch, other, commoninc, commoninc[1] |
|
5028 | return source, sbranch, other, commoninc, commoninc[1] | |
5029 |
|
5029 | |||
5030 | if needsincoming: |
|
5030 | if needsincoming: | |
5031 | source, sbranch, sother, commoninc, incoming = getincoming() |
|
5031 | source, sbranch, sother, commoninc, incoming = getincoming() | |
5032 | else: |
|
5032 | else: | |
5033 | source = sbranch = sother = commoninc = incoming = None |
|
5033 | source = sbranch = sother = commoninc = incoming = None | |
5034 |
|
5034 | |||
5035 | def getoutgoing(): |
|
5035 | def getoutgoing(): | |
5036 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
5036 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | |
5037 | dbranch = branches[0] |
|
5037 | dbranch = branches[0] | |
5038 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
5038 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | |
5039 | if source != dest: |
|
5039 | if source != dest: | |
5040 | try: |
|
5040 | try: | |
5041 | dother = hg.peer(repo, {}, dest) |
|
5041 | dother = hg.peer(repo, {}, dest) | |
5042 | except error.RepoError: |
|
5042 | except error.RepoError: | |
5043 | if opts.get('remote'): |
|
5043 | if opts.get('remote'): | |
5044 | raise |
|
5044 | raise | |
5045 | return dest, dbranch, None, None |
|
5045 | return dest, dbranch, None, None | |
5046 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
5046 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) | |
5047 | elif sother is None: |
|
5047 | elif sother is None: | |
5048 | # there is no explicit destination peer, but source one is invalid |
|
5048 | # there is no explicit destination peer, but source one is invalid | |
5049 | return dest, dbranch, None, None |
|
5049 | return dest, dbranch, None, None | |
5050 | else: |
|
5050 | else: | |
5051 | dother = sother |
|
5051 | dother = sother | |
5052 | if (source != dest or (sbranch is not None and sbranch != dbranch)): |
|
5052 | if (source != dest or (sbranch is not None and sbranch != dbranch)): | |
5053 | common = None |
|
5053 | common = None | |
5054 | else: |
|
5054 | else: | |
5055 | common = commoninc |
|
5055 | common = commoninc | |
5056 | if revs: |
|
5056 | if revs: | |
5057 | revs = [repo.lookup(rev) for rev in revs] |
|
5057 | revs = [repo.lookup(rev) for rev in revs] | |
5058 | repo.ui.pushbuffer() |
|
5058 | repo.ui.pushbuffer() | |
5059 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, |
|
5059 | outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs, | |
5060 | commoninc=common) |
|
5060 | commoninc=common) | |
5061 | repo.ui.popbuffer() |
|
5061 | repo.ui.popbuffer() | |
5062 | return dest, dbranch, dother, outgoing |
|
5062 | return dest, dbranch, dother, outgoing | |
5063 |
|
5063 | |||
5064 | if needsoutgoing: |
|
5064 | if needsoutgoing: | |
5065 | dest, dbranch, dother, outgoing = getoutgoing() |
|
5065 | dest, dbranch, dother, outgoing = getoutgoing() | |
5066 | else: |
|
5066 | else: | |
5067 | dest = dbranch = dother = outgoing = None |
|
5067 | dest = dbranch = dother = outgoing = None | |
5068 |
|
5068 | |||
5069 | if opts.get('remote'): |
|
5069 | if opts.get('remote'): | |
5070 | t = [] |
|
5070 | t = [] | |
5071 | if incoming: |
|
5071 | if incoming: | |
5072 | t.append(_('1 or more incoming')) |
|
5072 | t.append(_('1 or more incoming')) | |
5073 | o = outgoing.missing |
|
5073 | o = outgoing.missing | |
5074 | if o: |
|
5074 | if o: | |
5075 | t.append(_('%d outgoing') % len(o)) |
|
5075 | t.append(_('%d outgoing') % len(o)) | |
5076 | other = dother or sother |
|
5076 | other = dother or sother | |
5077 | if 'bookmarks' in other.listkeys('namespaces'): |
|
5077 | if 'bookmarks' in other.listkeys('namespaces'): | |
5078 | counts = bookmarks.summary(repo, other) |
|
5078 | counts = bookmarks.summary(repo, other) | |
5079 | if counts[0] > 0: |
|
5079 | if counts[0] > 0: | |
5080 | t.append(_('%d incoming bookmarks') % counts[0]) |
|
5080 | t.append(_('%d incoming bookmarks') % counts[0]) | |
5081 | if counts[1] > 0: |
|
5081 | if counts[1] > 0: | |
5082 | t.append(_('%d outgoing bookmarks') % counts[1]) |
|
5082 | t.append(_('%d outgoing bookmarks') % counts[1]) | |
5083 |
|
5083 | |||
5084 | if t: |
|
5084 | if t: | |
5085 | # i18n: column positioning for "hg summary" |
|
5085 | # i18n: column positioning for "hg summary" | |
5086 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
5086 | ui.write(_('remote: %s\n') % (', '.join(t))) | |
5087 | else: |
|
5087 | else: | |
5088 | # i18n: column positioning for "hg summary" |
|
5088 | # i18n: column positioning for "hg summary" | |
5089 | ui.status(_('remote: (synced)\n')) |
|
5089 | ui.status(_('remote: (synced)\n')) | |
5090 |
|
5090 | |||
5091 | cmdutil.summaryremotehooks(ui, repo, opts, |
|
5091 | cmdutil.summaryremotehooks(ui, repo, opts, | |
5092 | ((source, sbranch, sother, commoninc), |
|
5092 | ((source, sbranch, sother, commoninc), | |
5093 | (dest, dbranch, dother, outgoing))) |
|
5093 | (dest, dbranch, dother, outgoing))) | |
5094 |
|
5094 | |||
5095 | @command('tag', |
|
5095 | @command('tag', | |
5096 | [('f', 'force', None, _('force tag')), |
|
5096 | [('f', 'force', None, _('force tag')), | |
5097 | ('l', 'local', None, _('make the tag local')), |
|
5097 | ('l', 'local', None, _('make the tag local')), | |
5098 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
5098 | ('r', 'rev', '', _('revision to tag'), _('REV')), | |
5099 | ('', 'remove', None, _('remove a tag')), |
|
5099 | ('', 'remove', None, _('remove a tag')), | |
5100 | # -l/--local is already there, commitopts cannot be used |
|
5100 | # -l/--local is already there, commitopts cannot be used | |
5101 | ('e', 'edit', None, _('invoke editor on commit messages')), |
|
5101 | ('e', 'edit', None, _('invoke editor on commit messages')), | |
5102 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), |
|
5102 | ('m', 'message', '', _('use text as commit message'), _('TEXT')), | |
5103 | ] + commitopts2, |
|
5103 | ] + commitopts2, | |
5104 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
5104 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) | |
5105 | def tag(ui, repo, name1, *names, **opts): |
|
5105 | def tag(ui, repo, name1, *names, **opts): | |
5106 | """add one or more tags for the current or given revision |
|
5106 | """add one or more tags for the current or given revision | |
5107 |
|
5107 | |||
5108 | Name a particular revision using <name>. |
|
5108 | Name a particular revision using <name>. | |
5109 |
|
5109 | |||
5110 | Tags are used to name particular revisions of the repository and are |
|
5110 | Tags are used to name particular revisions of the repository and are | |
5111 | very useful to compare different revisions, to go back to significant |
|
5111 | very useful to compare different revisions, to go back to significant | |
5112 | earlier versions or to mark branch points as releases, etc. Changing |
|
5112 | earlier versions or to mark branch points as releases, etc. Changing | |
5113 | an existing tag is normally disallowed; use -f/--force to override. |
|
5113 | an existing tag is normally disallowed; use -f/--force to override. | |
5114 |
|
5114 | |||
5115 | If no revision is given, the parent of the working directory is |
|
5115 | If no revision is given, the parent of the working directory is | |
5116 | used. |
|
5116 | used. | |
5117 |
|
5117 | |||
5118 | To facilitate version control, distribution, and merging of tags, |
|
5118 | To facilitate version control, distribution, and merging of tags, | |
5119 | they are stored as a file named ".hgtags" which is managed similarly |
|
5119 | they are stored as a file named ".hgtags" which is managed similarly | |
5120 | to other project files and can be hand-edited if necessary. This |
|
5120 | to other project files and can be hand-edited if necessary. This | |
5121 | also means that tagging creates a new commit. The file |
|
5121 | also means that tagging creates a new commit. The file | |
5122 | ".hg/localtags" is used for local tags (not shared among |
|
5122 | ".hg/localtags" is used for local tags (not shared among | |
5123 | repositories). |
|
5123 | repositories). | |
5124 |
|
5124 | |||
5125 | Tag commits are usually made at the head of a branch. If the parent |
|
5125 | Tag commits are usually made at the head of a branch. If the parent | |
5126 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
5126 | of the working directory is not a branch head, :hg:`tag` aborts; use | |
5127 | -f/--force to force the tag commit to be based on a non-head |
|
5127 | -f/--force to force the tag commit to be based on a non-head | |
5128 | changeset. |
|
5128 | changeset. | |
5129 |
|
5129 | |||
5130 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5130 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
5131 |
|
5131 | |||
5132 | Since tag names have priority over branch names during revision |
|
5132 | Since tag names have priority over branch names during revision | |
5133 | lookup, using an existing branch name as a tag name is discouraged. |
|
5133 | lookup, using an existing branch name as a tag name is discouraged. | |
5134 |
|
5134 | |||
5135 | Returns 0 on success. |
|
5135 | Returns 0 on success. | |
5136 | """ |
|
5136 | """ | |
5137 | opts = pycompat.byteskwargs(opts) |
|
5137 | opts = pycompat.byteskwargs(opts) | |
5138 | wlock = lock = None |
|
5138 | wlock = lock = None | |
5139 | try: |
|
5139 | try: | |
5140 | wlock = repo.wlock() |
|
5140 | wlock = repo.wlock() | |
5141 | lock = repo.lock() |
|
5141 | lock = repo.lock() | |
5142 | rev_ = "." |
|
5142 | rev_ = "." | |
5143 | names = [t.strip() for t in (name1,) + names] |
|
5143 | names = [t.strip() for t in (name1,) + names] | |
5144 | if len(names) != len(set(names)): |
|
5144 | if len(names) != len(set(names)): | |
5145 | raise error.Abort(_('tag names must be unique')) |
|
5145 | raise error.Abort(_('tag names must be unique')) | |
5146 | for n in names: |
|
5146 | for n in names: | |
5147 | scmutil.checknewlabel(repo, n, 'tag') |
|
5147 | scmutil.checknewlabel(repo, n, 'tag') | |
5148 | if not n: |
|
5148 | if not n: | |
5149 | raise error.Abort(_('tag names cannot consist entirely of ' |
|
5149 | raise error.Abort(_('tag names cannot consist entirely of ' | |
5150 | 'whitespace')) |
|
5150 | 'whitespace')) | |
5151 | if opts.get('rev') and opts.get('remove'): |
|
5151 | if opts.get('rev') and opts.get('remove'): | |
5152 | raise error.Abort(_("--rev and --remove are incompatible")) |
|
5152 | raise error.Abort(_("--rev and --remove are incompatible")) | |
5153 | if opts.get('rev'): |
|
5153 | if opts.get('rev'): | |
5154 | rev_ = opts['rev'] |
|
5154 | rev_ = opts['rev'] | |
5155 | message = opts.get('message') |
|
5155 | message = opts.get('message') | |
5156 | if opts.get('remove'): |
|
5156 | if opts.get('remove'): | |
5157 | if opts.get('local'): |
|
5157 | if opts.get('local'): | |
5158 | expectedtype = 'local' |
|
5158 | expectedtype = 'local' | |
5159 | else: |
|
5159 | else: | |
5160 | expectedtype = 'global' |
|
5160 | expectedtype = 'global' | |
5161 |
|
5161 | |||
5162 | for n in names: |
|
5162 | for n in names: | |
5163 | if not repo.tagtype(n): |
|
5163 | if not repo.tagtype(n): | |
5164 | raise error.Abort(_("tag '%s' does not exist") % n) |
|
5164 | raise error.Abort(_("tag '%s' does not exist") % n) | |
5165 | if repo.tagtype(n) != expectedtype: |
|
5165 | if repo.tagtype(n) != expectedtype: | |
5166 | if expectedtype == 'global': |
|
5166 | if expectedtype == 'global': | |
5167 | raise error.Abort(_("tag '%s' is not a global tag") % n) |
|
5167 | raise error.Abort(_("tag '%s' is not a global tag") % n) | |
5168 | else: |
|
5168 | else: | |
5169 | raise error.Abort(_("tag '%s' is not a local tag") % n) |
|
5169 | raise error.Abort(_("tag '%s' is not a local tag") % n) | |
5170 | rev_ = 'null' |
|
5170 | rev_ = 'null' | |
5171 | if not message: |
|
5171 | if not message: | |
5172 | # we don't translate commit messages |
|
5172 | # we don't translate commit messages | |
5173 | message = 'Removed tag %s' % ', '.join(names) |
|
5173 | message = 'Removed tag %s' % ', '.join(names) | |
5174 | elif not opts.get('force'): |
|
5174 | elif not opts.get('force'): | |
5175 | for n in names: |
|
5175 | for n in names: | |
5176 | if n in repo.tags(): |
|
5176 | if n in repo.tags(): | |
5177 | raise error.Abort(_("tag '%s' already exists " |
|
5177 | raise error.Abort(_("tag '%s' already exists " | |
5178 | "(use -f to force)") % n) |
|
5178 | "(use -f to force)") % n) | |
5179 | if not opts.get('local'): |
|
5179 | if not opts.get('local'): | |
5180 | p1, p2 = repo.dirstate.parents() |
|
5180 | p1, p2 = repo.dirstate.parents() | |
5181 | if p2 != nullid: |
|
5181 | if p2 != nullid: | |
5182 | raise error.Abort(_('uncommitted merge')) |
|
5182 | raise error.Abort(_('uncommitted merge')) | |
5183 | bheads = repo.branchheads() |
|
5183 | bheads = repo.branchheads() | |
5184 | if not opts.get('force') and bheads and p1 not in bheads: |
|
5184 | if not opts.get('force') and bheads and p1 not in bheads: | |
5185 | raise error.Abort(_('working directory is not at a branch head ' |
|
5185 | raise error.Abort(_('working directory is not at a branch head ' | |
5186 | '(use -f to force)')) |
|
5186 | '(use -f to force)')) | |
5187 | r = scmutil.revsingle(repo, rev_).node() |
|
5187 | r = scmutil.revsingle(repo, rev_).node() | |
5188 |
|
5188 | |||
5189 | if not message: |
|
5189 | if not message: | |
5190 | # we don't translate commit messages |
|
5190 | # we don't translate commit messages | |
5191 | message = ('Added tag %s for changeset %s' % |
|
5191 | message = ('Added tag %s for changeset %s' % | |
5192 | (', '.join(names), short(r))) |
|
5192 | (', '.join(names), short(r))) | |
5193 |
|
5193 | |||
5194 | date = opts.get('date') |
|
5194 | date = opts.get('date') | |
5195 | if date: |
|
5195 | if date: | |
5196 | date = util.parsedate(date) |
|
5196 | date = util.parsedate(date) | |
5197 |
|
5197 | |||
5198 | if opts.get('remove'): |
|
5198 | if opts.get('remove'): | |
5199 | editform = 'tag.remove' |
|
5199 | editform = 'tag.remove' | |
5200 | else: |
|
5200 | else: | |
5201 | editform = 'tag.add' |
|
5201 | editform = 'tag.add' | |
5202 | editor = cmdutil.getcommiteditor(editform=editform, |
|
5202 | editor = cmdutil.getcommiteditor(editform=editform, | |
5203 | **pycompat.strkwargs(opts)) |
|
5203 | **pycompat.strkwargs(opts)) | |
5204 |
|
5204 | |||
5205 | # don't allow tagging the null rev |
|
5205 | # don't allow tagging the null rev | |
5206 | if (not opts.get('remove') and |
|
5206 | if (not opts.get('remove') and | |
5207 | scmutil.revsingle(repo, rev_).rev() == nullrev): |
|
5207 | scmutil.revsingle(repo, rev_).rev() == nullrev): | |
5208 | raise error.Abort(_("cannot tag null revision")) |
|
5208 | raise error.Abort(_("cannot tag null revision")) | |
5209 |
|
5209 | |||
5210 | tagsmod.tag(repo, names, r, message, opts.get('local'), |
|
5210 | tagsmod.tag(repo, names, r, message, opts.get('local'), | |
5211 | opts.get('user'), date, editor=editor) |
|
5211 | opts.get('user'), date, editor=editor) | |
5212 | finally: |
|
5212 | finally: | |
5213 | release(lock, wlock) |
|
5213 | release(lock, wlock) | |
5214 |
|
5214 | |||
5215 | @command('tags', formatteropts, '') |
|
5215 | @command('tags', formatteropts, '') | |
5216 | def tags(ui, repo, **opts): |
|
5216 | def tags(ui, repo, **opts): | |
5217 | """list repository tags |
|
5217 | """list repository tags | |
5218 |
|
5218 | |||
5219 | This lists both regular and local tags. When the -v/--verbose |
|
5219 | This lists both regular and local tags. When the -v/--verbose | |
5220 | switch is used, a third column "local" is printed for local tags. |
|
5220 | switch is used, a third column "local" is printed for local tags. | |
5221 | When the -q/--quiet switch is used, only the tag name is printed. |
|
5221 | When the -q/--quiet switch is used, only the tag name is printed. | |
5222 |
|
5222 | |||
5223 | Returns 0 on success. |
|
5223 | Returns 0 on success. | |
5224 | """ |
|
5224 | """ | |
5225 |
|
5225 | |||
5226 | opts = pycompat.byteskwargs(opts) |
|
5226 | opts = pycompat.byteskwargs(opts) | |
5227 | ui.pager('tags') |
|
5227 | ui.pager('tags') | |
5228 | fm = ui.formatter('tags', opts) |
|
5228 | fm = ui.formatter('tags', opts) | |
5229 | hexfunc = fm.hexfunc |
|
5229 | hexfunc = fm.hexfunc | |
5230 | tagtype = "" |
|
5230 | tagtype = "" | |
5231 |
|
5231 | |||
5232 | for t, n in reversed(repo.tagslist()): |
|
5232 | for t, n in reversed(repo.tagslist()): | |
5233 | hn = hexfunc(n) |
|
5233 | hn = hexfunc(n) | |
5234 | label = 'tags.normal' |
|
5234 | label = 'tags.normal' | |
5235 | tagtype = '' |
|
5235 | tagtype = '' | |
5236 | if repo.tagtype(t) == 'local': |
|
5236 | if repo.tagtype(t) == 'local': | |
5237 | label = 'tags.local' |
|
5237 | label = 'tags.local' | |
5238 | tagtype = 'local' |
|
5238 | tagtype = 'local' | |
5239 |
|
5239 | |||
5240 | fm.startitem() |
|
5240 | fm.startitem() | |
5241 | fm.write('tag', '%s', t, label=label) |
|
5241 | fm.write('tag', '%s', t, label=label) | |
5242 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' |
|
5242 | fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s' | |
5243 | fm.condwrite(not ui.quiet, 'rev node', fmt, |
|
5243 | fm.condwrite(not ui.quiet, 'rev node', fmt, | |
5244 | repo.changelog.rev(n), hn, label=label) |
|
5244 | repo.changelog.rev(n), hn, label=label) | |
5245 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', |
|
5245 | fm.condwrite(ui.verbose and tagtype, 'type', ' %s', | |
5246 | tagtype, label=label) |
|
5246 | tagtype, label=label) | |
5247 | fm.plain('\n') |
|
5247 | fm.plain('\n') | |
5248 | fm.end() |
|
5248 | fm.end() | |
5249 |
|
5249 | |||
5250 | @command('tip', |
|
5250 | @command('tip', | |
5251 | [('p', 'patch', None, _('show patch')), |
|
5251 | [('p', 'patch', None, _('show patch')), | |
5252 | ('g', 'git', None, _('use git extended diff format')), |
|
5252 | ('g', 'git', None, _('use git extended diff format')), | |
5253 | ] + templateopts, |
|
5253 | ] + templateopts, | |
5254 | _('[-p] [-g]')) |
|
5254 | _('[-p] [-g]')) | |
5255 | def tip(ui, repo, **opts): |
|
5255 | def tip(ui, repo, **opts): | |
5256 | """show the tip revision (DEPRECATED) |
|
5256 | """show the tip revision (DEPRECATED) | |
5257 |
|
5257 | |||
5258 | The tip revision (usually just called the tip) is the changeset |
|
5258 | The tip revision (usually just called the tip) is the changeset | |
5259 | most recently added to the repository (and therefore the most |
|
5259 | most recently added to the repository (and therefore the most | |
5260 | recently changed head). |
|
5260 | recently changed head). | |
5261 |
|
5261 | |||
5262 | If you have just made a commit, that commit will be the tip. If |
|
5262 | If you have just made a commit, that commit will be the tip. If | |
5263 | you have just pulled changes from another repository, the tip of |
|
5263 | you have just pulled changes from another repository, the tip of | |
5264 | that repository becomes the current tip. The "tip" tag is special |
|
5264 | that repository becomes the current tip. The "tip" tag is special | |
5265 | and cannot be renamed or assigned to a different changeset. |
|
5265 | and cannot be renamed or assigned to a different changeset. | |
5266 |
|
5266 | |||
5267 | This command is deprecated, please use :hg:`heads` instead. |
|
5267 | This command is deprecated, please use :hg:`heads` instead. | |
5268 |
|
5268 | |||
5269 | Returns 0 on success. |
|
5269 | Returns 0 on success. | |
5270 | """ |
|
5270 | """ | |
5271 | opts = pycompat.byteskwargs(opts) |
|
5271 | opts = pycompat.byteskwargs(opts) | |
5272 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5272 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
5273 | displayer.show(repo['tip']) |
|
5273 | displayer.show(repo['tip']) | |
5274 | displayer.close() |
|
5274 | displayer.close() | |
5275 |
|
5275 | |||
5276 | @command('unbundle', |
|
5276 | @command('unbundle', | |
5277 | [('u', 'update', None, |
|
5277 | [('u', 'update', None, | |
5278 | _('update to new branch head if changesets were unbundled'))], |
|
5278 | _('update to new branch head if changesets were unbundled'))], | |
5279 | _('[-u] FILE...')) |
|
5279 | _('[-u] FILE...')) | |
5280 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
5280 | def unbundle(ui, repo, fname1, *fnames, **opts): | |
5281 | """apply one or more bundle files |
|
5281 | """apply one or more bundle files | |
5282 |
|
5282 | |||
5283 | Apply one or more bundle files generated by :hg:`bundle`. |
|
5283 | Apply one or more bundle files generated by :hg:`bundle`. | |
5284 |
|
5284 | |||
5285 | Returns 0 on success, 1 if an update has unresolved files. |
|
5285 | Returns 0 on success, 1 if an update has unresolved files. | |
5286 | """ |
|
5286 | """ | |
5287 | fnames = (fname1,) + fnames |
|
5287 | fnames = (fname1,) + fnames | |
5288 |
|
5288 | |||
5289 | with repo.lock(): |
|
5289 | with repo.lock(): | |
5290 | for fname in fnames: |
|
5290 | for fname in fnames: | |
5291 | f = hg.openpath(ui, fname) |
|
5291 | f = hg.openpath(ui, fname) | |
5292 | gen = exchange.readbundle(ui, f, fname) |
|
5292 | gen = exchange.readbundle(ui, f, fname) | |
5293 | if isinstance(gen, streamclone.streamcloneapplier): |
|
5293 | if isinstance(gen, streamclone.streamcloneapplier): | |
5294 | raise error.Abort( |
|
5294 | raise error.Abort( | |
5295 | _('packed bundles cannot be applied with ' |
|
5295 | _('packed bundles cannot be applied with ' | |
5296 | '"hg unbundle"'), |
|
5296 | '"hg unbundle"'), | |
5297 | hint=_('use "hg debugapplystreamclonebundle"')) |
|
5297 | hint=_('use "hg debugapplystreamclonebundle"')) | |
5298 | url = 'bundle:' + fname |
|
5298 | url = 'bundle:' + fname | |
5299 | try: |
|
5299 | try: | |
5300 | txnname = 'unbundle' |
|
5300 | txnname = 'unbundle' | |
5301 | if not isinstance(gen, bundle2.unbundle20): |
|
5301 | if not isinstance(gen, bundle2.unbundle20): | |
5302 | txnname = 'unbundle\n%s' % util.hidepassword(url) |
|
5302 | txnname = 'unbundle\n%s' % util.hidepassword(url) | |
5303 | with repo.transaction(txnname) as tr: |
|
5303 | with repo.transaction(txnname) as tr: | |
5304 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', |
|
5304 | op = bundle2.applybundle(repo, gen, tr, source='unbundle', | |
5305 | url=url) |
|
5305 | url=url) | |
5306 | except error.BundleUnknownFeatureError as exc: |
|
5306 | except error.BundleUnknownFeatureError as exc: | |
5307 | raise error.Abort( |
|
5307 | raise error.Abort( | |
5308 | _('%s: unknown bundle feature, %s') % (fname, exc), |
|
5308 | _('%s: unknown bundle feature, %s') % (fname, exc), | |
5309 | hint=_("see https://mercurial-scm.org/" |
|
5309 | hint=_("see https://mercurial-scm.org/" | |
5310 | "wiki/BundleFeature for more " |
|
5310 | "wiki/BundleFeature for more " | |
5311 | "information")) |
|
5311 | "information")) | |
5312 | modheads = bundle2.combinechangegroupresults(op) |
|
5312 | modheads = bundle2.combinechangegroupresults(op) | |
5313 |
|
5313 | |||
5314 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) |
|
5314 | return postincoming(ui, repo, modheads, opts.get(r'update'), None, None) | |
5315 |
|
5315 | |||
5316 | @command('^update|up|checkout|co', |
|
5316 | @command('^update|up|checkout|co', | |
5317 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
5317 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), | |
5318 | ('c', 'check', None, _('require clean working directory')), |
|
5318 | ('c', 'check', None, _('require clean working directory')), | |
5319 | ('m', 'merge', None, _('merge uncommitted changes')), |
|
5319 | ('m', 'merge', None, _('merge uncommitted changes')), | |
5320 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5320 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
5321 | ('r', 'rev', '', _('revision'), _('REV')) |
|
5321 | ('r', 'rev', '', _('revision'), _('REV')) | |
5322 | ] + mergetoolopts, |
|
5322 | ] + mergetoolopts, | |
5323 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) |
|
5323 | _('[-C|-c|-m] [-d DATE] [[-r] REV]')) | |
5324 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, |
|
5324 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False, | |
5325 | merge=None, tool=None): |
|
5325 | merge=None, tool=None): | |
5326 | """update working directory (or switch revisions) |
|
5326 | """update working directory (or switch revisions) | |
5327 |
|
5327 | |||
5328 | Update the repository's working directory to the specified |
|
5328 | Update the repository's working directory to the specified | |
5329 | changeset. If no changeset is specified, update to the tip of the |
|
5329 | changeset. If no changeset is specified, update to the tip of the | |
5330 | current named branch and move the active bookmark (see :hg:`help |
|
5330 | current named branch and move the active bookmark (see :hg:`help | |
5331 | bookmarks`). |
|
5331 | bookmarks`). | |
5332 |
|
5332 | |||
5333 | Update sets the working directory's parent revision to the specified |
|
5333 | Update sets the working directory's parent revision to the specified | |
5334 | changeset (see :hg:`help parents`). |
|
5334 | changeset (see :hg:`help parents`). | |
5335 |
|
5335 | |||
5336 | If the changeset is not a descendant or ancestor of the working |
|
5336 | If the changeset is not a descendant or ancestor of the working | |
5337 | directory's parent and there are uncommitted changes, the update is |
|
5337 | directory's parent and there are uncommitted changes, the update is | |
5338 | aborted. With the -c/--check option, the working directory is checked |
|
5338 | aborted. With the -c/--check option, the working directory is checked | |
5339 | for uncommitted changes; if none are found, the working directory is |
|
5339 | for uncommitted changes; if none are found, the working directory is | |
5340 | updated to the specified changeset. |
|
5340 | updated to the specified changeset. | |
5341 |
|
5341 | |||
5342 | .. container:: verbose |
|
5342 | .. container:: verbose | |
5343 |
|
5343 | |||
5344 | The -C/--clean, -c/--check, and -m/--merge options control what |
|
5344 | The -C/--clean, -c/--check, and -m/--merge options control what | |
5345 | happens if the working directory contains uncommitted changes. |
|
5345 | happens if the working directory contains uncommitted changes. | |
5346 | At most of one of them can be specified. |
|
5346 | At most of one of them can be specified. | |
5347 |
|
5347 | |||
5348 | 1. If no option is specified, and if |
|
5348 | 1. If no option is specified, and if | |
5349 | the requested changeset is an ancestor or descendant of |
|
5349 | the requested changeset is an ancestor or descendant of | |
5350 | the working directory's parent, the uncommitted changes |
|
5350 | the working directory's parent, the uncommitted changes | |
5351 | are merged into the requested changeset and the merged |
|
5351 | are merged into the requested changeset and the merged | |
5352 | result is left uncommitted. If the requested changeset is |
|
5352 | result is left uncommitted. If the requested changeset is | |
5353 | not an ancestor or descendant (that is, it is on another |
|
5353 | not an ancestor or descendant (that is, it is on another | |
5354 | branch), the update is aborted and the uncommitted changes |
|
5354 | branch), the update is aborted and the uncommitted changes | |
5355 | are preserved. |
|
5355 | are preserved. | |
5356 |
|
5356 | |||
5357 | 2. With the -m/--merge option, the update is allowed even if the |
|
5357 | 2. With the -m/--merge option, the update is allowed even if the | |
5358 | requested changeset is not an ancestor or descendant of |
|
5358 | requested changeset is not an ancestor or descendant of | |
5359 | the working directory's parent. |
|
5359 | the working directory's parent. | |
5360 |
|
5360 | |||
5361 | 3. With the -c/--check option, the update is aborted and the |
|
5361 | 3. With the -c/--check option, the update is aborted and the | |
5362 | uncommitted changes are preserved. |
|
5362 | uncommitted changes are preserved. | |
5363 |
|
5363 | |||
5364 | 4. With the -C/--clean option, uncommitted changes are discarded and |
|
5364 | 4. With the -C/--clean option, uncommitted changes are discarded and | |
5365 | the working directory is updated to the requested changeset. |
|
5365 | the working directory is updated to the requested changeset. | |
5366 |
|
5366 | |||
5367 | To cancel an uncommitted merge (and lose your changes), use |
|
5367 | To cancel an uncommitted merge (and lose your changes), use | |
5368 | :hg:`update --clean .`. |
|
5368 | :hg:`update --clean .`. | |
5369 |
|
5369 | |||
5370 | Use null as the changeset to remove the working directory (like |
|
5370 | Use null as the changeset to remove the working directory (like | |
5371 | :hg:`clone -U`). |
|
5371 | :hg:`clone -U`). | |
5372 |
|
5372 | |||
5373 | If you want to revert just one file to an older revision, use |
|
5373 | If you want to revert just one file to an older revision, use | |
5374 | :hg:`revert [-r REV] NAME`. |
|
5374 | :hg:`revert [-r REV] NAME`. | |
5375 |
|
5375 | |||
5376 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5376 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
5377 |
|
5377 | |||
5378 | Returns 0 on success, 1 if there are unresolved files. |
|
5378 | Returns 0 on success, 1 if there are unresolved files. | |
5379 | """ |
|
5379 | """ | |
5380 | if rev and node: |
|
5380 | if rev and node: | |
5381 | raise error.Abort(_("please specify just one revision")) |
|
5381 | raise error.Abort(_("please specify just one revision")) | |
5382 |
|
5382 | |||
5383 | if ui.configbool('commands', 'update.requiredest'): |
|
5383 | if ui.configbool('commands', 'update.requiredest'): | |
5384 | if not node and not rev and not date: |
|
5384 | if not node and not rev and not date: | |
5385 | raise error.Abort(_('you must specify a destination'), |
|
5385 | raise error.Abort(_('you must specify a destination'), | |
5386 | hint=_('for example: hg update ".::"')) |
|
5386 | hint=_('for example: hg update ".::"')) | |
5387 |
|
5387 | |||
5388 | if rev is None or rev == '': |
|
5388 | if rev is None or rev == '': | |
5389 | rev = node |
|
5389 | rev = node | |
5390 |
|
5390 | |||
5391 | if date and rev is not None: |
|
5391 | if date and rev is not None: | |
5392 | raise error.Abort(_("you can't specify a revision and a date")) |
|
5392 | raise error.Abort(_("you can't specify a revision and a date")) | |
5393 |
|
5393 | |||
5394 | if len([x for x in (clean, check, merge) if x]) > 1: |
|
5394 | if len([x for x in (clean, check, merge) if x]) > 1: | |
5395 | raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " |
|
5395 | raise error.Abort(_("can only specify one of -C/--clean, -c/--check, " | |
5396 | "or -m/merge")) |
|
5396 | "or -m/merge")) | |
5397 |
|
5397 | |||
5398 | updatecheck = None |
|
5398 | updatecheck = None | |
5399 | if check: |
|
5399 | if check: | |
5400 | updatecheck = 'abort' |
|
5400 | updatecheck = 'abort' | |
5401 | elif merge: |
|
5401 | elif merge: | |
5402 | updatecheck = 'none' |
|
5402 | updatecheck = 'none' | |
5403 |
|
5403 | |||
5404 | with repo.wlock(): |
|
5404 | with repo.wlock(): | |
5405 | cmdutil.clearunfinished(repo) |
|
5405 | cmdutil.clearunfinished(repo) | |
5406 |
|
5406 | |||
5407 | if date: |
|
5407 | if date: | |
5408 | rev = cmdutil.finddate(ui, repo, date) |
|
5408 | rev = cmdutil.finddate(ui, repo, date) | |
5409 |
|
5409 | |||
5410 | # if we defined a bookmark, we have to remember the original name |
|
5410 | # if we defined a bookmark, we have to remember the original name | |
5411 | brev = rev |
|
5411 | brev = rev | |
5412 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
5412 | rev = scmutil.revsingle(repo, rev, rev).rev() | |
5413 |
|
5413 | |||
5414 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') |
|
5414 | repo.ui.setconfig('ui', 'forcemerge', tool, 'update') | |
5415 |
|
5415 | |||
5416 | return hg.updatetotally(ui, repo, rev, brev, clean=clean, |
|
5416 | return hg.updatetotally(ui, repo, rev, brev, clean=clean, | |
5417 | updatecheck=updatecheck) |
|
5417 | updatecheck=updatecheck) | |
5418 |
|
5418 | |||
5419 | @command('verify', []) |
|
5419 | @command('verify', []) | |
5420 | def verify(ui, repo): |
|
5420 | def verify(ui, repo): | |
5421 | """verify the integrity of the repository |
|
5421 | """verify the integrity of the repository | |
5422 |
|
5422 | |||
5423 | Verify the integrity of the current repository. |
|
5423 | Verify the integrity of the current repository. | |
5424 |
|
5424 | |||
5425 | This will perform an extensive check of the repository's |
|
5425 | This will perform an extensive check of the repository's | |
5426 | integrity, validating the hashes and checksums of each entry in |
|
5426 | integrity, validating the hashes and checksums of each entry in | |
5427 | the changelog, manifest, and tracked files, as well as the |
|
5427 | the changelog, manifest, and tracked files, as well as the | |
5428 | integrity of their crosslinks and indices. |
|
5428 | integrity of their crosslinks and indices. | |
5429 |
|
5429 | |||
5430 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption |
|
5430 | Please see https://mercurial-scm.org/wiki/RepositoryCorruption | |
5431 | for more information about recovery from corruption of the |
|
5431 | for more information about recovery from corruption of the | |
5432 | repository. |
|
5432 | repository. | |
5433 |
|
5433 | |||
5434 | Returns 0 on success, 1 if errors are encountered. |
|
5434 | Returns 0 on success, 1 if errors are encountered. | |
5435 | """ |
|
5435 | """ | |
5436 | return hg.verify(repo) |
|
5436 | return hg.verify(repo) | |
5437 |
|
5437 | |||
5438 | @command('version', [] + formatteropts, norepo=True) |
|
5438 | @command('version', [] + formatteropts, norepo=True) | |
5439 | def version_(ui, **opts): |
|
5439 | def version_(ui, **opts): | |
5440 | """output version and copyright information""" |
|
5440 | """output version and copyright information""" | |
5441 | opts = pycompat.byteskwargs(opts) |
|
5441 | opts = pycompat.byteskwargs(opts) | |
5442 | if ui.verbose: |
|
5442 | if ui.verbose: | |
5443 | ui.pager('version') |
|
5443 | ui.pager('version') | |
5444 | fm = ui.formatter("version", opts) |
|
5444 | fm = ui.formatter("version", opts) | |
5445 | fm.startitem() |
|
5445 | fm.startitem() | |
5446 | fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), |
|
5446 | fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"), | |
5447 | util.version()) |
|
5447 | util.version()) | |
5448 | license = _( |
|
5448 | license = _( | |
5449 | "(see https://mercurial-scm.org for more information)\n" |
|
5449 | "(see https://mercurial-scm.org for more information)\n" | |
5450 | "\nCopyright (C) 2005-2017 Matt Mackall and others\n" |
|
5450 | "\nCopyright (C) 2005-2017 Matt Mackall and others\n" | |
5451 | "This is free software; see the source for copying conditions. " |
|
5451 | "This is free software; see the source for copying conditions. " | |
5452 | "There is NO\nwarranty; " |
|
5452 | "There is NO\nwarranty; " | |
5453 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5453 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
5454 | ) |
|
5454 | ) | |
5455 | if not ui.quiet: |
|
5455 | if not ui.quiet: | |
5456 | fm.plain(license) |
|
5456 | fm.plain(license) | |
5457 |
|
5457 | |||
5458 | if ui.verbose: |
|
5458 | if ui.verbose: | |
5459 | fm.plain(_("\nEnabled extensions:\n\n")) |
|
5459 | fm.plain(_("\nEnabled extensions:\n\n")) | |
5460 | # format names and versions into columns |
|
5460 | # format names and versions into columns | |
5461 | names = [] |
|
5461 | names = [] | |
5462 | vers = [] |
|
5462 | vers = [] | |
5463 | isinternals = [] |
|
5463 | isinternals = [] | |
5464 | for name, module in extensions.extensions(): |
|
5464 | for name, module in extensions.extensions(): | |
5465 | names.append(name) |
|
5465 | names.append(name) | |
5466 | vers.append(extensions.moduleversion(module) or None) |
|
5466 | vers.append(extensions.moduleversion(module) or None) | |
5467 | isinternals.append(extensions.ismoduleinternal(module)) |
|
5467 | isinternals.append(extensions.ismoduleinternal(module)) | |
5468 | fn = fm.nested("extensions") |
|
5468 | fn = fm.nested("extensions") | |
5469 | if names: |
|
5469 | if names: | |
5470 | namefmt = " %%-%ds " % max(len(n) for n in names) |
|
5470 | namefmt = " %%-%ds " % max(len(n) for n in names) | |
5471 | places = [_("external"), _("internal")] |
|
5471 | places = [_("external"), _("internal")] | |
5472 | for n, v, p in zip(names, vers, isinternals): |
|
5472 | for n, v, p in zip(names, vers, isinternals): | |
5473 | fn.startitem() |
|
5473 | fn.startitem() | |
5474 | fn.condwrite(ui.verbose, "name", namefmt, n) |
|
5474 | fn.condwrite(ui.verbose, "name", namefmt, n) | |
5475 | if ui.verbose: |
|
5475 | if ui.verbose: | |
5476 | fn.plain("%s " % places[p]) |
|
5476 | fn.plain("%s " % places[p]) | |
5477 | fn.data(bundled=p) |
|
5477 | fn.data(bundled=p) | |
5478 | fn.condwrite(ui.verbose and v, "ver", "%s", v) |
|
5478 | fn.condwrite(ui.verbose and v, "ver", "%s", v) | |
5479 | if ui.verbose: |
|
5479 | if ui.verbose: | |
5480 | fn.plain("\n") |
|
5480 | fn.plain("\n") | |
5481 | fn.end() |
|
5481 | fn.end() | |
5482 | fm.end() |
|
5482 | fm.end() | |
5483 |
|
5483 | |||
5484 | def loadcmdtable(ui, name, cmdtable): |
|
5484 | def loadcmdtable(ui, name, cmdtable): | |
5485 | """Load command functions from specified cmdtable |
|
5485 | """Load command functions from specified cmdtable | |
5486 | """ |
|
5486 | """ | |
5487 | overrides = [cmd for cmd in cmdtable if cmd in table] |
|
5487 | overrides = [cmd for cmd in cmdtable if cmd in table] | |
5488 | if overrides: |
|
5488 | if overrides: | |
5489 | ui.warn(_("extension '%s' overrides commands: %s\n") |
|
5489 | ui.warn(_("extension '%s' overrides commands: %s\n") | |
5490 | % (name, " ".join(overrides))) |
|
5490 | % (name, " ".join(overrides))) | |
5491 | table.update(cmdtable) |
|
5491 | table.update(cmdtable) |
@@ -1,2557 +1,2566 | |||||
1 | # context.py - changeset and file context objects for mercurial |
|
1 | # context.py - changeset and file context objects for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2006, 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 errno |
|
10 | import errno | |
11 | import os |
|
11 | import os | |
12 | import re |
|
12 | import re | |
13 | import stat |
|
13 | import stat | |
14 |
|
14 | |||
15 | from .i18n import _ |
|
15 | from .i18n import _ | |
16 | from .node import ( |
|
16 | from .node import ( | |
17 | addednodeid, |
|
17 | addednodeid, | |
18 | bin, |
|
18 | bin, | |
19 | hex, |
|
19 | hex, | |
20 | modifiednodeid, |
|
20 | modifiednodeid, | |
21 | nullid, |
|
21 | nullid, | |
22 | nullrev, |
|
22 | nullrev, | |
23 | short, |
|
23 | short, | |
24 | wdirid, |
|
24 | wdirid, | |
25 | wdirnodes, |
|
25 | wdirnodes, | |
26 | wdirrev, |
|
26 | wdirrev, | |
27 | ) |
|
27 | ) | |
|
28 | from .thirdparty import ( | |||
|
29 | attr, | |||
|
30 | ) | |||
28 | from . import ( |
|
31 | from . import ( | |
29 | encoding, |
|
32 | encoding, | |
30 | error, |
|
33 | error, | |
31 | fileset, |
|
34 | fileset, | |
32 | match as matchmod, |
|
35 | match as matchmod, | |
33 | mdiff, |
|
36 | mdiff, | |
34 | obsolete as obsmod, |
|
37 | obsolete as obsmod, | |
35 | patch, |
|
38 | patch, | |
36 | pathutil, |
|
39 | pathutil, | |
37 | phases, |
|
40 | phases, | |
38 | pycompat, |
|
41 | pycompat, | |
39 | repoview, |
|
42 | repoview, | |
40 | revlog, |
|
43 | revlog, | |
41 | scmutil, |
|
44 | scmutil, | |
42 | sparse, |
|
45 | sparse, | |
43 | subrepo, |
|
46 | subrepo, | |
44 | util, |
|
47 | util, | |
45 | ) |
|
48 | ) | |
46 |
|
49 | |||
47 | propertycache = util.propertycache |
|
50 | propertycache = util.propertycache | |
48 |
|
51 | |||
49 | nonascii = re.compile(r'[^\x21-\x7f]').search |
|
52 | nonascii = re.compile(r'[^\x21-\x7f]').search | |
50 |
|
53 | |||
51 | class basectx(object): |
|
54 | class basectx(object): | |
52 | """A basectx object represents the common logic for its children: |
|
55 | """A basectx object represents the common logic for its children: | |
53 | changectx: read-only context that is already present in the repo, |
|
56 | changectx: read-only context that is already present in the repo, | |
54 | workingctx: a context that represents the working directory and can |
|
57 | workingctx: a context that represents the working directory and can | |
55 | be committed, |
|
58 | be committed, | |
56 | memctx: a context that represents changes in-memory and can also |
|
59 | memctx: a context that represents changes in-memory and can also | |
57 | be committed.""" |
|
60 | be committed.""" | |
58 | def __new__(cls, repo, changeid='', *args, **kwargs): |
|
61 | def __new__(cls, repo, changeid='', *args, **kwargs): | |
59 | if isinstance(changeid, basectx): |
|
62 | if isinstance(changeid, basectx): | |
60 | return changeid |
|
63 | return changeid | |
61 |
|
64 | |||
62 | o = super(basectx, cls).__new__(cls) |
|
65 | o = super(basectx, cls).__new__(cls) | |
63 |
|
66 | |||
64 | o._repo = repo |
|
67 | o._repo = repo | |
65 | o._rev = nullrev |
|
68 | o._rev = nullrev | |
66 | o._node = nullid |
|
69 | o._node = nullid | |
67 |
|
70 | |||
68 | return o |
|
71 | return o | |
69 |
|
72 | |||
70 | def __bytes__(self): |
|
73 | def __bytes__(self): | |
71 | return short(self.node()) |
|
74 | return short(self.node()) | |
72 |
|
75 | |||
73 | __str__ = encoding.strmethod(__bytes__) |
|
76 | __str__ = encoding.strmethod(__bytes__) | |
74 |
|
77 | |||
75 | def __int__(self): |
|
78 | def __int__(self): | |
76 | return self.rev() |
|
79 | return self.rev() | |
77 |
|
80 | |||
78 | def __repr__(self): |
|
81 | def __repr__(self): | |
79 | return r"<%s %s>" % (type(self).__name__, str(self)) |
|
82 | return r"<%s %s>" % (type(self).__name__, str(self)) | |
80 |
|
83 | |||
81 | def __eq__(self, other): |
|
84 | def __eq__(self, other): | |
82 | try: |
|
85 | try: | |
83 | return type(self) == type(other) and self._rev == other._rev |
|
86 | return type(self) == type(other) and self._rev == other._rev | |
84 | except AttributeError: |
|
87 | except AttributeError: | |
85 | return False |
|
88 | return False | |
86 |
|
89 | |||
87 | def __ne__(self, other): |
|
90 | def __ne__(self, other): | |
88 | return not (self == other) |
|
91 | return not (self == other) | |
89 |
|
92 | |||
90 | def __contains__(self, key): |
|
93 | def __contains__(self, key): | |
91 | return key in self._manifest |
|
94 | return key in self._manifest | |
92 |
|
95 | |||
93 | def __getitem__(self, key): |
|
96 | def __getitem__(self, key): | |
94 | return self.filectx(key) |
|
97 | return self.filectx(key) | |
95 |
|
98 | |||
96 | def __iter__(self): |
|
99 | def __iter__(self): | |
97 | return iter(self._manifest) |
|
100 | return iter(self._manifest) | |
98 |
|
101 | |||
99 | def _buildstatusmanifest(self, status): |
|
102 | def _buildstatusmanifest(self, status): | |
100 | """Builds a manifest that includes the given status results, if this is |
|
103 | """Builds a manifest that includes the given status results, if this is | |
101 | a working copy context. For non-working copy contexts, it just returns |
|
104 | a working copy context. For non-working copy contexts, it just returns | |
102 | the normal manifest.""" |
|
105 | the normal manifest.""" | |
103 | return self.manifest() |
|
106 | return self.manifest() | |
104 |
|
107 | |||
105 | def _matchstatus(self, other, match): |
|
108 | def _matchstatus(self, other, match): | |
106 | """This internal method provides a way for child objects to override the |
|
109 | """This internal method provides a way for child objects to override the | |
107 | match operator. |
|
110 | match operator. | |
108 | """ |
|
111 | """ | |
109 | return match |
|
112 | return match | |
110 |
|
113 | |||
111 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
114 | def _buildstatus(self, other, s, match, listignored, listclean, | |
112 | listunknown): |
|
115 | listunknown): | |
113 | """build a status with respect to another context""" |
|
116 | """build a status with respect to another context""" | |
114 | # Load earliest manifest first for caching reasons. More specifically, |
|
117 | # Load earliest manifest first for caching reasons. More specifically, | |
115 | # if you have revisions 1000 and 1001, 1001 is probably stored as a |
|
118 | # if you have revisions 1000 and 1001, 1001 is probably stored as a | |
116 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct |
|
119 | # delta against 1000. Thus, if you read 1000 first, we'll reconstruct | |
117 | # 1000 and cache it so that when you read 1001, we just need to apply a |
|
120 | # 1000 and cache it so that when you read 1001, we just need to apply a | |
118 | # delta to what's in the cache. So that's one full reconstruction + one |
|
121 | # delta to what's in the cache. So that's one full reconstruction + one | |
119 | # delta application. |
|
122 | # delta application. | |
120 | mf2 = None |
|
123 | mf2 = None | |
121 | if self.rev() is not None and self.rev() < other.rev(): |
|
124 | if self.rev() is not None and self.rev() < other.rev(): | |
122 | mf2 = self._buildstatusmanifest(s) |
|
125 | mf2 = self._buildstatusmanifest(s) | |
123 | mf1 = other._buildstatusmanifest(s) |
|
126 | mf1 = other._buildstatusmanifest(s) | |
124 | if mf2 is None: |
|
127 | if mf2 is None: | |
125 | mf2 = self._buildstatusmanifest(s) |
|
128 | mf2 = self._buildstatusmanifest(s) | |
126 |
|
129 | |||
127 | modified, added = [], [] |
|
130 | modified, added = [], [] | |
128 | removed = [] |
|
131 | removed = [] | |
129 | clean = [] |
|
132 | clean = [] | |
130 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored |
|
133 | deleted, unknown, ignored = s.deleted, s.unknown, s.ignored | |
131 | deletedset = set(deleted) |
|
134 | deletedset = set(deleted) | |
132 | d = mf1.diff(mf2, match=match, clean=listclean) |
|
135 | d = mf1.diff(mf2, match=match, clean=listclean) | |
133 | for fn, value in d.iteritems(): |
|
136 | for fn, value in d.iteritems(): | |
134 | if fn in deletedset: |
|
137 | if fn in deletedset: | |
135 | continue |
|
138 | continue | |
136 | if value is None: |
|
139 | if value is None: | |
137 | clean.append(fn) |
|
140 | clean.append(fn) | |
138 | continue |
|
141 | continue | |
139 | (node1, flag1), (node2, flag2) = value |
|
142 | (node1, flag1), (node2, flag2) = value | |
140 | if node1 is None: |
|
143 | if node1 is None: | |
141 | added.append(fn) |
|
144 | added.append(fn) | |
142 | elif node2 is None: |
|
145 | elif node2 is None: | |
143 | removed.append(fn) |
|
146 | removed.append(fn) | |
144 | elif flag1 != flag2: |
|
147 | elif flag1 != flag2: | |
145 | modified.append(fn) |
|
148 | modified.append(fn) | |
146 | elif node2 not in wdirnodes: |
|
149 | elif node2 not in wdirnodes: | |
147 | # When comparing files between two commits, we save time by |
|
150 | # When comparing files between two commits, we save time by | |
148 | # not comparing the file contents when the nodeids differ. |
|
151 | # not comparing the file contents when the nodeids differ. | |
149 | # Note that this means we incorrectly report a reverted change |
|
152 | # Note that this means we incorrectly report a reverted change | |
150 | # to a file as a modification. |
|
153 | # to a file as a modification. | |
151 | modified.append(fn) |
|
154 | modified.append(fn) | |
152 | elif self[fn].cmp(other[fn]): |
|
155 | elif self[fn].cmp(other[fn]): | |
153 | modified.append(fn) |
|
156 | modified.append(fn) | |
154 | else: |
|
157 | else: | |
155 | clean.append(fn) |
|
158 | clean.append(fn) | |
156 |
|
159 | |||
157 | if removed: |
|
160 | if removed: | |
158 | # need to filter files if they are already reported as removed |
|
161 | # need to filter files if they are already reported as removed | |
159 | unknown = [fn for fn in unknown if fn not in mf1 and |
|
162 | unknown = [fn for fn in unknown if fn not in mf1 and | |
160 | (not match or match(fn))] |
|
163 | (not match or match(fn))] | |
161 | ignored = [fn for fn in ignored if fn not in mf1 and |
|
164 | ignored = [fn for fn in ignored if fn not in mf1 and | |
162 | (not match or match(fn))] |
|
165 | (not match or match(fn))] | |
163 | # if they're deleted, don't report them as removed |
|
166 | # if they're deleted, don't report them as removed | |
164 | removed = [fn for fn in removed if fn not in deletedset] |
|
167 | removed = [fn for fn in removed if fn not in deletedset] | |
165 |
|
168 | |||
166 | return scmutil.status(modified, added, removed, deleted, unknown, |
|
169 | return scmutil.status(modified, added, removed, deleted, unknown, | |
167 | ignored, clean) |
|
170 | ignored, clean) | |
168 |
|
171 | |||
169 | @propertycache |
|
172 | @propertycache | |
170 | def substate(self): |
|
173 | def substate(self): | |
171 | return subrepo.state(self, self._repo.ui) |
|
174 | return subrepo.state(self, self._repo.ui) | |
172 |
|
175 | |||
173 | def subrev(self, subpath): |
|
176 | def subrev(self, subpath): | |
174 | return self.substate[subpath][1] |
|
177 | return self.substate[subpath][1] | |
175 |
|
178 | |||
176 | def rev(self): |
|
179 | def rev(self): | |
177 | return self._rev |
|
180 | return self._rev | |
178 | def node(self): |
|
181 | def node(self): | |
179 | return self._node |
|
182 | return self._node | |
180 | def hex(self): |
|
183 | def hex(self): | |
181 | return hex(self.node()) |
|
184 | return hex(self.node()) | |
182 | def manifest(self): |
|
185 | def manifest(self): | |
183 | return self._manifest |
|
186 | return self._manifest | |
184 | def manifestctx(self): |
|
187 | def manifestctx(self): | |
185 | return self._manifestctx |
|
188 | return self._manifestctx | |
186 | def repo(self): |
|
189 | def repo(self): | |
187 | return self._repo |
|
190 | return self._repo | |
188 | def phasestr(self): |
|
191 | def phasestr(self): | |
189 | return phases.phasenames[self.phase()] |
|
192 | return phases.phasenames[self.phase()] | |
190 | def mutable(self): |
|
193 | def mutable(self): | |
191 | return self.phase() > phases.public |
|
194 | return self.phase() > phases.public | |
192 |
|
195 | |||
193 | def getfileset(self, expr): |
|
196 | def getfileset(self, expr): | |
194 | return fileset.getfileset(self, expr) |
|
197 | return fileset.getfileset(self, expr) | |
195 |
|
198 | |||
196 | def obsolete(self): |
|
199 | def obsolete(self): | |
197 | """True if the changeset is obsolete""" |
|
200 | """True if the changeset is obsolete""" | |
198 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') |
|
201 | return self.rev() in obsmod.getrevs(self._repo, 'obsolete') | |
199 |
|
202 | |||
200 | def extinct(self): |
|
203 | def extinct(self): | |
201 | """True if the changeset is extinct""" |
|
204 | """True if the changeset is extinct""" | |
202 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') |
|
205 | return self.rev() in obsmod.getrevs(self._repo, 'extinct') | |
203 |
|
206 | |||
204 | def unstable(self): |
|
207 | def unstable(self): | |
205 | msg = ("'context.unstable' is deprecated, " |
|
208 | msg = ("'context.unstable' is deprecated, " | |
206 | "use 'context.orphan'") |
|
209 | "use 'context.orphan'") | |
207 | self._repo.ui.deprecwarn(msg, '4.4') |
|
210 | self._repo.ui.deprecwarn(msg, '4.4') | |
208 | return self.orphan() |
|
211 | return self.orphan() | |
209 |
|
212 | |||
210 | def orphan(self): |
|
213 | def orphan(self): | |
211 | """True if the changeset is not obsolete but it's ancestor are""" |
|
214 | """True if the changeset is not obsolete but it's ancestor are""" | |
212 | return self.rev() in obsmod.getrevs(self._repo, 'orphan') |
|
215 | return self.rev() in obsmod.getrevs(self._repo, 'orphan') | |
213 |
|
216 | |||
214 | def bumped(self): |
|
217 | def bumped(self): | |
215 | msg = ("'context.bumped' is deprecated, " |
|
218 | msg = ("'context.bumped' is deprecated, " | |
216 | "use 'context.phasedivergent'") |
|
219 | "use 'context.phasedivergent'") | |
217 | self._repo.ui.deprecwarn(msg, '4.4') |
|
220 | self._repo.ui.deprecwarn(msg, '4.4') | |
218 | return self.phasedivergent() |
|
221 | return self.phasedivergent() | |
219 |
|
222 | |||
220 | def phasedivergent(self): |
|
223 | def phasedivergent(self): | |
221 | """True if the changeset try to be a successor of a public changeset |
|
224 | """True if the changeset try to be a successor of a public changeset | |
222 |
|
225 | |||
223 | Only non-public and non-obsolete changesets may be bumped. |
|
226 | Only non-public and non-obsolete changesets may be bumped. | |
224 | """ |
|
227 | """ | |
225 | return self.rev() in obsmod.getrevs(self._repo, 'phasedivergent') |
|
228 | return self.rev() in obsmod.getrevs(self._repo, 'phasedivergent') | |
226 |
|
229 | |||
227 | def divergent(self): |
|
230 | def divergent(self): | |
228 | msg = ("'context.divergent' is deprecated, " |
|
231 | msg = ("'context.divergent' is deprecated, " | |
229 | "use 'context.contentdivergent'") |
|
232 | "use 'context.contentdivergent'") | |
230 | self._repo.ui.deprecwarn(msg, '4.4') |
|
233 | self._repo.ui.deprecwarn(msg, '4.4') | |
231 | return self.contentdivergent() |
|
234 | return self.contentdivergent() | |
232 |
|
235 | |||
233 | def contentdivergent(self): |
|
236 | def contentdivergent(self): | |
234 | """Is a successors of a changeset with multiple possible successors set |
|
237 | """Is a successors of a changeset with multiple possible successors set | |
235 |
|
238 | |||
236 | Only non-public and non-obsolete changesets may be divergent. |
|
239 | Only non-public and non-obsolete changesets may be divergent. | |
237 | """ |
|
240 | """ | |
238 | return self.rev() in obsmod.getrevs(self._repo, 'contentdivergent') |
|
241 | return self.rev() in obsmod.getrevs(self._repo, 'contentdivergent') | |
239 |
|
242 | |||
240 | def troubled(self): |
|
243 | def troubled(self): | |
241 | msg = ("'context.troubled' is deprecated, " |
|
244 | msg = ("'context.troubled' is deprecated, " | |
242 | "use 'context.isunstable'") |
|
245 | "use 'context.isunstable'") | |
243 | self._repo.ui.deprecwarn(msg, '4.4') |
|
246 | self._repo.ui.deprecwarn(msg, '4.4') | |
244 | return self.isunstable() |
|
247 | return self.isunstable() | |
245 |
|
248 | |||
246 | def isunstable(self): |
|
249 | def isunstable(self): | |
247 | """True if the changeset is either unstable, bumped or divergent""" |
|
250 | """True if the changeset is either unstable, bumped or divergent""" | |
248 | return self.orphan() or self.phasedivergent() or self.contentdivergent() |
|
251 | return self.orphan() or self.phasedivergent() or self.contentdivergent() | |
249 |
|
252 | |||
250 | def troubles(self): |
|
253 | def troubles(self): | |
251 | """Keep the old version around in order to avoid breaking extensions |
|
254 | """Keep the old version around in order to avoid breaking extensions | |
252 | about different return values. |
|
255 | about different return values. | |
253 | """ |
|
256 | """ | |
254 | msg = ("'context.troubles' is deprecated, " |
|
257 | msg = ("'context.troubles' is deprecated, " | |
255 | "use 'context.instabilities'") |
|
258 | "use 'context.instabilities'") | |
256 | self._repo.ui.deprecwarn(msg, '4.4') |
|
259 | self._repo.ui.deprecwarn(msg, '4.4') | |
257 |
|
260 | |||
258 | troubles = [] |
|
261 | troubles = [] | |
259 | if self.orphan(): |
|
262 | if self.orphan(): | |
260 | troubles.append('orphan') |
|
263 | troubles.append('orphan') | |
261 | if self.phasedivergent(): |
|
264 | if self.phasedivergent(): | |
262 | troubles.append('bumped') |
|
265 | troubles.append('bumped') | |
263 | if self.contentdivergent(): |
|
266 | if self.contentdivergent(): | |
264 | troubles.append('divergent') |
|
267 | troubles.append('divergent') | |
265 | return troubles |
|
268 | return troubles | |
266 |
|
269 | |||
267 | def instabilities(self): |
|
270 | def instabilities(self): | |
268 | """return the list of instabilities affecting this changeset. |
|
271 | """return the list of instabilities affecting this changeset. | |
269 |
|
272 | |||
270 | Instabilities are returned as strings. possible values are: |
|
273 | Instabilities are returned as strings. possible values are: | |
271 | - orphan, |
|
274 | - orphan, | |
272 | - phase-divergent, |
|
275 | - phase-divergent, | |
273 | - content-divergent. |
|
276 | - content-divergent. | |
274 | """ |
|
277 | """ | |
275 | instabilities = [] |
|
278 | instabilities = [] | |
276 | if self.orphan(): |
|
279 | if self.orphan(): | |
277 | instabilities.append('orphan') |
|
280 | instabilities.append('orphan') | |
278 | if self.phasedivergent(): |
|
281 | if self.phasedivergent(): | |
279 | instabilities.append('phase-divergent') |
|
282 | instabilities.append('phase-divergent') | |
280 | if self.contentdivergent(): |
|
283 | if self.contentdivergent(): | |
281 | instabilities.append('content-divergent') |
|
284 | instabilities.append('content-divergent') | |
282 | return instabilities |
|
285 | return instabilities | |
283 |
|
286 | |||
284 | def parents(self): |
|
287 | def parents(self): | |
285 | """return contexts for each parent changeset""" |
|
288 | """return contexts for each parent changeset""" | |
286 | return self._parents |
|
289 | return self._parents | |
287 |
|
290 | |||
288 | def p1(self): |
|
291 | def p1(self): | |
289 | return self._parents[0] |
|
292 | return self._parents[0] | |
290 |
|
293 | |||
291 | def p2(self): |
|
294 | def p2(self): | |
292 | parents = self._parents |
|
295 | parents = self._parents | |
293 | if len(parents) == 2: |
|
296 | if len(parents) == 2: | |
294 | return parents[1] |
|
297 | return parents[1] | |
295 | return changectx(self._repo, nullrev) |
|
298 | return changectx(self._repo, nullrev) | |
296 |
|
299 | |||
297 | def _fileinfo(self, path): |
|
300 | def _fileinfo(self, path): | |
298 | if r'_manifest' in self.__dict__: |
|
301 | if r'_manifest' in self.__dict__: | |
299 | try: |
|
302 | try: | |
300 | return self._manifest[path], self._manifest.flags(path) |
|
303 | return self._manifest[path], self._manifest.flags(path) | |
301 | except KeyError: |
|
304 | except KeyError: | |
302 | raise error.ManifestLookupError(self._node, path, |
|
305 | raise error.ManifestLookupError(self._node, path, | |
303 | _('not found in manifest')) |
|
306 | _('not found in manifest')) | |
304 | if r'_manifestdelta' in self.__dict__ or path in self.files(): |
|
307 | if r'_manifestdelta' in self.__dict__ or path in self.files(): | |
305 | if path in self._manifestdelta: |
|
308 | if path in self._manifestdelta: | |
306 | return (self._manifestdelta[path], |
|
309 | return (self._manifestdelta[path], | |
307 | self._manifestdelta.flags(path)) |
|
310 | self._manifestdelta.flags(path)) | |
308 | mfl = self._repo.manifestlog |
|
311 | mfl = self._repo.manifestlog | |
309 | try: |
|
312 | try: | |
310 | node, flag = mfl[self._changeset.manifest].find(path) |
|
313 | node, flag = mfl[self._changeset.manifest].find(path) | |
311 | except KeyError: |
|
314 | except KeyError: | |
312 | raise error.ManifestLookupError(self._node, path, |
|
315 | raise error.ManifestLookupError(self._node, path, | |
313 | _('not found in manifest')) |
|
316 | _('not found in manifest')) | |
314 |
|
317 | |||
315 | return node, flag |
|
318 | return node, flag | |
316 |
|
319 | |||
317 | def filenode(self, path): |
|
320 | def filenode(self, path): | |
318 | return self._fileinfo(path)[0] |
|
321 | return self._fileinfo(path)[0] | |
319 |
|
322 | |||
320 | def flags(self, path): |
|
323 | def flags(self, path): | |
321 | try: |
|
324 | try: | |
322 | return self._fileinfo(path)[1] |
|
325 | return self._fileinfo(path)[1] | |
323 | except error.LookupError: |
|
326 | except error.LookupError: | |
324 | return '' |
|
327 | return '' | |
325 |
|
328 | |||
326 | def sub(self, path, allowcreate=True): |
|
329 | def sub(self, path, allowcreate=True): | |
327 | '''return a subrepo for the stored revision of path, never wdir()''' |
|
330 | '''return a subrepo for the stored revision of path, never wdir()''' | |
328 | return subrepo.subrepo(self, path, allowcreate=allowcreate) |
|
331 | return subrepo.subrepo(self, path, allowcreate=allowcreate) | |
329 |
|
332 | |||
330 | def nullsub(self, path, pctx): |
|
333 | def nullsub(self, path, pctx): | |
331 | return subrepo.nullsubrepo(self, path, pctx) |
|
334 | return subrepo.nullsubrepo(self, path, pctx) | |
332 |
|
335 | |||
333 | def workingsub(self, path): |
|
336 | def workingsub(self, path): | |
334 | '''return a subrepo for the stored revision, or wdir if this is a wdir |
|
337 | '''return a subrepo for the stored revision, or wdir if this is a wdir | |
335 | context. |
|
338 | context. | |
336 | ''' |
|
339 | ''' | |
337 | return subrepo.subrepo(self, path, allowwdir=True) |
|
340 | return subrepo.subrepo(self, path, allowwdir=True) | |
338 |
|
341 | |||
339 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
342 | def match(self, pats=None, include=None, exclude=None, default='glob', | |
340 | listsubrepos=False, badfn=None): |
|
343 | listsubrepos=False, badfn=None): | |
341 | r = self._repo |
|
344 | r = self._repo | |
342 | return matchmod.match(r.root, r.getcwd(), pats, |
|
345 | return matchmod.match(r.root, r.getcwd(), pats, | |
343 | include, exclude, default, |
|
346 | include, exclude, default, | |
344 | auditor=r.nofsauditor, ctx=self, |
|
347 | auditor=r.nofsauditor, ctx=self, | |
345 | listsubrepos=listsubrepos, badfn=badfn) |
|
348 | listsubrepos=listsubrepos, badfn=badfn) | |
346 |
|
349 | |||
347 | def diff(self, ctx2=None, match=None, **opts): |
|
350 | def diff(self, ctx2=None, match=None, **opts): | |
348 | """Returns a diff generator for the given contexts and matcher""" |
|
351 | """Returns a diff generator for the given contexts and matcher""" | |
349 | if ctx2 is None: |
|
352 | if ctx2 is None: | |
350 | ctx2 = self.p1() |
|
353 | ctx2 = self.p1() | |
351 | if ctx2 is not None: |
|
354 | if ctx2 is not None: | |
352 | ctx2 = self._repo[ctx2] |
|
355 | ctx2 = self._repo[ctx2] | |
353 | diffopts = patch.diffopts(self._repo.ui, opts) |
|
356 | diffopts = patch.diffopts(self._repo.ui, opts) | |
354 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) |
|
357 | return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts) | |
355 |
|
358 | |||
356 | def dirs(self): |
|
359 | def dirs(self): | |
357 | return self._manifest.dirs() |
|
360 | return self._manifest.dirs() | |
358 |
|
361 | |||
359 | def hasdir(self, dir): |
|
362 | def hasdir(self, dir): | |
360 | return self._manifest.hasdir(dir) |
|
363 | return self._manifest.hasdir(dir) | |
361 |
|
364 | |||
362 | def status(self, other=None, match=None, listignored=False, |
|
365 | def status(self, other=None, match=None, listignored=False, | |
363 | listclean=False, listunknown=False, listsubrepos=False): |
|
366 | listclean=False, listunknown=False, listsubrepos=False): | |
364 | """return status of files between two nodes or node and working |
|
367 | """return status of files between two nodes or node and working | |
365 | directory. |
|
368 | directory. | |
366 |
|
369 | |||
367 | If other is None, compare this node with working directory. |
|
370 | If other is None, compare this node with working directory. | |
368 |
|
371 | |||
369 | returns (modified, added, removed, deleted, unknown, ignored, clean) |
|
372 | returns (modified, added, removed, deleted, unknown, ignored, clean) | |
370 | """ |
|
373 | """ | |
371 |
|
374 | |||
372 | ctx1 = self |
|
375 | ctx1 = self | |
373 | ctx2 = self._repo[other] |
|
376 | ctx2 = self._repo[other] | |
374 |
|
377 | |||
375 | # This next code block is, admittedly, fragile logic that tests for |
|
378 | # This next code block is, admittedly, fragile logic that tests for | |
376 | # reversing the contexts and wouldn't need to exist if it weren't for |
|
379 | # reversing the contexts and wouldn't need to exist if it weren't for | |
377 | # the fast (and common) code path of comparing the working directory |
|
380 | # the fast (and common) code path of comparing the working directory | |
378 | # with its first parent. |
|
381 | # with its first parent. | |
379 | # |
|
382 | # | |
380 | # What we're aiming for here is the ability to call: |
|
383 | # What we're aiming for here is the ability to call: | |
381 | # |
|
384 | # | |
382 | # workingctx.status(parentctx) |
|
385 | # workingctx.status(parentctx) | |
383 | # |
|
386 | # | |
384 | # If we always built the manifest for each context and compared those, |
|
387 | # If we always built the manifest for each context and compared those, | |
385 | # then we'd be done. But the special case of the above call means we |
|
388 | # then we'd be done. But the special case of the above call means we | |
386 | # just copy the manifest of the parent. |
|
389 | # just copy the manifest of the parent. | |
387 | reversed = False |
|
390 | reversed = False | |
388 | if (not isinstance(ctx1, changectx) |
|
391 | if (not isinstance(ctx1, changectx) | |
389 | and isinstance(ctx2, changectx)): |
|
392 | and isinstance(ctx2, changectx)): | |
390 | reversed = True |
|
393 | reversed = True | |
391 | ctx1, ctx2 = ctx2, ctx1 |
|
394 | ctx1, ctx2 = ctx2, ctx1 | |
392 |
|
395 | |||
393 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) |
|
396 | match = match or matchmod.always(self._repo.root, self._repo.getcwd()) | |
394 | match = ctx2._matchstatus(ctx1, match) |
|
397 | match = ctx2._matchstatus(ctx1, match) | |
395 | r = scmutil.status([], [], [], [], [], [], []) |
|
398 | r = scmutil.status([], [], [], [], [], [], []) | |
396 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, |
|
399 | r = ctx2._buildstatus(ctx1, r, match, listignored, listclean, | |
397 | listunknown) |
|
400 | listunknown) | |
398 |
|
401 | |||
399 | if reversed: |
|
402 | if reversed: | |
400 | # Reverse added and removed. Clear deleted, unknown and ignored as |
|
403 | # Reverse added and removed. Clear deleted, unknown and ignored as | |
401 | # these make no sense to reverse. |
|
404 | # these make no sense to reverse. | |
402 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], |
|
405 | r = scmutil.status(r.modified, r.removed, r.added, [], [], [], | |
403 | r.clean) |
|
406 | r.clean) | |
404 |
|
407 | |||
405 | if listsubrepos: |
|
408 | if listsubrepos: | |
406 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
|
409 | for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): | |
407 | try: |
|
410 | try: | |
408 | rev2 = ctx2.subrev(subpath) |
|
411 | rev2 = ctx2.subrev(subpath) | |
409 | except KeyError: |
|
412 | except KeyError: | |
410 | # A subrepo that existed in node1 was deleted between |
|
413 | # A subrepo that existed in node1 was deleted between | |
411 | # node1 and node2 (inclusive). Thus, ctx2's substate |
|
414 | # node1 and node2 (inclusive). Thus, ctx2's substate | |
412 | # won't contain that subpath. The best we can do ignore it. |
|
415 | # won't contain that subpath. The best we can do ignore it. | |
413 | rev2 = None |
|
416 | rev2 = None | |
414 | submatch = matchmod.subdirmatcher(subpath, match) |
|
417 | submatch = matchmod.subdirmatcher(subpath, match) | |
415 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
418 | s = sub.status(rev2, match=submatch, ignored=listignored, | |
416 | clean=listclean, unknown=listunknown, |
|
419 | clean=listclean, unknown=listunknown, | |
417 | listsubrepos=True) |
|
420 | listsubrepos=True) | |
418 | for rfiles, sfiles in zip(r, s): |
|
421 | for rfiles, sfiles in zip(r, s): | |
419 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
422 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) | |
420 |
|
423 | |||
421 | for l in r: |
|
424 | for l in r: | |
422 | l.sort() |
|
425 | l.sort() | |
423 |
|
426 | |||
424 | return r |
|
427 | return r | |
425 |
|
428 | |||
426 | def _filterederror(repo, changeid): |
|
429 | def _filterederror(repo, changeid): | |
427 | """build an exception to be raised about a filtered changeid |
|
430 | """build an exception to be raised about a filtered changeid | |
428 |
|
431 | |||
429 | This is extracted in a function to help extensions (eg: evolve) to |
|
432 | This is extracted in a function to help extensions (eg: evolve) to | |
430 | experiment with various message variants.""" |
|
433 | experiment with various message variants.""" | |
431 | if repo.filtername.startswith('visible'): |
|
434 | if repo.filtername.startswith('visible'): | |
432 | msg = _("hidden revision '%s'") % changeid |
|
435 | msg = _("hidden revision '%s'") % changeid | |
433 | hint = _('use --hidden to access hidden revisions') |
|
436 | hint = _('use --hidden to access hidden revisions') | |
434 | return error.FilteredRepoLookupError(msg, hint=hint) |
|
437 | return error.FilteredRepoLookupError(msg, hint=hint) | |
435 | msg = _("filtered revision '%s' (not in '%s' subset)") |
|
438 | msg = _("filtered revision '%s' (not in '%s' subset)") | |
436 | msg %= (changeid, repo.filtername) |
|
439 | msg %= (changeid, repo.filtername) | |
437 | return error.FilteredRepoLookupError(msg) |
|
440 | return error.FilteredRepoLookupError(msg) | |
438 |
|
441 | |||
439 | class changectx(basectx): |
|
442 | class changectx(basectx): | |
440 | """A changecontext object makes access to data related to a particular |
|
443 | """A changecontext object makes access to data related to a particular | |
441 | changeset convenient. It represents a read-only context already present in |
|
444 | changeset convenient. It represents a read-only context already present in | |
442 | the repo.""" |
|
445 | the repo.""" | |
443 | def __init__(self, repo, changeid=''): |
|
446 | def __init__(self, repo, changeid=''): | |
444 | """changeid is a revision number, node, or tag""" |
|
447 | """changeid is a revision number, node, or tag""" | |
445 |
|
448 | |||
446 | # since basectx.__new__ already took care of copying the object, we |
|
449 | # since basectx.__new__ already took care of copying the object, we | |
447 | # don't need to do anything in __init__, so we just exit here |
|
450 | # don't need to do anything in __init__, so we just exit here | |
448 | if isinstance(changeid, basectx): |
|
451 | if isinstance(changeid, basectx): | |
449 | return |
|
452 | return | |
450 |
|
453 | |||
451 | if changeid == '': |
|
454 | if changeid == '': | |
452 | changeid = '.' |
|
455 | changeid = '.' | |
453 | self._repo = repo |
|
456 | self._repo = repo | |
454 |
|
457 | |||
455 | try: |
|
458 | try: | |
456 | if isinstance(changeid, int): |
|
459 | if isinstance(changeid, int): | |
457 | self._node = repo.changelog.node(changeid) |
|
460 | self._node = repo.changelog.node(changeid) | |
458 | self._rev = changeid |
|
461 | self._rev = changeid | |
459 | return |
|
462 | return | |
460 | if not pycompat.ispy3 and isinstance(changeid, long): |
|
463 | if not pycompat.ispy3 and isinstance(changeid, long): | |
461 | changeid = str(changeid) |
|
464 | changeid = str(changeid) | |
462 | if changeid == 'null': |
|
465 | if changeid == 'null': | |
463 | self._node = nullid |
|
466 | self._node = nullid | |
464 | self._rev = nullrev |
|
467 | self._rev = nullrev | |
465 | return |
|
468 | return | |
466 | if changeid == 'tip': |
|
469 | if changeid == 'tip': | |
467 | self._node = repo.changelog.tip() |
|
470 | self._node = repo.changelog.tip() | |
468 | self._rev = repo.changelog.rev(self._node) |
|
471 | self._rev = repo.changelog.rev(self._node) | |
469 | return |
|
472 | return | |
470 | if changeid == '.' or changeid == repo.dirstate.p1(): |
|
473 | if changeid == '.' or changeid == repo.dirstate.p1(): | |
471 | # this is a hack to delay/avoid loading obsmarkers |
|
474 | # this is a hack to delay/avoid loading obsmarkers | |
472 | # when we know that '.' won't be hidden |
|
475 | # when we know that '.' won't be hidden | |
473 | self._node = repo.dirstate.p1() |
|
476 | self._node = repo.dirstate.p1() | |
474 | self._rev = repo.unfiltered().changelog.rev(self._node) |
|
477 | self._rev = repo.unfiltered().changelog.rev(self._node) | |
475 | return |
|
478 | return | |
476 | if len(changeid) == 20: |
|
479 | if len(changeid) == 20: | |
477 | try: |
|
480 | try: | |
478 | self._node = changeid |
|
481 | self._node = changeid | |
479 | self._rev = repo.changelog.rev(changeid) |
|
482 | self._rev = repo.changelog.rev(changeid) | |
480 | return |
|
483 | return | |
481 | except error.FilteredRepoLookupError: |
|
484 | except error.FilteredRepoLookupError: | |
482 | raise |
|
485 | raise | |
483 | except LookupError: |
|
486 | except LookupError: | |
484 | pass |
|
487 | pass | |
485 |
|
488 | |||
486 | try: |
|
489 | try: | |
487 | r = int(changeid) |
|
490 | r = int(changeid) | |
488 | if '%d' % r != changeid: |
|
491 | if '%d' % r != changeid: | |
489 | raise ValueError |
|
492 | raise ValueError | |
490 | l = len(repo.changelog) |
|
493 | l = len(repo.changelog) | |
491 | if r < 0: |
|
494 | if r < 0: | |
492 | r += l |
|
495 | r += l | |
493 | if r < 0 or r >= l and r != wdirrev: |
|
496 | if r < 0 or r >= l and r != wdirrev: | |
494 | raise ValueError |
|
497 | raise ValueError | |
495 | self._rev = r |
|
498 | self._rev = r | |
496 | self._node = repo.changelog.node(r) |
|
499 | self._node = repo.changelog.node(r) | |
497 | return |
|
500 | return | |
498 | except error.FilteredIndexError: |
|
501 | except error.FilteredIndexError: | |
499 | raise |
|
502 | raise | |
500 | except (ValueError, OverflowError, IndexError): |
|
503 | except (ValueError, OverflowError, IndexError): | |
501 | pass |
|
504 | pass | |
502 |
|
505 | |||
503 | if len(changeid) == 40: |
|
506 | if len(changeid) == 40: | |
504 | try: |
|
507 | try: | |
505 | self._node = bin(changeid) |
|
508 | self._node = bin(changeid) | |
506 | self._rev = repo.changelog.rev(self._node) |
|
509 | self._rev = repo.changelog.rev(self._node) | |
507 | return |
|
510 | return | |
508 | except error.FilteredLookupError: |
|
511 | except error.FilteredLookupError: | |
509 | raise |
|
512 | raise | |
510 | except (TypeError, LookupError): |
|
513 | except (TypeError, LookupError): | |
511 | pass |
|
514 | pass | |
512 |
|
515 | |||
513 | # lookup bookmarks through the name interface |
|
516 | # lookup bookmarks through the name interface | |
514 | try: |
|
517 | try: | |
515 | self._node = repo.names.singlenode(repo, changeid) |
|
518 | self._node = repo.names.singlenode(repo, changeid) | |
516 | self._rev = repo.changelog.rev(self._node) |
|
519 | self._rev = repo.changelog.rev(self._node) | |
517 | return |
|
520 | return | |
518 | except KeyError: |
|
521 | except KeyError: | |
519 | pass |
|
522 | pass | |
520 | except error.FilteredRepoLookupError: |
|
523 | except error.FilteredRepoLookupError: | |
521 | raise |
|
524 | raise | |
522 | except error.RepoLookupError: |
|
525 | except error.RepoLookupError: | |
523 | pass |
|
526 | pass | |
524 |
|
527 | |||
525 | self._node = repo.unfiltered().changelog._partialmatch(changeid) |
|
528 | self._node = repo.unfiltered().changelog._partialmatch(changeid) | |
526 | if self._node is not None: |
|
529 | if self._node is not None: | |
527 | self._rev = repo.changelog.rev(self._node) |
|
530 | self._rev = repo.changelog.rev(self._node) | |
528 | return |
|
531 | return | |
529 |
|
532 | |||
530 | # lookup failed |
|
533 | # lookup failed | |
531 | # check if it might have come from damaged dirstate |
|
534 | # check if it might have come from damaged dirstate | |
532 | # |
|
535 | # | |
533 | # XXX we could avoid the unfiltered if we had a recognizable |
|
536 | # XXX we could avoid the unfiltered if we had a recognizable | |
534 | # exception for filtered changeset access |
|
537 | # exception for filtered changeset access | |
535 | if changeid in repo.unfiltered().dirstate.parents(): |
|
538 | if changeid in repo.unfiltered().dirstate.parents(): | |
536 | msg = _("working directory has unknown parent '%s'!") |
|
539 | msg = _("working directory has unknown parent '%s'!") | |
537 | raise error.Abort(msg % short(changeid)) |
|
540 | raise error.Abort(msg % short(changeid)) | |
538 | try: |
|
541 | try: | |
539 | if len(changeid) == 20 and nonascii(changeid): |
|
542 | if len(changeid) == 20 and nonascii(changeid): | |
540 | changeid = hex(changeid) |
|
543 | changeid = hex(changeid) | |
541 | except TypeError: |
|
544 | except TypeError: | |
542 | pass |
|
545 | pass | |
543 | except (error.FilteredIndexError, error.FilteredLookupError, |
|
546 | except (error.FilteredIndexError, error.FilteredLookupError, | |
544 | error.FilteredRepoLookupError): |
|
547 | error.FilteredRepoLookupError): | |
545 | raise _filterederror(repo, changeid) |
|
548 | raise _filterederror(repo, changeid) | |
546 | except IndexError: |
|
549 | except IndexError: | |
547 | pass |
|
550 | pass | |
548 | raise error.RepoLookupError( |
|
551 | raise error.RepoLookupError( | |
549 | _("unknown revision '%s'") % changeid) |
|
552 | _("unknown revision '%s'") % changeid) | |
550 |
|
553 | |||
551 | def __hash__(self): |
|
554 | def __hash__(self): | |
552 | try: |
|
555 | try: | |
553 | return hash(self._rev) |
|
556 | return hash(self._rev) | |
554 | except AttributeError: |
|
557 | except AttributeError: | |
555 | return id(self) |
|
558 | return id(self) | |
556 |
|
559 | |||
557 | def __nonzero__(self): |
|
560 | def __nonzero__(self): | |
558 | return self._rev != nullrev |
|
561 | return self._rev != nullrev | |
559 |
|
562 | |||
560 | __bool__ = __nonzero__ |
|
563 | __bool__ = __nonzero__ | |
561 |
|
564 | |||
562 | @propertycache |
|
565 | @propertycache | |
563 | def _changeset(self): |
|
566 | def _changeset(self): | |
564 | return self._repo.changelog.changelogrevision(self.rev()) |
|
567 | return self._repo.changelog.changelogrevision(self.rev()) | |
565 |
|
568 | |||
566 | @propertycache |
|
569 | @propertycache | |
567 | def _manifest(self): |
|
570 | def _manifest(self): | |
568 | return self._manifestctx.read() |
|
571 | return self._manifestctx.read() | |
569 |
|
572 | |||
570 | @property |
|
573 | @property | |
571 | def _manifestctx(self): |
|
574 | def _manifestctx(self): | |
572 | return self._repo.manifestlog[self._changeset.manifest] |
|
575 | return self._repo.manifestlog[self._changeset.manifest] | |
573 |
|
576 | |||
574 | @propertycache |
|
577 | @propertycache | |
575 | def _manifestdelta(self): |
|
578 | def _manifestdelta(self): | |
576 | return self._manifestctx.readdelta() |
|
579 | return self._manifestctx.readdelta() | |
577 |
|
580 | |||
578 | @propertycache |
|
581 | @propertycache | |
579 | def _parents(self): |
|
582 | def _parents(self): | |
580 | repo = self._repo |
|
583 | repo = self._repo | |
581 | p1, p2 = repo.changelog.parentrevs(self._rev) |
|
584 | p1, p2 = repo.changelog.parentrevs(self._rev) | |
582 | if p2 == nullrev: |
|
585 | if p2 == nullrev: | |
583 | return [changectx(repo, p1)] |
|
586 | return [changectx(repo, p1)] | |
584 | return [changectx(repo, p1), changectx(repo, p2)] |
|
587 | return [changectx(repo, p1), changectx(repo, p2)] | |
585 |
|
588 | |||
586 | def changeset(self): |
|
589 | def changeset(self): | |
587 | c = self._changeset |
|
590 | c = self._changeset | |
588 | return ( |
|
591 | return ( | |
589 | c.manifest, |
|
592 | c.manifest, | |
590 | c.user, |
|
593 | c.user, | |
591 | c.date, |
|
594 | c.date, | |
592 | c.files, |
|
595 | c.files, | |
593 | c.description, |
|
596 | c.description, | |
594 | c.extra, |
|
597 | c.extra, | |
595 | ) |
|
598 | ) | |
596 | def manifestnode(self): |
|
599 | def manifestnode(self): | |
597 | return self._changeset.manifest |
|
600 | return self._changeset.manifest | |
598 |
|
601 | |||
599 | def user(self): |
|
602 | def user(self): | |
600 | return self._changeset.user |
|
603 | return self._changeset.user | |
601 | def date(self): |
|
604 | def date(self): | |
602 | return self._changeset.date |
|
605 | return self._changeset.date | |
603 | def files(self): |
|
606 | def files(self): | |
604 | return self._changeset.files |
|
607 | return self._changeset.files | |
605 | def description(self): |
|
608 | def description(self): | |
606 | return self._changeset.description |
|
609 | return self._changeset.description | |
607 | def branch(self): |
|
610 | def branch(self): | |
608 | return encoding.tolocal(self._changeset.extra.get("branch")) |
|
611 | return encoding.tolocal(self._changeset.extra.get("branch")) | |
609 | def closesbranch(self): |
|
612 | def closesbranch(self): | |
610 | return 'close' in self._changeset.extra |
|
613 | return 'close' in self._changeset.extra | |
611 | def extra(self): |
|
614 | def extra(self): | |
612 | return self._changeset.extra |
|
615 | return self._changeset.extra | |
613 | def tags(self): |
|
616 | def tags(self): | |
614 | return self._repo.nodetags(self._node) |
|
617 | return self._repo.nodetags(self._node) | |
615 | def bookmarks(self): |
|
618 | def bookmarks(self): | |
616 | return self._repo.nodebookmarks(self._node) |
|
619 | return self._repo.nodebookmarks(self._node) | |
617 | def phase(self): |
|
620 | def phase(self): | |
618 | return self._repo._phasecache.phase(self._repo, self._rev) |
|
621 | return self._repo._phasecache.phase(self._repo, self._rev) | |
619 | def hidden(self): |
|
622 | def hidden(self): | |
620 | return self._rev in repoview.filterrevs(self._repo, 'visible') |
|
623 | return self._rev in repoview.filterrevs(self._repo, 'visible') | |
621 |
|
624 | |||
622 | def children(self): |
|
625 | def children(self): | |
623 | """return contexts for each child changeset""" |
|
626 | """return contexts for each child changeset""" | |
624 | c = self._repo.changelog.children(self._node) |
|
627 | c = self._repo.changelog.children(self._node) | |
625 | return [changectx(self._repo, x) for x in c] |
|
628 | return [changectx(self._repo, x) for x in c] | |
626 |
|
629 | |||
627 | def ancestors(self): |
|
630 | def ancestors(self): | |
628 | for a in self._repo.changelog.ancestors([self._rev]): |
|
631 | for a in self._repo.changelog.ancestors([self._rev]): | |
629 | yield changectx(self._repo, a) |
|
632 | yield changectx(self._repo, a) | |
630 |
|
633 | |||
631 | def descendants(self): |
|
634 | def descendants(self): | |
632 | for d in self._repo.changelog.descendants([self._rev]): |
|
635 | for d in self._repo.changelog.descendants([self._rev]): | |
633 | yield changectx(self._repo, d) |
|
636 | yield changectx(self._repo, d) | |
634 |
|
637 | |||
635 | def filectx(self, path, fileid=None, filelog=None): |
|
638 | def filectx(self, path, fileid=None, filelog=None): | |
636 | """get a file context from this changeset""" |
|
639 | """get a file context from this changeset""" | |
637 | if fileid is None: |
|
640 | if fileid is None: | |
638 | fileid = self.filenode(path) |
|
641 | fileid = self.filenode(path) | |
639 | return filectx(self._repo, path, fileid=fileid, |
|
642 | return filectx(self._repo, path, fileid=fileid, | |
640 | changectx=self, filelog=filelog) |
|
643 | changectx=self, filelog=filelog) | |
641 |
|
644 | |||
642 | def ancestor(self, c2, warn=False): |
|
645 | def ancestor(self, c2, warn=False): | |
643 | """return the "best" ancestor context of self and c2 |
|
646 | """return the "best" ancestor context of self and c2 | |
644 |
|
647 | |||
645 | If there are multiple candidates, it will show a message and check |
|
648 | If there are multiple candidates, it will show a message and check | |
646 | merge.preferancestor configuration before falling back to the |
|
649 | merge.preferancestor configuration before falling back to the | |
647 | revlog ancestor.""" |
|
650 | revlog ancestor.""" | |
648 | # deal with workingctxs |
|
651 | # deal with workingctxs | |
649 | n2 = c2._node |
|
652 | n2 = c2._node | |
650 | if n2 is None: |
|
653 | if n2 is None: | |
651 | n2 = c2._parents[0]._node |
|
654 | n2 = c2._parents[0]._node | |
652 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) |
|
655 | cahs = self._repo.changelog.commonancestorsheads(self._node, n2) | |
653 | if not cahs: |
|
656 | if not cahs: | |
654 | anc = nullid |
|
657 | anc = nullid | |
655 | elif len(cahs) == 1: |
|
658 | elif len(cahs) == 1: | |
656 | anc = cahs[0] |
|
659 | anc = cahs[0] | |
657 | else: |
|
660 | else: | |
658 | # experimental config: merge.preferancestor |
|
661 | # experimental config: merge.preferancestor | |
659 | for r in self._repo.ui.configlist('merge', 'preferancestor', ['*']): |
|
662 | for r in self._repo.ui.configlist('merge', 'preferancestor', ['*']): | |
660 | try: |
|
663 | try: | |
661 | ctx = changectx(self._repo, r) |
|
664 | ctx = changectx(self._repo, r) | |
662 | except error.RepoLookupError: |
|
665 | except error.RepoLookupError: | |
663 | continue |
|
666 | continue | |
664 | anc = ctx.node() |
|
667 | anc = ctx.node() | |
665 | if anc in cahs: |
|
668 | if anc in cahs: | |
666 | break |
|
669 | break | |
667 | else: |
|
670 | else: | |
668 | anc = self._repo.changelog.ancestor(self._node, n2) |
|
671 | anc = self._repo.changelog.ancestor(self._node, n2) | |
669 | if warn: |
|
672 | if warn: | |
670 | self._repo.ui.status( |
|
673 | self._repo.ui.status( | |
671 | (_("note: using %s as ancestor of %s and %s\n") % |
|
674 | (_("note: using %s as ancestor of %s and %s\n") % | |
672 | (short(anc), short(self._node), short(n2))) + |
|
675 | (short(anc), short(self._node), short(n2))) + | |
673 | ''.join(_(" alternatively, use --config " |
|
676 | ''.join(_(" alternatively, use --config " | |
674 | "merge.preferancestor=%s\n") % |
|
677 | "merge.preferancestor=%s\n") % | |
675 | short(n) for n in sorted(cahs) if n != anc)) |
|
678 | short(n) for n in sorted(cahs) if n != anc)) | |
676 | return changectx(self._repo, anc) |
|
679 | return changectx(self._repo, anc) | |
677 |
|
680 | |||
678 | def descendant(self, other): |
|
681 | def descendant(self, other): | |
679 | """True if other is descendant of this changeset""" |
|
682 | """True if other is descendant of this changeset""" | |
680 | return self._repo.changelog.descendant(self._rev, other._rev) |
|
683 | return self._repo.changelog.descendant(self._rev, other._rev) | |
681 |
|
684 | |||
682 | def walk(self, match): |
|
685 | def walk(self, match): | |
683 | '''Generates matching file names.''' |
|
686 | '''Generates matching file names.''' | |
684 |
|
687 | |||
685 | # Wrap match.bad method to have message with nodeid |
|
688 | # Wrap match.bad method to have message with nodeid | |
686 | def bad(fn, msg): |
|
689 | def bad(fn, msg): | |
687 | # The manifest doesn't know about subrepos, so don't complain about |
|
690 | # The manifest doesn't know about subrepos, so don't complain about | |
688 | # paths into valid subrepos. |
|
691 | # paths into valid subrepos. | |
689 | if any(fn == s or fn.startswith(s + '/') |
|
692 | if any(fn == s or fn.startswith(s + '/') | |
690 | for s in self.substate): |
|
693 | for s in self.substate): | |
691 | return |
|
694 | return | |
692 | match.bad(fn, _('no such file in rev %s') % self) |
|
695 | match.bad(fn, _('no such file in rev %s') % self) | |
693 |
|
696 | |||
694 | m = matchmod.badmatch(match, bad) |
|
697 | m = matchmod.badmatch(match, bad) | |
695 | return self._manifest.walk(m) |
|
698 | return self._manifest.walk(m) | |
696 |
|
699 | |||
697 | def matches(self, match): |
|
700 | def matches(self, match): | |
698 | return self.walk(match) |
|
701 | return self.walk(match) | |
699 |
|
702 | |||
700 | class basefilectx(object): |
|
703 | class basefilectx(object): | |
701 | """A filecontext object represents the common logic for its children: |
|
704 | """A filecontext object represents the common logic for its children: | |
702 | filectx: read-only access to a filerevision that is already present |
|
705 | filectx: read-only access to a filerevision that is already present | |
703 | in the repo, |
|
706 | in the repo, | |
704 | workingfilectx: a filecontext that represents files from the working |
|
707 | workingfilectx: a filecontext that represents files from the working | |
705 | directory, |
|
708 | directory, | |
706 | memfilectx: a filecontext that represents files in-memory, |
|
709 | memfilectx: a filecontext that represents files in-memory, | |
707 | overlayfilectx: duplicate another filecontext with some fields overridden. |
|
710 | overlayfilectx: duplicate another filecontext with some fields overridden. | |
708 | """ |
|
711 | """ | |
709 | @propertycache |
|
712 | @propertycache | |
710 | def _filelog(self): |
|
713 | def _filelog(self): | |
711 | return self._repo.file(self._path) |
|
714 | return self._repo.file(self._path) | |
712 |
|
715 | |||
713 | @propertycache |
|
716 | @propertycache | |
714 | def _changeid(self): |
|
717 | def _changeid(self): | |
715 | if r'_changeid' in self.__dict__: |
|
718 | if r'_changeid' in self.__dict__: | |
716 | return self._changeid |
|
719 | return self._changeid | |
717 | elif r'_changectx' in self.__dict__: |
|
720 | elif r'_changectx' in self.__dict__: | |
718 | return self._changectx.rev() |
|
721 | return self._changectx.rev() | |
719 | elif r'_descendantrev' in self.__dict__: |
|
722 | elif r'_descendantrev' in self.__dict__: | |
720 | # this file context was created from a revision with a known |
|
723 | # this file context was created from a revision with a known | |
721 | # descendant, we can (lazily) correct for linkrev aliases |
|
724 | # descendant, we can (lazily) correct for linkrev aliases | |
722 | return self._adjustlinkrev(self._descendantrev) |
|
725 | return self._adjustlinkrev(self._descendantrev) | |
723 | else: |
|
726 | else: | |
724 | return self._filelog.linkrev(self._filerev) |
|
727 | return self._filelog.linkrev(self._filerev) | |
725 |
|
728 | |||
726 | @propertycache |
|
729 | @propertycache | |
727 | def _filenode(self): |
|
730 | def _filenode(self): | |
728 | if r'_fileid' in self.__dict__: |
|
731 | if r'_fileid' in self.__dict__: | |
729 | return self._filelog.lookup(self._fileid) |
|
732 | return self._filelog.lookup(self._fileid) | |
730 | else: |
|
733 | else: | |
731 | return self._changectx.filenode(self._path) |
|
734 | return self._changectx.filenode(self._path) | |
732 |
|
735 | |||
733 | @propertycache |
|
736 | @propertycache | |
734 | def _filerev(self): |
|
737 | def _filerev(self): | |
735 | return self._filelog.rev(self._filenode) |
|
738 | return self._filelog.rev(self._filenode) | |
736 |
|
739 | |||
737 | @propertycache |
|
740 | @propertycache | |
738 | def _repopath(self): |
|
741 | def _repopath(self): | |
739 | return self._path |
|
742 | return self._path | |
740 |
|
743 | |||
741 | def __nonzero__(self): |
|
744 | def __nonzero__(self): | |
742 | try: |
|
745 | try: | |
743 | self._filenode |
|
746 | self._filenode | |
744 | return True |
|
747 | return True | |
745 | except error.LookupError: |
|
748 | except error.LookupError: | |
746 | # file is missing |
|
749 | # file is missing | |
747 | return False |
|
750 | return False | |
748 |
|
751 | |||
749 | __bool__ = __nonzero__ |
|
752 | __bool__ = __nonzero__ | |
750 |
|
753 | |||
751 | def __bytes__(self): |
|
754 | def __bytes__(self): | |
752 | try: |
|
755 | try: | |
753 | return "%s@%s" % (self.path(), self._changectx) |
|
756 | return "%s@%s" % (self.path(), self._changectx) | |
754 | except error.LookupError: |
|
757 | except error.LookupError: | |
755 | return "%s@???" % self.path() |
|
758 | return "%s@???" % self.path() | |
756 |
|
759 | |||
757 | __str__ = encoding.strmethod(__bytes__) |
|
760 | __str__ = encoding.strmethod(__bytes__) | |
758 |
|
761 | |||
759 | def __repr__(self): |
|
762 | def __repr__(self): | |
760 | return "<%s %s>" % (type(self).__name__, str(self)) |
|
763 | return "<%s %s>" % (type(self).__name__, str(self)) | |
761 |
|
764 | |||
762 | def __hash__(self): |
|
765 | def __hash__(self): | |
763 | try: |
|
766 | try: | |
764 | return hash((self._path, self._filenode)) |
|
767 | return hash((self._path, self._filenode)) | |
765 | except AttributeError: |
|
768 | except AttributeError: | |
766 | return id(self) |
|
769 | return id(self) | |
767 |
|
770 | |||
768 | def __eq__(self, other): |
|
771 | def __eq__(self, other): | |
769 | try: |
|
772 | try: | |
770 | return (type(self) == type(other) and self._path == other._path |
|
773 | return (type(self) == type(other) and self._path == other._path | |
771 | and self._filenode == other._filenode) |
|
774 | and self._filenode == other._filenode) | |
772 | except AttributeError: |
|
775 | except AttributeError: | |
773 | return False |
|
776 | return False | |
774 |
|
777 | |||
775 | def __ne__(self, other): |
|
778 | def __ne__(self, other): | |
776 | return not (self == other) |
|
779 | return not (self == other) | |
777 |
|
780 | |||
778 | def filerev(self): |
|
781 | def filerev(self): | |
779 | return self._filerev |
|
782 | return self._filerev | |
780 | def filenode(self): |
|
783 | def filenode(self): | |
781 | return self._filenode |
|
784 | return self._filenode | |
782 | @propertycache |
|
785 | @propertycache | |
783 | def _flags(self): |
|
786 | def _flags(self): | |
784 | return self._changectx.flags(self._path) |
|
787 | return self._changectx.flags(self._path) | |
785 | def flags(self): |
|
788 | def flags(self): | |
786 | return self._flags |
|
789 | return self._flags | |
787 | def filelog(self): |
|
790 | def filelog(self): | |
788 | return self._filelog |
|
791 | return self._filelog | |
789 | def rev(self): |
|
792 | def rev(self): | |
790 | return self._changeid |
|
793 | return self._changeid | |
791 | def linkrev(self): |
|
794 | def linkrev(self): | |
792 | return self._filelog.linkrev(self._filerev) |
|
795 | return self._filelog.linkrev(self._filerev) | |
793 | def node(self): |
|
796 | def node(self): | |
794 | return self._changectx.node() |
|
797 | return self._changectx.node() | |
795 | def hex(self): |
|
798 | def hex(self): | |
796 | return self._changectx.hex() |
|
799 | return self._changectx.hex() | |
797 | def user(self): |
|
800 | def user(self): | |
798 | return self._changectx.user() |
|
801 | return self._changectx.user() | |
799 | def date(self): |
|
802 | def date(self): | |
800 | return self._changectx.date() |
|
803 | return self._changectx.date() | |
801 | def files(self): |
|
804 | def files(self): | |
802 | return self._changectx.files() |
|
805 | return self._changectx.files() | |
803 | def description(self): |
|
806 | def description(self): | |
804 | return self._changectx.description() |
|
807 | return self._changectx.description() | |
805 | def branch(self): |
|
808 | def branch(self): | |
806 | return self._changectx.branch() |
|
809 | return self._changectx.branch() | |
807 | def extra(self): |
|
810 | def extra(self): | |
808 | return self._changectx.extra() |
|
811 | return self._changectx.extra() | |
809 | def phase(self): |
|
812 | def phase(self): | |
810 | return self._changectx.phase() |
|
813 | return self._changectx.phase() | |
811 | def phasestr(self): |
|
814 | def phasestr(self): | |
812 | return self._changectx.phasestr() |
|
815 | return self._changectx.phasestr() | |
813 | def manifest(self): |
|
816 | def manifest(self): | |
814 | return self._changectx.manifest() |
|
817 | return self._changectx.manifest() | |
815 | def changectx(self): |
|
818 | def changectx(self): | |
816 | return self._changectx |
|
819 | return self._changectx | |
817 | def renamed(self): |
|
820 | def renamed(self): | |
818 | return self._copied |
|
821 | return self._copied | |
819 | def repo(self): |
|
822 | def repo(self): | |
820 | return self._repo |
|
823 | return self._repo | |
821 | def size(self): |
|
824 | def size(self): | |
822 | return len(self.data()) |
|
825 | return len(self.data()) | |
823 |
|
826 | |||
824 | def path(self): |
|
827 | def path(self): | |
825 | return self._path |
|
828 | return self._path | |
826 |
|
829 | |||
827 | def isbinary(self): |
|
830 | def isbinary(self): | |
828 | try: |
|
831 | try: | |
829 | return util.binary(self.data()) |
|
832 | return util.binary(self.data()) | |
830 | except IOError: |
|
833 | except IOError: | |
831 | return False |
|
834 | return False | |
832 | def isexec(self): |
|
835 | def isexec(self): | |
833 | return 'x' in self.flags() |
|
836 | return 'x' in self.flags() | |
834 | def islink(self): |
|
837 | def islink(self): | |
835 | return 'l' in self.flags() |
|
838 | return 'l' in self.flags() | |
836 |
|
839 | |||
837 | def isabsent(self): |
|
840 | def isabsent(self): | |
838 | """whether this filectx represents a file not in self._changectx |
|
841 | """whether this filectx represents a file not in self._changectx | |
839 |
|
842 | |||
840 | This is mainly for merge code to detect change/delete conflicts. This is |
|
843 | This is mainly for merge code to detect change/delete conflicts. This is | |
841 | expected to be True for all subclasses of basectx.""" |
|
844 | expected to be True for all subclasses of basectx.""" | |
842 | return False |
|
845 | return False | |
843 |
|
846 | |||
844 | _customcmp = False |
|
847 | _customcmp = False | |
845 | def cmp(self, fctx): |
|
848 | def cmp(self, fctx): | |
846 | """compare with other file context |
|
849 | """compare with other file context | |
847 |
|
850 | |||
848 | returns True if different than fctx. |
|
851 | returns True if different than fctx. | |
849 | """ |
|
852 | """ | |
850 | if fctx._customcmp: |
|
853 | if fctx._customcmp: | |
851 | return fctx.cmp(self) |
|
854 | return fctx.cmp(self) | |
852 |
|
855 | |||
853 | if (fctx._filenode is None |
|
856 | if (fctx._filenode is None | |
854 | and (self._repo._encodefilterpats |
|
857 | and (self._repo._encodefilterpats | |
855 | # if file data starts with '\1\n', empty metadata block is |
|
858 | # if file data starts with '\1\n', empty metadata block is | |
856 | # prepended, which adds 4 bytes to filelog.size(). |
|
859 | # prepended, which adds 4 bytes to filelog.size(). | |
857 | or self.size() - 4 == fctx.size()) |
|
860 | or self.size() - 4 == fctx.size()) | |
858 | or self.size() == fctx.size()): |
|
861 | or self.size() == fctx.size()): | |
859 | return self._filelog.cmp(self._filenode, fctx.data()) |
|
862 | return self._filelog.cmp(self._filenode, fctx.data()) | |
860 |
|
863 | |||
861 | return True |
|
864 | return True | |
862 |
|
865 | |||
863 | def _adjustlinkrev(self, srcrev, inclusive=False): |
|
866 | def _adjustlinkrev(self, srcrev, inclusive=False): | |
864 | """return the first ancestor of <srcrev> introducing <fnode> |
|
867 | """return the first ancestor of <srcrev> introducing <fnode> | |
865 |
|
868 | |||
866 | If the linkrev of the file revision does not point to an ancestor of |
|
869 | If the linkrev of the file revision does not point to an ancestor of | |
867 | srcrev, we'll walk down the ancestors until we find one introducing |
|
870 | srcrev, we'll walk down the ancestors until we find one introducing | |
868 | this file revision. |
|
871 | this file revision. | |
869 |
|
872 | |||
870 | :srcrev: the changeset revision we search ancestors from |
|
873 | :srcrev: the changeset revision we search ancestors from | |
871 | :inclusive: if true, the src revision will also be checked |
|
874 | :inclusive: if true, the src revision will also be checked | |
872 | """ |
|
875 | """ | |
873 | repo = self._repo |
|
876 | repo = self._repo | |
874 | cl = repo.unfiltered().changelog |
|
877 | cl = repo.unfiltered().changelog | |
875 | mfl = repo.manifestlog |
|
878 | mfl = repo.manifestlog | |
876 | # fetch the linkrev |
|
879 | # fetch the linkrev | |
877 | lkr = self.linkrev() |
|
880 | lkr = self.linkrev() | |
878 | # hack to reuse ancestor computation when searching for renames |
|
881 | # hack to reuse ancestor computation when searching for renames | |
879 | memberanc = getattr(self, '_ancestrycontext', None) |
|
882 | memberanc = getattr(self, '_ancestrycontext', None) | |
880 | iteranc = None |
|
883 | iteranc = None | |
881 | if srcrev is None: |
|
884 | if srcrev is None: | |
882 | # wctx case, used by workingfilectx during mergecopy |
|
885 | # wctx case, used by workingfilectx during mergecopy | |
883 | revs = [p.rev() for p in self._repo[None].parents()] |
|
886 | revs = [p.rev() for p in self._repo[None].parents()] | |
884 | inclusive = True # we skipped the real (revless) source |
|
887 | inclusive = True # we skipped the real (revless) source | |
885 | else: |
|
888 | else: | |
886 | revs = [srcrev] |
|
889 | revs = [srcrev] | |
887 | if memberanc is None: |
|
890 | if memberanc is None: | |
888 | memberanc = iteranc = cl.ancestors(revs, lkr, |
|
891 | memberanc = iteranc = cl.ancestors(revs, lkr, | |
889 | inclusive=inclusive) |
|
892 | inclusive=inclusive) | |
890 | # check if this linkrev is an ancestor of srcrev |
|
893 | # check if this linkrev is an ancestor of srcrev | |
891 | if lkr not in memberanc: |
|
894 | if lkr not in memberanc: | |
892 | if iteranc is None: |
|
895 | if iteranc is None: | |
893 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) |
|
896 | iteranc = cl.ancestors(revs, lkr, inclusive=inclusive) | |
894 | fnode = self._filenode |
|
897 | fnode = self._filenode | |
895 | path = self._path |
|
898 | path = self._path | |
896 | for a in iteranc: |
|
899 | for a in iteranc: | |
897 | ac = cl.read(a) # get changeset data (we avoid object creation) |
|
900 | ac = cl.read(a) # get changeset data (we avoid object creation) | |
898 | if path in ac[3]: # checking the 'files' field. |
|
901 | if path in ac[3]: # checking the 'files' field. | |
899 | # The file has been touched, check if the content is |
|
902 | # The file has been touched, check if the content is | |
900 | # similar to the one we search for. |
|
903 | # similar to the one we search for. | |
901 | if fnode == mfl[ac[0]].readfast().get(path): |
|
904 | if fnode == mfl[ac[0]].readfast().get(path): | |
902 | return a |
|
905 | return a | |
903 | # In theory, we should never get out of that loop without a result. |
|
906 | # In theory, we should never get out of that loop without a result. | |
904 | # But if manifest uses a buggy file revision (not children of the |
|
907 | # But if manifest uses a buggy file revision (not children of the | |
905 | # one it replaces) we could. Such a buggy situation will likely |
|
908 | # one it replaces) we could. Such a buggy situation will likely | |
906 | # result is crash somewhere else at to some point. |
|
909 | # result is crash somewhere else at to some point. | |
907 | return lkr |
|
910 | return lkr | |
908 |
|
911 | |||
909 | def introrev(self): |
|
912 | def introrev(self): | |
910 | """return the rev of the changeset which introduced this file revision |
|
913 | """return the rev of the changeset which introduced this file revision | |
911 |
|
914 | |||
912 | This method is different from linkrev because it take into account the |
|
915 | This method is different from linkrev because it take into account the | |
913 | changeset the filectx was created from. It ensures the returned |
|
916 | changeset the filectx was created from. It ensures the returned | |
914 | revision is one of its ancestors. This prevents bugs from |
|
917 | revision is one of its ancestors. This prevents bugs from | |
915 | 'linkrev-shadowing' when a file revision is used by multiple |
|
918 | 'linkrev-shadowing' when a file revision is used by multiple | |
916 | changesets. |
|
919 | changesets. | |
917 | """ |
|
920 | """ | |
918 | lkr = self.linkrev() |
|
921 | lkr = self.linkrev() | |
919 | attrs = vars(self) |
|
922 | attrs = vars(self) | |
920 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) |
|
923 | noctx = not ('_changeid' in attrs or '_changectx' in attrs) | |
921 | if noctx or self.rev() == lkr: |
|
924 | if noctx or self.rev() == lkr: | |
922 | return self.linkrev() |
|
925 | return self.linkrev() | |
923 | return self._adjustlinkrev(self.rev(), inclusive=True) |
|
926 | return self._adjustlinkrev(self.rev(), inclusive=True) | |
924 |
|
927 | |||
925 | def _parentfilectx(self, path, fileid, filelog): |
|
928 | def _parentfilectx(self, path, fileid, filelog): | |
926 | """create parent filectx keeping ancestry info for _adjustlinkrev()""" |
|
929 | """create parent filectx keeping ancestry info for _adjustlinkrev()""" | |
927 | fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) |
|
930 | fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) | |
928 | if '_changeid' in vars(self) or '_changectx' in vars(self): |
|
931 | if '_changeid' in vars(self) or '_changectx' in vars(self): | |
929 | # If self is associated with a changeset (probably explicitly |
|
932 | # If self is associated with a changeset (probably explicitly | |
930 | # fed), ensure the created filectx is associated with a |
|
933 | # fed), ensure the created filectx is associated with a | |
931 | # changeset that is an ancestor of self.changectx. |
|
934 | # changeset that is an ancestor of self.changectx. | |
932 | # This lets us later use _adjustlinkrev to get a correct link. |
|
935 | # This lets us later use _adjustlinkrev to get a correct link. | |
933 | fctx._descendantrev = self.rev() |
|
936 | fctx._descendantrev = self.rev() | |
934 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
937 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
935 | elif '_descendantrev' in vars(self): |
|
938 | elif '_descendantrev' in vars(self): | |
936 | # Otherwise propagate _descendantrev if we have one associated. |
|
939 | # Otherwise propagate _descendantrev if we have one associated. | |
937 | fctx._descendantrev = self._descendantrev |
|
940 | fctx._descendantrev = self._descendantrev | |
938 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) |
|
941 | fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) | |
939 | return fctx |
|
942 | return fctx | |
940 |
|
943 | |||
941 | def parents(self): |
|
944 | def parents(self): | |
942 | _path = self._path |
|
945 | _path = self._path | |
943 | fl = self._filelog |
|
946 | fl = self._filelog | |
944 | parents = self._filelog.parents(self._filenode) |
|
947 | parents = self._filelog.parents(self._filenode) | |
945 | pl = [(_path, node, fl) for node in parents if node != nullid] |
|
948 | pl = [(_path, node, fl) for node in parents if node != nullid] | |
946 |
|
949 | |||
947 | r = fl.renamed(self._filenode) |
|
950 | r = fl.renamed(self._filenode) | |
948 | if r: |
|
951 | if r: | |
949 | # - In the simple rename case, both parent are nullid, pl is empty. |
|
952 | # - In the simple rename case, both parent are nullid, pl is empty. | |
950 | # - In case of merge, only one of the parent is null id and should |
|
953 | # - In case of merge, only one of the parent is null id and should | |
951 | # be replaced with the rename information. This parent is -always- |
|
954 | # be replaced with the rename information. This parent is -always- | |
952 | # the first one. |
|
955 | # the first one. | |
953 | # |
|
956 | # | |
954 | # As null id have always been filtered out in the previous list |
|
957 | # As null id have always been filtered out in the previous list | |
955 | # comprehension, inserting to 0 will always result in "replacing |
|
958 | # comprehension, inserting to 0 will always result in "replacing | |
956 | # first nullid parent with rename information. |
|
959 | # first nullid parent with rename information. | |
957 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) |
|
960 | pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) | |
958 |
|
961 | |||
959 | return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] |
|
962 | return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] | |
960 |
|
963 | |||
961 | def p1(self): |
|
964 | def p1(self): | |
962 | return self.parents()[0] |
|
965 | return self.parents()[0] | |
963 |
|
966 | |||
964 | def p2(self): |
|
967 | def p2(self): | |
965 | p = self.parents() |
|
968 | p = self.parents() | |
966 | if len(p) == 2: |
|
969 | if len(p) == 2: | |
967 | return p[1] |
|
970 | return p[1] | |
968 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) |
|
971 | return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog) | |
969 |
|
972 | |||
970 | def annotate(self, follow=False, linenumber=False, skiprevs=None, |
|
973 | def annotate(self, follow=False, linenumber=False, skiprevs=None, | |
971 | diffopts=None): |
|
974 | diffopts=None): | |
972 | '''returns a list of tuples of ((ctx, number), line) for each line |
|
975 | '''returns a list of tuples of ((ctx, number), line) for each line | |
973 | in the file, where ctx is the filectx of the node where |
|
976 | in the file, where ctx is the filectx of the node where | |
974 | that line was last changed; if linenumber parameter is true, number is |
|
977 | that line was last changed; if linenumber parameter is true, number is | |
975 | the line number at the first appearance in the managed file, otherwise, |
|
978 | the line number at the first appearance in the managed file, otherwise, | |
976 | number has a fixed value of False. |
|
979 | number has a fixed value of False. | |
977 | ''' |
|
980 | ''' | |
978 |
|
981 | |||
979 | def lines(text): |
|
982 | def lines(text): | |
980 | if text.endswith("\n"): |
|
983 | if text.endswith("\n"): | |
981 | return text.count("\n") |
|
984 | return text.count("\n") | |
982 | return text.count("\n") + int(bool(text)) |
|
985 | return text.count("\n") + int(bool(text)) | |
983 |
|
986 | |||
984 | if linenumber: |
|
987 | if linenumber: | |
985 | def decorate(text, rev): |
|
988 | def decorate(text, rev): | |
986 | return ([(rev, i) for i in xrange(1, lines(text) + 1)], text) |
|
989 | return ([annotateline(fctx=rev, lineno=i) | |
|
990 | for i in xrange(1, lines(text) + 1)], text) | |||
987 | else: |
|
991 | else: | |
988 | def decorate(text, rev): |
|
992 | def decorate(text, rev): | |
989 |
return ([(rev |
|
993 | return ([annotateline(fctx=rev)] * lines(text), text) | |
990 |
|
994 | |||
991 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
|
995 | getlog = util.lrucachefunc(lambda x: self._repo.file(x)) | |
992 |
|
996 | |||
993 | def parents(f): |
|
997 | def parents(f): | |
994 | # Cut _descendantrev here to mitigate the penalty of lazy linkrev |
|
998 | # Cut _descendantrev here to mitigate the penalty of lazy linkrev | |
995 | # adjustment. Otherwise, p._adjustlinkrev() would walk changelog |
|
999 | # adjustment. Otherwise, p._adjustlinkrev() would walk changelog | |
996 | # from the topmost introrev (= srcrev) down to p.linkrev() if it |
|
1000 | # from the topmost introrev (= srcrev) down to p.linkrev() if it | |
997 | # isn't an ancestor of the srcrev. |
|
1001 | # isn't an ancestor of the srcrev. | |
998 | f._changeid |
|
1002 | f._changeid | |
999 | pl = f.parents() |
|
1003 | pl = f.parents() | |
1000 |
|
1004 | |||
1001 | # Don't return renamed parents if we aren't following. |
|
1005 | # Don't return renamed parents if we aren't following. | |
1002 | if not follow: |
|
1006 | if not follow: | |
1003 | pl = [p for p in pl if p.path() == f.path()] |
|
1007 | pl = [p for p in pl if p.path() == f.path()] | |
1004 |
|
1008 | |||
1005 | # renamed filectx won't have a filelog yet, so set it |
|
1009 | # renamed filectx won't have a filelog yet, so set it | |
1006 | # from the cache to save time |
|
1010 | # from the cache to save time | |
1007 | for p in pl: |
|
1011 | for p in pl: | |
1008 | if not '_filelog' in p.__dict__: |
|
1012 | if not '_filelog' in p.__dict__: | |
1009 | p._filelog = getlog(p.path()) |
|
1013 | p._filelog = getlog(p.path()) | |
1010 |
|
1014 | |||
1011 | return pl |
|
1015 | return pl | |
1012 |
|
1016 | |||
1013 | # use linkrev to find the first changeset where self appeared |
|
1017 | # use linkrev to find the first changeset where self appeared | |
1014 | base = self |
|
1018 | base = self | |
1015 | introrev = self.introrev() |
|
1019 | introrev = self.introrev() | |
1016 | if self.rev() != introrev: |
|
1020 | if self.rev() != introrev: | |
1017 | base = self.filectx(self.filenode(), changeid=introrev) |
|
1021 | base = self.filectx(self.filenode(), changeid=introrev) | |
1018 | if getattr(base, '_ancestrycontext', None) is None: |
|
1022 | if getattr(base, '_ancestrycontext', None) is None: | |
1019 | cl = self._repo.changelog |
|
1023 | cl = self._repo.changelog | |
1020 | if introrev is None: |
|
1024 | if introrev is None: | |
1021 | # wctx is not inclusive, but works because _ancestrycontext |
|
1025 | # wctx is not inclusive, but works because _ancestrycontext | |
1022 | # is used to test filelog revisions |
|
1026 | # is used to test filelog revisions | |
1023 | ac = cl.ancestors([p.rev() for p in base.parents()], |
|
1027 | ac = cl.ancestors([p.rev() for p in base.parents()], | |
1024 | inclusive=True) |
|
1028 | inclusive=True) | |
1025 | else: |
|
1029 | else: | |
1026 | ac = cl.ancestors([introrev], inclusive=True) |
|
1030 | ac = cl.ancestors([introrev], inclusive=True) | |
1027 | base._ancestrycontext = ac |
|
1031 | base._ancestrycontext = ac | |
1028 |
|
1032 | |||
1029 | # This algorithm would prefer to be recursive, but Python is a |
|
1033 | # This algorithm would prefer to be recursive, but Python is a | |
1030 | # bit recursion-hostile. Instead we do an iterative |
|
1034 | # bit recursion-hostile. Instead we do an iterative | |
1031 | # depth-first search. |
|
1035 | # depth-first search. | |
1032 |
|
1036 | |||
1033 | # 1st DFS pre-calculates pcache and needed |
|
1037 | # 1st DFS pre-calculates pcache and needed | |
1034 | visit = [base] |
|
1038 | visit = [base] | |
1035 | pcache = {} |
|
1039 | pcache = {} | |
1036 | needed = {base: 1} |
|
1040 | needed = {base: 1} | |
1037 | while visit: |
|
1041 | while visit: | |
1038 | f = visit.pop() |
|
1042 | f = visit.pop() | |
1039 | if f in pcache: |
|
1043 | if f in pcache: | |
1040 | continue |
|
1044 | continue | |
1041 | pl = parents(f) |
|
1045 | pl = parents(f) | |
1042 | pcache[f] = pl |
|
1046 | pcache[f] = pl | |
1043 | for p in pl: |
|
1047 | for p in pl: | |
1044 | needed[p] = needed.get(p, 0) + 1 |
|
1048 | needed[p] = needed.get(p, 0) + 1 | |
1045 | if p not in pcache: |
|
1049 | if p not in pcache: | |
1046 | visit.append(p) |
|
1050 | visit.append(p) | |
1047 |
|
1051 | |||
1048 | # 2nd DFS does the actual annotate |
|
1052 | # 2nd DFS does the actual annotate | |
1049 | visit[:] = [base] |
|
1053 | visit[:] = [base] | |
1050 | hist = {} |
|
1054 | hist = {} | |
1051 | while visit: |
|
1055 | while visit: | |
1052 | f = visit[-1] |
|
1056 | f = visit[-1] | |
1053 | if f in hist: |
|
1057 | if f in hist: | |
1054 | visit.pop() |
|
1058 | visit.pop() | |
1055 | continue |
|
1059 | continue | |
1056 |
|
1060 | |||
1057 | ready = True |
|
1061 | ready = True | |
1058 | pl = pcache[f] |
|
1062 | pl = pcache[f] | |
1059 | for p in pl: |
|
1063 | for p in pl: | |
1060 | if p not in hist: |
|
1064 | if p not in hist: | |
1061 | ready = False |
|
1065 | ready = False | |
1062 | visit.append(p) |
|
1066 | visit.append(p) | |
1063 | if ready: |
|
1067 | if ready: | |
1064 | visit.pop() |
|
1068 | visit.pop() | |
1065 | curr = decorate(f.data(), f) |
|
1069 | curr = decorate(f.data(), f) | |
1066 | skipchild = False |
|
1070 | skipchild = False | |
1067 | if skiprevs is not None: |
|
1071 | if skiprevs is not None: | |
1068 | skipchild = f._changeid in skiprevs |
|
1072 | skipchild = f._changeid in skiprevs | |
1069 | curr = _annotatepair([hist[p] for p in pl], f, curr, skipchild, |
|
1073 | curr = _annotatepair([hist[p] for p in pl], f, curr, skipchild, | |
1070 | diffopts) |
|
1074 | diffopts) | |
1071 | for p in pl: |
|
1075 | for p in pl: | |
1072 | if needed[p] == 1: |
|
1076 | if needed[p] == 1: | |
1073 | del hist[p] |
|
1077 | del hist[p] | |
1074 | del needed[p] |
|
1078 | del needed[p] | |
1075 | else: |
|
1079 | else: | |
1076 | needed[p] -= 1 |
|
1080 | needed[p] -= 1 | |
1077 |
|
1081 | |||
1078 | hist[f] = curr |
|
1082 | hist[f] = curr | |
1079 | del pcache[f] |
|
1083 | del pcache[f] | |
1080 |
|
1084 | |||
1081 | return zip(hist[base][0], hist[base][1].splitlines(True)) |
|
1085 | return zip(hist[base][0], hist[base][1].splitlines(True)) | |
1082 |
|
1086 | |||
1083 | def ancestors(self, followfirst=False): |
|
1087 | def ancestors(self, followfirst=False): | |
1084 | visit = {} |
|
1088 | visit = {} | |
1085 | c = self |
|
1089 | c = self | |
1086 | if followfirst: |
|
1090 | if followfirst: | |
1087 | cut = 1 |
|
1091 | cut = 1 | |
1088 | else: |
|
1092 | else: | |
1089 | cut = None |
|
1093 | cut = None | |
1090 |
|
1094 | |||
1091 | while True: |
|
1095 | while True: | |
1092 | for parent in c.parents()[:cut]: |
|
1096 | for parent in c.parents()[:cut]: | |
1093 | visit[(parent.linkrev(), parent.filenode())] = parent |
|
1097 | visit[(parent.linkrev(), parent.filenode())] = parent | |
1094 | if not visit: |
|
1098 | if not visit: | |
1095 | break |
|
1099 | break | |
1096 | c = visit.pop(max(visit)) |
|
1100 | c = visit.pop(max(visit)) | |
1097 | yield c |
|
1101 | yield c | |
1098 |
|
1102 | |||
1099 | def decodeddata(self): |
|
1103 | def decodeddata(self): | |
1100 | """Returns `data()` after running repository decoding filters. |
|
1104 | """Returns `data()` after running repository decoding filters. | |
1101 |
|
1105 | |||
1102 | This is often equivalent to how the data would be expressed on disk. |
|
1106 | This is often equivalent to how the data would be expressed on disk. | |
1103 | """ |
|
1107 | """ | |
1104 | return self._repo.wwritedata(self.path(), self.data()) |
|
1108 | return self._repo.wwritedata(self.path(), self.data()) | |
1105 |
|
1109 | |||
|
1110 | @attr.s(slots=True, frozen=True) | |||
|
1111 | class annotateline(object): | |||
|
1112 | fctx = attr.ib() | |||
|
1113 | lineno = attr.ib(default=False) | |||
|
1114 | ||||
1106 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): |
|
1115 | def _annotatepair(parents, childfctx, child, skipchild, diffopts): | |
1107 | r''' |
|
1116 | r''' | |
1108 | Given parent and child fctxes and annotate data for parents, for all lines |
|
1117 | Given parent and child fctxes and annotate data for parents, for all lines | |
1109 | in either parent that match the child, annotate the child with the parent's |
|
1118 | in either parent that match the child, annotate the child with the parent's | |
1110 | data. |
|
1119 | data. | |
1111 |
|
1120 | |||
1112 | Additionally, if `skipchild` is True, replace all other lines with parent |
|
1121 | Additionally, if `skipchild` is True, replace all other lines with parent | |
1113 | annotate data as well such that child is never blamed for any lines. |
|
1122 | annotate data as well such that child is never blamed for any lines. | |
1114 |
|
1123 | |||
1115 | See test-annotate.py for unit tests. |
|
1124 | See test-annotate.py for unit tests. | |
1116 | ''' |
|
1125 | ''' | |
1117 | pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts)) |
|
1126 | pblocks = [(parent, mdiff.allblocks(parent[1], child[1], opts=diffopts)) | |
1118 | for parent in parents] |
|
1127 | for parent in parents] | |
1119 |
|
1128 | |||
1120 | if skipchild: |
|
1129 | if skipchild: | |
1121 | # Need to iterate over the blocks twice -- make it a list |
|
1130 | # Need to iterate over the blocks twice -- make it a list | |
1122 | pblocks = [(p, list(blocks)) for (p, blocks) in pblocks] |
|
1131 | pblocks = [(p, list(blocks)) for (p, blocks) in pblocks] | |
1123 | # Mercurial currently prefers p2 over p1 for annotate. |
|
1132 | # Mercurial currently prefers p2 over p1 for annotate. | |
1124 | # TODO: change this? |
|
1133 | # TODO: change this? | |
1125 | for parent, blocks in pblocks: |
|
1134 | for parent, blocks in pblocks: | |
1126 | for (a1, a2, b1, b2), t in blocks: |
|
1135 | for (a1, a2, b1, b2), t in blocks: | |
1127 | # Changed blocks ('!') or blocks made only of blank lines ('~') |
|
1136 | # Changed blocks ('!') or blocks made only of blank lines ('~') | |
1128 | # belong to the child. |
|
1137 | # belong to the child. | |
1129 | if t == '=': |
|
1138 | if t == '=': | |
1130 | child[0][b1:b2] = parent[0][a1:a2] |
|
1139 | child[0][b1:b2] = parent[0][a1:a2] | |
1131 |
|
1140 | |||
1132 | if skipchild: |
|
1141 | if skipchild: | |
1133 | # Now try and match up anything that couldn't be matched, |
|
1142 | # Now try and match up anything that couldn't be matched, | |
1134 | # Reversing pblocks maintains bias towards p2, matching above |
|
1143 | # Reversing pblocks maintains bias towards p2, matching above | |
1135 | # behavior. |
|
1144 | # behavior. | |
1136 | pblocks.reverse() |
|
1145 | pblocks.reverse() | |
1137 |
|
1146 | |||
1138 | # The heuristics are: |
|
1147 | # The heuristics are: | |
1139 | # * Work on blocks of changed lines (effectively diff hunks with -U0). |
|
1148 | # * Work on blocks of changed lines (effectively diff hunks with -U0). | |
1140 | # This could potentially be smarter but works well enough. |
|
1149 | # This could potentially be smarter but works well enough. | |
1141 | # * For a non-matching section, do a best-effort fit. Match lines in |
|
1150 | # * For a non-matching section, do a best-effort fit. Match lines in | |
1142 | # diff hunks 1:1, dropping lines as necessary. |
|
1151 | # diff hunks 1:1, dropping lines as necessary. | |
1143 | # * Repeat the last line as a last resort. |
|
1152 | # * Repeat the last line as a last resort. | |
1144 |
|
1153 | |||
1145 | # First, replace as much as possible without repeating the last line. |
|
1154 | # First, replace as much as possible without repeating the last line. | |
1146 | remaining = [(parent, []) for parent, _blocks in pblocks] |
|
1155 | remaining = [(parent, []) for parent, _blocks in pblocks] | |
1147 | for idx, (parent, blocks) in enumerate(pblocks): |
|
1156 | for idx, (parent, blocks) in enumerate(pblocks): | |
1148 | for (a1, a2, b1, b2), _t in blocks: |
|
1157 | for (a1, a2, b1, b2), _t in blocks: | |
1149 | if a2 - a1 >= b2 - b1: |
|
1158 | if a2 - a1 >= b2 - b1: | |
1150 | for bk in xrange(b1, b2): |
|
1159 | for bk in xrange(b1, b2): | |
1151 |
if child[0][bk] |
|
1160 | if child[0][bk].fctx == childfctx: | |
1152 | ak = min(a1 + (bk - b1), a2 - 1) |
|
1161 | ak = min(a1 + (bk - b1), a2 - 1) | |
1153 | child[0][bk] = parent[0][ak] |
|
1162 | child[0][bk] = parent[0][ak] | |
1154 | else: |
|
1163 | else: | |
1155 | remaining[idx][1].append((a1, a2, b1, b2)) |
|
1164 | remaining[idx][1].append((a1, a2, b1, b2)) | |
1156 |
|
1165 | |||
1157 | # Then, look at anything left, which might involve repeating the last |
|
1166 | # Then, look at anything left, which might involve repeating the last | |
1158 | # line. |
|
1167 | # line. | |
1159 | for parent, blocks in remaining: |
|
1168 | for parent, blocks in remaining: | |
1160 | for a1, a2, b1, b2 in blocks: |
|
1169 | for a1, a2, b1, b2 in blocks: | |
1161 | for bk in xrange(b1, b2): |
|
1170 | for bk in xrange(b1, b2): | |
1162 |
if child[0][bk] |
|
1171 | if child[0][bk].fctx == childfctx: | |
1163 | ak = min(a1 + (bk - b1), a2 - 1) |
|
1172 | ak = min(a1 + (bk - b1), a2 - 1) | |
1164 | child[0][bk] = parent[0][ak] |
|
1173 | child[0][bk] = parent[0][ak] | |
1165 | return child |
|
1174 | return child | |
1166 |
|
1175 | |||
1167 | class filectx(basefilectx): |
|
1176 | class filectx(basefilectx): | |
1168 | """A filecontext object makes access to data related to a particular |
|
1177 | """A filecontext object makes access to data related to a particular | |
1169 | filerevision convenient.""" |
|
1178 | filerevision convenient.""" | |
1170 | def __init__(self, repo, path, changeid=None, fileid=None, |
|
1179 | def __init__(self, repo, path, changeid=None, fileid=None, | |
1171 | filelog=None, changectx=None): |
|
1180 | filelog=None, changectx=None): | |
1172 | """changeid can be a changeset revision, node, or tag. |
|
1181 | """changeid can be a changeset revision, node, or tag. | |
1173 | fileid can be a file revision or node.""" |
|
1182 | fileid can be a file revision or node.""" | |
1174 | self._repo = repo |
|
1183 | self._repo = repo | |
1175 | self._path = path |
|
1184 | self._path = path | |
1176 |
|
1185 | |||
1177 | assert (changeid is not None |
|
1186 | assert (changeid is not None | |
1178 | or fileid is not None |
|
1187 | or fileid is not None | |
1179 | or changectx is not None), \ |
|
1188 | or changectx is not None), \ | |
1180 | ("bad args: changeid=%r, fileid=%r, changectx=%r" |
|
1189 | ("bad args: changeid=%r, fileid=%r, changectx=%r" | |
1181 | % (changeid, fileid, changectx)) |
|
1190 | % (changeid, fileid, changectx)) | |
1182 |
|
1191 | |||
1183 | if filelog is not None: |
|
1192 | if filelog is not None: | |
1184 | self._filelog = filelog |
|
1193 | self._filelog = filelog | |
1185 |
|
1194 | |||
1186 | if changeid is not None: |
|
1195 | if changeid is not None: | |
1187 | self._changeid = changeid |
|
1196 | self._changeid = changeid | |
1188 | if changectx is not None: |
|
1197 | if changectx is not None: | |
1189 | self._changectx = changectx |
|
1198 | self._changectx = changectx | |
1190 | if fileid is not None: |
|
1199 | if fileid is not None: | |
1191 | self._fileid = fileid |
|
1200 | self._fileid = fileid | |
1192 |
|
1201 | |||
1193 | @propertycache |
|
1202 | @propertycache | |
1194 | def _changectx(self): |
|
1203 | def _changectx(self): | |
1195 | try: |
|
1204 | try: | |
1196 | return changectx(self._repo, self._changeid) |
|
1205 | return changectx(self._repo, self._changeid) | |
1197 | except error.FilteredRepoLookupError: |
|
1206 | except error.FilteredRepoLookupError: | |
1198 | # Linkrev may point to any revision in the repository. When the |
|
1207 | # Linkrev may point to any revision in the repository. When the | |
1199 | # repository is filtered this may lead to `filectx` trying to build |
|
1208 | # repository is filtered this may lead to `filectx` trying to build | |
1200 | # `changectx` for filtered revision. In such case we fallback to |
|
1209 | # `changectx` for filtered revision. In such case we fallback to | |
1201 | # creating `changectx` on the unfiltered version of the reposition. |
|
1210 | # creating `changectx` on the unfiltered version of the reposition. | |
1202 | # This fallback should not be an issue because `changectx` from |
|
1211 | # This fallback should not be an issue because `changectx` from | |
1203 | # `filectx` are not used in complex operations that care about |
|
1212 | # `filectx` are not used in complex operations that care about | |
1204 | # filtering. |
|
1213 | # filtering. | |
1205 | # |
|
1214 | # | |
1206 | # This fallback is a cheap and dirty fix that prevent several |
|
1215 | # This fallback is a cheap and dirty fix that prevent several | |
1207 | # crashes. It does not ensure the behavior is correct. However the |
|
1216 | # crashes. It does not ensure the behavior is correct. However the | |
1208 | # behavior was not correct before filtering either and "incorrect |
|
1217 | # behavior was not correct before filtering either and "incorrect | |
1209 | # behavior" is seen as better as "crash" |
|
1218 | # behavior" is seen as better as "crash" | |
1210 | # |
|
1219 | # | |
1211 | # Linkrevs have several serious troubles with filtering that are |
|
1220 | # Linkrevs have several serious troubles with filtering that are | |
1212 | # complicated to solve. Proper handling of the issue here should be |
|
1221 | # complicated to solve. Proper handling of the issue here should be | |
1213 | # considered when solving linkrev issue are on the table. |
|
1222 | # considered when solving linkrev issue are on the table. | |
1214 | return changectx(self._repo.unfiltered(), self._changeid) |
|
1223 | return changectx(self._repo.unfiltered(), self._changeid) | |
1215 |
|
1224 | |||
1216 | def filectx(self, fileid, changeid=None): |
|
1225 | def filectx(self, fileid, changeid=None): | |
1217 | '''opens an arbitrary revision of the file without |
|
1226 | '''opens an arbitrary revision of the file without | |
1218 | opening a new filelog''' |
|
1227 | opening a new filelog''' | |
1219 | return filectx(self._repo, self._path, fileid=fileid, |
|
1228 | return filectx(self._repo, self._path, fileid=fileid, | |
1220 | filelog=self._filelog, changeid=changeid) |
|
1229 | filelog=self._filelog, changeid=changeid) | |
1221 |
|
1230 | |||
1222 | def rawdata(self): |
|
1231 | def rawdata(self): | |
1223 | return self._filelog.revision(self._filenode, raw=True) |
|
1232 | return self._filelog.revision(self._filenode, raw=True) | |
1224 |
|
1233 | |||
1225 | def rawflags(self): |
|
1234 | def rawflags(self): | |
1226 | """low-level revlog flags""" |
|
1235 | """low-level revlog flags""" | |
1227 | return self._filelog.flags(self._filerev) |
|
1236 | return self._filelog.flags(self._filerev) | |
1228 |
|
1237 | |||
1229 | def data(self): |
|
1238 | def data(self): | |
1230 | try: |
|
1239 | try: | |
1231 | return self._filelog.read(self._filenode) |
|
1240 | return self._filelog.read(self._filenode) | |
1232 | except error.CensoredNodeError: |
|
1241 | except error.CensoredNodeError: | |
1233 | if self._repo.ui.config("censor", "policy") == "ignore": |
|
1242 | if self._repo.ui.config("censor", "policy") == "ignore": | |
1234 | return "" |
|
1243 | return "" | |
1235 | raise error.Abort(_("censored node: %s") % short(self._filenode), |
|
1244 | raise error.Abort(_("censored node: %s") % short(self._filenode), | |
1236 | hint=_("set censor.policy to ignore errors")) |
|
1245 | hint=_("set censor.policy to ignore errors")) | |
1237 |
|
1246 | |||
1238 | def size(self): |
|
1247 | def size(self): | |
1239 | return self._filelog.size(self._filerev) |
|
1248 | return self._filelog.size(self._filerev) | |
1240 |
|
1249 | |||
1241 | @propertycache |
|
1250 | @propertycache | |
1242 | def _copied(self): |
|
1251 | def _copied(self): | |
1243 | """check if file was actually renamed in this changeset revision |
|
1252 | """check if file was actually renamed in this changeset revision | |
1244 |
|
1253 | |||
1245 | If rename logged in file revision, we report copy for changeset only |
|
1254 | If rename logged in file revision, we report copy for changeset only | |
1246 | if file revisions linkrev points back to the changeset in question |
|
1255 | if file revisions linkrev points back to the changeset in question | |
1247 | or both changeset parents contain different file revisions. |
|
1256 | or both changeset parents contain different file revisions. | |
1248 | """ |
|
1257 | """ | |
1249 |
|
1258 | |||
1250 | renamed = self._filelog.renamed(self._filenode) |
|
1259 | renamed = self._filelog.renamed(self._filenode) | |
1251 | if not renamed: |
|
1260 | if not renamed: | |
1252 | return renamed |
|
1261 | return renamed | |
1253 |
|
1262 | |||
1254 | if self.rev() == self.linkrev(): |
|
1263 | if self.rev() == self.linkrev(): | |
1255 | return renamed |
|
1264 | return renamed | |
1256 |
|
1265 | |||
1257 | name = self.path() |
|
1266 | name = self.path() | |
1258 | fnode = self._filenode |
|
1267 | fnode = self._filenode | |
1259 | for p in self._changectx.parents(): |
|
1268 | for p in self._changectx.parents(): | |
1260 | try: |
|
1269 | try: | |
1261 | if fnode == p.filenode(name): |
|
1270 | if fnode == p.filenode(name): | |
1262 | return None |
|
1271 | return None | |
1263 | except error.LookupError: |
|
1272 | except error.LookupError: | |
1264 | pass |
|
1273 | pass | |
1265 | return renamed |
|
1274 | return renamed | |
1266 |
|
1275 | |||
1267 | def children(self): |
|
1276 | def children(self): | |
1268 | # hard for renames |
|
1277 | # hard for renames | |
1269 | c = self._filelog.children(self._filenode) |
|
1278 | c = self._filelog.children(self._filenode) | |
1270 | return [filectx(self._repo, self._path, fileid=x, |
|
1279 | return [filectx(self._repo, self._path, fileid=x, | |
1271 | filelog=self._filelog) for x in c] |
|
1280 | filelog=self._filelog) for x in c] | |
1272 |
|
1281 | |||
1273 | class committablectx(basectx): |
|
1282 | class committablectx(basectx): | |
1274 | """A committablectx object provides common functionality for a context that |
|
1283 | """A committablectx object provides common functionality for a context that | |
1275 | wants the ability to commit, e.g. workingctx or memctx.""" |
|
1284 | wants the ability to commit, e.g. workingctx or memctx.""" | |
1276 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1285 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1277 | changes=None): |
|
1286 | changes=None): | |
1278 | self._repo = repo |
|
1287 | self._repo = repo | |
1279 | self._rev = None |
|
1288 | self._rev = None | |
1280 | self._node = None |
|
1289 | self._node = None | |
1281 | self._text = text |
|
1290 | self._text = text | |
1282 | if date: |
|
1291 | if date: | |
1283 | self._date = util.parsedate(date) |
|
1292 | self._date = util.parsedate(date) | |
1284 | if user: |
|
1293 | if user: | |
1285 | self._user = user |
|
1294 | self._user = user | |
1286 | if changes: |
|
1295 | if changes: | |
1287 | self._status = changes |
|
1296 | self._status = changes | |
1288 |
|
1297 | |||
1289 | self._extra = {} |
|
1298 | self._extra = {} | |
1290 | if extra: |
|
1299 | if extra: | |
1291 | self._extra = extra.copy() |
|
1300 | self._extra = extra.copy() | |
1292 | if 'branch' not in self._extra: |
|
1301 | if 'branch' not in self._extra: | |
1293 | try: |
|
1302 | try: | |
1294 | branch = encoding.fromlocal(self._repo.dirstate.branch()) |
|
1303 | branch = encoding.fromlocal(self._repo.dirstate.branch()) | |
1295 | except UnicodeDecodeError: |
|
1304 | except UnicodeDecodeError: | |
1296 | raise error.Abort(_('branch name not in UTF-8!')) |
|
1305 | raise error.Abort(_('branch name not in UTF-8!')) | |
1297 | self._extra['branch'] = branch |
|
1306 | self._extra['branch'] = branch | |
1298 | if self._extra['branch'] == '': |
|
1307 | if self._extra['branch'] == '': | |
1299 | self._extra['branch'] = 'default' |
|
1308 | self._extra['branch'] = 'default' | |
1300 |
|
1309 | |||
1301 | def __bytes__(self): |
|
1310 | def __bytes__(self): | |
1302 | return bytes(self._parents[0]) + "+" |
|
1311 | return bytes(self._parents[0]) + "+" | |
1303 |
|
1312 | |||
1304 | __str__ = encoding.strmethod(__bytes__) |
|
1313 | __str__ = encoding.strmethod(__bytes__) | |
1305 |
|
1314 | |||
1306 | def __nonzero__(self): |
|
1315 | def __nonzero__(self): | |
1307 | return True |
|
1316 | return True | |
1308 |
|
1317 | |||
1309 | __bool__ = __nonzero__ |
|
1318 | __bool__ = __nonzero__ | |
1310 |
|
1319 | |||
1311 | def _buildflagfunc(self): |
|
1320 | def _buildflagfunc(self): | |
1312 | # Create a fallback function for getting file flags when the |
|
1321 | # Create a fallback function for getting file flags when the | |
1313 | # filesystem doesn't support them |
|
1322 | # filesystem doesn't support them | |
1314 |
|
1323 | |||
1315 | copiesget = self._repo.dirstate.copies().get |
|
1324 | copiesget = self._repo.dirstate.copies().get | |
1316 | parents = self.parents() |
|
1325 | parents = self.parents() | |
1317 | if len(parents) < 2: |
|
1326 | if len(parents) < 2: | |
1318 | # when we have one parent, it's easy: copy from parent |
|
1327 | # when we have one parent, it's easy: copy from parent | |
1319 | man = parents[0].manifest() |
|
1328 | man = parents[0].manifest() | |
1320 | def func(f): |
|
1329 | def func(f): | |
1321 | f = copiesget(f, f) |
|
1330 | f = copiesget(f, f) | |
1322 | return man.flags(f) |
|
1331 | return man.flags(f) | |
1323 | else: |
|
1332 | else: | |
1324 | # merges are tricky: we try to reconstruct the unstored |
|
1333 | # merges are tricky: we try to reconstruct the unstored | |
1325 | # result from the merge (issue1802) |
|
1334 | # result from the merge (issue1802) | |
1326 | p1, p2 = parents |
|
1335 | p1, p2 = parents | |
1327 | pa = p1.ancestor(p2) |
|
1336 | pa = p1.ancestor(p2) | |
1328 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() |
|
1337 | m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1329 |
|
1338 | |||
1330 | def func(f): |
|
1339 | def func(f): | |
1331 | f = copiesget(f, f) # may be wrong for merges with copies |
|
1340 | f = copiesget(f, f) # may be wrong for merges with copies | |
1332 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) |
|
1341 | fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1333 | if fl1 == fl2: |
|
1342 | if fl1 == fl2: | |
1334 | return fl1 |
|
1343 | return fl1 | |
1335 | if fl1 == fla: |
|
1344 | if fl1 == fla: | |
1336 | return fl2 |
|
1345 | return fl2 | |
1337 | if fl2 == fla: |
|
1346 | if fl2 == fla: | |
1338 | return fl1 |
|
1347 | return fl1 | |
1339 | return '' # punt for conflicts |
|
1348 | return '' # punt for conflicts | |
1340 |
|
1349 | |||
1341 | return func |
|
1350 | return func | |
1342 |
|
1351 | |||
1343 | @propertycache |
|
1352 | @propertycache | |
1344 | def _flagfunc(self): |
|
1353 | def _flagfunc(self): | |
1345 | return self._repo.dirstate.flagfunc(self._buildflagfunc) |
|
1354 | return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1346 |
|
1355 | |||
1347 | @propertycache |
|
1356 | @propertycache | |
1348 | def _status(self): |
|
1357 | def _status(self): | |
1349 | return self._repo.status() |
|
1358 | return self._repo.status() | |
1350 |
|
1359 | |||
1351 | @propertycache |
|
1360 | @propertycache | |
1352 | def _user(self): |
|
1361 | def _user(self): | |
1353 | return self._repo.ui.username() |
|
1362 | return self._repo.ui.username() | |
1354 |
|
1363 | |||
1355 | @propertycache |
|
1364 | @propertycache | |
1356 | def _date(self): |
|
1365 | def _date(self): | |
1357 | ui = self._repo.ui |
|
1366 | ui = self._repo.ui | |
1358 | date = ui.configdate('devel', 'default-date') |
|
1367 | date = ui.configdate('devel', 'default-date') | |
1359 | if date is None: |
|
1368 | if date is None: | |
1360 | date = util.makedate() |
|
1369 | date = util.makedate() | |
1361 | return date |
|
1370 | return date | |
1362 |
|
1371 | |||
1363 | def subrev(self, subpath): |
|
1372 | def subrev(self, subpath): | |
1364 | return None |
|
1373 | return None | |
1365 |
|
1374 | |||
1366 | def manifestnode(self): |
|
1375 | def manifestnode(self): | |
1367 | return None |
|
1376 | return None | |
1368 | def user(self): |
|
1377 | def user(self): | |
1369 | return self._user or self._repo.ui.username() |
|
1378 | return self._user or self._repo.ui.username() | |
1370 | def date(self): |
|
1379 | def date(self): | |
1371 | return self._date |
|
1380 | return self._date | |
1372 | def description(self): |
|
1381 | def description(self): | |
1373 | return self._text |
|
1382 | return self._text | |
1374 | def files(self): |
|
1383 | def files(self): | |
1375 | return sorted(self._status.modified + self._status.added + |
|
1384 | return sorted(self._status.modified + self._status.added + | |
1376 | self._status.removed) |
|
1385 | self._status.removed) | |
1377 |
|
1386 | |||
1378 | def modified(self): |
|
1387 | def modified(self): | |
1379 | return self._status.modified |
|
1388 | return self._status.modified | |
1380 | def added(self): |
|
1389 | def added(self): | |
1381 | return self._status.added |
|
1390 | return self._status.added | |
1382 | def removed(self): |
|
1391 | def removed(self): | |
1383 | return self._status.removed |
|
1392 | return self._status.removed | |
1384 | def deleted(self): |
|
1393 | def deleted(self): | |
1385 | return self._status.deleted |
|
1394 | return self._status.deleted | |
1386 | def branch(self): |
|
1395 | def branch(self): | |
1387 | return encoding.tolocal(self._extra['branch']) |
|
1396 | return encoding.tolocal(self._extra['branch']) | |
1388 | def closesbranch(self): |
|
1397 | def closesbranch(self): | |
1389 | return 'close' in self._extra |
|
1398 | return 'close' in self._extra | |
1390 | def extra(self): |
|
1399 | def extra(self): | |
1391 | return self._extra |
|
1400 | return self._extra | |
1392 |
|
1401 | |||
1393 | def tags(self): |
|
1402 | def tags(self): | |
1394 | return [] |
|
1403 | return [] | |
1395 |
|
1404 | |||
1396 | def bookmarks(self): |
|
1405 | def bookmarks(self): | |
1397 | b = [] |
|
1406 | b = [] | |
1398 | for p in self.parents(): |
|
1407 | for p in self.parents(): | |
1399 | b.extend(p.bookmarks()) |
|
1408 | b.extend(p.bookmarks()) | |
1400 | return b |
|
1409 | return b | |
1401 |
|
1410 | |||
1402 | def phase(self): |
|
1411 | def phase(self): | |
1403 | phase = phases.draft # default phase to draft |
|
1412 | phase = phases.draft # default phase to draft | |
1404 | for p in self.parents(): |
|
1413 | for p in self.parents(): | |
1405 | phase = max(phase, p.phase()) |
|
1414 | phase = max(phase, p.phase()) | |
1406 | return phase |
|
1415 | return phase | |
1407 |
|
1416 | |||
1408 | def hidden(self): |
|
1417 | def hidden(self): | |
1409 | return False |
|
1418 | return False | |
1410 |
|
1419 | |||
1411 | def children(self): |
|
1420 | def children(self): | |
1412 | return [] |
|
1421 | return [] | |
1413 |
|
1422 | |||
1414 | def flags(self, path): |
|
1423 | def flags(self, path): | |
1415 | if r'_manifest' in self.__dict__: |
|
1424 | if r'_manifest' in self.__dict__: | |
1416 | try: |
|
1425 | try: | |
1417 | return self._manifest.flags(path) |
|
1426 | return self._manifest.flags(path) | |
1418 | except KeyError: |
|
1427 | except KeyError: | |
1419 | return '' |
|
1428 | return '' | |
1420 |
|
1429 | |||
1421 | try: |
|
1430 | try: | |
1422 | return self._flagfunc(path) |
|
1431 | return self._flagfunc(path) | |
1423 | except OSError: |
|
1432 | except OSError: | |
1424 | return '' |
|
1433 | return '' | |
1425 |
|
1434 | |||
1426 | def ancestor(self, c2): |
|
1435 | def ancestor(self, c2): | |
1427 | """return the "best" ancestor context of self and c2""" |
|
1436 | """return the "best" ancestor context of self and c2""" | |
1428 | return self._parents[0].ancestor(c2) # punt on two parents for now |
|
1437 | return self._parents[0].ancestor(c2) # punt on two parents for now | |
1429 |
|
1438 | |||
1430 | def walk(self, match): |
|
1439 | def walk(self, match): | |
1431 | '''Generates matching file names.''' |
|
1440 | '''Generates matching file names.''' | |
1432 | return sorted(self._repo.dirstate.walk(match, |
|
1441 | return sorted(self._repo.dirstate.walk(match, | |
1433 | subrepos=sorted(self.substate), |
|
1442 | subrepos=sorted(self.substate), | |
1434 | unknown=True, ignored=False)) |
|
1443 | unknown=True, ignored=False)) | |
1435 |
|
1444 | |||
1436 | def matches(self, match): |
|
1445 | def matches(self, match): | |
1437 | return sorted(self._repo.dirstate.matches(match)) |
|
1446 | return sorted(self._repo.dirstate.matches(match)) | |
1438 |
|
1447 | |||
1439 | def ancestors(self): |
|
1448 | def ancestors(self): | |
1440 | for p in self._parents: |
|
1449 | for p in self._parents: | |
1441 | yield p |
|
1450 | yield p | |
1442 | for a in self._repo.changelog.ancestors( |
|
1451 | for a in self._repo.changelog.ancestors( | |
1443 | [p.rev() for p in self._parents]): |
|
1452 | [p.rev() for p in self._parents]): | |
1444 | yield changectx(self._repo, a) |
|
1453 | yield changectx(self._repo, a) | |
1445 |
|
1454 | |||
1446 | def markcommitted(self, node): |
|
1455 | def markcommitted(self, node): | |
1447 | """Perform post-commit cleanup necessary after committing this ctx |
|
1456 | """Perform post-commit cleanup necessary after committing this ctx | |
1448 |
|
1457 | |||
1449 | Specifically, this updates backing stores this working context |
|
1458 | Specifically, this updates backing stores this working context | |
1450 | wraps to reflect the fact that the changes reflected by this |
|
1459 | wraps to reflect the fact that the changes reflected by this | |
1451 | workingctx have been committed. For example, it marks |
|
1460 | workingctx have been committed. For example, it marks | |
1452 | modified and added files as normal in the dirstate. |
|
1461 | modified and added files as normal in the dirstate. | |
1453 |
|
1462 | |||
1454 | """ |
|
1463 | """ | |
1455 |
|
1464 | |||
1456 | with self._repo.dirstate.parentchange(): |
|
1465 | with self._repo.dirstate.parentchange(): | |
1457 | for f in self.modified() + self.added(): |
|
1466 | for f in self.modified() + self.added(): | |
1458 | self._repo.dirstate.normal(f) |
|
1467 | self._repo.dirstate.normal(f) | |
1459 | for f in self.removed(): |
|
1468 | for f in self.removed(): | |
1460 | self._repo.dirstate.drop(f) |
|
1469 | self._repo.dirstate.drop(f) | |
1461 | self._repo.dirstate.setparents(node) |
|
1470 | self._repo.dirstate.setparents(node) | |
1462 |
|
1471 | |||
1463 | # write changes out explicitly, because nesting wlock at |
|
1472 | # write changes out explicitly, because nesting wlock at | |
1464 | # runtime may prevent 'wlock.release()' in 'repo.commit()' |
|
1473 | # runtime may prevent 'wlock.release()' in 'repo.commit()' | |
1465 | # from immediately doing so for subsequent changing files |
|
1474 | # from immediately doing so for subsequent changing files | |
1466 | self._repo.dirstate.write(self._repo.currenttransaction()) |
|
1475 | self._repo.dirstate.write(self._repo.currenttransaction()) | |
1467 |
|
1476 | |||
1468 | def dirty(self, missing=False, merge=True, branch=True): |
|
1477 | def dirty(self, missing=False, merge=True, branch=True): | |
1469 | return False |
|
1478 | return False | |
1470 |
|
1479 | |||
1471 | class workingctx(committablectx): |
|
1480 | class workingctx(committablectx): | |
1472 | """A workingctx object makes access to data related to |
|
1481 | """A workingctx object makes access to data related to | |
1473 | the current working directory convenient. |
|
1482 | the current working directory convenient. | |
1474 | date - any valid date string or (unixtime, offset), or None. |
|
1483 | date - any valid date string or (unixtime, offset), or None. | |
1475 | user - username string, or None. |
|
1484 | user - username string, or None. | |
1476 | extra - a dictionary of extra values, or None. |
|
1485 | extra - a dictionary of extra values, or None. | |
1477 | changes - a list of file lists as returned by localrepo.status() |
|
1486 | changes - a list of file lists as returned by localrepo.status() | |
1478 | or None to use the repository status. |
|
1487 | or None to use the repository status. | |
1479 | """ |
|
1488 | """ | |
1480 | def __init__(self, repo, text="", user=None, date=None, extra=None, |
|
1489 | def __init__(self, repo, text="", user=None, date=None, extra=None, | |
1481 | changes=None): |
|
1490 | changes=None): | |
1482 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) |
|
1491 | super(workingctx, self).__init__(repo, text, user, date, extra, changes) | |
1483 |
|
1492 | |||
1484 | def __iter__(self): |
|
1493 | def __iter__(self): | |
1485 | d = self._repo.dirstate |
|
1494 | d = self._repo.dirstate | |
1486 | for f in d: |
|
1495 | for f in d: | |
1487 | if d[f] != 'r': |
|
1496 | if d[f] != 'r': | |
1488 | yield f |
|
1497 | yield f | |
1489 |
|
1498 | |||
1490 | def __contains__(self, key): |
|
1499 | def __contains__(self, key): | |
1491 | return self._repo.dirstate[key] not in "?r" |
|
1500 | return self._repo.dirstate[key] not in "?r" | |
1492 |
|
1501 | |||
1493 | def hex(self): |
|
1502 | def hex(self): | |
1494 | return hex(wdirid) |
|
1503 | return hex(wdirid) | |
1495 |
|
1504 | |||
1496 | @propertycache |
|
1505 | @propertycache | |
1497 | def _parents(self): |
|
1506 | def _parents(self): | |
1498 | p = self._repo.dirstate.parents() |
|
1507 | p = self._repo.dirstate.parents() | |
1499 | if p[1] == nullid: |
|
1508 | if p[1] == nullid: | |
1500 | p = p[:-1] |
|
1509 | p = p[:-1] | |
1501 | return [changectx(self._repo, x) for x in p] |
|
1510 | return [changectx(self._repo, x) for x in p] | |
1502 |
|
1511 | |||
1503 | def filectx(self, path, filelog=None): |
|
1512 | def filectx(self, path, filelog=None): | |
1504 | """get a file context from the working directory""" |
|
1513 | """get a file context from the working directory""" | |
1505 | return workingfilectx(self._repo, path, workingctx=self, |
|
1514 | return workingfilectx(self._repo, path, workingctx=self, | |
1506 | filelog=filelog) |
|
1515 | filelog=filelog) | |
1507 |
|
1516 | |||
1508 | def dirty(self, missing=False, merge=True, branch=True): |
|
1517 | def dirty(self, missing=False, merge=True, branch=True): | |
1509 | "check whether a working directory is modified" |
|
1518 | "check whether a working directory is modified" | |
1510 | # check subrepos first |
|
1519 | # check subrepos first | |
1511 | for s in sorted(self.substate): |
|
1520 | for s in sorted(self.substate): | |
1512 | if self.sub(s).dirty(missing=missing): |
|
1521 | if self.sub(s).dirty(missing=missing): | |
1513 | return True |
|
1522 | return True | |
1514 | # check current working dir |
|
1523 | # check current working dir | |
1515 | return ((merge and self.p2()) or |
|
1524 | return ((merge and self.p2()) or | |
1516 | (branch and self.branch() != self.p1().branch()) or |
|
1525 | (branch and self.branch() != self.p1().branch()) or | |
1517 | self.modified() or self.added() or self.removed() or |
|
1526 | self.modified() or self.added() or self.removed() or | |
1518 | (missing and self.deleted())) |
|
1527 | (missing and self.deleted())) | |
1519 |
|
1528 | |||
1520 | def add(self, list, prefix=""): |
|
1529 | def add(self, list, prefix=""): | |
1521 | with self._repo.wlock(): |
|
1530 | with self._repo.wlock(): | |
1522 | ui, ds = self._repo.ui, self._repo.dirstate |
|
1531 | ui, ds = self._repo.ui, self._repo.dirstate | |
1523 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1532 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) | |
1524 | rejected = [] |
|
1533 | rejected = [] | |
1525 | lstat = self._repo.wvfs.lstat |
|
1534 | lstat = self._repo.wvfs.lstat | |
1526 | for f in list: |
|
1535 | for f in list: | |
1527 | # ds.pathto() returns an absolute file when this is invoked from |
|
1536 | # ds.pathto() returns an absolute file when this is invoked from | |
1528 | # the keyword extension. That gets flagged as non-portable on |
|
1537 | # the keyword extension. That gets flagged as non-portable on | |
1529 | # Windows, since it contains the drive letter and colon. |
|
1538 | # Windows, since it contains the drive letter and colon. | |
1530 | scmutil.checkportable(ui, os.path.join(prefix, f)) |
|
1539 | scmutil.checkportable(ui, os.path.join(prefix, f)) | |
1531 | try: |
|
1540 | try: | |
1532 | st = lstat(f) |
|
1541 | st = lstat(f) | |
1533 | except OSError: |
|
1542 | except OSError: | |
1534 | ui.warn(_("%s does not exist!\n") % uipath(f)) |
|
1543 | ui.warn(_("%s does not exist!\n") % uipath(f)) | |
1535 | rejected.append(f) |
|
1544 | rejected.append(f) | |
1536 | continue |
|
1545 | continue | |
1537 | if st.st_size > 10000000: |
|
1546 | if st.st_size > 10000000: | |
1538 | ui.warn(_("%s: up to %d MB of RAM may be required " |
|
1547 | ui.warn(_("%s: up to %d MB of RAM may be required " | |
1539 | "to manage this file\n" |
|
1548 | "to manage this file\n" | |
1540 | "(use 'hg revert %s' to cancel the " |
|
1549 | "(use 'hg revert %s' to cancel the " | |
1541 | "pending addition)\n") |
|
1550 | "pending addition)\n") | |
1542 | % (f, 3 * st.st_size // 1000000, uipath(f))) |
|
1551 | % (f, 3 * st.st_size // 1000000, uipath(f))) | |
1543 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1552 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1544 | ui.warn(_("%s not added: only files and symlinks " |
|
1553 | ui.warn(_("%s not added: only files and symlinks " | |
1545 | "supported currently\n") % uipath(f)) |
|
1554 | "supported currently\n") % uipath(f)) | |
1546 | rejected.append(f) |
|
1555 | rejected.append(f) | |
1547 | elif ds[f] in 'amn': |
|
1556 | elif ds[f] in 'amn': | |
1548 | ui.warn(_("%s already tracked!\n") % uipath(f)) |
|
1557 | ui.warn(_("%s already tracked!\n") % uipath(f)) | |
1549 | elif ds[f] == 'r': |
|
1558 | elif ds[f] == 'r': | |
1550 | ds.normallookup(f) |
|
1559 | ds.normallookup(f) | |
1551 | else: |
|
1560 | else: | |
1552 | ds.add(f) |
|
1561 | ds.add(f) | |
1553 | return rejected |
|
1562 | return rejected | |
1554 |
|
1563 | |||
1555 | def forget(self, files, prefix=""): |
|
1564 | def forget(self, files, prefix=""): | |
1556 | with self._repo.wlock(): |
|
1565 | with self._repo.wlock(): | |
1557 | ds = self._repo.dirstate |
|
1566 | ds = self._repo.dirstate | |
1558 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) |
|
1567 | uipath = lambda f: ds.pathto(pathutil.join(prefix, f)) | |
1559 | rejected = [] |
|
1568 | rejected = [] | |
1560 | for f in files: |
|
1569 | for f in files: | |
1561 | if f not in self._repo.dirstate: |
|
1570 | if f not in self._repo.dirstate: | |
1562 | self._repo.ui.warn(_("%s not tracked!\n") % uipath(f)) |
|
1571 | self._repo.ui.warn(_("%s not tracked!\n") % uipath(f)) | |
1563 | rejected.append(f) |
|
1572 | rejected.append(f) | |
1564 | elif self._repo.dirstate[f] != 'a': |
|
1573 | elif self._repo.dirstate[f] != 'a': | |
1565 | self._repo.dirstate.remove(f) |
|
1574 | self._repo.dirstate.remove(f) | |
1566 | else: |
|
1575 | else: | |
1567 | self._repo.dirstate.drop(f) |
|
1576 | self._repo.dirstate.drop(f) | |
1568 | return rejected |
|
1577 | return rejected | |
1569 |
|
1578 | |||
1570 | def undelete(self, list): |
|
1579 | def undelete(self, list): | |
1571 | pctxs = self.parents() |
|
1580 | pctxs = self.parents() | |
1572 | with self._repo.wlock(): |
|
1581 | with self._repo.wlock(): | |
1573 | ds = self._repo.dirstate |
|
1582 | ds = self._repo.dirstate | |
1574 | for f in list: |
|
1583 | for f in list: | |
1575 | if self._repo.dirstate[f] != 'r': |
|
1584 | if self._repo.dirstate[f] != 'r': | |
1576 | self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f)) |
|
1585 | self._repo.ui.warn(_("%s not removed!\n") % ds.pathto(f)) | |
1577 | else: |
|
1586 | else: | |
1578 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
|
1587 | fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] | |
1579 | t = fctx.data() |
|
1588 | t = fctx.data() | |
1580 | self._repo.wwrite(f, t, fctx.flags()) |
|
1589 | self._repo.wwrite(f, t, fctx.flags()) | |
1581 | self._repo.dirstate.normal(f) |
|
1590 | self._repo.dirstate.normal(f) | |
1582 |
|
1591 | |||
1583 | def copy(self, source, dest): |
|
1592 | def copy(self, source, dest): | |
1584 | try: |
|
1593 | try: | |
1585 | st = self._repo.wvfs.lstat(dest) |
|
1594 | st = self._repo.wvfs.lstat(dest) | |
1586 | except OSError as err: |
|
1595 | except OSError as err: | |
1587 | if err.errno != errno.ENOENT: |
|
1596 | if err.errno != errno.ENOENT: | |
1588 | raise |
|
1597 | raise | |
1589 | self._repo.ui.warn(_("%s does not exist!\n") |
|
1598 | self._repo.ui.warn(_("%s does not exist!\n") | |
1590 | % self._repo.dirstate.pathto(dest)) |
|
1599 | % self._repo.dirstate.pathto(dest)) | |
1591 | return |
|
1600 | return | |
1592 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
|
1601 | if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | |
1593 | self._repo.ui.warn(_("copy failed: %s is not a file or a " |
|
1602 | self._repo.ui.warn(_("copy failed: %s is not a file or a " | |
1594 | "symbolic link\n") |
|
1603 | "symbolic link\n") | |
1595 | % self._repo.dirstate.pathto(dest)) |
|
1604 | % self._repo.dirstate.pathto(dest)) | |
1596 | else: |
|
1605 | else: | |
1597 | with self._repo.wlock(): |
|
1606 | with self._repo.wlock(): | |
1598 | if self._repo.dirstate[dest] in '?': |
|
1607 | if self._repo.dirstate[dest] in '?': | |
1599 | self._repo.dirstate.add(dest) |
|
1608 | self._repo.dirstate.add(dest) | |
1600 | elif self._repo.dirstate[dest] in 'r': |
|
1609 | elif self._repo.dirstate[dest] in 'r': | |
1601 | self._repo.dirstate.normallookup(dest) |
|
1610 | self._repo.dirstate.normallookup(dest) | |
1602 | self._repo.dirstate.copy(source, dest) |
|
1611 | self._repo.dirstate.copy(source, dest) | |
1603 |
|
1612 | |||
1604 | def match(self, pats=None, include=None, exclude=None, default='glob', |
|
1613 | def match(self, pats=None, include=None, exclude=None, default='glob', | |
1605 | listsubrepos=False, badfn=None): |
|
1614 | listsubrepos=False, badfn=None): | |
1606 | r = self._repo |
|
1615 | r = self._repo | |
1607 |
|
1616 | |||
1608 | # Only a case insensitive filesystem needs magic to translate user input |
|
1617 | # Only a case insensitive filesystem needs magic to translate user input | |
1609 | # to actual case in the filesystem. |
|
1618 | # to actual case in the filesystem. | |
1610 | icasefs = not util.fscasesensitive(r.root) |
|
1619 | icasefs = not util.fscasesensitive(r.root) | |
1611 | return matchmod.match(r.root, r.getcwd(), pats, include, exclude, |
|
1620 | return matchmod.match(r.root, r.getcwd(), pats, include, exclude, | |
1612 | default, auditor=r.auditor, ctx=self, |
|
1621 | default, auditor=r.auditor, ctx=self, | |
1613 | listsubrepos=listsubrepos, badfn=badfn, |
|
1622 | listsubrepos=listsubrepos, badfn=badfn, | |
1614 | icasefs=icasefs) |
|
1623 | icasefs=icasefs) | |
1615 |
|
1624 | |||
1616 | def flushall(self): |
|
1625 | def flushall(self): | |
1617 | pass # For overlayworkingfilectx compatibility. |
|
1626 | pass # For overlayworkingfilectx compatibility. | |
1618 |
|
1627 | |||
1619 | def _filtersuspectsymlink(self, files): |
|
1628 | def _filtersuspectsymlink(self, files): | |
1620 | if not files or self._repo.dirstate._checklink: |
|
1629 | if not files or self._repo.dirstate._checklink: | |
1621 | return files |
|
1630 | return files | |
1622 |
|
1631 | |||
1623 | # Symlink placeholders may get non-symlink-like contents |
|
1632 | # Symlink placeholders may get non-symlink-like contents | |
1624 | # via user error or dereferencing by NFS or Samba servers, |
|
1633 | # via user error or dereferencing by NFS or Samba servers, | |
1625 | # so we filter out any placeholders that don't look like a |
|
1634 | # so we filter out any placeholders that don't look like a | |
1626 | # symlink |
|
1635 | # symlink | |
1627 | sane = [] |
|
1636 | sane = [] | |
1628 | for f in files: |
|
1637 | for f in files: | |
1629 | if self.flags(f) == 'l': |
|
1638 | if self.flags(f) == 'l': | |
1630 | d = self[f].data() |
|
1639 | d = self[f].data() | |
1631 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): |
|
1640 | if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d): | |
1632 | self._repo.ui.debug('ignoring suspect symlink placeholder' |
|
1641 | self._repo.ui.debug('ignoring suspect symlink placeholder' | |
1633 | ' "%s"\n' % f) |
|
1642 | ' "%s"\n' % f) | |
1634 | continue |
|
1643 | continue | |
1635 | sane.append(f) |
|
1644 | sane.append(f) | |
1636 | return sane |
|
1645 | return sane | |
1637 |
|
1646 | |||
1638 | def _checklookup(self, files): |
|
1647 | def _checklookup(self, files): | |
1639 | # check for any possibly clean files |
|
1648 | # check for any possibly clean files | |
1640 | if not files: |
|
1649 | if not files: | |
1641 | return [], [], [] |
|
1650 | return [], [], [] | |
1642 |
|
1651 | |||
1643 | modified = [] |
|
1652 | modified = [] | |
1644 | deleted = [] |
|
1653 | deleted = [] | |
1645 | fixup = [] |
|
1654 | fixup = [] | |
1646 | pctx = self._parents[0] |
|
1655 | pctx = self._parents[0] | |
1647 | # do a full compare of any files that might have changed |
|
1656 | # do a full compare of any files that might have changed | |
1648 | for f in sorted(files): |
|
1657 | for f in sorted(files): | |
1649 | try: |
|
1658 | try: | |
1650 | # This will return True for a file that got replaced by a |
|
1659 | # This will return True for a file that got replaced by a | |
1651 | # directory in the interim, but fixing that is pretty hard. |
|
1660 | # directory in the interim, but fixing that is pretty hard. | |
1652 | if (f not in pctx or self.flags(f) != pctx.flags(f) |
|
1661 | if (f not in pctx or self.flags(f) != pctx.flags(f) | |
1653 | or pctx[f].cmp(self[f])): |
|
1662 | or pctx[f].cmp(self[f])): | |
1654 | modified.append(f) |
|
1663 | modified.append(f) | |
1655 | else: |
|
1664 | else: | |
1656 | fixup.append(f) |
|
1665 | fixup.append(f) | |
1657 | except (IOError, OSError): |
|
1666 | except (IOError, OSError): | |
1658 | # A file become inaccessible in between? Mark it as deleted, |
|
1667 | # A file become inaccessible in between? Mark it as deleted, | |
1659 | # matching dirstate behavior (issue5584). |
|
1668 | # matching dirstate behavior (issue5584). | |
1660 | # The dirstate has more complex behavior around whether a |
|
1669 | # The dirstate has more complex behavior around whether a | |
1661 | # missing file matches a directory, etc, but we don't need to |
|
1670 | # missing file matches a directory, etc, but we don't need to | |
1662 | # bother with that: if f has made it to this point, we're sure |
|
1671 | # bother with that: if f has made it to this point, we're sure | |
1663 | # it's in the dirstate. |
|
1672 | # it's in the dirstate. | |
1664 | deleted.append(f) |
|
1673 | deleted.append(f) | |
1665 |
|
1674 | |||
1666 | return modified, deleted, fixup |
|
1675 | return modified, deleted, fixup | |
1667 |
|
1676 | |||
1668 | def _poststatusfixup(self, status, fixup): |
|
1677 | def _poststatusfixup(self, status, fixup): | |
1669 | """update dirstate for files that are actually clean""" |
|
1678 | """update dirstate for files that are actually clean""" | |
1670 | poststatus = self._repo.postdsstatus() |
|
1679 | poststatus = self._repo.postdsstatus() | |
1671 | if fixup or poststatus: |
|
1680 | if fixup or poststatus: | |
1672 | try: |
|
1681 | try: | |
1673 | oldid = self._repo.dirstate.identity() |
|
1682 | oldid = self._repo.dirstate.identity() | |
1674 |
|
1683 | |||
1675 | # updating the dirstate is optional |
|
1684 | # updating the dirstate is optional | |
1676 | # so we don't wait on the lock |
|
1685 | # so we don't wait on the lock | |
1677 | # wlock can invalidate the dirstate, so cache normal _after_ |
|
1686 | # wlock can invalidate the dirstate, so cache normal _after_ | |
1678 | # taking the lock |
|
1687 | # taking the lock | |
1679 | with self._repo.wlock(False): |
|
1688 | with self._repo.wlock(False): | |
1680 | if self._repo.dirstate.identity() == oldid: |
|
1689 | if self._repo.dirstate.identity() == oldid: | |
1681 | if fixup: |
|
1690 | if fixup: | |
1682 | normal = self._repo.dirstate.normal |
|
1691 | normal = self._repo.dirstate.normal | |
1683 | for f in fixup: |
|
1692 | for f in fixup: | |
1684 | normal(f) |
|
1693 | normal(f) | |
1685 | # write changes out explicitly, because nesting |
|
1694 | # write changes out explicitly, because nesting | |
1686 | # wlock at runtime may prevent 'wlock.release()' |
|
1695 | # wlock at runtime may prevent 'wlock.release()' | |
1687 | # after this block from doing so for subsequent |
|
1696 | # after this block from doing so for subsequent | |
1688 | # changing files |
|
1697 | # changing files | |
1689 | tr = self._repo.currenttransaction() |
|
1698 | tr = self._repo.currenttransaction() | |
1690 | self._repo.dirstate.write(tr) |
|
1699 | self._repo.dirstate.write(tr) | |
1691 |
|
1700 | |||
1692 | if poststatus: |
|
1701 | if poststatus: | |
1693 | for ps in poststatus: |
|
1702 | for ps in poststatus: | |
1694 | ps(self, status) |
|
1703 | ps(self, status) | |
1695 | else: |
|
1704 | else: | |
1696 | # in this case, writing changes out breaks |
|
1705 | # in this case, writing changes out breaks | |
1697 | # consistency, because .hg/dirstate was |
|
1706 | # consistency, because .hg/dirstate was | |
1698 | # already changed simultaneously after last |
|
1707 | # already changed simultaneously after last | |
1699 | # caching (see also issue5584 for detail) |
|
1708 | # caching (see also issue5584 for detail) | |
1700 | self._repo.ui.debug('skip updating dirstate: ' |
|
1709 | self._repo.ui.debug('skip updating dirstate: ' | |
1701 | 'identity mismatch\n') |
|
1710 | 'identity mismatch\n') | |
1702 | except error.LockError: |
|
1711 | except error.LockError: | |
1703 | pass |
|
1712 | pass | |
1704 | finally: |
|
1713 | finally: | |
1705 | # Even if the wlock couldn't be grabbed, clear out the list. |
|
1714 | # Even if the wlock couldn't be grabbed, clear out the list. | |
1706 | self._repo.clearpostdsstatus() |
|
1715 | self._repo.clearpostdsstatus() | |
1707 |
|
1716 | |||
1708 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
1717 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): | |
1709 | '''Gets the status from the dirstate -- internal use only.''' |
|
1718 | '''Gets the status from the dirstate -- internal use only.''' | |
1710 | subrepos = [] |
|
1719 | subrepos = [] | |
1711 | if '.hgsub' in self: |
|
1720 | if '.hgsub' in self: | |
1712 | subrepos = sorted(self.substate) |
|
1721 | subrepos = sorted(self.substate) | |
1713 | cmp, s = self._repo.dirstate.status(match, subrepos, ignored=ignored, |
|
1722 | cmp, s = self._repo.dirstate.status(match, subrepos, ignored=ignored, | |
1714 | clean=clean, unknown=unknown) |
|
1723 | clean=clean, unknown=unknown) | |
1715 |
|
1724 | |||
1716 | # check for any possibly clean files |
|
1725 | # check for any possibly clean files | |
1717 | fixup = [] |
|
1726 | fixup = [] | |
1718 | if cmp: |
|
1727 | if cmp: | |
1719 | modified2, deleted2, fixup = self._checklookup(cmp) |
|
1728 | modified2, deleted2, fixup = self._checklookup(cmp) | |
1720 | s.modified.extend(modified2) |
|
1729 | s.modified.extend(modified2) | |
1721 | s.deleted.extend(deleted2) |
|
1730 | s.deleted.extend(deleted2) | |
1722 |
|
1731 | |||
1723 | if fixup and clean: |
|
1732 | if fixup and clean: | |
1724 | s.clean.extend(fixup) |
|
1733 | s.clean.extend(fixup) | |
1725 |
|
1734 | |||
1726 | self._poststatusfixup(s, fixup) |
|
1735 | self._poststatusfixup(s, fixup) | |
1727 |
|
1736 | |||
1728 | if match.always(): |
|
1737 | if match.always(): | |
1729 | # cache for performance |
|
1738 | # cache for performance | |
1730 | if s.unknown or s.ignored or s.clean: |
|
1739 | if s.unknown or s.ignored or s.clean: | |
1731 | # "_status" is cached with list*=False in the normal route |
|
1740 | # "_status" is cached with list*=False in the normal route | |
1732 | self._status = scmutil.status(s.modified, s.added, s.removed, |
|
1741 | self._status = scmutil.status(s.modified, s.added, s.removed, | |
1733 | s.deleted, [], [], []) |
|
1742 | s.deleted, [], [], []) | |
1734 | else: |
|
1743 | else: | |
1735 | self._status = s |
|
1744 | self._status = s | |
1736 |
|
1745 | |||
1737 | return s |
|
1746 | return s | |
1738 |
|
1747 | |||
1739 | @propertycache |
|
1748 | @propertycache | |
1740 | def _manifest(self): |
|
1749 | def _manifest(self): | |
1741 | """generate a manifest corresponding to the values in self._status |
|
1750 | """generate a manifest corresponding to the values in self._status | |
1742 |
|
1751 | |||
1743 | This reuse the file nodeid from parent, but we use special node |
|
1752 | This reuse the file nodeid from parent, but we use special node | |
1744 | identifiers for added and modified files. This is used by manifests |
|
1753 | identifiers for added and modified files. This is used by manifests | |
1745 | merge to see that files are different and by update logic to avoid |
|
1754 | merge to see that files are different and by update logic to avoid | |
1746 | deleting newly added files. |
|
1755 | deleting newly added files. | |
1747 | """ |
|
1756 | """ | |
1748 | return self._buildstatusmanifest(self._status) |
|
1757 | return self._buildstatusmanifest(self._status) | |
1749 |
|
1758 | |||
1750 | def _buildstatusmanifest(self, status): |
|
1759 | def _buildstatusmanifest(self, status): | |
1751 | """Builds a manifest that includes the given status results.""" |
|
1760 | """Builds a manifest that includes the given status results.""" | |
1752 | parents = self.parents() |
|
1761 | parents = self.parents() | |
1753 |
|
1762 | |||
1754 | man = parents[0].manifest().copy() |
|
1763 | man = parents[0].manifest().copy() | |
1755 |
|
1764 | |||
1756 | ff = self._flagfunc |
|
1765 | ff = self._flagfunc | |
1757 | for i, l in ((addednodeid, status.added), |
|
1766 | for i, l in ((addednodeid, status.added), | |
1758 | (modifiednodeid, status.modified)): |
|
1767 | (modifiednodeid, status.modified)): | |
1759 | for f in l: |
|
1768 | for f in l: | |
1760 | man[f] = i |
|
1769 | man[f] = i | |
1761 | try: |
|
1770 | try: | |
1762 | man.setflag(f, ff(f)) |
|
1771 | man.setflag(f, ff(f)) | |
1763 | except OSError: |
|
1772 | except OSError: | |
1764 | pass |
|
1773 | pass | |
1765 |
|
1774 | |||
1766 | for f in status.deleted + status.removed: |
|
1775 | for f in status.deleted + status.removed: | |
1767 | if f in man: |
|
1776 | if f in man: | |
1768 | del man[f] |
|
1777 | del man[f] | |
1769 |
|
1778 | |||
1770 | return man |
|
1779 | return man | |
1771 |
|
1780 | |||
1772 | def _buildstatus(self, other, s, match, listignored, listclean, |
|
1781 | def _buildstatus(self, other, s, match, listignored, listclean, | |
1773 | listunknown): |
|
1782 | listunknown): | |
1774 | """build a status with respect to another context |
|
1783 | """build a status with respect to another context | |
1775 |
|
1784 | |||
1776 | This includes logic for maintaining the fast path of status when |
|
1785 | This includes logic for maintaining the fast path of status when | |
1777 | comparing the working directory against its parent, which is to skip |
|
1786 | comparing the working directory against its parent, which is to skip | |
1778 | building a new manifest if self (working directory) is not comparing |
|
1787 | building a new manifest if self (working directory) is not comparing | |
1779 | against its parent (repo['.']). |
|
1788 | against its parent (repo['.']). | |
1780 | """ |
|
1789 | """ | |
1781 | s = self._dirstatestatus(match, listignored, listclean, listunknown) |
|
1790 | s = self._dirstatestatus(match, listignored, listclean, listunknown) | |
1782 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, |
|
1791 | # Filter out symlinks that, in the case of FAT32 and NTFS filesystems, | |
1783 | # might have accidentally ended up with the entire contents of the file |
|
1792 | # might have accidentally ended up with the entire contents of the file | |
1784 | # they are supposed to be linking to. |
|
1793 | # they are supposed to be linking to. | |
1785 | s.modified[:] = self._filtersuspectsymlink(s.modified) |
|
1794 | s.modified[:] = self._filtersuspectsymlink(s.modified) | |
1786 | if other != self._repo['.']: |
|
1795 | if other != self._repo['.']: | |
1787 | s = super(workingctx, self)._buildstatus(other, s, match, |
|
1796 | s = super(workingctx, self)._buildstatus(other, s, match, | |
1788 | listignored, listclean, |
|
1797 | listignored, listclean, | |
1789 | listunknown) |
|
1798 | listunknown) | |
1790 | return s |
|
1799 | return s | |
1791 |
|
1800 | |||
1792 | def _matchstatus(self, other, match): |
|
1801 | def _matchstatus(self, other, match): | |
1793 | """override the match method with a filter for directory patterns |
|
1802 | """override the match method with a filter for directory patterns | |
1794 |
|
1803 | |||
1795 | We use inheritance to customize the match.bad method only in cases of |
|
1804 | We use inheritance to customize the match.bad method only in cases of | |
1796 | workingctx since it belongs only to the working directory when |
|
1805 | workingctx since it belongs only to the working directory when | |
1797 | comparing against the parent changeset. |
|
1806 | comparing against the parent changeset. | |
1798 |
|
1807 | |||
1799 | If we aren't comparing against the working directory's parent, then we |
|
1808 | If we aren't comparing against the working directory's parent, then we | |
1800 | just use the default match object sent to us. |
|
1809 | just use the default match object sent to us. | |
1801 | """ |
|
1810 | """ | |
1802 | if other != self._repo['.']: |
|
1811 | if other != self._repo['.']: | |
1803 | def bad(f, msg): |
|
1812 | def bad(f, msg): | |
1804 | # 'f' may be a directory pattern from 'match.files()', |
|
1813 | # 'f' may be a directory pattern from 'match.files()', | |
1805 | # so 'f not in ctx1' is not enough |
|
1814 | # so 'f not in ctx1' is not enough | |
1806 | if f not in other and not other.hasdir(f): |
|
1815 | if f not in other and not other.hasdir(f): | |
1807 | self._repo.ui.warn('%s: %s\n' % |
|
1816 | self._repo.ui.warn('%s: %s\n' % | |
1808 | (self._repo.dirstate.pathto(f), msg)) |
|
1817 | (self._repo.dirstate.pathto(f), msg)) | |
1809 | match.bad = bad |
|
1818 | match.bad = bad | |
1810 | return match |
|
1819 | return match | |
1811 |
|
1820 | |||
1812 | def markcommitted(self, node): |
|
1821 | def markcommitted(self, node): | |
1813 | super(workingctx, self).markcommitted(node) |
|
1822 | super(workingctx, self).markcommitted(node) | |
1814 |
|
1823 | |||
1815 | sparse.aftercommit(self._repo, node) |
|
1824 | sparse.aftercommit(self._repo, node) | |
1816 |
|
1825 | |||
1817 | class committablefilectx(basefilectx): |
|
1826 | class committablefilectx(basefilectx): | |
1818 | """A committablefilectx provides common functionality for a file context |
|
1827 | """A committablefilectx provides common functionality for a file context | |
1819 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" |
|
1828 | that wants the ability to commit, e.g. workingfilectx or memfilectx.""" | |
1820 | def __init__(self, repo, path, filelog=None, ctx=None): |
|
1829 | def __init__(self, repo, path, filelog=None, ctx=None): | |
1821 | self._repo = repo |
|
1830 | self._repo = repo | |
1822 | self._path = path |
|
1831 | self._path = path | |
1823 | self._changeid = None |
|
1832 | self._changeid = None | |
1824 | self._filerev = self._filenode = None |
|
1833 | self._filerev = self._filenode = None | |
1825 |
|
1834 | |||
1826 | if filelog is not None: |
|
1835 | if filelog is not None: | |
1827 | self._filelog = filelog |
|
1836 | self._filelog = filelog | |
1828 | if ctx: |
|
1837 | if ctx: | |
1829 | self._changectx = ctx |
|
1838 | self._changectx = ctx | |
1830 |
|
1839 | |||
1831 | def __nonzero__(self): |
|
1840 | def __nonzero__(self): | |
1832 | return True |
|
1841 | return True | |
1833 |
|
1842 | |||
1834 | __bool__ = __nonzero__ |
|
1843 | __bool__ = __nonzero__ | |
1835 |
|
1844 | |||
1836 | def linkrev(self): |
|
1845 | def linkrev(self): | |
1837 | # linked to self._changectx no matter if file is modified or not |
|
1846 | # linked to self._changectx no matter if file is modified or not | |
1838 | return self.rev() |
|
1847 | return self.rev() | |
1839 |
|
1848 | |||
1840 | def parents(self): |
|
1849 | def parents(self): | |
1841 | '''return parent filectxs, following copies if necessary''' |
|
1850 | '''return parent filectxs, following copies if necessary''' | |
1842 | def filenode(ctx, path): |
|
1851 | def filenode(ctx, path): | |
1843 | return ctx._manifest.get(path, nullid) |
|
1852 | return ctx._manifest.get(path, nullid) | |
1844 |
|
1853 | |||
1845 | path = self._path |
|
1854 | path = self._path | |
1846 | fl = self._filelog |
|
1855 | fl = self._filelog | |
1847 | pcl = self._changectx._parents |
|
1856 | pcl = self._changectx._parents | |
1848 | renamed = self.renamed() |
|
1857 | renamed = self.renamed() | |
1849 |
|
1858 | |||
1850 | if renamed: |
|
1859 | if renamed: | |
1851 | pl = [renamed + (None,)] |
|
1860 | pl = [renamed + (None,)] | |
1852 | else: |
|
1861 | else: | |
1853 | pl = [(path, filenode(pcl[0], path), fl)] |
|
1862 | pl = [(path, filenode(pcl[0], path), fl)] | |
1854 |
|
1863 | |||
1855 | for pc in pcl[1:]: |
|
1864 | for pc in pcl[1:]: | |
1856 | pl.append((path, filenode(pc, path), fl)) |
|
1865 | pl.append((path, filenode(pc, path), fl)) | |
1857 |
|
1866 | |||
1858 | return [self._parentfilectx(p, fileid=n, filelog=l) |
|
1867 | return [self._parentfilectx(p, fileid=n, filelog=l) | |
1859 | for p, n, l in pl if n != nullid] |
|
1868 | for p, n, l in pl if n != nullid] | |
1860 |
|
1869 | |||
1861 | def children(self): |
|
1870 | def children(self): | |
1862 | return [] |
|
1871 | return [] | |
1863 |
|
1872 | |||
1864 | class workingfilectx(committablefilectx): |
|
1873 | class workingfilectx(committablefilectx): | |
1865 | """A workingfilectx object makes access to data related to a particular |
|
1874 | """A workingfilectx object makes access to data related to a particular | |
1866 | file in the working directory convenient.""" |
|
1875 | file in the working directory convenient.""" | |
1867 | def __init__(self, repo, path, filelog=None, workingctx=None): |
|
1876 | def __init__(self, repo, path, filelog=None, workingctx=None): | |
1868 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) |
|
1877 | super(workingfilectx, self).__init__(repo, path, filelog, workingctx) | |
1869 |
|
1878 | |||
1870 | @propertycache |
|
1879 | @propertycache | |
1871 | def _changectx(self): |
|
1880 | def _changectx(self): | |
1872 | return workingctx(self._repo) |
|
1881 | return workingctx(self._repo) | |
1873 |
|
1882 | |||
1874 | def data(self): |
|
1883 | def data(self): | |
1875 | return self._repo.wread(self._path) |
|
1884 | return self._repo.wread(self._path) | |
1876 | def renamed(self): |
|
1885 | def renamed(self): | |
1877 | rp = self._repo.dirstate.copied(self._path) |
|
1886 | rp = self._repo.dirstate.copied(self._path) | |
1878 | if not rp: |
|
1887 | if not rp: | |
1879 | return None |
|
1888 | return None | |
1880 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
1889 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
1881 |
|
1890 | |||
1882 | def size(self): |
|
1891 | def size(self): | |
1883 | return self._repo.wvfs.lstat(self._path).st_size |
|
1892 | return self._repo.wvfs.lstat(self._path).st_size | |
1884 | def date(self): |
|
1893 | def date(self): | |
1885 | t, tz = self._changectx.date() |
|
1894 | t, tz = self._changectx.date() | |
1886 | try: |
|
1895 | try: | |
1887 | return (self._repo.wvfs.lstat(self._path).st_mtime, tz) |
|
1896 | return (self._repo.wvfs.lstat(self._path).st_mtime, tz) | |
1888 | except OSError as err: |
|
1897 | except OSError as err: | |
1889 | if err.errno != errno.ENOENT: |
|
1898 | if err.errno != errno.ENOENT: | |
1890 | raise |
|
1899 | raise | |
1891 | return (t, tz) |
|
1900 | return (t, tz) | |
1892 |
|
1901 | |||
1893 | def exists(self): |
|
1902 | def exists(self): | |
1894 | return self._repo.wvfs.exists(self._path) |
|
1903 | return self._repo.wvfs.exists(self._path) | |
1895 |
|
1904 | |||
1896 | def lexists(self): |
|
1905 | def lexists(self): | |
1897 | return self._repo.wvfs.lexists(self._path) |
|
1906 | return self._repo.wvfs.lexists(self._path) | |
1898 |
|
1907 | |||
1899 | def audit(self): |
|
1908 | def audit(self): | |
1900 | return self._repo.wvfs.audit(self._path) |
|
1909 | return self._repo.wvfs.audit(self._path) | |
1901 |
|
1910 | |||
1902 | def cmp(self, fctx): |
|
1911 | def cmp(self, fctx): | |
1903 | """compare with other file context |
|
1912 | """compare with other file context | |
1904 |
|
1913 | |||
1905 | returns True if different than fctx. |
|
1914 | returns True if different than fctx. | |
1906 | """ |
|
1915 | """ | |
1907 | # fctx should be a filectx (not a workingfilectx) |
|
1916 | # fctx should be a filectx (not a workingfilectx) | |
1908 | # invert comparison to reuse the same code path |
|
1917 | # invert comparison to reuse the same code path | |
1909 | return fctx.cmp(self) |
|
1918 | return fctx.cmp(self) | |
1910 |
|
1919 | |||
1911 | def remove(self, ignoremissing=False): |
|
1920 | def remove(self, ignoremissing=False): | |
1912 | """wraps unlink for a repo's working directory""" |
|
1921 | """wraps unlink for a repo's working directory""" | |
1913 | self._repo.wvfs.unlinkpath(self._path, ignoremissing=ignoremissing) |
|
1922 | self._repo.wvfs.unlinkpath(self._path, ignoremissing=ignoremissing) | |
1914 |
|
1923 | |||
1915 | def write(self, data, flags, backgroundclose=False): |
|
1924 | def write(self, data, flags, backgroundclose=False): | |
1916 | """wraps repo.wwrite""" |
|
1925 | """wraps repo.wwrite""" | |
1917 | self._repo.wwrite(self._path, data, flags, |
|
1926 | self._repo.wwrite(self._path, data, flags, | |
1918 | backgroundclose=backgroundclose) |
|
1927 | backgroundclose=backgroundclose) | |
1919 |
|
1928 | |||
1920 | def clearunknown(self): |
|
1929 | def clearunknown(self): | |
1921 | """Removes conflicting items in the working directory so that |
|
1930 | """Removes conflicting items in the working directory so that | |
1922 | ``write()`` can be called successfully. |
|
1931 | ``write()`` can be called successfully. | |
1923 | """ |
|
1932 | """ | |
1924 | wvfs = self._repo.wvfs |
|
1933 | wvfs = self._repo.wvfs | |
1925 | if wvfs.isdir(self._path) and not wvfs.islink(self._path): |
|
1934 | if wvfs.isdir(self._path) and not wvfs.islink(self._path): | |
1926 | wvfs.removedirs(self._path) |
|
1935 | wvfs.removedirs(self._path) | |
1927 |
|
1936 | |||
1928 | def setflags(self, l, x): |
|
1937 | def setflags(self, l, x): | |
1929 | self._repo.wvfs.setflags(self._path, l, x) |
|
1938 | self._repo.wvfs.setflags(self._path, l, x) | |
1930 |
|
1939 | |||
1931 | class overlayworkingctx(workingctx): |
|
1940 | class overlayworkingctx(workingctx): | |
1932 | """Wraps another mutable context with a write-back cache that can be flushed |
|
1941 | """Wraps another mutable context with a write-back cache that can be flushed | |
1933 | at a later time. |
|
1942 | at a later time. | |
1934 |
|
1943 | |||
1935 | self._cache[path] maps to a dict with keys: { |
|
1944 | self._cache[path] maps to a dict with keys: { | |
1936 | 'exists': bool? |
|
1945 | 'exists': bool? | |
1937 | 'date': date? |
|
1946 | 'date': date? | |
1938 | 'data': str? |
|
1947 | 'data': str? | |
1939 | 'flags': str? |
|
1948 | 'flags': str? | |
1940 | } |
|
1949 | } | |
1941 | If `exists` is True, `flags` must be non-None and 'date' is non-None. If it |
|
1950 | If `exists` is True, `flags` must be non-None and 'date' is non-None. If it | |
1942 | is `False`, the file was deleted. |
|
1951 | is `False`, the file was deleted. | |
1943 | """ |
|
1952 | """ | |
1944 |
|
1953 | |||
1945 | def __init__(self, repo, wrappedctx): |
|
1954 | def __init__(self, repo, wrappedctx): | |
1946 | super(overlayworkingctx, self).__init__(repo) |
|
1955 | super(overlayworkingctx, self).__init__(repo) | |
1947 | self._repo = repo |
|
1956 | self._repo = repo | |
1948 | self._wrappedctx = wrappedctx |
|
1957 | self._wrappedctx = wrappedctx | |
1949 | self._clean() |
|
1958 | self._clean() | |
1950 |
|
1959 | |||
1951 | def data(self, path): |
|
1960 | def data(self, path): | |
1952 | if self.isdirty(path): |
|
1961 | if self.isdirty(path): | |
1953 | if self._cache[path]['exists']: |
|
1962 | if self._cache[path]['exists']: | |
1954 | if self._cache[path]['data']: |
|
1963 | if self._cache[path]['data']: | |
1955 | return self._cache[path]['data'] |
|
1964 | return self._cache[path]['data'] | |
1956 | else: |
|
1965 | else: | |
1957 | # Must fallback here, too, because we only set flags. |
|
1966 | # Must fallback here, too, because we only set flags. | |
1958 | return self._wrappedctx[path].data() |
|
1967 | return self._wrappedctx[path].data() | |
1959 | else: |
|
1968 | else: | |
1960 | raise error.ProgrammingError("No such file or directory: %s" % |
|
1969 | raise error.ProgrammingError("No such file or directory: %s" % | |
1961 | self._path) |
|
1970 | self._path) | |
1962 | else: |
|
1971 | else: | |
1963 | return self._wrappedctx[path].data() |
|
1972 | return self._wrappedctx[path].data() | |
1964 |
|
1973 | |||
1965 | def filedate(self, path): |
|
1974 | def filedate(self, path): | |
1966 | if self.isdirty(path): |
|
1975 | if self.isdirty(path): | |
1967 | return self._cache[path]['date'] |
|
1976 | return self._cache[path]['date'] | |
1968 | else: |
|
1977 | else: | |
1969 | return self._wrappedctx[path].date() |
|
1978 | return self._wrappedctx[path].date() | |
1970 |
|
1979 | |||
1971 | def flags(self, path): |
|
1980 | def flags(self, path): | |
1972 | if self.isdirty(path): |
|
1981 | if self.isdirty(path): | |
1973 | if self._cache[path]['exists']: |
|
1982 | if self._cache[path]['exists']: | |
1974 | return self._cache[path]['flags'] |
|
1983 | return self._cache[path]['flags'] | |
1975 | else: |
|
1984 | else: | |
1976 | raise error.ProgrammingError("No such file or directory: %s" % |
|
1985 | raise error.ProgrammingError("No such file or directory: %s" % | |
1977 | self._path) |
|
1986 | self._path) | |
1978 | else: |
|
1987 | else: | |
1979 | return self._wrappedctx[path].flags() |
|
1988 | return self._wrappedctx[path].flags() | |
1980 |
|
1989 | |||
1981 | def write(self, path, data, flags=''): |
|
1990 | def write(self, path, data, flags=''): | |
1982 | if data is None: |
|
1991 | if data is None: | |
1983 | raise error.ProgrammingError("data must be non-None") |
|
1992 | raise error.ProgrammingError("data must be non-None") | |
1984 | self._markdirty(path, exists=True, data=data, date=util.makedate(), |
|
1993 | self._markdirty(path, exists=True, data=data, date=util.makedate(), | |
1985 | flags=flags) |
|
1994 | flags=flags) | |
1986 |
|
1995 | |||
1987 | def setflags(self, path, l, x): |
|
1996 | def setflags(self, path, l, x): | |
1988 | self._markdirty(path, exists=True, date=util.makedate(), |
|
1997 | self._markdirty(path, exists=True, date=util.makedate(), | |
1989 | flags=(l and 'l' or '') + (x and 'x' or '')) |
|
1998 | flags=(l and 'l' or '') + (x and 'x' or '')) | |
1990 |
|
1999 | |||
1991 | def remove(self, path): |
|
2000 | def remove(self, path): | |
1992 | self._markdirty(path, exists=False) |
|
2001 | self._markdirty(path, exists=False) | |
1993 |
|
2002 | |||
1994 | def exists(self, path): |
|
2003 | def exists(self, path): | |
1995 | """exists behaves like `lexists`, but needs to follow symlinks and |
|
2004 | """exists behaves like `lexists`, but needs to follow symlinks and | |
1996 | return False if they are broken. |
|
2005 | return False if they are broken. | |
1997 | """ |
|
2006 | """ | |
1998 | if self.isdirty(path): |
|
2007 | if self.isdirty(path): | |
1999 | # If this path exists and is a symlink, "follow" it by calling |
|
2008 | # If this path exists and is a symlink, "follow" it by calling | |
2000 | # exists on the destination path. |
|
2009 | # exists on the destination path. | |
2001 | if (self._cache[path]['exists'] and |
|
2010 | if (self._cache[path]['exists'] and | |
2002 | 'l' in self._cache[path]['flags']): |
|
2011 | 'l' in self._cache[path]['flags']): | |
2003 | return self.exists(self._cache[path]['data'].strip()) |
|
2012 | return self.exists(self._cache[path]['data'].strip()) | |
2004 | else: |
|
2013 | else: | |
2005 | return self._cache[path]['exists'] |
|
2014 | return self._cache[path]['exists'] | |
2006 | return self._wrappedctx[path].exists() |
|
2015 | return self._wrappedctx[path].exists() | |
2007 |
|
2016 | |||
2008 | def lexists(self, path): |
|
2017 | def lexists(self, path): | |
2009 | """lexists returns True if the path exists""" |
|
2018 | """lexists returns True if the path exists""" | |
2010 | if self.isdirty(path): |
|
2019 | if self.isdirty(path): | |
2011 | return self._cache[path]['exists'] |
|
2020 | return self._cache[path]['exists'] | |
2012 | return self._wrappedctx[path].lexists() |
|
2021 | return self._wrappedctx[path].lexists() | |
2013 |
|
2022 | |||
2014 | def size(self, path): |
|
2023 | def size(self, path): | |
2015 | if self.isdirty(path): |
|
2024 | if self.isdirty(path): | |
2016 | if self._cache[path]['exists']: |
|
2025 | if self._cache[path]['exists']: | |
2017 | return len(self._cache[path]['data']) |
|
2026 | return len(self._cache[path]['data']) | |
2018 | else: |
|
2027 | else: | |
2019 | raise error.ProgrammingError("No such file or directory: %s" % |
|
2028 | raise error.ProgrammingError("No such file or directory: %s" % | |
2020 | self._path) |
|
2029 | self._path) | |
2021 | return self._wrappedctx[path].size() |
|
2030 | return self._wrappedctx[path].size() | |
2022 |
|
2031 | |||
2023 | def flushall(self): |
|
2032 | def flushall(self): | |
2024 | for path in self._writeorder: |
|
2033 | for path in self._writeorder: | |
2025 | entry = self._cache[path] |
|
2034 | entry = self._cache[path] | |
2026 | if entry['exists']: |
|
2035 | if entry['exists']: | |
2027 | self._wrappedctx[path].clearunknown() |
|
2036 | self._wrappedctx[path].clearunknown() | |
2028 | if entry['data'] is not None: |
|
2037 | if entry['data'] is not None: | |
2029 | if entry['flags'] is None: |
|
2038 | if entry['flags'] is None: | |
2030 | raise error.ProgrammingError('data set but not flags') |
|
2039 | raise error.ProgrammingError('data set but not flags') | |
2031 | self._wrappedctx[path].write( |
|
2040 | self._wrappedctx[path].write( | |
2032 | entry['data'], |
|
2041 | entry['data'], | |
2033 | entry['flags']) |
|
2042 | entry['flags']) | |
2034 | else: |
|
2043 | else: | |
2035 | self._wrappedctx[path].setflags( |
|
2044 | self._wrappedctx[path].setflags( | |
2036 | 'l' in entry['flags'], |
|
2045 | 'l' in entry['flags'], | |
2037 | 'x' in entry['flags']) |
|
2046 | 'x' in entry['flags']) | |
2038 | else: |
|
2047 | else: | |
2039 | self._wrappedctx[path].remove(path) |
|
2048 | self._wrappedctx[path].remove(path) | |
2040 | self._clean() |
|
2049 | self._clean() | |
2041 |
|
2050 | |||
2042 | def isdirty(self, path): |
|
2051 | def isdirty(self, path): | |
2043 | return path in self._cache |
|
2052 | return path in self._cache | |
2044 |
|
2053 | |||
2045 | def _clean(self): |
|
2054 | def _clean(self): | |
2046 | self._cache = {} |
|
2055 | self._cache = {} | |
2047 | self._writeorder = [] |
|
2056 | self._writeorder = [] | |
2048 |
|
2057 | |||
2049 | def _markdirty(self, path, exists, data=None, date=None, flags=''): |
|
2058 | def _markdirty(self, path, exists, data=None, date=None, flags=''): | |
2050 | if path not in self._cache: |
|
2059 | if path not in self._cache: | |
2051 | self._writeorder.append(path) |
|
2060 | self._writeorder.append(path) | |
2052 |
|
2061 | |||
2053 | self._cache[path] = { |
|
2062 | self._cache[path] = { | |
2054 | 'exists': exists, |
|
2063 | 'exists': exists, | |
2055 | 'data': data, |
|
2064 | 'data': data, | |
2056 | 'date': date, |
|
2065 | 'date': date, | |
2057 | 'flags': flags, |
|
2066 | 'flags': flags, | |
2058 | } |
|
2067 | } | |
2059 |
|
2068 | |||
2060 | def filectx(self, path, filelog=None): |
|
2069 | def filectx(self, path, filelog=None): | |
2061 | return overlayworkingfilectx(self._repo, path, parent=self, |
|
2070 | return overlayworkingfilectx(self._repo, path, parent=self, | |
2062 | filelog=filelog) |
|
2071 | filelog=filelog) | |
2063 |
|
2072 | |||
2064 | class overlayworkingfilectx(workingfilectx): |
|
2073 | class overlayworkingfilectx(workingfilectx): | |
2065 | """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory |
|
2074 | """Wrap a ``workingfilectx`` but intercepts all writes into an in-memory | |
2066 | cache, which can be flushed through later by calling ``flush()``.""" |
|
2075 | cache, which can be flushed through later by calling ``flush()``.""" | |
2067 |
|
2076 | |||
2068 | def __init__(self, repo, path, filelog=None, parent=None): |
|
2077 | def __init__(self, repo, path, filelog=None, parent=None): | |
2069 | super(overlayworkingfilectx, self).__init__(repo, path, filelog, |
|
2078 | super(overlayworkingfilectx, self).__init__(repo, path, filelog, | |
2070 | parent) |
|
2079 | parent) | |
2071 | self._repo = repo |
|
2080 | self._repo = repo | |
2072 | self._parent = parent |
|
2081 | self._parent = parent | |
2073 | self._path = path |
|
2082 | self._path = path | |
2074 |
|
2083 | |||
2075 | def ctx(self): |
|
2084 | def ctx(self): | |
2076 | return self._parent |
|
2085 | return self._parent | |
2077 |
|
2086 | |||
2078 | def data(self): |
|
2087 | def data(self): | |
2079 | return self._parent.data(self._path) |
|
2088 | return self._parent.data(self._path) | |
2080 |
|
2089 | |||
2081 | def date(self): |
|
2090 | def date(self): | |
2082 | return self._parent.filedate(self._path) |
|
2091 | return self._parent.filedate(self._path) | |
2083 |
|
2092 | |||
2084 | def exists(self): |
|
2093 | def exists(self): | |
2085 | return self.lexists() |
|
2094 | return self.lexists() | |
2086 |
|
2095 | |||
2087 | def lexists(self): |
|
2096 | def lexists(self): | |
2088 | return self._parent.exists(self._path) |
|
2097 | return self._parent.exists(self._path) | |
2089 |
|
2098 | |||
2090 | def renamed(self): |
|
2099 | def renamed(self): | |
2091 | # Copies are currently tracked in the dirstate as before. Straight copy |
|
2100 | # Copies are currently tracked in the dirstate as before. Straight copy | |
2092 | # from workingfilectx. |
|
2101 | # from workingfilectx. | |
2093 | rp = self._repo.dirstate.copied(self._path) |
|
2102 | rp = self._repo.dirstate.copied(self._path) | |
2094 | if not rp: |
|
2103 | if not rp: | |
2095 | return None |
|
2104 | return None | |
2096 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
|
2105 | return rp, self._changectx._parents[0]._manifest.get(rp, nullid) | |
2097 |
|
2106 | |||
2098 | def size(self): |
|
2107 | def size(self): | |
2099 | return self._parent.size(self._path) |
|
2108 | return self._parent.size(self._path) | |
2100 |
|
2109 | |||
2101 | def audit(self): |
|
2110 | def audit(self): | |
2102 | pass |
|
2111 | pass | |
2103 |
|
2112 | |||
2104 | def flags(self): |
|
2113 | def flags(self): | |
2105 | return self._parent.flags(self._path) |
|
2114 | return self._parent.flags(self._path) | |
2106 |
|
2115 | |||
2107 | def setflags(self, islink, isexec): |
|
2116 | def setflags(self, islink, isexec): | |
2108 | return self._parent.setflags(self._path, islink, isexec) |
|
2117 | return self._parent.setflags(self._path, islink, isexec) | |
2109 |
|
2118 | |||
2110 | def write(self, data, flags, backgroundclose=False): |
|
2119 | def write(self, data, flags, backgroundclose=False): | |
2111 | return self._parent.write(self._path, data, flags) |
|
2120 | return self._parent.write(self._path, data, flags) | |
2112 |
|
2121 | |||
2113 | def remove(self, ignoremissing=False): |
|
2122 | def remove(self, ignoremissing=False): | |
2114 | return self._parent.remove(self._path) |
|
2123 | return self._parent.remove(self._path) | |
2115 |
|
2124 | |||
2116 | class workingcommitctx(workingctx): |
|
2125 | class workingcommitctx(workingctx): | |
2117 | """A workingcommitctx object makes access to data related to |
|
2126 | """A workingcommitctx object makes access to data related to | |
2118 | the revision being committed convenient. |
|
2127 | the revision being committed convenient. | |
2119 |
|
2128 | |||
2120 | This hides changes in the working directory, if they aren't |
|
2129 | This hides changes in the working directory, if they aren't | |
2121 | committed in this context. |
|
2130 | committed in this context. | |
2122 | """ |
|
2131 | """ | |
2123 | def __init__(self, repo, changes, |
|
2132 | def __init__(self, repo, changes, | |
2124 | text="", user=None, date=None, extra=None): |
|
2133 | text="", user=None, date=None, extra=None): | |
2125 | super(workingctx, self).__init__(repo, text, user, date, extra, |
|
2134 | super(workingctx, self).__init__(repo, text, user, date, extra, | |
2126 | changes) |
|
2135 | changes) | |
2127 |
|
2136 | |||
2128 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): |
|
2137 | def _dirstatestatus(self, match, ignored=False, clean=False, unknown=False): | |
2129 | """Return matched files only in ``self._status`` |
|
2138 | """Return matched files only in ``self._status`` | |
2130 |
|
2139 | |||
2131 | Uncommitted files appear "clean" via this context, even if |
|
2140 | Uncommitted files appear "clean" via this context, even if | |
2132 | they aren't actually so in the working directory. |
|
2141 | they aren't actually so in the working directory. | |
2133 | """ |
|
2142 | """ | |
2134 | if clean: |
|
2143 | if clean: | |
2135 | clean = [f for f in self._manifest if f not in self._changedset] |
|
2144 | clean = [f for f in self._manifest if f not in self._changedset] | |
2136 | else: |
|
2145 | else: | |
2137 | clean = [] |
|
2146 | clean = [] | |
2138 | return scmutil.status([f for f in self._status.modified if match(f)], |
|
2147 | return scmutil.status([f for f in self._status.modified if match(f)], | |
2139 | [f for f in self._status.added if match(f)], |
|
2148 | [f for f in self._status.added if match(f)], | |
2140 | [f for f in self._status.removed if match(f)], |
|
2149 | [f for f in self._status.removed if match(f)], | |
2141 | [], [], [], clean) |
|
2150 | [], [], [], clean) | |
2142 |
|
2151 | |||
2143 | @propertycache |
|
2152 | @propertycache | |
2144 | def _changedset(self): |
|
2153 | def _changedset(self): | |
2145 | """Return the set of files changed in this context |
|
2154 | """Return the set of files changed in this context | |
2146 | """ |
|
2155 | """ | |
2147 | changed = set(self._status.modified) |
|
2156 | changed = set(self._status.modified) | |
2148 | changed.update(self._status.added) |
|
2157 | changed.update(self._status.added) | |
2149 | changed.update(self._status.removed) |
|
2158 | changed.update(self._status.removed) | |
2150 | return changed |
|
2159 | return changed | |
2151 |
|
2160 | |||
2152 | def makecachingfilectxfn(func): |
|
2161 | def makecachingfilectxfn(func): | |
2153 | """Create a filectxfn that caches based on the path. |
|
2162 | """Create a filectxfn that caches based on the path. | |
2154 |
|
2163 | |||
2155 | We can't use util.cachefunc because it uses all arguments as the cache |
|
2164 | We can't use util.cachefunc because it uses all arguments as the cache | |
2156 | key and this creates a cycle since the arguments include the repo and |
|
2165 | key and this creates a cycle since the arguments include the repo and | |
2157 | memctx. |
|
2166 | memctx. | |
2158 | """ |
|
2167 | """ | |
2159 | cache = {} |
|
2168 | cache = {} | |
2160 |
|
2169 | |||
2161 | def getfilectx(repo, memctx, path): |
|
2170 | def getfilectx(repo, memctx, path): | |
2162 | if path not in cache: |
|
2171 | if path not in cache: | |
2163 | cache[path] = func(repo, memctx, path) |
|
2172 | cache[path] = func(repo, memctx, path) | |
2164 | return cache[path] |
|
2173 | return cache[path] | |
2165 |
|
2174 | |||
2166 | return getfilectx |
|
2175 | return getfilectx | |
2167 |
|
2176 | |||
2168 | def memfilefromctx(ctx): |
|
2177 | def memfilefromctx(ctx): | |
2169 | """Given a context return a memfilectx for ctx[path] |
|
2178 | """Given a context return a memfilectx for ctx[path] | |
2170 |
|
2179 | |||
2171 | This is a convenience method for building a memctx based on another |
|
2180 | This is a convenience method for building a memctx based on another | |
2172 | context. |
|
2181 | context. | |
2173 | """ |
|
2182 | """ | |
2174 | def getfilectx(repo, memctx, path): |
|
2183 | def getfilectx(repo, memctx, path): | |
2175 | fctx = ctx[path] |
|
2184 | fctx = ctx[path] | |
2176 | # this is weird but apparently we only keep track of one parent |
|
2185 | # this is weird but apparently we only keep track of one parent | |
2177 | # (why not only store that instead of a tuple?) |
|
2186 | # (why not only store that instead of a tuple?) | |
2178 | copied = fctx.renamed() |
|
2187 | copied = fctx.renamed() | |
2179 | if copied: |
|
2188 | if copied: | |
2180 | copied = copied[0] |
|
2189 | copied = copied[0] | |
2181 | return memfilectx(repo, path, fctx.data(), |
|
2190 | return memfilectx(repo, path, fctx.data(), | |
2182 | islink=fctx.islink(), isexec=fctx.isexec(), |
|
2191 | islink=fctx.islink(), isexec=fctx.isexec(), | |
2183 | copied=copied, memctx=memctx) |
|
2192 | copied=copied, memctx=memctx) | |
2184 |
|
2193 | |||
2185 | return getfilectx |
|
2194 | return getfilectx | |
2186 |
|
2195 | |||
2187 | def memfilefrompatch(patchstore): |
|
2196 | def memfilefrompatch(patchstore): | |
2188 | """Given a patch (e.g. patchstore object) return a memfilectx |
|
2197 | """Given a patch (e.g. patchstore object) return a memfilectx | |
2189 |
|
2198 | |||
2190 | This is a convenience method for building a memctx based on a patchstore. |
|
2199 | This is a convenience method for building a memctx based on a patchstore. | |
2191 | """ |
|
2200 | """ | |
2192 | def getfilectx(repo, memctx, path): |
|
2201 | def getfilectx(repo, memctx, path): | |
2193 | data, mode, copied = patchstore.getfile(path) |
|
2202 | data, mode, copied = patchstore.getfile(path) | |
2194 | if data is None: |
|
2203 | if data is None: | |
2195 | return None |
|
2204 | return None | |
2196 | islink, isexec = mode |
|
2205 | islink, isexec = mode | |
2197 | return memfilectx(repo, path, data, islink=islink, |
|
2206 | return memfilectx(repo, path, data, islink=islink, | |
2198 | isexec=isexec, copied=copied, |
|
2207 | isexec=isexec, copied=copied, | |
2199 | memctx=memctx) |
|
2208 | memctx=memctx) | |
2200 |
|
2209 | |||
2201 | return getfilectx |
|
2210 | return getfilectx | |
2202 |
|
2211 | |||
2203 | class memctx(committablectx): |
|
2212 | class memctx(committablectx): | |
2204 | """Use memctx to perform in-memory commits via localrepo.commitctx(). |
|
2213 | """Use memctx to perform in-memory commits via localrepo.commitctx(). | |
2205 |
|
2214 | |||
2206 | Revision information is supplied at initialization time while |
|
2215 | Revision information is supplied at initialization time while | |
2207 | related files data and is made available through a callback |
|
2216 | related files data and is made available through a callback | |
2208 | mechanism. 'repo' is the current localrepo, 'parents' is a |
|
2217 | mechanism. 'repo' is the current localrepo, 'parents' is a | |
2209 | sequence of two parent revisions identifiers (pass None for every |
|
2218 | sequence of two parent revisions identifiers (pass None for every | |
2210 | missing parent), 'text' is the commit message and 'files' lists |
|
2219 | missing parent), 'text' is the commit message and 'files' lists | |
2211 | names of files touched by the revision (normalized and relative to |
|
2220 | names of files touched by the revision (normalized and relative to | |
2212 | repository root). |
|
2221 | repository root). | |
2213 |
|
2222 | |||
2214 | filectxfn(repo, memctx, path) is a callable receiving the |
|
2223 | filectxfn(repo, memctx, path) is a callable receiving the | |
2215 | repository, the current memctx object and the normalized path of |
|
2224 | repository, the current memctx object and the normalized path of | |
2216 | requested file, relative to repository root. It is fired by the |
|
2225 | requested file, relative to repository root. It is fired by the | |
2217 | commit function for every file in 'files', but calls order is |
|
2226 | commit function for every file in 'files', but calls order is | |
2218 | undefined. If the file is available in the revision being |
|
2227 | undefined. If the file is available in the revision being | |
2219 | committed (updated or added), filectxfn returns a memfilectx |
|
2228 | committed (updated or added), filectxfn returns a memfilectx | |
2220 | object. If the file was removed, filectxfn return None for recent |
|
2229 | object. If the file was removed, filectxfn return None for recent | |
2221 | Mercurial. Moved files are represented by marking the source file |
|
2230 | Mercurial. Moved files are represented by marking the source file | |
2222 | removed and the new file added with copy information (see |
|
2231 | removed and the new file added with copy information (see | |
2223 | memfilectx). |
|
2232 | memfilectx). | |
2224 |
|
2233 | |||
2225 | user receives the committer name and defaults to current |
|
2234 | user receives the committer name and defaults to current | |
2226 | repository username, date is the commit date in any format |
|
2235 | repository username, date is the commit date in any format | |
2227 | supported by util.parsedate() and defaults to current date, extra |
|
2236 | supported by util.parsedate() and defaults to current date, extra | |
2228 | is a dictionary of metadata or is left empty. |
|
2237 | is a dictionary of metadata or is left empty. | |
2229 | """ |
|
2238 | """ | |
2230 |
|
2239 | |||
2231 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. |
|
2240 | # Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files. | |
2232 | # Extensions that need to retain compatibility across Mercurial 3.1 can use |
|
2241 | # Extensions that need to retain compatibility across Mercurial 3.1 can use | |
2233 | # this field to determine what to do in filectxfn. |
|
2242 | # this field to determine what to do in filectxfn. | |
2234 | _returnnoneformissingfiles = True |
|
2243 | _returnnoneformissingfiles = True | |
2235 |
|
2244 | |||
2236 | def __init__(self, repo, parents, text, files, filectxfn, user=None, |
|
2245 | def __init__(self, repo, parents, text, files, filectxfn, user=None, | |
2237 | date=None, extra=None, branch=None, editor=False): |
|
2246 | date=None, extra=None, branch=None, editor=False): | |
2238 | super(memctx, self).__init__(repo, text, user, date, extra) |
|
2247 | super(memctx, self).__init__(repo, text, user, date, extra) | |
2239 | self._rev = None |
|
2248 | self._rev = None | |
2240 | self._node = None |
|
2249 | self._node = None | |
2241 | parents = [(p or nullid) for p in parents] |
|
2250 | parents = [(p or nullid) for p in parents] | |
2242 | p1, p2 = parents |
|
2251 | p1, p2 = parents | |
2243 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
|
2252 | self._parents = [changectx(self._repo, p) for p in (p1, p2)] | |
2244 | files = sorted(set(files)) |
|
2253 | files = sorted(set(files)) | |
2245 | self._files = files |
|
2254 | self._files = files | |
2246 | if branch is not None: |
|
2255 | if branch is not None: | |
2247 | self._extra['branch'] = encoding.fromlocal(branch) |
|
2256 | self._extra['branch'] = encoding.fromlocal(branch) | |
2248 | self.substate = {} |
|
2257 | self.substate = {} | |
2249 |
|
2258 | |||
2250 | if isinstance(filectxfn, patch.filestore): |
|
2259 | if isinstance(filectxfn, patch.filestore): | |
2251 | filectxfn = memfilefrompatch(filectxfn) |
|
2260 | filectxfn = memfilefrompatch(filectxfn) | |
2252 | elif not callable(filectxfn): |
|
2261 | elif not callable(filectxfn): | |
2253 | # if store is not callable, wrap it in a function |
|
2262 | # if store is not callable, wrap it in a function | |
2254 | filectxfn = memfilefromctx(filectxfn) |
|
2263 | filectxfn = memfilefromctx(filectxfn) | |
2255 |
|
2264 | |||
2256 | # memoizing increases performance for e.g. vcs convert scenarios. |
|
2265 | # memoizing increases performance for e.g. vcs convert scenarios. | |
2257 | self._filectxfn = makecachingfilectxfn(filectxfn) |
|
2266 | self._filectxfn = makecachingfilectxfn(filectxfn) | |
2258 |
|
2267 | |||
2259 | if editor: |
|
2268 | if editor: | |
2260 | self._text = editor(self._repo, self, []) |
|
2269 | self._text = editor(self._repo, self, []) | |
2261 | self._repo.savecommitmessage(self._text) |
|
2270 | self._repo.savecommitmessage(self._text) | |
2262 |
|
2271 | |||
2263 | def filectx(self, path, filelog=None): |
|
2272 | def filectx(self, path, filelog=None): | |
2264 | """get a file context from the working directory |
|
2273 | """get a file context from the working directory | |
2265 |
|
2274 | |||
2266 | Returns None if file doesn't exist and should be removed.""" |
|
2275 | Returns None if file doesn't exist and should be removed.""" | |
2267 | return self._filectxfn(self._repo, self, path) |
|
2276 | return self._filectxfn(self._repo, self, path) | |
2268 |
|
2277 | |||
2269 | def commit(self): |
|
2278 | def commit(self): | |
2270 | """commit context to the repo""" |
|
2279 | """commit context to the repo""" | |
2271 | return self._repo.commitctx(self) |
|
2280 | return self._repo.commitctx(self) | |
2272 |
|
2281 | |||
2273 | @propertycache |
|
2282 | @propertycache | |
2274 | def _manifest(self): |
|
2283 | def _manifest(self): | |
2275 | """generate a manifest based on the return values of filectxfn""" |
|
2284 | """generate a manifest based on the return values of filectxfn""" | |
2276 |
|
2285 | |||
2277 | # keep this simple for now; just worry about p1 |
|
2286 | # keep this simple for now; just worry about p1 | |
2278 | pctx = self._parents[0] |
|
2287 | pctx = self._parents[0] | |
2279 | man = pctx.manifest().copy() |
|
2288 | man = pctx.manifest().copy() | |
2280 |
|
2289 | |||
2281 | for f in self._status.modified: |
|
2290 | for f in self._status.modified: | |
2282 | p1node = nullid |
|
2291 | p1node = nullid | |
2283 | p2node = nullid |
|
2292 | p2node = nullid | |
2284 | p = pctx[f].parents() # if file isn't in pctx, check p2? |
|
2293 | p = pctx[f].parents() # if file isn't in pctx, check p2? | |
2285 | if len(p) > 0: |
|
2294 | if len(p) > 0: | |
2286 | p1node = p[0].filenode() |
|
2295 | p1node = p[0].filenode() | |
2287 | if len(p) > 1: |
|
2296 | if len(p) > 1: | |
2288 | p2node = p[1].filenode() |
|
2297 | p2node = p[1].filenode() | |
2289 | man[f] = revlog.hash(self[f].data(), p1node, p2node) |
|
2298 | man[f] = revlog.hash(self[f].data(), p1node, p2node) | |
2290 |
|
2299 | |||
2291 | for f in self._status.added: |
|
2300 | for f in self._status.added: | |
2292 | man[f] = revlog.hash(self[f].data(), nullid, nullid) |
|
2301 | man[f] = revlog.hash(self[f].data(), nullid, nullid) | |
2293 |
|
2302 | |||
2294 | for f in self._status.removed: |
|
2303 | for f in self._status.removed: | |
2295 | if f in man: |
|
2304 | if f in man: | |
2296 | del man[f] |
|
2305 | del man[f] | |
2297 |
|
2306 | |||
2298 | return man |
|
2307 | return man | |
2299 |
|
2308 | |||
2300 | @propertycache |
|
2309 | @propertycache | |
2301 | def _status(self): |
|
2310 | def _status(self): | |
2302 | """Calculate exact status from ``files`` specified at construction |
|
2311 | """Calculate exact status from ``files`` specified at construction | |
2303 | """ |
|
2312 | """ | |
2304 | man1 = self.p1().manifest() |
|
2313 | man1 = self.p1().manifest() | |
2305 | p2 = self._parents[1] |
|
2314 | p2 = self._parents[1] | |
2306 | # "1 < len(self._parents)" can't be used for checking |
|
2315 | # "1 < len(self._parents)" can't be used for checking | |
2307 | # existence of the 2nd parent, because "memctx._parents" is |
|
2316 | # existence of the 2nd parent, because "memctx._parents" is | |
2308 | # explicitly initialized by the list, of which length is 2. |
|
2317 | # explicitly initialized by the list, of which length is 2. | |
2309 | if p2.node() != nullid: |
|
2318 | if p2.node() != nullid: | |
2310 | man2 = p2.manifest() |
|
2319 | man2 = p2.manifest() | |
2311 | managing = lambda f: f in man1 or f in man2 |
|
2320 | managing = lambda f: f in man1 or f in man2 | |
2312 | else: |
|
2321 | else: | |
2313 | managing = lambda f: f in man1 |
|
2322 | managing = lambda f: f in man1 | |
2314 |
|
2323 | |||
2315 | modified, added, removed = [], [], [] |
|
2324 | modified, added, removed = [], [], [] | |
2316 | for f in self._files: |
|
2325 | for f in self._files: | |
2317 | if not managing(f): |
|
2326 | if not managing(f): | |
2318 | added.append(f) |
|
2327 | added.append(f) | |
2319 | elif self[f]: |
|
2328 | elif self[f]: | |
2320 | modified.append(f) |
|
2329 | modified.append(f) | |
2321 | else: |
|
2330 | else: | |
2322 | removed.append(f) |
|
2331 | removed.append(f) | |
2323 |
|
2332 | |||
2324 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2333 | return scmutil.status(modified, added, removed, [], [], [], []) | |
2325 |
|
2334 | |||
2326 | class memfilectx(committablefilectx): |
|
2335 | class memfilectx(committablefilectx): | |
2327 | """memfilectx represents an in-memory file to commit. |
|
2336 | """memfilectx represents an in-memory file to commit. | |
2328 |
|
2337 | |||
2329 | See memctx and committablefilectx for more details. |
|
2338 | See memctx and committablefilectx for more details. | |
2330 | """ |
|
2339 | """ | |
2331 | def __init__(self, repo, path, data, islink=False, |
|
2340 | def __init__(self, repo, path, data, islink=False, | |
2332 | isexec=False, copied=None, memctx=None): |
|
2341 | isexec=False, copied=None, memctx=None): | |
2333 | """ |
|
2342 | """ | |
2334 | path is the normalized file path relative to repository root. |
|
2343 | path is the normalized file path relative to repository root. | |
2335 | data is the file content as a string. |
|
2344 | data is the file content as a string. | |
2336 | islink is True if the file is a symbolic link. |
|
2345 | islink is True if the file is a symbolic link. | |
2337 | isexec is True if the file is executable. |
|
2346 | isexec is True if the file is executable. | |
2338 | copied is the source file path if current file was copied in the |
|
2347 | copied is the source file path if current file was copied in the | |
2339 | revision being committed, or None.""" |
|
2348 | revision being committed, or None.""" | |
2340 | super(memfilectx, self).__init__(repo, path, None, memctx) |
|
2349 | super(memfilectx, self).__init__(repo, path, None, memctx) | |
2341 | self._data = data |
|
2350 | self._data = data | |
2342 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
|
2351 | self._flags = (islink and 'l' or '') + (isexec and 'x' or '') | |
2343 | self._copied = None |
|
2352 | self._copied = None | |
2344 | if copied: |
|
2353 | if copied: | |
2345 | self._copied = (copied, nullid) |
|
2354 | self._copied = (copied, nullid) | |
2346 |
|
2355 | |||
2347 | def data(self): |
|
2356 | def data(self): | |
2348 | return self._data |
|
2357 | return self._data | |
2349 |
|
2358 | |||
2350 | def remove(self, ignoremissing=False): |
|
2359 | def remove(self, ignoremissing=False): | |
2351 | """wraps unlink for a repo's working directory""" |
|
2360 | """wraps unlink for a repo's working directory""" | |
2352 | # need to figure out what to do here |
|
2361 | # need to figure out what to do here | |
2353 | del self._changectx[self._path] |
|
2362 | del self._changectx[self._path] | |
2354 |
|
2363 | |||
2355 | def write(self, data, flags): |
|
2364 | def write(self, data, flags): | |
2356 | """wraps repo.wwrite""" |
|
2365 | """wraps repo.wwrite""" | |
2357 | self._data = data |
|
2366 | self._data = data | |
2358 |
|
2367 | |||
2359 | class overlayfilectx(committablefilectx): |
|
2368 | class overlayfilectx(committablefilectx): | |
2360 | """Like memfilectx but take an original filectx and optional parameters to |
|
2369 | """Like memfilectx but take an original filectx and optional parameters to | |
2361 | override parts of it. This is useful when fctx.data() is expensive (i.e. |
|
2370 | override parts of it. This is useful when fctx.data() is expensive (i.e. | |
2362 | flag processor is expensive) and raw data, flags, and filenode could be |
|
2371 | flag processor is expensive) and raw data, flags, and filenode could be | |
2363 | reused (ex. rebase or mode-only amend a REVIDX_EXTSTORED file). |
|
2372 | reused (ex. rebase or mode-only amend a REVIDX_EXTSTORED file). | |
2364 | """ |
|
2373 | """ | |
2365 |
|
2374 | |||
2366 | def __init__(self, originalfctx, datafunc=None, path=None, flags=None, |
|
2375 | def __init__(self, originalfctx, datafunc=None, path=None, flags=None, | |
2367 | copied=None, ctx=None): |
|
2376 | copied=None, ctx=None): | |
2368 | """originalfctx: filecontext to duplicate |
|
2377 | """originalfctx: filecontext to duplicate | |
2369 |
|
2378 | |||
2370 | datafunc: None or a function to override data (file content). It is a |
|
2379 | datafunc: None or a function to override data (file content). It is a | |
2371 | function to be lazy. path, flags, copied, ctx: None or overridden value |
|
2380 | function to be lazy. path, flags, copied, ctx: None or overridden value | |
2372 |
|
2381 | |||
2373 | copied could be (path, rev), or False. copied could also be just path, |
|
2382 | copied could be (path, rev), or False. copied could also be just path, | |
2374 | and will be converted to (path, nullid). This simplifies some callers. |
|
2383 | and will be converted to (path, nullid). This simplifies some callers. | |
2375 | """ |
|
2384 | """ | |
2376 |
|
2385 | |||
2377 | if path is None: |
|
2386 | if path is None: | |
2378 | path = originalfctx.path() |
|
2387 | path = originalfctx.path() | |
2379 | if ctx is None: |
|
2388 | if ctx is None: | |
2380 | ctx = originalfctx.changectx() |
|
2389 | ctx = originalfctx.changectx() | |
2381 | ctxmatch = lambda: True |
|
2390 | ctxmatch = lambda: True | |
2382 | else: |
|
2391 | else: | |
2383 | ctxmatch = lambda: ctx == originalfctx.changectx() |
|
2392 | ctxmatch = lambda: ctx == originalfctx.changectx() | |
2384 |
|
2393 | |||
2385 | repo = originalfctx.repo() |
|
2394 | repo = originalfctx.repo() | |
2386 | flog = originalfctx.filelog() |
|
2395 | flog = originalfctx.filelog() | |
2387 | super(overlayfilectx, self).__init__(repo, path, flog, ctx) |
|
2396 | super(overlayfilectx, self).__init__(repo, path, flog, ctx) | |
2388 |
|
2397 | |||
2389 | if copied is None: |
|
2398 | if copied is None: | |
2390 | copied = originalfctx.renamed() |
|
2399 | copied = originalfctx.renamed() | |
2391 | copiedmatch = lambda: True |
|
2400 | copiedmatch = lambda: True | |
2392 | else: |
|
2401 | else: | |
2393 | if copied and not isinstance(copied, tuple): |
|
2402 | if copied and not isinstance(copied, tuple): | |
2394 | # repo._filecommit will recalculate copyrev so nullid is okay |
|
2403 | # repo._filecommit will recalculate copyrev so nullid is okay | |
2395 | copied = (copied, nullid) |
|
2404 | copied = (copied, nullid) | |
2396 | copiedmatch = lambda: copied == originalfctx.renamed() |
|
2405 | copiedmatch = lambda: copied == originalfctx.renamed() | |
2397 |
|
2406 | |||
2398 | # When data, copied (could affect data), ctx (could affect filelog |
|
2407 | # When data, copied (could affect data), ctx (could affect filelog | |
2399 | # parents) are not overridden, rawdata, rawflags, and filenode may be |
|
2408 | # parents) are not overridden, rawdata, rawflags, and filenode may be | |
2400 | # reused (repo._filecommit should double check filelog parents). |
|
2409 | # reused (repo._filecommit should double check filelog parents). | |
2401 | # |
|
2410 | # | |
2402 | # path, flags are not hashed in filelog (but in manifestlog) so they do |
|
2411 | # path, flags are not hashed in filelog (but in manifestlog) so they do | |
2403 | # not affect reusable here. |
|
2412 | # not affect reusable here. | |
2404 | # |
|
2413 | # | |
2405 | # If ctx or copied is overridden to a same value with originalfctx, |
|
2414 | # If ctx or copied is overridden to a same value with originalfctx, | |
2406 | # still consider it's reusable. originalfctx.renamed() may be a bit |
|
2415 | # still consider it's reusable. originalfctx.renamed() may be a bit | |
2407 | # expensive so it's not called unless necessary. Assuming datafunc is |
|
2416 | # expensive so it's not called unless necessary. Assuming datafunc is | |
2408 | # always expensive, do not call it for this "reusable" test. |
|
2417 | # always expensive, do not call it for this "reusable" test. | |
2409 | reusable = datafunc is None and ctxmatch() and copiedmatch() |
|
2418 | reusable = datafunc is None and ctxmatch() and copiedmatch() | |
2410 |
|
2419 | |||
2411 | if datafunc is None: |
|
2420 | if datafunc is None: | |
2412 | datafunc = originalfctx.data |
|
2421 | datafunc = originalfctx.data | |
2413 | if flags is None: |
|
2422 | if flags is None: | |
2414 | flags = originalfctx.flags() |
|
2423 | flags = originalfctx.flags() | |
2415 |
|
2424 | |||
2416 | self._datafunc = datafunc |
|
2425 | self._datafunc = datafunc | |
2417 | self._flags = flags |
|
2426 | self._flags = flags | |
2418 | self._copied = copied |
|
2427 | self._copied = copied | |
2419 |
|
2428 | |||
2420 | if reusable: |
|
2429 | if reusable: | |
2421 | # copy extra fields from originalfctx |
|
2430 | # copy extra fields from originalfctx | |
2422 | attrs = ['rawdata', 'rawflags', '_filenode', '_filerev'] |
|
2431 | attrs = ['rawdata', 'rawflags', '_filenode', '_filerev'] | |
2423 | for attr_ in attrs: |
|
2432 | for attr_ in attrs: | |
2424 | if util.safehasattr(originalfctx, attr_): |
|
2433 | if util.safehasattr(originalfctx, attr_): | |
2425 | setattr(self, attr_, getattr(originalfctx, attr_)) |
|
2434 | setattr(self, attr_, getattr(originalfctx, attr_)) | |
2426 |
|
2435 | |||
2427 | def data(self): |
|
2436 | def data(self): | |
2428 | return self._datafunc() |
|
2437 | return self._datafunc() | |
2429 |
|
2438 | |||
2430 | class metadataonlyctx(committablectx): |
|
2439 | class metadataonlyctx(committablectx): | |
2431 | """Like memctx but it's reusing the manifest of different commit. |
|
2440 | """Like memctx but it's reusing the manifest of different commit. | |
2432 | Intended to be used by lightweight operations that are creating |
|
2441 | Intended to be used by lightweight operations that are creating | |
2433 | metadata-only changes. |
|
2442 | metadata-only changes. | |
2434 |
|
2443 | |||
2435 | Revision information is supplied at initialization time. 'repo' is the |
|
2444 | Revision information is supplied at initialization time. 'repo' is the | |
2436 | current localrepo, 'ctx' is original revision which manifest we're reuisng |
|
2445 | current localrepo, 'ctx' is original revision which manifest we're reuisng | |
2437 | 'parents' is a sequence of two parent revisions identifiers (pass None for |
|
2446 | 'parents' is a sequence of two parent revisions identifiers (pass None for | |
2438 | every missing parent), 'text' is the commit. |
|
2447 | every missing parent), 'text' is the commit. | |
2439 |
|
2448 | |||
2440 | user receives the committer name and defaults to current repository |
|
2449 | user receives the committer name and defaults to current repository | |
2441 | username, date is the commit date in any format supported by |
|
2450 | username, date is the commit date in any format supported by | |
2442 | util.parsedate() and defaults to current date, extra is a dictionary of |
|
2451 | util.parsedate() and defaults to current date, extra is a dictionary of | |
2443 | metadata or is left empty. |
|
2452 | metadata or is left empty. | |
2444 | """ |
|
2453 | """ | |
2445 | def __new__(cls, repo, originalctx, *args, **kwargs): |
|
2454 | def __new__(cls, repo, originalctx, *args, **kwargs): | |
2446 | return super(metadataonlyctx, cls).__new__(cls, repo) |
|
2455 | return super(metadataonlyctx, cls).__new__(cls, repo) | |
2447 |
|
2456 | |||
2448 | def __init__(self, repo, originalctx, parents=None, text=None, user=None, |
|
2457 | def __init__(self, repo, originalctx, parents=None, text=None, user=None, | |
2449 | date=None, extra=None, editor=False): |
|
2458 | date=None, extra=None, editor=False): | |
2450 | if text is None: |
|
2459 | if text is None: | |
2451 | text = originalctx.description() |
|
2460 | text = originalctx.description() | |
2452 | super(metadataonlyctx, self).__init__(repo, text, user, date, extra) |
|
2461 | super(metadataonlyctx, self).__init__(repo, text, user, date, extra) | |
2453 | self._rev = None |
|
2462 | self._rev = None | |
2454 | self._node = None |
|
2463 | self._node = None | |
2455 | self._originalctx = originalctx |
|
2464 | self._originalctx = originalctx | |
2456 | self._manifestnode = originalctx.manifestnode() |
|
2465 | self._manifestnode = originalctx.manifestnode() | |
2457 | if parents is None: |
|
2466 | if parents is None: | |
2458 | parents = originalctx.parents() |
|
2467 | parents = originalctx.parents() | |
2459 | else: |
|
2468 | else: | |
2460 | parents = [repo[p] for p in parents if p is not None] |
|
2469 | parents = [repo[p] for p in parents if p is not None] | |
2461 | parents = parents[:] |
|
2470 | parents = parents[:] | |
2462 | while len(parents) < 2: |
|
2471 | while len(parents) < 2: | |
2463 | parents.append(repo[nullid]) |
|
2472 | parents.append(repo[nullid]) | |
2464 | p1, p2 = self._parents = parents |
|
2473 | p1, p2 = self._parents = parents | |
2465 |
|
2474 | |||
2466 | # sanity check to ensure that the reused manifest parents are |
|
2475 | # sanity check to ensure that the reused manifest parents are | |
2467 | # manifests of our commit parents |
|
2476 | # manifests of our commit parents | |
2468 | mp1, mp2 = self.manifestctx().parents |
|
2477 | mp1, mp2 = self.manifestctx().parents | |
2469 | if p1 != nullid and p1.manifestnode() != mp1: |
|
2478 | if p1 != nullid and p1.manifestnode() != mp1: | |
2470 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2479 | raise RuntimeError('can\'t reuse the manifest: ' | |
2471 | 'its p1 doesn\'t match the new ctx p1') |
|
2480 | 'its p1 doesn\'t match the new ctx p1') | |
2472 | if p2 != nullid and p2.manifestnode() != mp2: |
|
2481 | if p2 != nullid and p2.manifestnode() != mp2: | |
2473 | raise RuntimeError('can\'t reuse the manifest: ' |
|
2482 | raise RuntimeError('can\'t reuse the manifest: ' | |
2474 | 'its p2 doesn\'t match the new ctx p2') |
|
2483 | 'its p2 doesn\'t match the new ctx p2') | |
2475 |
|
2484 | |||
2476 | self._files = originalctx.files() |
|
2485 | self._files = originalctx.files() | |
2477 | self.substate = {} |
|
2486 | self.substate = {} | |
2478 |
|
2487 | |||
2479 | if editor: |
|
2488 | if editor: | |
2480 | self._text = editor(self._repo, self, []) |
|
2489 | self._text = editor(self._repo, self, []) | |
2481 | self._repo.savecommitmessage(self._text) |
|
2490 | self._repo.savecommitmessage(self._text) | |
2482 |
|
2491 | |||
2483 | def manifestnode(self): |
|
2492 | def manifestnode(self): | |
2484 | return self._manifestnode |
|
2493 | return self._manifestnode | |
2485 |
|
2494 | |||
2486 | @property |
|
2495 | @property | |
2487 | def _manifestctx(self): |
|
2496 | def _manifestctx(self): | |
2488 | return self._repo.manifestlog[self._manifestnode] |
|
2497 | return self._repo.manifestlog[self._manifestnode] | |
2489 |
|
2498 | |||
2490 | def filectx(self, path, filelog=None): |
|
2499 | def filectx(self, path, filelog=None): | |
2491 | return self._originalctx.filectx(path, filelog=filelog) |
|
2500 | return self._originalctx.filectx(path, filelog=filelog) | |
2492 |
|
2501 | |||
2493 | def commit(self): |
|
2502 | def commit(self): | |
2494 | """commit context to the repo""" |
|
2503 | """commit context to the repo""" | |
2495 | return self._repo.commitctx(self) |
|
2504 | return self._repo.commitctx(self) | |
2496 |
|
2505 | |||
2497 | @property |
|
2506 | @property | |
2498 | def _manifest(self): |
|
2507 | def _manifest(self): | |
2499 | return self._originalctx.manifest() |
|
2508 | return self._originalctx.manifest() | |
2500 |
|
2509 | |||
2501 | @propertycache |
|
2510 | @propertycache | |
2502 | def _status(self): |
|
2511 | def _status(self): | |
2503 | """Calculate exact status from ``files`` specified in the ``origctx`` |
|
2512 | """Calculate exact status from ``files`` specified in the ``origctx`` | |
2504 | and parents manifests. |
|
2513 | and parents manifests. | |
2505 | """ |
|
2514 | """ | |
2506 | man1 = self.p1().manifest() |
|
2515 | man1 = self.p1().manifest() | |
2507 | p2 = self._parents[1] |
|
2516 | p2 = self._parents[1] | |
2508 | # "1 < len(self._parents)" can't be used for checking |
|
2517 | # "1 < len(self._parents)" can't be used for checking | |
2509 | # existence of the 2nd parent, because "metadataonlyctx._parents" is |
|
2518 | # existence of the 2nd parent, because "metadataonlyctx._parents" is | |
2510 | # explicitly initialized by the list, of which length is 2. |
|
2519 | # explicitly initialized by the list, of which length is 2. | |
2511 | if p2.node() != nullid: |
|
2520 | if p2.node() != nullid: | |
2512 | man2 = p2.manifest() |
|
2521 | man2 = p2.manifest() | |
2513 | managing = lambda f: f in man1 or f in man2 |
|
2522 | managing = lambda f: f in man1 or f in man2 | |
2514 | else: |
|
2523 | else: | |
2515 | managing = lambda f: f in man1 |
|
2524 | managing = lambda f: f in man1 | |
2516 |
|
2525 | |||
2517 | modified, added, removed = [], [], [] |
|
2526 | modified, added, removed = [], [], [] | |
2518 | for f in self._files: |
|
2527 | for f in self._files: | |
2519 | if not managing(f): |
|
2528 | if not managing(f): | |
2520 | added.append(f) |
|
2529 | added.append(f) | |
2521 | elif f in self: |
|
2530 | elif f in self: | |
2522 | modified.append(f) |
|
2531 | modified.append(f) | |
2523 | else: |
|
2532 | else: | |
2524 | removed.append(f) |
|
2533 | removed.append(f) | |
2525 |
|
2534 | |||
2526 | return scmutil.status(modified, added, removed, [], [], [], []) |
|
2535 | return scmutil.status(modified, added, removed, [], [], [], []) | |
2527 |
|
2536 | |||
2528 | class arbitraryfilectx(object): |
|
2537 | class arbitraryfilectx(object): | |
2529 | """Allows you to use filectx-like functions on a file in an arbitrary |
|
2538 | """Allows you to use filectx-like functions on a file in an arbitrary | |
2530 | location on disk, possibly not in the working directory. |
|
2539 | location on disk, possibly not in the working directory. | |
2531 | """ |
|
2540 | """ | |
2532 | def __init__(self, path): |
|
2541 | def __init__(self, path): | |
2533 | self._path = path |
|
2542 | self._path = path | |
2534 |
|
2543 | |||
2535 | def cmp(self, otherfilectx): |
|
2544 | def cmp(self, otherfilectx): | |
2536 | return self.data() != otherfilectx.data() |
|
2545 | return self.data() != otherfilectx.data() | |
2537 |
|
2546 | |||
2538 | def path(self): |
|
2547 | def path(self): | |
2539 | return self._path |
|
2548 | return self._path | |
2540 |
|
2549 | |||
2541 | def flags(self): |
|
2550 | def flags(self): | |
2542 | return '' |
|
2551 | return '' | |
2543 |
|
2552 | |||
2544 | def data(self): |
|
2553 | def data(self): | |
2545 | return util.readfile(self._path) |
|
2554 | return util.readfile(self._path) | |
2546 |
|
2555 | |||
2547 | def decodeddata(self): |
|
2556 | def decodeddata(self): | |
2548 | with open(self._path, "rb") as f: |
|
2557 | with open(self._path, "rb") as f: | |
2549 | return f.read() |
|
2558 | return f.read() | |
2550 |
|
2559 | |||
2551 | def remove(self): |
|
2560 | def remove(self): | |
2552 | util.unlink(self._path) |
|
2561 | util.unlink(self._path) | |
2553 |
|
2562 | |||
2554 | def write(self, data, flags): |
|
2563 | def write(self, data, flags): | |
2555 | assert not flags |
|
2564 | assert not flags | |
2556 | with open(self._path, "w") as f: |
|
2565 | with open(self._path, "w") as f: | |
2557 | f.write(data) |
|
2566 | f.write(data) |
@@ -1,1399 +1,1400 | |||||
1 | # |
|
1 | # | |
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | |
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 cgi |
|
10 | import cgi | |
11 | import copy |
|
11 | import copy | |
12 | import mimetypes |
|
12 | import mimetypes | |
13 | import os |
|
13 | import os | |
14 | import re |
|
14 | import re | |
15 |
|
15 | |||
16 | from ..i18n import _ |
|
16 | from ..i18n import _ | |
17 | from ..node import hex, short |
|
17 | from ..node import hex, short | |
18 |
|
18 | |||
19 | from .common import ( |
|
19 | from .common import ( | |
20 | ErrorResponse, |
|
20 | ErrorResponse, | |
21 | HTTP_FORBIDDEN, |
|
21 | HTTP_FORBIDDEN, | |
22 | HTTP_NOT_FOUND, |
|
22 | HTTP_NOT_FOUND, | |
23 | HTTP_OK, |
|
23 | HTTP_OK, | |
24 | get_contact, |
|
24 | get_contact, | |
25 | paritygen, |
|
25 | paritygen, | |
26 | staticfile, |
|
26 | staticfile, | |
27 | ) |
|
27 | ) | |
28 |
|
28 | |||
29 | from .. import ( |
|
29 | from .. import ( | |
30 | archival, |
|
30 | archival, | |
31 | dagop, |
|
31 | dagop, | |
32 | encoding, |
|
32 | encoding, | |
33 | error, |
|
33 | error, | |
34 | graphmod, |
|
34 | graphmod, | |
35 | revset, |
|
35 | revset, | |
36 | revsetlang, |
|
36 | revsetlang, | |
37 | scmutil, |
|
37 | scmutil, | |
38 | smartset, |
|
38 | smartset, | |
39 | templatefilters, |
|
39 | templatefilters, | |
40 | templater, |
|
40 | templater, | |
41 | util, |
|
41 | util, | |
42 | ) |
|
42 | ) | |
43 |
|
43 | |||
44 | from . import ( |
|
44 | from . import ( | |
45 | webutil, |
|
45 | webutil, | |
46 | ) |
|
46 | ) | |
47 |
|
47 | |||
48 | __all__ = [] |
|
48 | __all__ = [] | |
49 | commands = {} |
|
49 | commands = {} | |
50 |
|
50 | |||
51 | class webcommand(object): |
|
51 | class webcommand(object): | |
52 | """Decorator used to register a web command handler. |
|
52 | """Decorator used to register a web command handler. | |
53 |
|
53 | |||
54 | The decorator takes as its positional arguments the name/path the |
|
54 | The decorator takes as its positional arguments the name/path the | |
55 | command should be accessible under. |
|
55 | command should be accessible under. | |
56 |
|
56 | |||
57 | Usage: |
|
57 | Usage: | |
58 |
|
58 | |||
59 | @webcommand('mycommand') |
|
59 | @webcommand('mycommand') | |
60 | def mycommand(web, req, tmpl): |
|
60 | def mycommand(web, req, tmpl): | |
61 | pass |
|
61 | pass | |
62 | """ |
|
62 | """ | |
63 |
|
63 | |||
64 | def __init__(self, name): |
|
64 | def __init__(self, name): | |
65 | self.name = name |
|
65 | self.name = name | |
66 |
|
66 | |||
67 | def __call__(self, func): |
|
67 | def __call__(self, func): | |
68 | __all__.append(self.name) |
|
68 | __all__.append(self.name) | |
69 | commands[self.name] = func |
|
69 | commands[self.name] = func | |
70 | return func |
|
70 | return func | |
71 |
|
71 | |||
72 | @webcommand('log') |
|
72 | @webcommand('log') | |
73 | def log(web, req, tmpl): |
|
73 | def log(web, req, tmpl): | |
74 | """ |
|
74 | """ | |
75 | /log[/{revision}[/{path}]] |
|
75 | /log[/{revision}[/{path}]] | |
76 | -------------------------- |
|
76 | -------------------------- | |
77 |
|
77 | |||
78 | Show repository or file history. |
|
78 | Show repository or file history. | |
79 |
|
79 | |||
80 | For URLs of the form ``/log/{revision}``, a list of changesets starting at |
|
80 | For URLs of the form ``/log/{revision}``, a list of changesets starting at | |
81 | the specified changeset identifier is shown. If ``{revision}`` is not |
|
81 | the specified changeset identifier is shown. If ``{revision}`` is not | |
82 | defined, the default is ``tip``. This form is equivalent to the |
|
82 | defined, the default is ``tip``. This form is equivalent to the | |
83 | ``changelog`` handler. |
|
83 | ``changelog`` handler. | |
84 |
|
84 | |||
85 | For URLs of the form ``/log/{revision}/{file}``, the history for a specific |
|
85 | For URLs of the form ``/log/{revision}/{file}``, the history for a specific | |
86 | file will be shown. This form is equivalent to the ``filelog`` handler. |
|
86 | file will be shown. This form is equivalent to the ``filelog`` handler. | |
87 | """ |
|
87 | """ | |
88 |
|
88 | |||
89 | if 'file' in req.form and req.form['file'][0]: |
|
89 | if 'file' in req.form and req.form['file'][0]: | |
90 | return filelog(web, req, tmpl) |
|
90 | return filelog(web, req, tmpl) | |
91 | else: |
|
91 | else: | |
92 | return changelog(web, req, tmpl) |
|
92 | return changelog(web, req, tmpl) | |
93 |
|
93 | |||
94 | @webcommand('rawfile') |
|
94 | @webcommand('rawfile') | |
95 | def rawfile(web, req, tmpl): |
|
95 | def rawfile(web, req, tmpl): | |
96 | guessmime = web.configbool('web', 'guessmime', False) |
|
96 | guessmime = web.configbool('web', 'guessmime', False) | |
97 |
|
97 | |||
98 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
98 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
99 | if not path: |
|
99 | if not path: | |
100 | content = manifest(web, req, tmpl) |
|
100 | content = manifest(web, req, tmpl) | |
101 | req.respond(HTTP_OK, web.ctype) |
|
101 | req.respond(HTTP_OK, web.ctype) | |
102 | return content |
|
102 | return content | |
103 |
|
103 | |||
104 | try: |
|
104 | try: | |
105 | fctx = webutil.filectx(web.repo, req) |
|
105 | fctx = webutil.filectx(web.repo, req) | |
106 | except error.LookupError as inst: |
|
106 | except error.LookupError as inst: | |
107 | try: |
|
107 | try: | |
108 | content = manifest(web, req, tmpl) |
|
108 | content = manifest(web, req, tmpl) | |
109 | req.respond(HTTP_OK, web.ctype) |
|
109 | req.respond(HTTP_OK, web.ctype) | |
110 | return content |
|
110 | return content | |
111 | except ErrorResponse: |
|
111 | except ErrorResponse: | |
112 | raise inst |
|
112 | raise inst | |
113 |
|
113 | |||
114 | path = fctx.path() |
|
114 | path = fctx.path() | |
115 | text = fctx.data() |
|
115 | text = fctx.data() | |
116 | mt = 'application/binary' |
|
116 | mt = 'application/binary' | |
117 | if guessmime: |
|
117 | if guessmime: | |
118 | mt = mimetypes.guess_type(path)[0] |
|
118 | mt = mimetypes.guess_type(path)[0] | |
119 | if mt is None: |
|
119 | if mt is None: | |
120 | if util.binary(text): |
|
120 | if util.binary(text): | |
121 | mt = 'application/binary' |
|
121 | mt = 'application/binary' | |
122 | else: |
|
122 | else: | |
123 | mt = 'text/plain' |
|
123 | mt = 'text/plain' | |
124 | if mt.startswith('text/'): |
|
124 | if mt.startswith('text/'): | |
125 | mt += '; charset="%s"' % encoding.encoding |
|
125 | mt += '; charset="%s"' % encoding.encoding | |
126 |
|
126 | |||
127 | req.respond(HTTP_OK, mt, path, body=text) |
|
127 | req.respond(HTTP_OK, mt, path, body=text) | |
128 | return [] |
|
128 | return [] | |
129 |
|
129 | |||
130 | def _filerevision(web, req, tmpl, fctx): |
|
130 | def _filerevision(web, req, tmpl, fctx): | |
131 | f = fctx.path() |
|
131 | f = fctx.path() | |
132 | text = fctx.data() |
|
132 | text = fctx.data() | |
133 | parity = paritygen(web.stripecount) |
|
133 | parity = paritygen(web.stripecount) | |
134 | ishead = fctx.filerev() in fctx.filelog().headrevs() |
|
134 | ishead = fctx.filerev() in fctx.filelog().headrevs() | |
135 |
|
135 | |||
136 | if util.binary(text): |
|
136 | if util.binary(text): | |
137 | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
|
137 | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' | |
138 | text = '(binary:%s)' % mt |
|
138 | text = '(binary:%s)' % mt | |
139 |
|
139 | |||
140 | def lines(): |
|
140 | def lines(): | |
141 | for lineno, t in enumerate(text.splitlines(True)): |
|
141 | for lineno, t in enumerate(text.splitlines(True)): | |
142 | yield {"line": t, |
|
142 | yield {"line": t, | |
143 | "lineid": "l%d" % (lineno + 1), |
|
143 | "lineid": "l%d" % (lineno + 1), | |
144 | "linenumber": "% 6d" % (lineno + 1), |
|
144 | "linenumber": "% 6d" % (lineno + 1), | |
145 | "parity": next(parity)} |
|
145 | "parity": next(parity)} | |
146 |
|
146 | |||
147 | return tmpl("filerevision", |
|
147 | return tmpl("filerevision", | |
148 | file=f, |
|
148 | file=f, | |
149 | path=webutil.up(f), |
|
149 | path=webutil.up(f), | |
150 | text=lines(), |
|
150 | text=lines(), | |
151 | symrev=webutil.symrevorshortnode(req, fctx), |
|
151 | symrev=webutil.symrevorshortnode(req, fctx), | |
152 | rename=webutil.renamelink(fctx), |
|
152 | rename=webutil.renamelink(fctx), | |
153 | permissions=fctx.manifest().flags(f), |
|
153 | permissions=fctx.manifest().flags(f), | |
154 | ishead=int(ishead), |
|
154 | ishead=int(ishead), | |
155 | **webutil.commonentry(web.repo, fctx)) |
|
155 | **webutil.commonentry(web.repo, fctx)) | |
156 |
|
156 | |||
157 | @webcommand('file') |
|
157 | @webcommand('file') | |
158 | def file(web, req, tmpl): |
|
158 | def file(web, req, tmpl): | |
159 | """ |
|
159 | """ | |
160 | /file/{revision}[/{path}] |
|
160 | /file/{revision}[/{path}] | |
161 | ------------------------- |
|
161 | ------------------------- | |
162 |
|
162 | |||
163 | Show information about a directory or file in the repository. |
|
163 | Show information about a directory or file in the repository. | |
164 |
|
164 | |||
165 | Info about the ``path`` given as a URL parameter will be rendered. |
|
165 | Info about the ``path`` given as a URL parameter will be rendered. | |
166 |
|
166 | |||
167 | If ``path`` is a directory, information about the entries in that |
|
167 | If ``path`` is a directory, information about the entries in that | |
168 | directory will be rendered. This form is equivalent to the ``manifest`` |
|
168 | directory will be rendered. This form is equivalent to the ``manifest`` | |
169 | handler. |
|
169 | handler. | |
170 |
|
170 | |||
171 | If ``path`` is a file, information about that file will be shown via |
|
171 | If ``path`` is a file, information about that file will be shown via | |
172 | the ``filerevision`` template. |
|
172 | the ``filerevision`` template. | |
173 |
|
173 | |||
174 | If ``path`` is not defined, information about the root directory will |
|
174 | If ``path`` is not defined, information about the root directory will | |
175 | be rendered. |
|
175 | be rendered. | |
176 | """ |
|
176 | """ | |
177 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
177 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
178 | if not path: |
|
178 | if not path: | |
179 | return manifest(web, req, tmpl) |
|
179 | return manifest(web, req, tmpl) | |
180 | try: |
|
180 | try: | |
181 | return _filerevision(web, req, tmpl, webutil.filectx(web.repo, req)) |
|
181 | return _filerevision(web, req, tmpl, webutil.filectx(web.repo, req)) | |
182 | except error.LookupError as inst: |
|
182 | except error.LookupError as inst: | |
183 | try: |
|
183 | try: | |
184 | return manifest(web, req, tmpl) |
|
184 | return manifest(web, req, tmpl) | |
185 | except ErrorResponse: |
|
185 | except ErrorResponse: | |
186 | raise inst |
|
186 | raise inst | |
187 |
|
187 | |||
188 | def _search(web, req, tmpl): |
|
188 | def _search(web, req, tmpl): | |
189 | MODE_REVISION = 'rev' |
|
189 | MODE_REVISION = 'rev' | |
190 | MODE_KEYWORD = 'keyword' |
|
190 | MODE_KEYWORD = 'keyword' | |
191 | MODE_REVSET = 'revset' |
|
191 | MODE_REVSET = 'revset' | |
192 |
|
192 | |||
193 | def revsearch(ctx): |
|
193 | def revsearch(ctx): | |
194 | yield ctx |
|
194 | yield ctx | |
195 |
|
195 | |||
196 | def keywordsearch(query): |
|
196 | def keywordsearch(query): | |
197 | lower = encoding.lower |
|
197 | lower = encoding.lower | |
198 | qw = lower(query).split() |
|
198 | qw = lower(query).split() | |
199 |
|
199 | |||
200 | def revgen(): |
|
200 | def revgen(): | |
201 | cl = web.repo.changelog |
|
201 | cl = web.repo.changelog | |
202 | for i in xrange(len(web.repo) - 1, 0, -100): |
|
202 | for i in xrange(len(web.repo) - 1, 0, -100): | |
203 | l = [] |
|
203 | l = [] | |
204 | for j in cl.revs(max(0, i - 99), i): |
|
204 | for j in cl.revs(max(0, i - 99), i): | |
205 | ctx = web.repo[j] |
|
205 | ctx = web.repo[j] | |
206 | l.append(ctx) |
|
206 | l.append(ctx) | |
207 | l.reverse() |
|
207 | l.reverse() | |
208 | for e in l: |
|
208 | for e in l: | |
209 | yield e |
|
209 | yield e | |
210 |
|
210 | |||
211 | for ctx in revgen(): |
|
211 | for ctx in revgen(): | |
212 | miss = 0 |
|
212 | miss = 0 | |
213 | for q in qw: |
|
213 | for q in qw: | |
214 | if not (q in lower(ctx.user()) or |
|
214 | if not (q in lower(ctx.user()) or | |
215 | q in lower(ctx.description()) or |
|
215 | q in lower(ctx.description()) or | |
216 | q in lower(" ".join(ctx.files()))): |
|
216 | q in lower(" ".join(ctx.files()))): | |
217 | miss = 1 |
|
217 | miss = 1 | |
218 | break |
|
218 | break | |
219 | if miss: |
|
219 | if miss: | |
220 | continue |
|
220 | continue | |
221 |
|
221 | |||
222 | yield ctx |
|
222 | yield ctx | |
223 |
|
223 | |||
224 | def revsetsearch(revs): |
|
224 | def revsetsearch(revs): | |
225 | for r in revs: |
|
225 | for r in revs: | |
226 | yield web.repo[r] |
|
226 | yield web.repo[r] | |
227 |
|
227 | |||
228 | searchfuncs = { |
|
228 | searchfuncs = { | |
229 | MODE_REVISION: (revsearch, 'exact revision search'), |
|
229 | MODE_REVISION: (revsearch, 'exact revision search'), | |
230 | MODE_KEYWORD: (keywordsearch, 'literal keyword search'), |
|
230 | MODE_KEYWORD: (keywordsearch, 'literal keyword search'), | |
231 | MODE_REVSET: (revsetsearch, 'revset expression search'), |
|
231 | MODE_REVSET: (revsetsearch, 'revset expression search'), | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | def getsearchmode(query): |
|
234 | def getsearchmode(query): | |
235 | try: |
|
235 | try: | |
236 | ctx = web.repo[query] |
|
236 | ctx = web.repo[query] | |
237 | except (error.RepoError, error.LookupError): |
|
237 | except (error.RepoError, error.LookupError): | |
238 | # query is not an exact revision pointer, need to |
|
238 | # query is not an exact revision pointer, need to | |
239 | # decide if it's a revset expression or keywords |
|
239 | # decide if it's a revset expression or keywords | |
240 | pass |
|
240 | pass | |
241 | else: |
|
241 | else: | |
242 | return MODE_REVISION, ctx |
|
242 | return MODE_REVISION, ctx | |
243 |
|
243 | |||
244 | revdef = 'reverse(%s)' % query |
|
244 | revdef = 'reverse(%s)' % query | |
245 | try: |
|
245 | try: | |
246 | tree = revsetlang.parse(revdef) |
|
246 | tree = revsetlang.parse(revdef) | |
247 | except error.ParseError: |
|
247 | except error.ParseError: | |
248 | # can't parse to a revset tree |
|
248 | # can't parse to a revset tree | |
249 | return MODE_KEYWORD, query |
|
249 | return MODE_KEYWORD, query | |
250 |
|
250 | |||
251 | if revsetlang.depth(tree) <= 2: |
|
251 | if revsetlang.depth(tree) <= 2: | |
252 | # no revset syntax used |
|
252 | # no revset syntax used | |
253 | return MODE_KEYWORD, query |
|
253 | return MODE_KEYWORD, query | |
254 |
|
254 | |||
255 | if any((token, (value or '')[:3]) == ('string', 're:') |
|
255 | if any((token, (value or '')[:3]) == ('string', 're:') | |
256 | for token, value, pos in revsetlang.tokenize(revdef)): |
|
256 | for token, value, pos in revsetlang.tokenize(revdef)): | |
257 | return MODE_KEYWORD, query |
|
257 | return MODE_KEYWORD, query | |
258 |
|
258 | |||
259 | funcsused = revsetlang.funcsused(tree) |
|
259 | funcsused = revsetlang.funcsused(tree) | |
260 | if not funcsused.issubset(revset.safesymbols): |
|
260 | if not funcsused.issubset(revset.safesymbols): | |
261 | return MODE_KEYWORD, query |
|
261 | return MODE_KEYWORD, query | |
262 |
|
262 | |||
263 | mfunc = revset.match(web.repo.ui, revdef, repo=web.repo) |
|
263 | mfunc = revset.match(web.repo.ui, revdef, repo=web.repo) | |
264 | try: |
|
264 | try: | |
265 | revs = mfunc(web.repo) |
|
265 | revs = mfunc(web.repo) | |
266 | return MODE_REVSET, revs |
|
266 | return MODE_REVSET, revs | |
267 | # ParseError: wrongly placed tokens, wrongs arguments, etc |
|
267 | # ParseError: wrongly placed tokens, wrongs arguments, etc | |
268 | # RepoLookupError: no such revision, e.g. in 'revision:' |
|
268 | # RepoLookupError: no such revision, e.g. in 'revision:' | |
269 | # Abort: bookmark/tag not exists |
|
269 | # Abort: bookmark/tag not exists | |
270 | # LookupError: ambiguous identifier, e.g. in '(bc)' on a large repo |
|
270 | # LookupError: ambiguous identifier, e.g. in '(bc)' on a large repo | |
271 | except (error.ParseError, error.RepoLookupError, error.Abort, |
|
271 | except (error.ParseError, error.RepoLookupError, error.Abort, | |
272 | LookupError): |
|
272 | LookupError): | |
273 | return MODE_KEYWORD, query |
|
273 | return MODE_KEYWORD, query | |
274 |
|
274 | |||
275 | def changelist(**map): |
|
275 | def changelist(**map): | |
276 | count = 0 |
|
276 | count = 0 | |
277 |
|
277 | |||
278 | for ctx in searchfunc[0](funcarg): |
|
278 | for ctx in searchfunc[0](funcarg): | |
279 | count += 1 |
|
279 | count += 1 | |
280 | n = ctx.node() |
|
280 | n = ctx.node() | |
281 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
|
281 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) | |
282 | files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
|
282 | files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) | |
283 |
|
283 | |||
284 | yield tmpl('searchentry', |
|
284 | yield tmpl('searchentry', | |
285 | parity=next(parity), |
|
285 | parity=next(parity), | |
286 | changelogtag=showtags, |
|
286 | changelogtag=showtags, | |
287 | files=files, |
|
287 | files=files, | |
288 | **webutil.commonentry(web.repo, ctx)) |
|
288 | **webutil.commonentry(web.repo, ctx)) | |
289 |
|
289 | |||
290 | if count >= revcount: |
|
290 | if count >= revcount: | |
291 | break |
|
291 | break | |
292 |
|
292 | |||
293 | query = req.form['rev'][0] |
|
293 | query = req.form['rev'][0] | |
294 | revcount = web.maxchanges |
|
294 | revcount = web.maxchanges | |
295 | if 'revcount' in req.form: |
|
295 | if 'revcount' in req.form: | |
296 | try: |
|
296 | try: | |
297 | revcount = int(req.form.get('revcount', [revcount])[0]) |
|
297 | revcount = int(req.form.get('revcount', [revcount])[0]) | |
298 | revcount = max(revcount, 1) |
|
298 | revcount = max(revcount, 1) | |
299 | tmpl.defaults['sessionvars']['revcount'] = revcount |
|
299 | tmpl.defaults['sessionvars']['revcount'] = revcount | |
300 | except ValueError: |
|
300 | except ValueError: | |
301 | pass |
|
301 | pass | |
302 |
|
302 | |||
303 | lessvars = copy.copy(tmpl.defaults['sessionvars']) |
|
303 | lessvars = copy.copy(tmpl.defaults['sessionvars']) | |
304 | lessvars['revcount'] = max(revcount / 2, 1) |
|
304 | lessvars['revcount'] = max(revcount / 2, 1) | |
305 | lessvars['rev'] = query |
|
305 | lessvars['rev'] = query | |
306 | morevars = copy.copy(tmpl.defaults['sessionvars']) |
|
306 | morevars = copy.copy(tmpl.defaults['sessionvars']) | |
307 | morevars['revcount'] = revcount * 2 |
|
307 | morevars['revcount'] = revcount * 2 | |
308 | morevars['rev'] = query |
|
308 | morevars['rev'] = query | |
309 |
|
309 | |||
310 | mode, funcarg = getsearchmode(query) |
|
310 | mode, funcarg = getsearchmode(query) | |
311 |
|
311 | |||
312 | if 'forcekw' in req.form: |
|
312 | if 'forcekw' in req.form: | |
313 | showforcekw = '' |
|
313 | showforcekw = '' | |
314 | showunforcekw = searchfuncs[mode][1] |
|
314 | showunforcekw = searchfuncs[mode][1] | |
315 | mode = MODE_KEYWORD |
|
315 | mode = MODE_KEYWORD | |
316 | funcarg = query |
|
316 | funcarg = query | |
317 | else: |
|
317 | else: | |
318 | if mode != MODE_KEYWORD: |
|
318 | if mode != MODE_KEYWORD: | |
319 | showforcekw = searchfuncs[MODE_KEYWORD][1] |
|
319 | showforcekw = searchfuncs[MODE_KEYWORD][1] | |
320 | else: |
|
320 | else: | |
321 | showforcekw = '' |
|
321 | showforcekw = '' | |
322 | showunforcekw = '' |
|
322 | showunforcekw = '' | |
323 |
|
323 | |||
324 | searchfunc = searchfuncs[mode] |
|
324 | searchfunc = searchfuncs[mode] | |
325 |
|
325 | |||
326 | tip = web.repo['tip'] |
|
326 | tip = web.repo['tip'] | |
327 | parity = paritygen(web.stripecount) |
|
327 | parity = paritygen(web.stripecount) | |
328 |
|
328 | |||
329 | return tmpl('search', query=query, node=tip.hex(), symrev='tip', |
|
329 | return tmpl('search', query=query, node=tip.hex(), symrev='tip', | |
330 | entries=changelist, archives=web.archivelist("tip"), |
|
330 | entries=changelist, archives=web.archivelist("tip"), | |
331 | morevars=morevars, lessvars=lessvars, |
|
331 | morevars=morevars, lessvars=lessvars, | |
332 | modedesc=searchfunc[1], |
|
332 | modedesc=searchfunc[1], | |
333 | showforcekw=showforcekw, showunforcekw=showunforcekw) |
|
333 | showforcekw=showforcekw, showunforcekw=showunforcekw) | |
334 |
|
334 | |||
335 | @webcommand('changelog') |
|
335 | @webcommand('changelog') | |
336 | def changelog(web, req, tmpl, shortlog=False): |
|
336 | def changelog(web, req, tmpl, shortlog=False): | |
337 | """ |
|
337 | """ | |
338 | /changelog[/{revision}] |
|
338 | /changelog[/{revision}] | |
339 | ----------------------- |
|
339 | ----------------------- | |
340 |
|
340 | |||
341 | Show information about multiple changesets. |
|
341 | Show information about multiple changesets. | |
342 |
|
342 | |||
343 | If the optional ``revision`` URL argument is absent, information about |
|
343 | If the optional ``revision`` URL argument is absent, information about | |
344 | all changesets starting at ``tip`` will be rendered. If the ``revision`` |
|
344 | all changesets starting at ``tip`` will be rendered. If the ``revision`` | |
345 | argument is present, changesets will be shown starting from the specified |
|
345 | argument is present, changesets will be shown starting from the specified | |
346 | revision. |
|
346 | revision. | |
347 |
|
347 | |||
348 | If ``revision`` is absent, the ``rev`` query string argument may be |
|
348 | If ``revision`` is absent, the ``rev`` query string argument may be | |
349 | defined. This will perform a search for changesets. |
|
349 | defined. This will perform a search for changesets. | |
350 |
|
350 | |||
351 | The argument for ``rev`` can be a single revision, a revision set, |
|
351 | The argument for ``rev`` can be a single revision, a revision set, | |
352 | or a literal keyword to search for in changeset data (equivalent to |
|
352 | or a literal keyword to search for in changeset data (equivalent to | |
353 | :hg:`log -k`). |
|
353 | :hg:`log -k`). | |
354 |
|
354 | |||
355 | The ``revcount`` query string argument defines the maximum numbers of |
|
355 | The ``revcount`` query string argument defines the maximum numbers of | |
356 | changesets to render. |
|
356 | changesets to render. | |
357 |
|
357 | |||
358 | For non-searches, the ``changelog`` template will be rendered. |
|
358 | For non-searches, the ``changelog`` template will be rendered. | |
359 | """ |
|
359 | """ | |
360 |
|
360 | |||
361 | query = '' |
|
361 | query = '' | |
362 | if 'node' in req.form: |
|
362 | if 'node' in req.form: | |
363 | ctx = webutil.changectx(web.repo, req) |
|
363 | ctx = webutil.changectx(web.repo, req) | |
364 | symrev = webutil.symrevorshortnode(req, ctx) |
|
364 | symrev = webutil.symrevorshortnode(req, ctx) | |
365 | elif 'rev' in req.form: |
|
365 | elif 'rev' in req.form: | |
366 | return _search(web, req, tmpl) |
|
366 | return _search(web, req, tmpl) | |
367 | else: |
|
367 | else: | |
368 | ctx = web.repo['tip'] |
|
368 | ctx = web.repo['tip'] | |
369 | symrev = 'tip' |
|
369 | symrev = 'tip' | |
370 |
|
370 | |||
371 | def changelist(): |
|
371 | def changelist(): | |
372 | revs = [] |
|
372 | revs = [] | |
373 | if pos != -1: |
|
373 | if pos != -1: | |
374 | revs = web.repo.changelog.revs(pos, 0) |
|
374 | revs = web.repo.changelog.revs(pos, 0) | |
375 | curcount = 0 |
|
375 | curcount = 0 | |
376 | for rev in revs: |
|
376 | for rev in revs: | |
377 | curcount += 1 |
|
377 | curcount += 1 | |
378 | if curcount > revcount + 1: |
|
378 | if curcount > revcount + 1: | |
379 | break |
|
379 | break | |
380 |
|
380 | |||
381 | entry = webutil.changelistentry(web, web.repo[rev], tmpl) |
|
381 | entry = webutil.changelistentry(web, web.repo[rev], tmpl) | |
382 | entry['parity'] = next(parity) |
|
382 | entry['parity'] = next(parity) | |
383 | yield entry |
|
383 | yield entry | |
384 |
|
384 | |||
385 | if shortlog: |
|
385 | if shortlog: | |
386 | revcount = web.maxshortchanges |
|
386 | revcount = web.maxshortchanges | |
387 | else: |
|
387 | else: | |
388 | revcount = web.maxchanges |
|
388 | revcount = web.maxchanges | |
389 |
|
389 | |||
390 | if 'revcount' in req.form: |
|
390 | if 'revcount' in req.form: | |
391 | try: |
|
391 | try: | |
392 | revcount = int(req.form.get('revcount', [revcount])[0]) |
|
392 | revcount = int(req.form.get('revcount', [revcount])[0]) | |
393 | revcount = max(revcount, 1) |
|
393 | revcount = max(revcount, 1) | |
394 | tmpl.defaults['sessionvars']['revcount'] = revcount |
|
394 | tmpl.defaults['sessionvars']['revcount'] = revcount | |
395 | except ValueError: |
|
395 | except ValueError: | |
396 | pass |
|
396 | pass | |
397 |
|
397 | |||
398 | lessvars = copy.copy(tmpl.defaults['sessionvars']) |
|
398 | lessvars = copy.copy(tmpl.defaults['sessionvars']) | |
399 | lessvars['revcount'] = max(revcount / 2, 1) |
|
399 | lessvars['revcount'] = max(revcount / 2, 1) | |
400 | morevars = copy.copy(tmpl.defaults['sessionvars']) |
|
400 | morevars = copy.copy(tmpl.defaults['sessionvars']) | |
401 | morevars['revcount'] = revcount * 2 |
|
401 | morevars['revcount'] = revcount * 2 | |
402 |
|
402 | |||
403 | count = len(web.repo) |
|
403 | count = len(web.repo) | |
404 | pos = ctx.rev() |
|
404 | pos = ctx.rev() | |
405 | parity = paritygen(web.stripecount) |
|
405 | parity = paritygen(web.stripecount) | |
406 |
|
406 | |||
407 | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
|
407 | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) | |
408 |
|
408 | |||
409 | entries = list(changelist()) |
|
409 | entries = list(changelist()) | |
410 | latestentry = entries[:1] |
|
410 | latestentry = entries[:1] | |
411 | if len(entries) > revcount: |
|
411 | if len(entries) > revcount: | |
412 | nextentry = entries[-1:] |
|
412 | nextentry = entries[-1:] | |
413 | entries = entries[:-1] |
|
413 | entries = entries[:-1] | |
414 | else: |
|
414 | else: | |
415 | nextentry = [] |
|
415 | nextentry = [] | |
416 |
|
416 | |||
417 | return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav, |
|
417 | return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav, | |
418 | node=ctx.hex(), rev=pos, symrev=symrev, changesets=count, |
|
418 | node=ctx.hex(), rev=pos, symrev=symrev, changesets=count, | |
419 | entries=entries, |
|
419 | entries=entries, | |
420 | latestentry=latestentry, nextentry=nextentry, |
|
420 | latestentry=latestentry, nextentry=nextentry, | |
421 | archives=web.archivelist("tip"), revcount=revcount, |
|
421 | archives=web.archivelist("tip"), revcount=revcount, | |
422 | morevars=morevars, lessvars=lessvars, query=query) |
|
422 | morevars=morevars, lessvars=lessvars, query=query) | |
423 |
|
423 | |||
424 | @webcommand('shortlog') |
|
424 | @webcommand('shortlog') | |
425 | def shortlog(web, req, tmpl): |
|
425 | def shortlog(web, req, tmpl): | |
426 | """ |
|
426 | """ | |
427 | /shortlog |
|
427 | /shortlog | |
428 | --------- |
|
428 | --------- | |
429 |
|
429 | |||
430 | Show basic information about a set of changesets. |
|
430 | Show basic information about a set of changesets. | |
431 |
|
431 | |||
432 | This accepts the same parameters as the ``changelog`` handler. The only |
|
432 | This accepts the same parameters as the ``changelog`` handler. The only | |
433 | difference is the ``shortlog`` template will be rendered instead of the |
|
433 | difference is the ``shortlog`` template will be rendered instead of the | |
434 | ``changelog`` template. |
|
434 | ``changelog`` template. | |
435 | """ |
|
435 | """ | |
436 | return changelog(web, req, tmpl, shortlog=True) |
|
436 | return changelog(web, req, tmpl, shortlog=True) | |
437 |
|
437 | |||
438 | @webcommand('changeset') |
|
438 | @webcommand('changeset') | |
439 | def changeset(web, req, tmpl): |
|
439 | def changeset(web, req, tmpl): | |
440 | """ |
|
440 | """ | |
441 | /changeset[/{revision}] |
|
441 | /changeset[/{revision}] | |
442 | ----------------------- |
|
442 | ----------------------- | |
443 |
|
443 | |||
444 | Show information about a single changeset. |
|
444 | Show information about a single changeset. | |
445 |
|
445 | |||
446 | A URL path argument is the changeset identifier to show. See ``hg help |
|
446 | A URL path argument is the changeset identifier to show. See ``hg help | |
447 | revisions`` for possible values. If not defined, the ``tip`` changeset |
|
447 | revisions`` for possible values. If not defined, the ``tip`` changeset | |
448 | will be shown. |
|
448 | will be shown. | |
449 |
|
449 | |||
450 | The ``changeset`` template is rendered. Contents of the ``changesettag``, |
|
450 | The ``changeset`` template is rendered. Contents of the ``changesettag``, | |
451 | ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many |
|
451 | ``changesetbookmark``, ``filenodelink``, ``filenolink``, and the many | |
452 | templates related to diffs may all be used to produce the output. |
|
452 | templates related to diffs may all be used to produce the output. | |
453 | """ |
|
453 | """ | |
454 | ctx = webutil.changectx(web.repo, req) |
|
454 | ctx = webutil.changectx(web.repo, req) | |
455 |
|
455 | |||
456 | return tmpl('changeset', **webutil.changesetentry(web, req, tmpl, ctx)) |
|
456 | return tmpl('changeset', **webutil.changesetentry(web, req, tmpl, ctx)) | |
457 |
|
457 | |||
458 | rev = webcommand('rev')(changeset) |
|
458 | rev = webcommand('rev')(changeset) | |
459 |
|
459 | |||
460 | def decodepath(path): |
|
460 | def decodepath(path): | |
461 | """Hook for mapping a path in the repository to a path in the |
|
461 | """Hook for mapping a path in the repository to a path in the | |
462 | working copy. |
|
462 | working copy. | |
463 |
|
463 | |||
464 | Extensions (e.g., largefiles) can override this to remap files in |
|
464 | Extensions (e.g., largefiles) can override this to remap files in | |
465 | the virtual file system presented by the manifest command below.""" |
|
465 | the virtual file system presented by the manifest command below.""" | |
466 | return path |
|
466 | return path | |
467 |
|
467 | |||
468 | @webcommand('manifest') |
|
468 | @webcommand('manifest') | |
469 | def manifest(web, req, tmpl): |
|
469 | def manifest(web, req, tmpl): | |
470 | """ |
|
470 | """ | |
471 | /manifest[/{revision}[/{path}]] |
|
471 | /manifest[/{revision}[/{path}]] | |
472 | ------------------------------- |
|
472 | ------------------------------- | |
473 |
|
473 | |||
474 | Show information about a directory. |
|
474 | Show information about a directory. | |
475 |
|
475 | |||
476 | If the URL path arguments are omitted, information about the root |
|
476 | If the URL path arguments are omitted, information about the root | |
477 | directory for the ``tip`` changeset will be shown. |
|
477 | directory for the ``tip`` changeset will be shown. | |
478 |
|
478 | |||
479 | Because this handler can only show information for directories, it |
|
479 | Because this handler can only show information for directories, it | |
480 | is recommended to use the ``file`` handler instead, as it can handle both |
|
480 | is recommended to use the ``file`` handler instead, as it can handle both | |
481 | directories and files. |
|
481 | directories and files. | |
482 |
|
482 | |||
483 | The ``manifest`` template will be rendered for this handler. |
|
483 | The ``manifest`` template will be rendered for this handler. | |
484 | """ |
|
484 | """ | |
485 | if 'node' in req.form: |
|
485 | if 'node' in req.form: | |
486 | ctx = webutil.changectx(web.repo, req) |
|
486 | ctx = webutil.changectx(web.repo, req) | |
487 | symrev = webutil.symrevorshortnode(req, ctx) |
|
487 | symrev = webutil.symrevorshortnode(req, ctx) | |
488 | else: |
|
488 | else: | |
489 | ctx = web.repo['tip'] |
|
489 | ctx = web.repo['tip'] | |
490 | symrev = 'tip' |
|
490 | symrev = 'tip' | |
491 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
491 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
492 | mf = ctx.manifest() |
|
492 | mf = ctx.manifest() | |
493 | node = ctx.node() |
|
493 | node = ctx.node() | |
494 |
|
494 | |||
495 | files = {} |
|
495 | files = {} | |
496 | dirs = {} |
|
496 | dirs = {} | |
497 | parity = paritygen(web.stripecount) |
|
497 | parity = paritygen(web.stripecount) | |
498 |
|
498 | |||
499 | if path and path[-1] != "/": |
|
499 | if path and path[-1] != "/": | |
500 | path += "/" |
|
500 | path += "/" | |
501 | l = len(path) |
|
501 | l = len(path) | |
502 | abspath = "/" + path |
|
502 | abspath = "/" + path | |
503 |
|
503 | |||
504 | for full, n in mf.iteritems(): |
|
504 | for full, n in mf.iteritems(): | |
505 | # the virtual path (working copy path) used for the full |
|
505 | # the virtual path (working copy path) used for the full | |
506 | # (repository) path |
|
506 | # (repository) path | |
507 | f = decodepath(full) |
|
507 | f = decodepath(full) | |
508 |
|
508 | |||
509 | if f[:l] != path: |
|
509 | if f[:l] != path: | |
510 | continue |
|
510 | continue | |
511 | remain = f[l:] |
|
511 | remain = f[l:] | |
512 | elements = remain.split('/') |
|
512 | elements = remain.split('/') | |
513 | if len(elements) == 1: |
|
513 | if len(elements) == 1: | |
514 | files[remain] = full |
|
514 | files[remain] = full | |
515 | else: |
|
515 | else: | |
516 | h = dirs # need to retain ref to dirs (root) |
|
516 | h = dirs # need to retain ref to dirs (root) | |
517 | for elem in elements[0:-1]: |
|
517 | for elem in elements[0:-1]: | |
518 | if elem not in h: |
|
518 | if elem not in h: | |
519 | h[elem] = {} |
|
519 | h[elem] = {} | |
520 | h = h[elem] |
|
520 | h = h[elem] | |
521 | if len(h) > 1: |
|
521 | if len(h) > 1: | |
522 | break |
|
522 | break | |
523 | h[None] = None # denotes files present |
|
523 | h[None] = None # denotes files present | |
524 |
|
524 | |||
525 | if mf and not files and not dirs: |
|
525 | if mf and not files and not dirs: | |
526 | raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
|
526 | raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) | |
527 |
|
527 | |||
528 | def filelist(**map): |
|
528 | def filelist(**map): | |
529 | for f in sorted(files): |
|
529 | for f in sorted(files): | |
530 | full = files[f] |
|
530 | full = files[f] | |
531 |
|
531 | |||
532 | fctx = ctx.filectx(full) |
|
532 | fctx = ctx.filectx(full) | |
533 | yield {"file": full, |
|
533 | yield {"file": full, | |
534 | "parity": next(parity), |
|
534 | "parity": next(parity), | |
535 | "basename": f, |
|
535 | "basename": f, | |
536 | "date": fctx.date(), |
|
536 | "date": fctx.date(), | |
537 | "size": fctx.size(), |
|
537 | "size": fctx.size(), | |
538 | "permissions": mf.flags(full)} |
|
538 | "permissions": mf.flags(full)} | |
539 |
|
539 | |||
540 | def dirlist(**map): |
|
540 | def dirlist(**map): | |
541 | for d in sorted(dirs): |
|
541 | for d in sorted(dirs): | |
542 |
|
542 | |||
543 | emptydirs = [] |
|
543 | emptydirs = [] | |
544 | h = dirs[d] |
|
544 | h = dirs[d] | |
545 | while isinstance(h, dict) and len(h) == 1: |
|
545 | while isinstance(h, dict) and len(h) == 1: | |
546 | k, v = h.items()[0] |
|
546 | k, v = h.items()[0] | |
547 | if v: |
|
547 | if v: | |
548 | emptydirs.append(k) |
|
548 | emptydirs.append(k) | |
549 | h = v |
|
549 | h = v | |
550 |
|
550 | |||
551 | path = "%s%s" % (abspath, d) |
|
551 | path = "%s%s" % (abspath, d) | |
552 | yield {"parity": next(parity), |
|
552 | yield {"parity": next(parity), | |
553 | "path": path, |
|
553 | "path": path, | |
554 | "emptydirs": "/".join(emptydirs), |
|
554 | "emptydirs": "/".join(emptydirs), | |
555 | "basename": d} |
|
555 | "basename": d} | |
556 |
|
556 | |||
557 | return tmpl("manifest", |
|
557 | return tmpl("manifest", | |
558 | symrev=symrev, |
|
558 | symrev=symrev, | |
559 | path=abspath, |
|
559 | path=abspath, | |
560 | up=webutil.up(abspath), |
|
560 | up=webutil.up(abspath), | |
561 | upparity=next(parity), |
|
561 | upparity=next(parity), | |
562 | fentries=filelist, |
|
562 | fentries=filelist, | |
563 | dentries=dirlist, |
|
563 | dentries=dirlist, | |
564 | archives=web.archivelist(hex(node)), |
|
564 | archives=web.archivelist(hex(node)), | |
565 | **webutil.commonentry(web.repo, ctx)) |
|
565 | **webutil.commonentry(web.repo, ctx)) | |
566 |
|
566 | |||
567 | @webcommand('tags') |
|
567 | @webcommand('tags') | |
568 | def tags(web, req, tmpl): |
|
568 | def tags(web, req, tmpl): | |
569 | """ |
|
569 | """ | |
570 | /tags |
|
570 | /tags | |
571 | ----- |
|
571 | ----- | |
572 |
|
572 | |||
573 | Show information about tags. |
|
573 | Show information about tags. | |
574 |
|
574 | |||
575 | No arguments are accepted. |
|
575 | No arguments are accepted. | |
576 |
|
576 | |||
577 | The ``tags`` template is rendered. |
|
577 | The ``tags`` template is rendered. | |
578 | """ |
|
578 | """ | |
579 | i = list(reversed(web.repo.tagslist())) |
|
579 | i = list(reversed(web.repo.tagslist())) | |
580 | parity = paritygen(web.stripecount) |
|
580 | parity = paritygen(web.stripecount) | |
581 |
|
581 | |||
582 | def entries(notip, latestonly, **map): |
|
582 | def entries(notip, latestonly, **map): | |
583 | t = i |
|
583 | t = i | |
584 | if notip: |
|
584 | if notip: | |
585 | t = [(k, n) for k, n in i if k != "tip"] |
|
585 | t = [(k, n) for k, n in i if k != "tip"] | |
586 | if latestonly: |
|
586 | if latestonly: | |
587 | t = t[:1] |
|
587 | t = t[:1] | |
588 | for k, n in t: |
|
588 | for k, n in t: | |
589 | yield {"parity": next(parity), |
|
589 | yield {"parity": next(parity), | |
590 | "tag": k, |
|
590 | "tag": k, | |
591 | "date": web.repo[n].date(), |
|
591 | "date": web.repo[n].date(), | |
592 | "node": hex(n)} |
|
592 | "node": hex(n)} | |
593 |
|
593 | |||
594 | return tmpl("tags", |
|
594 | return tmpl("tags", | |
595 | node=hex(web.repo.changelog.tip()), |
|
595 | node=hex(web.repo.changelog.tip()), | |
596 | entries=lambda **x: entries(False, False, **x), |
|
596 | entries=lambda **x: entries(False, False, **x), | |
597 | entriesnotip=lambda **x: entries(True, False, **x), |
|
597 | entriesnotip=lambda **x: entries(True, False, **x), | |
598 | latestentry=lambda **x: entries(True, True, **x)) |
|
598 | latestentry=lambda **x: entries(True, True, **x)) | |
599 |
|
599 | |||
600 | @webcommand('bookmarks') |
|
600 | @webcommand('bookmarks') | |
601 | def bookmarks(web, req, tmpl): |
|
601 | def bookmarks(web, req, tmpl): | |
602 | """ |
|
602 | """ | |
603 | /bookmarks |
|
603 | /bookmarks | |
604 | ---------- |
|
604 | ---------- | |
605 |
|
605 | |||
606 | Show information about bookmarks. |
|
606 | Show information about bookmarks. | |
607 |
|
607 | |||
608 | No arguments are accepted. |
|
608 | No arguments are accepted. | |
609 |
|
609 | |||
610 | The ``bookmarks`` template is rendered. |
|
610 | The ``bookmarks`` template is rendered. | |
611 | """ |
|
611 | """ | |
612 | i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
|
612 | i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] | |
613 | sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) |
|
613 | sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) | |
614 | i = sorted(i, key=sortkey, reverse=True) |
|
614 | i = sorted(i, key=sortkey, reverse=True) | |
615 | parity = paritygen(web.stripecount) |
|
615 | parity = paritygen(web.stripecount) | |
616 |
|
616 | |||
617 | def entries(latestonly, **map): |
|
617 | def entries(latestonly, **map): | |
618 | t = i |
|
618 | t = i | |
619 | if latestonly: |
|
619 | if latestonly: | |
620 | t = i[:1] |
|
620 | t = i[:1] | |
621 | for k, n in t: |
|
621 | for k, n in t: | |
622 | yield {"parity": next(parity), |
|
622 | yield {"parity": next(parity), | |
623 | "bookmark": k, |
|
623 | "bookmark": k, | |
624 | "date": web.repo[n].date(), |
|
624 | "date": web.repo[n].date(), | |
625 | "node": hex(n)} |
|
625 | "node": hex(n)} | |
626 |
|
626 | |||
627 | if i: |
|
627 | if i: | |
628 | latestrev = i[0][1] |
|
628 | latestrev = i[0][1] | |
629 | else: |
|
629 | else: | |
630 | latestrev = -1 |
|
630 | latestrev = -1 | |
631 |
|
631 | |||
632 | return tmpl("bookmarks", |
|
632 | return tmpl("bookmarks", | |
633 | node=hex(web.repo.changelog.tip()), |
|
633 | node=hex(web.repo.changelog.tip()), | |
634 | lastchange=[{"date": web.repo[latestrev].date()}], |
|
634 | lastchange=[{"date": web.repo[latestrev].date()}], | |
635 | entries=lambda **x: entries(latestonly=False, **x), |
|
635 | entries=lambda **x: entries(latestonly=False, **x), | |
636 | latestentry=lambda **x: entries(latestonly=True, **x)) |
|
636 | latestentry=lambda **x: entries(latestonly=True, **x)) | |
637 |
|
637 | |||
638 | @webcommand('branches') |
|
638 | @webcommand('branches') | |
639 | def branches(web, req, tmpl): |
|
639 | def branches(web, req, tmpl): | |
640 | """ |
|
640 | """ | |
641 | /branches |
|
641 | /branches | |
642 | --------- |
|
642 | --------- | |
643 |
|
643 | |||
644 | Show information about branches. |
|
644 | Show information about branches. | |
645 |
|
645 | |||
646 | All known branches are contained in the output, even closed branches. |
|
646 | All known branches are contained in the output, even closed branches. | |
647 |
|
647 | |||
648 | No arguments are accepted. |
|
648 | No arguments are accepted. | |
649 |
|
649 | |||
650 | The ``branches`` template is rendered. |
|
650 | The ``branches`` template is rendered. | |
651 | """ |
|
651 | """ | |
652 | entries = webutil.branchentries(web.repo, web.stripecount) |
|
652 | entries = webutil.branchentries(web.repo, web.stripecount) | |
653 | latestentry = webutil.branchentries(web.repo, web.stripecount, 1) |
|
653 | latestentry = webutil.branchentries(web.repo, web.stripecount, 1) | |
654 | return tmpl('branches', node=hex(web.repo.changelog.tip()), |
|
654 | return tmpl('branches', node=hex(web.repo.changelog.tip()), | |
655 | entries=entries, latestentry=latestentry) |
|
655 | entries=entries, latestentry=latestentry) | |
656 |
|
656 | |||
657 | @webcommand('summary') |
|
657 | @webcommand('summary') | |
658 | def summary(web, req, tmpl): |
|
658 | def summary(web, req, tmpl): | |
659 | """ |
|
659 | """ | |
660 | /summary |
|
660 | /summary | |
661 | -------- |
|
661 | -------- | |
662 |
|
662 | |||
663 | Show a summary of repository state. |
|
663 | Show a summary of repository state. | |
664 |
|
664 | |||
665 | Information about the latest changesets, bookmarks, tags, and branches |
|
665 | Information about the latest changesets, bookmarks, tags, and branches | |
666 | is captured by this handler. |
|
666 | is captured by this handler. | |
667 |
|
667 | |||
668 | The ``summary`` template is rendered. |
|
668 | The ``summary`` template is rendered. | |
669 | """ |
|
669 | """ | |
670 | i = reversed(web.repo.tagslist()) |
|
670 | i = reversed(web.repo.tagslist()) | |
671 |
|
671 | |||
672 | def tagentries(**map): |
|
672 | def tagentries(**map): | |
673 | parity = paritygen(web.stripecount) |
|
673 | parity = paritygen(web.stripecount) | |
674 | count = 0 |
|
674 | count = 0 | |
675 | for k, n in i: |
|
675 | for k, n in i: | |
676 | if k == "tip": # skip tip |
|
676 | if k == "tip": # skip tip | |
677 | continue |
|
677 | continue | |
678 |
|
678 | |||
679 | count += 1 |
|
679 | count += 1 | |
680 | if count > 10: # limit to 10 tags |
|
680 | if count > 10: # limit to 10 tags | |
681 | break |
|
681 | break | |
682 |
|
682 | |||
683 | yield tmpl("tagentry", |
|
683 | yield tmpl("tagentry", | |
684 | parity=next(parity), |
|
684 | parity=next(parity), | |
685 | tag=k, |
|
685 | tag=k, | |
686 | node=hex(n), |
|
686 | node=hex(n), | |
687 | date=web.repo[n].date()) |
|
687 | date=web.repo[n].date()) | |
688 |
|
688 | |||
689 | def bookmarks(**map): |
|
689 | def bookmarks(**map): | |
690 | parity = paritygen(web.stripecount) |
|
690 | parity = paritygen(web.stripecount) | |
691 | marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] |
|
691 | marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo] | |
692 | sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) |
|
692 | sortkey = lambda b: (web.repo[b[1]].rev(), b[0]) | |
693 | marks = sorted(marks, key=sortkey, reverse=True) |
|
693 | marks = sorted(marks, key=sortkey, reverse=True) | |
694 | for k, n in marks[:10]: # limit to 10 bookmarks |
|
694 | for k, n in marks[:10]: # limit to 10 bookmarks | |
695 | yield {'parity': next(parity), |
|
695 | yield {'parity': next(parity), | |
696 | 'bookmark': k, |
|
696 | 'bookmark': k, | |
697 | 'date': web.repo[n].date(), |
|
697 | 'date': web.repo[n].date(), | |
698 | 'node': hex(n)} |
|
698 | 'node': hex(n)} | |
699 |
|
699 | |||
700 | def changelist(**map): |
|
700 | def changelist(**map): | |
701 | parity = paritygen(web.stripecount, offset=start - end) |
|
701 | parity = paritygen(web.stripecount, offset=start - end) | |
702 | l = [] # build a list in forward order for efficiency |
|
702 | l = [] # build a list in forward order for efficiency | |
703 | revs = [] |
|
703 | revs = [] | |
704 | if start < end: |
|
704 | if start < end: | |
705 | revs = web.repo.changelog.revs(start, end - 1) |
|
705 | revs = web.repo.changelog.revs(start, end - 1) | |
706 | for i in revs: |
|
706 | for i in revs: | |
707 | ctx = web.repo[i] |
|
707 | ctx = web.repo[i] | |
708 |
|
708 | |||
709 | l.append(tmpl( |
|
709 | l.append(tmpl( | |
710 | 'shortlogentry', |
|
710 | 'shortlogentry', | |
711 | parity=next(parity), |
|
711 | parity=next(parity), | |
712 | **webutil.commonentry(web.repo, ctx))) |
|
712 | **webutil.commonentry(web.repo, ctx))) | |
713 |
|
713 | |||
714 | for entry in reversed(l): |
|
714 | for entry in reversed(l): | |
715 | yield entry |
|
715 | yield entry | |
716 |
|
716 | |||
717 | tip = web.repo['tip'] |
|
717 | tip = web.repo['tip'] | |
718 | count = len(web.repo) |
|
718 | count = len(web.repo) | |
719 | start = max(0, count - web.maxchanges) |
|
719 | start = max(0, count - web.maxchanges) | |
720 | end = min(count, start + web.maxchanges) |
|
720 | end = min(count, start + web.maxchanges) | |
721 |
|
721 | |||
722 | desc = web.config("web", "description") |
|
722 | desc = web.config("web", "description") | |
723 | if not desc: |
|
723 | if not desc: | |
724 | desc = 'unknown' |
|
724 | desc = 'unknown' | |
725 | return tmpl("summary", |
|
725 | return tmpl("summary", | |
726 | desc=desc, |
|
726 | desc=desc, | |
727 | owner=get_contact(web.config) or "unknown", |
|
727 | owner=get_contact(web.config) or "unknown", | |
728 | lastchange=tip.date(), |
|
728 | lastchange=tip.date(), | |
729 | tags=tagentries, |
|
729 | tags=tagentries, | |
730 | bookmarks=bookmarks, |
|
730 | bookmarks=bookmarks, | |
731 | branches=webutil.branchentries(web.repo, web.stripecount, 10), |
|
731 | branches=webutil.branchentries(web.repo, web.stripecount, 10), | |
732 | shortlog=changelist, |
|
732 | shortlog=changelist, | |
733 | node=tip.hex(), |
|
733 | node=tip.hex(), | |
734 | symrev='tip', |
|
734 | symrev='tip', | |
735 | archives=web.archivelist("tip"), |
|
735 | archives=web.archivelist("tip"), | |
736 | labels=web.configlist('web', 'labels')) |
|
736 | labels=web.configlist('web', 'labels')) | |
737 |
|
737 | |||
738 | @webcommand('filediff') |
|
738 | @webcommand('filediff') | |
739 | def filediff(web, req, tmpl): |
|
739 | def filediff(web, req, tmpl): | |
740 | """ |
|
740 | """ | |
741 | /diff/{revision}/{path} |
|
741 | /diff/{revision}/{path} | |
742 | ----------------------- |
|
742 | ----------------------- | |
743 |
|
743 | |||
744 | Show how a file changed in a particular commit. |
|
744 | Show how a file changed in a particular commit. | |
745 |
|
745 | |||
746 | The ``filediff`` template is rendered. |
|
746 | The ``filediff`` template is rendered. | |
747 |
|
747 | |||
748 | This handler is registered under both the ``/diff`` and ``/filediff`` |
|
748 | This handler is registered under both the ``/diff`` and ``/filediff`` | |
749 | paths. ``/diff`` is used in modern code. |
|
749 | paths. ``/diff`` is used in modern code. | |
750 | """ |
|
750 | """ | |
751 | fctx, ctx = None, None |
|
751 | fctx, ctx = None, None | |
752 | try: |
|
752 | try: | |
753 | fctx = webutil.filectx(web.repo, req) |
|
753 | fctx = webutil.filectx(web.repo, req) | |
754 | except LookupError: |
|
754 | except LookupError: | |
755 | ctx = webutil.changectx(web.repo, req) |
|
755 | ctx = webutil.changectx(web.repo, req) | |
756 | path = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
756 | path = webutil.cleanpath(web.repo, req.form['file'][0]) | |
757 | if path not in ctx.files(): |
|
757 | if path not in ctx.files(): | |
758 | raise |
|
758 | raise | |
759 |
|
759 | |||
760 | if fctx is not None: |
|
760 | if fctx is not None: | |
761 | path = fctx.path() |
|
761 | path = fctx.path() | |
762 | ctx = fctx.changectx() |
|
762 | ctx = fctx.changectx() | |
763 | basectx = ctx.p1() |
|
763 | basectx = ctx.p1() | |
764 |
|
764 | |||
765 | style = web.config('web', 'style') |
|
765 | style = web.config('web', 'style') | |
766 | if 'style' in req.form: |
|
766 | if 'style' in req.form: | |
767 | style = req.form['style'][0] |
|
767 | style = req.form['style'][0] | |
768 |
|
768 | |||
769 | diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style) |
|
769 | diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style) | |
770 | if fctx is not None: |
|
770 | if fctx is not None: | |
771 | rename = webutil.renamelink(fctx) |
|
771 | rename = webutil.renamelink(fctx) | |
772 | ctx = fctx |
|
772 | ctx = fctx | |
773 | else: |
|
773 | else: | |
774 | rename = [] |
|
774 | rename = [] | |
775 | ctx = ctx |
|
775 | ctx = ctx | |
776 | return tmpl("filediff", |
|
776 | return tmpl("filediff", | |
777 | file=path, |
|
777 | file=path, | |
778 | symrev=webutil.symrevorshortnode(req, ctx), |
|
778 | symrev=webutil.symrevorshortnode(req, ctx), | |
779 | rename=rename, |
|
779 | rename=rename, | |
780 | diff=diffs, |
|
780 | diff=diffs, | |
781 | **webutil.commonentry(web.repo, ctx)) |
|
781 | **webutil.commonentry(web.repo, ctx)) | |
782 |
|
782 | |||
783 | diff = webcommand('diff')(filediff) |
|
783 | diff = webcommand('diff')(filediff) | |
784 |
|
784 | |||
785 | @webcommand('comparison') |
|
785 | @webcommand('comparison') | |
786 | def comparison(web, req, tmpl): |
|
786 | def comparison(web, req, tmpl): | |
787 | """ |
|
787 | """ | |
788 | /comparison/{revision}/{path} |
|
788 | /comparison/{revision}/{path} | |
789 | ----------------------------- |
|
789 | ----------------------------- | |
790 |
|
790 | |||
791 | Show a comparison between the old and new versions of a file from changes |
|
791 | Show a comparison between the old and new versions of a file from changes | |
792 | made on a particular revision. |
|
792 | made on a particular revision. | |
793 |
|
793 | |||
794 | This is similar to the ``diff`` handler. However, this form features |
|
794 | This is similar to the ``diff`` handler. However, this form features | |
795 | a split or side-by-side diff rather than a unified diff. |
|
795 | a split or side-by-side diff rather than a unified diff. | |
796 |
|
796 | |||
797 | The ``context`` query string argument can be used to control the lines of |
|
797 | The ``context`` query string argument can be used to control the lines of | |
798 | context in the diff. |
|
798 | context in the diff. | |
799 |
|
799 | |||
800 | The ``filecomparison`` template is rendered. |
|
800 | The ``filecomparison`` template is rendered. | |
801 | """ |
|
801 | """ | |
802 | ctx = webutil.changectx(web.repo, req) |
|
802 | ctx = webutil.changectx(web.repo, req) | |
803 | if 'file' not in req.form: |
|
803 | if 'file' not in req.form: | |
804 | raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
|
804 | raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') | |
805 | path = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
805 | path = webutil.cleanpath(web.repo, req.form['file'][0]) | |
806 |
|
806 | |||
807 | parsecontext = lambda v: v == 'full' and -1 or int(v) |
|
807 | parsecontext = lambda v: v == 'full' and -1 or int(v) | |
808 | if 'context' in req.form: |
|
808 | if 'context' in req.form: | |
809 | context = parsecontext(req.form['context'][0]) |
|
809 | context = parsecontext(req.form['context'][0]) | |
810 | else: |
|
810 | else: | |
811 | context = parsecontext(web.config('web', 'comparisoncontext', '5')) |
|
811 | context = parsecontext(web.config('web', 'comparisoncontext', '5')) | |
812 |
|
812 | |||
813 | def filelines(f): |
|
813 | def filelines(f): | |
814 | if f.isbinary(): |
|
814 | if f.isbinary(): | |
815 | mt = mimetypes.guess_type(f.path())[0] |
|
815 | mt = mimetypes.guess_type(f.path())[0] | |
816 | if not mt: |
|
816 | if not mt: | |
817 | mt = 'application/octet-stream' |
|
817 | mt = 'application/octet-stream' | |
818 | return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] |
|
818 | return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] | |
819 | return f.data().splitlines() |
|
819 | return f.data().splitlines() | |
820 |
|
820 | |||
821 | fctx = None |
|
821 | fctx = None | |
822 | parent = ctx.p1() |
|
822 | parent = ctx.p1() | |
823 | leftrev = parent.rev() |
|
823 | leftrev = parent.rev() | |
824 | leftnode = parent.node() |
|
824 | leftnode = parent.node() | |
825 | rightrev = ctx.rev() |
|
825 | rightrev = ctx.rev() | |
826 | rightnode = ctx.node() |
|
826 | rightnode = ctx.node() | |
827 | if path in ctx: |
|
827 | if path in ctx: | |
828 | fctx = ctx[path] |
|
828 | fctx = ctx[path] | |
829 | rightlines = filelines(fctx) |
|
829 | rightlines = filelines(fctx) | |
830 | if path not in parent: |
|
830 | if path not in parent: | |
831 | leftlines = () |
|
831 | leftlines = () | |
832 | else: |
|
832 | else: | |
833 | pfctx = parent[path] |
|
833 | pfctx = parent[path] | |
834 | leftlines = filelines(pfctx) |
|
834 | leftlines = filelines(pfctx) | |
835 | else: |
|
835 | else: | |
836 | rightlines = () |
|
836 | rightlines = () | |
837 | pfctx = ctx.parents()[0][path] |
|
837 | pfctx = ctx.parents()[0][path] | |
838 | leftlines = filelines(pfctx) |
|
838 | leftlines = filelines(pfctx) | |
839 |
|
839 | |||
840 | comparison = webutil.compare(tmpl, context, leftlines, rightlines) |
|
840 | comparison = webutil.compare(tmpl, context, leftlines, rightlines) | |
841 | if fctx is not None: |
|
841 | if fctx is not None: | |
842 | rename = webutil.renamelink(fctx) |
|
842 | rename = webutil.renamelink(fctx) | |
843 | ctx = fctx |
|
843 | ctx = fctx | |
844 | else: |
|
844 | else: | |
845 | rename = [] |
|
845 | rename = [] | |
846 | ctx = ctx |
|
846 | ctx = ctx | |
847 | return tmpl('filecomparison', |
|
847 | return tmpl('filecomparison', | |
848 | file=path, |
|
848 | file=path, | |
849 | symrev=webutil.symrevorshortnode(req, ctx), |
|
849 | symrev=webutil.symrevorshortnode(req, ctx), | |
850 | rename=rename, |
|
850 | rename=rename, | |
851 | leftrev=leftrev, |
|
851 | leftrev=leftrev, | |
852 | leftnode=hex(leftnode), |
|
852 | leftnode=hex(leftnode), | |
853 | rightrev=rightrev, |
|
853 | rightrev=rightrev, | |
854 | rightnode=hex(rightnode), |
|
854 | rightnode=hex(rightnode), | |
855 | comparison=comparison, |
|
855 | comparison=comparison, | |
856 | **webutil.commonentry(web.repo, ctx)) |
|
856 | **webutil.commonentry(web.repo, ctx)) | |
857 |
|
857 | |||
858 | @webcommand('annotate') |
|
858 | @webcommand('annotate') | |
859 | def annotate(web, req, tmpl): |
|
859 | def annotate(web, req, tmpl): | |
860 | """ |
|
860 | """ | |
861 | /annotate/{revision}/{path} |
|
861 | /annotate/{revision}/{path} | |
862 | --------------------------- |
|
862 | --------------------------- | |
863 |
|
863 | |||
864 | Show changeset information for each line in a file. |
|
864 | Show changeset information for each line in a file. | |
865 |
|
865 | |||
866 | The ``ignorews``, ``ignorewsamount``, ``ignorewseol``, and |
|
866 | The ``ignorews``, ``ignorewsamount``, ``ignorewseol``, and | |
867 | ``ignoreblanklines`` query string arguments have the same meaning as |
|
867 | ``ignoreblanklines`` query string arguments have the same meaning as | |
868 | their ``[annotate]`` config equivalents. It uses the hgrc boolean |
|
868 | their ``[annotate]`` config equivalents. It uses the hgrc boolean | |
869 | parsing logic to interpret the value. e.g. ``0`` and ``false`` are |
|
869 | parsing logic to interpret the value. e.g. ``0`` and ``false`` are | |
870 | false and ``1`` and ``true`` are true. If not defined, the server |
|
870 | false and ``1`` and ``true`` are true. If not defined, the server | |
871 | default settings are used. |
|
871 | default settings are used. | |
872 |
|
872 | |||
873 | The ``fileannotate`` template is rendered. |
|
873 | The ``fileannotate`` template is rendered. | |
874 | """ |
|
874 | """ | |
875 | fctx = webutil.filectx(web.repo, req) |
|
875 | fctx = webutil.filectx(web.repo, req) | |
876 | f = fctx.path() |
|
876 | f = fctx.path() | |
877 | parity = paritygen(web.stripecount) |
|
877 | parity = paritygen(web.stripecount) | |
878 | ishead = fctx.filerev() in fctx.filelog().headrevs() |
|
878 | ishead = fctx.filerev() in fctx.filelog().headrevs() | |
879 |
|
879 | |||
880 | # parents() is called once per line and several lines likely belong to |
|
880 | # parents() is called once per line and several lines likely belong to | |
881 | # same revision. So it is worth caching. |
|
881 | # same revision. So it is worth caching. | |
882 | # TODO there are still redundant operations within basefilectx.parents() |
|
882 | # TODO there are still redundant operations within basefilectx.parents() | |
883 | # and from the fctx.annotate() call itself that could be cached. |
|
883 | # and from the fctx.annotate() call itself that could be cached. | |
884 | parentscache = {} |
|
884 | parentscache = {} | |
885 | def parents(f): |
|
885 | def parents(f): | |
886 | rev = f.rev() |
|
886 | rev = f.rev() | |
887 | if rev not in parentscache: |
|
887 | if rev not in parentscache: | |
888 | parentscache[rev] = [] |
|
888 | parentscache[rev] = [] | |
889 | for p in f.parents(): |
|
889 | for p in f.parents(): | |
890 | entry = { |
|
890 | entry = { | |
891 | 'node': p.hex(), |
|
891 | 'node': p.hex(), | |
892 | 'rev': p.rev(), |
|
892 | 'rev': p.rev(), | |
893 | } |
|
893 | } | |
894 | parentscache[rev].append(entry) |
|
894 | parentscache[rev].append(entry) | |
895 |
|
895 | |||
896 | for p in parentscache[rev]: |
|
896 | for p in parentscache[rev]: | |
897 | yield p |
|
897 | yield p | |
898 |
|
898 | |||
899 | def annotate(**map): |
|
899 | def annotate(**map): | |
900 | if fctx.isbinary(): |
|
900 | if fctx.isbinary(): | |
901 | mt = (mimetypes.guess_type(fctx.path())[0] |
|
901 | mt = (mimetypes.guess_type(fctx.path())[0] | |
902 | or 'application/octet-stream') |
|
902 | or 'application/octet-stream') | |
903 | lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)] |
|
903 | lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)] | |
904 | else: |
|
904 | else: | |
905 | lines = webutil.annotate(req, fctx, web.repo.ui) |
|
905 | lines = webutil.annotate(req, fctx, web.repo.ui) | |
906 |
|
906 | |||
907 | previousrev = None |
|
907 | previousrev = None | |
908 | blockparitygen = paritygen(1) |
|
908 | blockparitygen = paritygen(1) | |
909 |
for lineno, ( |
|
909 | for lineno, (aline, l) in enumerate(lines): | |
|
910 | f = aline.fctx | |||
910 | rev = f.rev() |
|
911 | rev = f.rev() | |
911 | if rev != previousrev: |
|
912 | if rev != previousrev: | |
912 | blockhead = True |
|
913 | blockhead = True | |
913 | blockparity = next(blockparitygen) |
|
914 | blockparity = next(blockparitygen) | |
914 | else: |
|
915 | else: | |
915 | blockhead = None |
|
916 | blockhead = None | |
916 | previousrev = rev |
|
917 | previousrev = rev | |
917 | yield {"parity": next(parity), |
|
918 | yield {"parity": next(parity), | |
918 | "node": f.hex(), |
|
919 | "node": f.hex(), | |
919 | "rev": rev, |
|
920 | "rev": rev, | |
920 | "author": f.user(), |
|
921 | "author": f.user(), | |
921 | "parents": parents(f), |
|
922 | "parents": parents(f), | |
922 | "desc": f.description(), |
|
923 | "desc": f.description(), | |
923 | "extra": f.extra(), |
|
924 | "extra": f.extra(), | |
924 | "file": f.path(), |
|
925 | "file": f.path(), | |
925 | "blockhead": blockhead, |
|
926 | "blockhead": blockhead, | |
926 | "blockparity": blockparity, |
|
927 | "blockparity": blockparity, | |
927 |
"targetline": |
|
928 | "targetline": aline.lineno, | |
928 | "line": l, |
|
929 | "line": l, | |
929 | "lineno": lineno + 1, |
|
930 | "lineno": lineno + 1, | |
930 | "lineid": "l%d" % (lineno + 1), |
|
931 | "lineid": "l%d" % (lineno + 1), | |
931 | "linenumber": "% 6d" % (lineno + 1), |
|
932 | "linenumber": "% 6d" % (lineno + 1), | |
932 | "revdate": f.date()} |
|
933 | "revdate": f.date()} | |
933 |
|
934 | |||
934 | diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate') |
|
935 | diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate') | |
935 | diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults} |
|
936 | diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults} | |
936 |
|
937 | |||
937 | return tmpl("fileannotate", |
|
938 | return tmpl("fileannotate", | |
938 | file=f, |
|
939 | file=f, | |
939 | annotate=annotate, |
|
940 | annotate=annotate, | |
940 | path=webutil.up(f), |
|
941 | path=webutil.up(f), | |
941 | symrev=webutil.symrevorshortnode(req, fctx), |
|
942 | symrev=webutil.symrevorshortnode(req, fctx), | |
942 | rename=webutil.renamelink(fctx), |
|
943 | rename=webutil.renamelink(fctx), | |
943 | permissions=fctx.manifest().flags(f), |
|
944 | permissions=fctx.manifest().flags(f), | |
944 | ishead=int(ishead), |
|
945 | ishead=int(ishead), | |
945 | diffopts=diffopts, |
|
946 | diffopts=diffopts, | |
946 | **webutil.commonentry(web.repo, fctx)) |
|
947 | **webutil.commonentry(web.repo, fctx)) | |
947 |
|
948 | |||
948 | @webcommand('filelog') |
|
949 | @webcommand('filelog') | |
949 | def filelog(web, req, tmpl): |
|
950 | def filelog(web, req, tmpl): | |
950 | """ |
|
951 | """ | |
951 | /filelog/{revision}/{path} |
|
952 | /filelog/{revision}/{path} | |
952 | -------------------------- |
|
953 | -------------------------- | |
953 |
|
954 | |||
954 | Show information about the history of a file in the repository. |
|
955 | Show information about the history of a file in the repository. | |
955 |
|
956 | |||
956 | The ``revcount`` query string argument can be defined to control the |
|
957 | The ``revcount`` query string argument can be defined to control the | |
957 | maximum number of entries to show. |
|
958 | maximum number of entries to show. | |
958 |
|
959 | |||
959 | The ``filelog`` template will be rendered. |
|
960 | The ``filelog`` template will be rendered. | |
960 | """ |
|
961 | """ | |
961 |
|
962 | |||
962 | try: |
|
963 | try: | |
963 | fctx = webutil.filectx(web.repo, req) |
|
964 | fctx = webutil.filectx(web.repo, req) | |
964 | f = fctx.path() |
|
965 | f = fctx.path() | |
965 | fl = fctx.filelog() |
|
966 | fl = fctx.filelog() | |
966 | except error.LookupError: |
|
967 | except error.LookupError: | |
967 | f = webutil.cleanpath(web.repo, req.form['file'][0]) |
|
968 | f = webutil.cleanpath(web.repo, req.form['file'][0]) | |
968 | fl = web.repo.file(f) |
|
969 | fl = web.repo.file(f) | |
969 | numrevs = len(fl) |
|
970 | numrevs = len(fl) | |
970 | if not numrevs: # file doesn't exist at all |
|
971 | if not numrevs: # file doesn't exist at all | |
971 | raise |
|
972 | raise | |
972 | rev = webutil.changectx(web.repo, req).rev() |
|
973 | rev = webutil.changectx(web.repo, req).rev() | |
973 | first = fl.linkrev(0) |
|
974 | first = fl.linkrev(0) | |
974 | if rev < first: # current rev is from before file existed |
|
975 | if rev < first: # current rev is from before file existed | |
975 | raise |
|
976 | raise | |
976 | frev = numrevs - 1 |
|
977 | frev = numrevs - 1 | |
977 | while fl.linkrev(frev) > rev: |
|
978 | while fl.linkrev(frev) > rev: | |
978 | frev -= 1 |
|
979 | frev -= 1 | |
979 | fctx = web.repo.filectx(f, fl.linkrev(frev)) |
|
980 | fctx = web.repo.filectx(f, fl.linkrev(frev)) | |
980 |
|
981 | |||
981 | revcount = web.maxshortchanges |
|
982 | revcount = web.maxshortchanges | |
982 | if 'revcount' in req.form: |
|
983 | if 'revcount' in req.form: | |
983 | try: |
|
984 | try: | |
984 | revcount = int(req.form.get('revcount', [revcount])[0]) |
|
985 | revcount = int(req.form.get('revcount', [revcount])[0]) | |
985 | revcount = max(revcount, 1) |
|
986 | revcount = max(revcount, 1) | |
986 | tmpl.defaults['sessionvars']['revcount'] = revcount |
|
987 | tmpl.defaults['sessionvars']['revcount'] = revcount | |
987 | except ValueError: |
|
988 | except ValueError: | |
988 | pass |
|
989 | pass | |
989 |
|
990 | |||
990 | lrange = webutil.linerange(req) |
|
991 | lrange = webutil.linerange(req) | |
991 |
|
992 | |||
992 | lessvars = copy.copy(tmpl.defaults['sessionvars']) |
|
993 | lessvars = copy.copy(tmpl.defaults['sessionvars']) | |
993 | lessvars['revcount'] = max(revcount / 2, 1) |
|
994 | lessvars['revcount'] = max(revcount / 2, 1) | |
994 | morevars = copy.copy(tmpl.defaults['sessionvars']) |
|
995 | morevars = copy.copy(tmpl.defaults['sessionvars']) | |
995 | morevars['revcount'] = revcount * 2 |
|
996 | morevars['revcount'] = revcount * 2 | |
996 |
|
997 | |||
997 | patch = 'patch' in req.form |
|
998 | patch = 'patch' in req.form | |
998 | if patch: |
|
999 | if patch: | |
999 | lessvars['patch'] = morevars['patch'] = req.form['patch'][0] |
|
1000 | lessvars['patch'] = morevars['patch'] = req.form['patch'][0] | |
1000 | descend = 'descend' in req.form |
|
1001 | descend = 'descend' in req.form | |
1001 | if descend: |
|
1002 | if descend: | |
1002 | lessvars['descend'] = morevars['descend'] = req.form['descend'][0] |
|
1003 | lessvars['descend'] = morevars['descend'] = req.form['descend'][0] | |
1003 |
|
1004 | |||
1004 | count = fctx.filerev() + 1 |
|
1005 | count = fctx.filerev() + 1 | |
1005 | start = max(0, count - revcount) # first rev on this page |
|
1006 | start = max(0, count - revcount) # first rev on this page | |
1006 | end = min(count, start + revcount) # last rev on this page |
|
1007 | end = min(count, start + revcount) # last rev on this page | |
1007 | parity = paritygen(web.stripecount, offset=start - end) |
|
1008 | parity = paritygen(web.stripecount, offset=start - end) | |
1008 |
|
1009 | |||
1009 | repo = web.repo |
|
1010 | repo = web.repo | |
1010 | revs = fctx.filelog().revs(start, end - 1) |
|
1011 | revs = fctx.filelog().revs(start, end - 1) | |
1011 | entries = [] |
|
1012 | entries = [] | |
1012 |
|
1013 | |||
1013 | diffstyle = web.config('web', 'style') |
|
1014 | diffstyle = web.config('web', 'style') | |
1014 | if 'style' in req.form: |
|
1015 | if 'style' in req.form: | |
1015 | diffstyle = req.form['style'][0] |
|
1016 | diffstyle = req.form['style'][0] | |
1016 |
|
1017 | |||
1017 | def diff(fctx, linerange=None): |
|
1018 | def diff(fctx, linerange=None): | |
1018 | ctx = fctx.changectx() |
|
1019 | ctx = fctx.changectx() | |
1019 | basectx = ctx.p1() |
|
1020 | basectx = ctx.p1() | |
1020 | path = fctx.path() |
|
1021 | path = fctx.path() | |
1021 | return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle, |
|
1022 | return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle, | |
1022 | linerange=linerange, |
|
1023 | linerange=linerange, | |
1023 | lineidprefix='%s-' % ctx.hex()[:12]) |
|
1024 | lineidprefix='%s-' % ctx.hex()[:12]) | |
1024 |
|
1025 | |||
1025 | linerange = None |
|
1026 | linerange = None | |
1026 | if lrange is not None: |
|
1027 | if lrange is not None: | |
1027 | linerange = webutil.formatlinerange(*lrange) |
|
1028 | linerange = webutil.formatlinerange(*lrange) | |
1028 | # deactivate numeric nav links when linerange is specified as this |
|
1029 | # deactivate numeric nav links when linerange is specified as this | |
1029 | # would required a dedicated "revnav" class |
|
1030 | # would required a dedicated "revnav" class | |
1030 | nav = None |
|
1031 | nav = None | |
1031 | if descend: |
|
1032 | if descend: | |
1032 | it = dagop.blockdescendants(fctx, *lrange) |
|
1033 | it = dagop.blockdescendants(fctx, *lrange) | |
1033 | else: |
|
1034 | else: | |
1034 | it = dagop.blockancestors(fctx, *lrange) |
|
1035 | it = dagop.blockancestors(fctx, *lrange) | |
1035 | for i, (c, lr) in enumerate(it, 1): |
|
1036 | for i, (c, lr) in enumerate(it, 1): | |
1036 | diffs = None |
|
1037 | diffs = None | |
1037 | if patch: |
|
1038 | if patch: | |
1038 | diffs = diff(c, linerange=lr) |
|
1039 | diffs = diff(c, linerange=lr) | |
1039 | # follow renames accross filtered (not in range) revisions |
|
1040 | # follow renames accross filtered (not in range) revisions | |
1040 | path = c.path() |
|
1041 | path = c.path() | |
1041 | entries.append(dict( |
|
1042 | entries.append(dict( | |
1042 | parity=next(parity), |
|
1043 | parity=next(parity), | |
1043 | filerev=c.rev(), |
|
1044 | filerev=c.rev(), | |
1044 | file=path, |
|
1045 | file=path, | |
1045 | diff=diffs, |
|
1046 | diff=diffs, | |
1046 | linerange=webutil.formatlinerange(*lr), |
|
1047 | linerange=webutil.formatlinerange(*lr), | |
1047 | **webutil.commonentry(repo, c))) |
|
1048 | **webutil.commonentry(repo, c))) | |
1048 | if i == revcount: |
|
1049 | if i == revcount: | |
1049 | break |
|
1050 | break | |
1050 | lessvars['linerange'] = webutil.formatlinerange(*lrange) |
|
1051 | lessvars['linerange'] = webutil.formatlinerange(*lrange) | |
1051 | morevars['linerange'] = lessvars['linerange'] |
|
1052 | morevars['linerange'] = lessvars['linerange'] | |
1052 | else: |
|
1053 | else: | |
1053 | for i in revs: |
|
1054 | for i in revs: | |
1054 | iterfctx = fctx.filectx(i) |
|
1055 | iterfctx = fctx.filectx(i) | |
1055 | diffs = None |
|
1056 | diffs = None | |
1056 | if patch: |
|
1057 | if patch: | |
1057 | diffs = diff(iterfctx) |
|
1058 | diffs = diff(iterfctx) | |
1058 | entries.append(dict( |
|
1059 | entries.append(dict( | |
1059 | parity=next(parity), |
|
1060 | parity=next(parity), | |
1060 | filerev=i, |
|
1061 | filerev=i, | |
1061 | file=f, |
|
1062 | file=f, | |
1062 | diff=diffs, |
|
1063 | diff=diffs, | |
1063 | rename=webutil.renamelink(iterfctx), |
|
1064 | rename=webutil.renamelink(iterfctx), | |
1064 | **webutil.commonentry(repo, iterfctx))) |
|
1065 | **webutil.commonentry(repo, iterfctx))) | |
1065 | entries.reverse() |
|
1066 | entries.reverse() | |
1066 | revnav = webutil.filerevnav(web.repo, fctx.path()) |
|
1067 | revnav = webutil.filerevnav(web.repo, fctx.path()) | |
1067 | nav = revnav.gen(end - 1, revcount, count) |
|
1068 | nav = revnav.gen(end - 1, revcount, count) | |
1068 |
|
1069 | |||
1069 | latestentry = entries[:1] |
|
1070 | latestentry = entries[:1] | |
1070 |
|
1071 | |||
1071 | return tmpl("filelog", |
|
1072 | return tmpl("filelog", | |
1072 | file=f, |
|
1073 | file=f, | |
1073 | nav=nav, |
|
1074 | nav=nav, | |
1074 | symrev=webutil.symrevorshortnode(req, fctx), |
|
1075 | symrev=webutil.symrevorshortnode(req, fctx), | |
1075 | entries=entries, |
|
1076 | entries=entries, | |
1076 | descend=descend, |
|
1077 | descend=descend, | |
1077 | patch=patch, |
|
1078 | patch=patch, | |
1078 | latestentry=latestentry, |
|
1079 | latestentry=latestentry, | |
1079 | linerange=linerange, |
|
1080 | linerange=linerange, | |
1080 | revcount=revcount, |
|
1081 | revcount=revcount, | |
1081 | morevars=morevars, |
|
1082 | morevars=morevars, | |
1082 | lessvars=lessvars, |
|
1083 | lessvars=lessvars, | |
1083 | **webutil.commonentry(web.repo, fctx)) |
|
1084 | **webutil.commonentry(web.repo, fctx)) | |
1084 |
|
1085 | |||
1085 | @webcommand('archive') |
|
1086 | @webcommand('archive') | |
1086 | def archive(web, req, tmpl): |
|
1087 | def archive(web, req, tmpl): | |
1087 | """ |
|
1088 | """ | |
1088 | /archive/{revision}.{format}[/{path}] |
|
1089 | /archive/{revision}.{format}[/{path}] | |
1089 | ------------------------------------- |
|
1090 | ------------------------------------- | |
1090 |
|
1091 | |||
1091 | Obtain an archive of repository content. |
|
1092 | Obtain an archive of repository content. | |
1092 |
|
1093 | |||
1093 | The content and type of the archive is defined by a URL path parameter. |
|
1094 | The content and type of the archive is defined by a URL path parameter. | |
1094 | ``format`` is the file extension of the archive type to be generated. e.g. |
|
1095 | ``format`` is the file extension of the archive type to be generated. e.g. | |
1095 | ``zip`` or ``tar.bz2``. Not all archive types may be allowed by your |
|
1096 | ``zip`` or ``tar.bz2``. Not all archive types may be allowed by your | |
1096 | server configuration. |
|
1097 | server configuration. | |
1097 |
|
1098 | |||
1098 | The optional ``path`` URL parameter controls content to include in the |
|
1099 | The optional ``path`` URL parameter controls content to include in the | |
1099 | archive. If omitted, every file in the specified revision is present in the |
|
1100 | archive. If omitted, every file in the specified revision is present in the | |
1100 | archive. If included, only the specified file or contents of the specified |
|
1101 | archive. If included, only the specified file or contents of the specified | |
1101 | directory will be included in the archive. |
|
1102 | directory will be included in the archive. | |
1102 |
|
1103 | |||
1103 | No template is used for this handler. Raw, binary content is generated. |
|
1104 | No template is used for this handler. Raw, binary content is generated. | |
1104 | """ |
|
1105 | """ | |
1105 |
|
1106 | |||
1106 | type_ = req.form.get('type', [None])[0] |
|
1107 | type_ = req.form.get('type', [None])[0] | |
1107 | allowed = web.configlist("web", "allow_archive") |
|
1108 | allowed = web.configlist("web", "allow_archive") | |
1108 | key = req.form['node'][0] |
|
1109 | key = req.form['node'][0] | |
1109 |
|
1110 | |||
1110 | if type_ not in web.archivespecs: |
|
1111 | if type_ not in web.archivespecs: | |
1111 | msg = 'Unsupported archive type: %s' % type_ |
|
1112 | msg = 'Unsupported archive type: %s' % type_ | |
1112 | raise ErrorResponse(HTTP_NOT_FOUND, msg) |
|
1113 | raise ErrorResponse(HTTP_NOT_FOUND, msg) | |
1113 |
|
1114 | |||
1114 | if not ((type_ in allowed or |
|
1115 | if not ((type_ in allowed or | |
1115 | web.configbool("web", "allow" + type_, False))): |
|
1116 | web.configbool("web", "allow" + type_, False))): | |
1116 | msg = 'Archive type not allowed: %s' % type_ |
|
1117 | msg = 'Archive type not allowed: %s' % type_ | |
1117 | raise ErrorResponse(HTTP_FORBIDDEN, msg) |
|
1118 | raise ErrorResponse(HTTP_FORBIDDEN, msg) | |
1118 |
|
1119 | |||
1119 | reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
|
1120 | reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) | |
1120 | cnode = web.repo.lookup(key) |
|
1121 | cnode = web.repo.lookup(key) | |
1121 | arch_version = key |
|
1122 | arch_version = key | |
1122 | if cnode == key or key == 'tip': |
|
1123 | if cnode == key or key == 'tip': | |
1123 | arch_version = short(cnode) |
|
1124 | arch_version = short(cnode) | |
1124 | name = "%s-%s" % (reponame, arch_version) |
|
1125 | name = "%s-%s" % (reponame, arch_version) | |
1125 |
|
1126 | |||
1126 | ctx = webutil.changectx(web.repo, req) |
|
1127 | ctx = webutil.changectx(web.repo, req) | |
1127 | pats = [] |
|
1128 | pats = [] | |
1128 | match = scmutil.match(ctx, []) |
|
1129 | match = scmutil.match(ctx, []) | |
1129 | file = req.form.get('file', None) |
|
1130 | file = req.form.get('file', None) | |
1130 | if file: |
|
1131 | if file: | |
1131 | pats = ['path:' + file[0]] |
|
1132 | pats = ['path:' + file[0]] | |
1132 | match = scmutil.match(ctx, pats, default='path') |
|
1133 | match = scmutil.match(ctx, pats, default='path') | |
1133 | if pats: |
|
1134 | if pats: | |
1134 | files = [f for f in ctx.manifest().keys() if match(f)] |
|
1135 | files = [f for f in ctx.manifest().keys() if match(f)] | |
1135 | if not files: |
|
1136 | if not files: | |
1136 | raise ErrorResponse(HTTP_NOT_FOUND, |
|
1137 | raise ErrorResponse(HTTP_NOT_FOUND, | |
1137 | 'file(s) not found: %s' % file[0]) |
|
1138 | 'file(s) not found: %s' % file[0]) | |
1138 |
|
1139 | |||
1139 | mimetype, artype, extension, encoding = web.archivespecs[type_] |
|
1140 | mimetype, artype, extension, encoding = web.archivespecs[type_] | |
1140 | headers = [ |
|
1141 | headers = [ | |
1141 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
|
1142 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) | |
1142 | ] |
|
1143 | ] | |
1143 | if encoding: |
|
1144 | if encoding: | |
1144 | headers.append(('Content-Encoding', encoding)) |
|
1145 | headers.append(('Content-Encoding', encoding)) | |
1145 | req.headers.extend(headers) |
|
1146 | req.headers.extend(headers) | |
1146 | req.respond(HTTP_OK, mimetype) |
|
1147 | req.respond(HTTP_OK, mimetype) | |
1147 |
|
1148 | |||
1148 | archival.archive(web.repo, req, cnode, artype, prefix=name, |
|
1149 | archival.archive(web.repo, req, cnode, artype, prefix=name, | |
1149 | matchfn=match, |
|
1150 | matchfn=match, | |
1150 | subrepos=web.configbool("web", "archivesubrepos")) |
|
1151 | subrepos=web.configbool("web", "archivesubrepos")) | |
1151 | return [] |
|
1152 | return [] | |
1152 |
|
1153 | |||
1153 |
|
1154 | |||
1154 | @webcommand('static') |
|
1155 | @webcommand('static') | |
1155 | def static(web, req, tmpl): |
|
1156 | def static(web, req, tmpl): | |
1156 | fname = req.form['file'][0] |
|
1157 | fname = req.form['file'][0] | |
1157 | # a repo owner may set web.static in .hg/hgrc to get any file |
|
1158 | # a repo owner may set web.static in .hg/hgrc to get any file | |
1158 | # readable by the user running the CGI script |
|
1159 | # readable by the user running the CGI script | |
1159 | static = web.config("web", "static", None, untrusted=False) |
|
1160 | static = web.config("web", "static", None, untrusted=False) | |
1160 | if not static: |
|
1161 | if not static: | |
1161 | tp = web.templatepath or templater.templatepaths() |
|
1162 | tp = web.templatepath or templater.templatepaths() | |
1162 | if isinstance(tp, str): |
|
1163 | if isinstance(tp, str): | |
1163 | tp = [tp] |
|
1164 | tp = [tp] | |
1164 | static = [os.path.join(p, 'static') for p in tp] |
|
1165 | static = [os.path.join(p, 'static') for p in tp] | |
1165 | staticfile(static, fname, req) |
|
1166 | staticfile(static, fname, req) | |
1166 | return [] |
|
1167 | return [] | |
1167 |
|
1168 | |||
1168 | @webcommand('graph') |
|
1169 | @webcommand('graph') | |
1169 | def graph(web, req, tmpl): |
|
1170 | def graph(web, req, tmpl): | |
1170 | """ |
|
1171 | """ | |
1171 | /graph[/{revision}] |
|
1172 | /graph[/{revision}] | |
1172 | ------------------- |
|
1173 | ------------------- | |
1173 |
|
1174 | |||
1174 | Show information about the graphical topology of the repository. |
|
1175 | Show information about the graphical topology of the repository. | |
1175 |
|
1176 | |||
1176 | Information rendered by this handler can be used to create visual |
|
1177 | Information rendered by this handler can be used to create visual | |
1177 | representations of repository topology. |
|
1178 | representations of repository topology. | |
1178 |
|
1179 | |||
1179 | The ``revision`` URL parameter controls the starting changeset. |
|
1180 | The ``revision`` URL parameter controls the starting changeset. | |
1180 |
|
1181 | |||
1181 | The ``revcount`` query string argument can define the number of changesets |
|
1182 | The ``revcount`` query string argument can define the number of changesets | |
1182 | to show information for. |
|
1183 | to show information for. | |
1183 |
|
1184 | |||
1184 | This handler will render the ``graph`` template. |
|
1185 | This handler will render the ``graph`` template. | |
1185 | """ |
|
1186 | """ | |
1186 |
|
1187 | |||
1187 | if 'node' in req.form: |
|
1188 | if 'node' in req.form: | |
1188 | ctx = webutil.changectx(web.repo, req) |
|
1189 | ctx = webutil.changectx(web.repo, req) | |
1189 | symrev = webutil.symrevorshortnode(req, ctx) |
|
1190 | symrev = webutil.symrevorshortnode(req, ctx) | |
1190 | else: |
|
1191 | else: | |
1191 | ctx = web.repo['tip'] |
|
1192 | ctx = web.repo['tip'] | |
1192 | symrev = 'tip' |
|
1193 | symrev = 'tip' | |
1193 | rev = ctx.rev() |
|
1194 | rev = ctx.rev() | |
1194 |
|
1195 | |||
1195 | bg_height = 39 |
|
1196 | bg_height = 39 | |
1196 | revcount = web.maxshortchanges |
|
1197 | revcount = web.maxshortchanges | |
1197 | if 'revcount' in req.form: |
|
1198 | if 'revcount' in req.form: | |
1198 | try: |
|
1199 | try: | |
1199 | revcount = int(req.form.get('revcount', [revcount])[0]) |
|
1200 | revcount = int(req.form.get('revcount', [revcount])[0]) | |
1200 | revcount = max(revcount, 1) |
|
1201 | revcount = max(revcount, 1) | |
1201 | tmpl.defaults['sessionvars']['revcount'] = revcount |
|
1202 | tmpl.defaults['sessionvars']['revcount'] = revcount | |
1202 | except ValueError: |
|
1203 | except ValueError: | |
1203 | pass |
|
1204 | pass | |
1204 |
|
1205 | |||
1205 | lessvars = copy.copy(tmpl.defaults['sessionvars']) |
|
1206 | lessvars = copy.copy(tmpl.defaults['sessionvars']) | |
1206 | lessvars['revcount'] = max(revcount / 2, 1) |
|
1207 | lessvars['revcount'] = max(revcount / 2, 1) | |
1207 | morevars = copy.copy(tmpl.defaults['sessionvars']) |
|
1208 | morevars = copy.copy(tmpl.defaults['sessionvars']) | |
1208 | morevars['revcount'] = revcount * 2 |
|
1209 | morevars['revcount'] = revcount * 2 | |
1209 |
|
1210 | |||
1210 | count = len(web.repo) |
|
1211 | count = len(web.repo) | |
1211 | pos = rev |
|
1212 | pos = rev | |
1212 |
|
1213 | |||
1213 | uprev = min(max(0, count - 1), rev + revcount) |
|
1214 | uprev = min(max(0, count - 1), rev + revcount) | |
1214 | downrev = max(0, rev - revcount) |
|
1215 | downrev = max(0, rev - revcount) | |
1215 | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
|
1216 | changenav = webutil.revnav(web.repo).gen(pos, revcount, count) | |
1216 |
|
1217 | |||
1217 | tree = [] |
|
1218 | tree = [] | |
1218 | if pos != -1: |
|
1219 | if pos != -1: | |
1219 | allrevs = web.repo.changelog.revs(pos, 0) |
|
1220 | allrevs = web.repo.changelog.revs(pos, 0) | |
1220 | revs = [] |
|
1221 | revs = [] | |
1221 | for i in allrevs: |
|
1222 | for i in allrevs: | |
1222 | revs.append(i) |
|
1223 | revs.append(i) | |
1223 | if len(revs) >= revcount: |
|
1224 | if len(revs) >= revcount: | |
1224 | break |
|
1225 | break | |
1225 |
|
1226 | |||
1226 | # We have to feed a baseset to dagwalker as it is expecting smartset |
|
1227 | # We have to feed a baseset to dagwalker as it is expecting smartset | |
1227 | # object. This does not have a big impact on hgweb performance itself |
|
1228 | # object. This does not have a big impact on hgweb performance itself | |
1228 | # since hgweb graphing code is not itself lazy yet. |
|
1229 | # since hgweb graphing code is not itself lazy yet. | |
1229 | dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
|
1230 | dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) | |
1230 | # As we said one line above... not lazy. |
|
1231 | # As we said one line above... not lazy. | |
1231 | tree = list(graphmod.colored(dag, web.repo)) |
|
1232 | tree = list(graphmod.colored(dag, web.repo)) | |
1232 |
|
1233 | |||
1233 | def getcolumns(tree): |
|
1234 | def getcolumns(tree): | |
1234 | cols = 0 |
|
1235 | cols = 0 | |
1235 | for (id, type, ctx, vtx, edges) in tree: |
|
1236 | for (id, type, ctx, vtx, edges) in tree: | |
1236 | if type != graphmod.CHANGESET: |
|
1237 | if type != graphmod.CHANGESET: | |
1237 | continue |
|
1238 | continue | |
1238 | cols = max(cols, max([edge[0] for edge in edges] or [0]), |
|
1239 | cols = max(cols, max([edge[0] for edge in edges] or [0]), | |
1239 | max([edge[1] for edge in edges] or [0])) |
|
1240 | max([edge[1] for edge in edges] or [0])) | |
1240 | return cols |
|
1241 | return cols | |
1241 |
|
1242 | |||
1242 | def graphdata(usetuples, encodestr): |
|
1243 | def graphdata(usetuples, encodestr): | |
1243 | data = [] |
|
1244 | data = [] | |
1244 |
|
1245 | |||
1245 | row = 0 |
|
1246 | row = 0 | |
1246 | for (id, type, ctx, vtx, edges) in tree: |
|
1247 | for (id, type, ctx, vtx, edges) in tree: | |
1247 | if type != graphmod.CHANGESET: |
|
1248 | if type != graphmod.CHANGESET: | |
1248 | continue |
|
1249 | continue | |
1249 | node = str(ctx) |
|
1250 | node = str(ctx) | |
1250 | age = encodestr(templatefilters.age(ctx.date())) |
|
1251 | age = encodestr(templatefilters.age(ctx.date())) | |
1251 | desc = templatefilters.firstline(encodestr(ctx.description())) |
|
1252 | desc = templatefilters.firstline(encodestr(ctx.description())) | |
1252 | desc = cgi.escape(templatefilters.nonempty(desc)) |
|
1253 | desc = cgi.escape(templatefilters.nonempty(desc)) | |
1253 | user = cgi.escape(templatefilters.person(encodestr(ctx.user()))) |
|
1254 | user = cgi.escape(templatefilters.person(encodestr(ctx.user()))) | |
1254 | branch = cgi.escape(encodestr(ctx.branch())) |
|
1255 | branch = cgi.escape(encodestr(ctx.branch())) | |
1255 | try: |
|
1256 | try: | |
1256 | branchnode = web.repo.branchtip(branch) |
|
1257 | branchnode = web.repo.branchtip(branch) | |
1257 | except error.RepoLookupError: |
|
1258 | except error.RepoLookupError: | |
1258 | branchnode = None |
|
1259 | branchnode = None | |
1259 | branch = branch, branchnode == ctx.node() |
|
1260 | branch = branch, branchnode == ctx.node() | |
1260 |
|
1261 | |||
1261 | if usetuples: |
|
1262 | if usetuples: | |
1262 | data.append((node, vtx, edges, desc, user, age, branch, |
|
1263 | data.append((node, vtx, edges, desc, user, age, branch, | |
1263 | [cgi.escape(encodestr(x)) for x in ctx.tags()], |
|
1264 | [cgi.escape(encodestr(x)) for x in ctx.tags()], | |
1264 | [cgi.escape(encodestr(x)) |
|
1265 | [cgi.escape(encodestr(x)) | |
1265 | for x in ctx.bookmarks()])) |
|
1266 | for x in ctx.bookmarks()])) | |
1266 | else: |
|
1267 | else: | |
1267 | edgedata = [{'col': edge[0], 'nextcol': edge[1], |
|
1268 | edgedata = [{'col': edge[0], 'nextcol': edge[1], | |
1268 | 'color': (edge[2] - 1) % 6 + 1, |
|
1269 | 'color': (edge[2] - 1) % 6 + 1, | |
1269 | 'width': edge[3], 'bcolor': edge[4]} |
|
1270 | 'width': edge[3], 'bcolor': edge[4]} | |
1270 | for edge in edges] |
|
1271 | for edge in edges] | |
1271 |
|
1272 | |||
1272 | data.append( |
|
1273 | data.append( | |
1273 | {'node': node, |
|
1274 | {'node': node, | |
1274 | 'col': vtx[0], |
|
1275 | 'col': vtx[0], | |
1275 | 'color': (vtx[1] - 1) % 6 + 1, |
|
1276 | 'color': (vtx[1] - 1) % 6 + 1, | |
1276 | 'edges': edgedata, |
|
1277 | 'edges': edgedata, | |
1277 | 'row': row, |
|
1278 | 'row': row, | |
1278 | 'nextrow': row + 1, |
|
1279 | 'nextrow': row + 1, | |
1279 | 'desc': desc, |
|
1280 | 'desc': desc, | |
1280 | 'user': user, |
|
1281 | 'user': user, | |
1281 | 'age': age, |
|
1282 | 'age': age, | |
1282 | 'bookmarks': webutil.nodebookmarksdict( |
|
1283 | 'bookmarks': webutil.nodebookmarksdict( | |
1283 | web.repo, ctx.node()), |
|
1284 | web.repo, ctx.node()), | |
1284 | 'branches': webutil.nodebranchdict(web.repo, ctx), |
|
1285 | 'branches': webutil.nodebranchdict(web.repo, ctx), | |
1285 | 'inbranch': webutil.nodeinbranch(web.repo, ctx), |
|
1286 | 'inbranch': webutil.nodeinbranch(web.repo, ctx), | |
1286 | 'tags': webutil.nodetagsdict(web.repo, ctx.node())}) |
|
1287 | 'tags': webutil.nodetagsdict(web.repo, ctx.node())}) | |
1287 |
|
1288 | |||
1288 | row += 1 |
|
1289 | row += 1 | |
1289 |
|
1290 | |||
1290 | return data |
|
1291 | return data | |
1291 |
|
1292 | |||
1292 | cols = getcolumns(tree) |
|
1293 | cols = getcolumns(tree) | |
1293 | rows = len(tree) |
|
1294 | rows = len(tree) | |
1294 | canvasheight = (rows + 1) * bg_height - 27 |
|
1295 | canvasheight = (rows + 1) * bg_height - 27 | |
1295 |
|
1296 | |||
1296 | return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, |
|
1297 | return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, | |
1297 | uprev=uprev, |
|
1298 | uprev=uprev, | |
1298 | lessvars=lessvars, morevars=morevars, downrev=downrev, |
|
1299 | lessvars=lessvars, morevars=morevars, downrev=downrev, | |
1299 | cols=cols, rows=rows, |
|
1300 | cols=cols, rows=rows, | |
1300 | canvaswidth=(cols + 1) * bg_height, |
|
1301 | canvaswidth=(cols + 1) * bg_height, | |
1301 | truecanvasheight=rows * bg_height, |
|
1302 | truecanvasheight=rows * bg_height, | |
1302 | canvasheight=canvasheight, bg_height=bg_height, |
|
1303 | canvasheight=canvasheight, bg_height=bg_height, | |
1303 | # {jsdata} will be passed to |json, so it must be in utf-8 |
|
1304 | # {jsdata} will be passed to |json, so it must be in utf-8 | |
1304 | jsdata=lambda **x: graphdata(True, encoding.fromlocal), |
|
1305 | jsdata=lambda **x: graphdata(True, encoding.fromlocal), | |
1305 | nodes=lambda **x: graphdata(False, str), |
|
1306 | nodes=lambda **x: graphdata(False, str), | |
1306 | node=ctx.hex(), changenav=changenav) |
|
1307 | node=ctx.hex(), changenav=changenav) | |
1307 |
|
1308 | |||
1308 | def _getdoc(e): |
|
1309 | def _getdoc(e): | |
1309 | doc = e[0].__doc__ |
|
1310 | doc = e[0].__doc__ | |
1310 | if doc: |
|
1311 | if doc: | |
1311 | doc = _(doc).partition('\n')[0] |
|
1312 | doc = _(doc).partition('\n')[0] | |
1312 | else: |
|
1313 | else: | |
1313 | doc = _('(no help text available)') |
|
1314 | doc = _('(no help text available)') | |
1314 | return doc |
|
1315 | return doc | |
1315 |
|
1316 | |||
1316 | @webcommand('help') |
|
1317 | @webcommand('help') | |
1317 | def help(web, req, tmpl): |
|
1318 | def help(web, req, tmpl): | |
1318 | """ |
|
1319 | """ | |
1319 | /help[/{topic}] |
|
1320 | /help[/{topic}] | |
1320 | --------------- |
|
1321 | --------------- | |
1321 |
|
1322 | |||
1322 | Render help documentation. |
|
1323 | Render help documentation. | |
1323 |
|
1324 | |||
1324 | This web command is roughly equivalent to :hg:`help`. If a ``topic`` |
|
1325 | This web command is roughly equivalent to :hg:`help`. If a ``topic`` | |
1325 | is defined, that help topic will be rendered. If not, an index of |
|
1326 | is defined, that help topic will be rendered. If not, an index of | |
1326 | available help topics will be rendered. |
|
1327 | available help topics will be rendered. | |
1327 |
|
1328 | |||
1328 | The ``help`` template will be rendered when requesting help for a topic. |
|
1329 | The ``help`` template will be rendered when requesting help for a topic. | |
1329 | ``helptopics`` will be rendered for the index of help topics. |
|
1330 | ``helptopics`` will be rendered for the index of help topics. | |
1330 | """ |
|
1331 | """ | |
1331 | from .. import commands, help as helpmod # avoid cycle |
|
1332 | from .. import commands, help as helpmod # avoid cycle | |
1332 |
|
1333 | |||
1333 | topicname = req.form.get('node', [None])[0] |
|
1334 | topicname = req.form.get('node', [None])[0] | |
1334 | if not topicname: |
|
1335 | if not topicname: | |
1335 | def topics(**map): |
|
1336 | def topics(**map): | |
1336 | for entries, summary, _doc in helpmod.helptable: |
|
1337 | for entries, summary, _doc in helpmod.helptable: | |
1337 | yield {'topic': entries[0], 'summary': summary} |
|
1338 | yield {'topic': entries[0], 'summary': summary} | |
1338 |
|
1339 | |||
1339 | early, other = [], [] |
|
1340 | early, other = [], [] | |
1340 | primary = lambda s: s.partition('|')[0] |
|
1341 | primary = lambda s: s.partition('|')[0] | |
1341 | for c, e in commands.table.iteritems(): |
|
1342 | for c, e in commands.table.iteritems(): | |
1342 | doc = _getdoc(e) |
|
1343 | doc = _getdoc(e) | |
1343 | if 'DEPRECATED' in doc or c.startswith('debug'): |
|
1344 | if 'DEPRECATED' in doc or c.startswith('debug'): | |
1344 | continue |
|
1345 | continue | |
1345 | cmd = primary(c) |
|
1346 | cmd = primary(c) | |
1346 | if cmd.startswith('^'): |
|
1347 | if cmd.startswith('^'): | |
1347 | early.append((cmd[1:], doc)) |
|
1348 | early.append((cmd[1:], doc)) | |
1348 | else: |
|
1349 | else: | |
1349 | other.append((cmd, doc)) |
|
1350 | other.append((cmd, doc)) | |
1350 |
|
1351 | |||
1351 | early.sort() |
|
1352 | early.sort() | |
1352 | other.sort() |
|
1353 | other.sort() | |
1353 |
|
1354 | |||
1354 | def earlycommands(**map): |
|
1355 | def earlycommands(**map): | |
1355 | for c, doc in early: |
|
1356 | for c, doc in early: | |
1356 | yield {'topic': c, 'summary': doc} |
|
1357 | yield {'topic': c, 'summary': doc} | |
1357 |
|
1358 | |||
1358 | def othercommands(**map): |
|
1359 | def othercommands(**map): | |
1359 | for c, doc in other: |
|
1360 | for c, doc in other: | |
1360 | yield {'topic': c, 'summary': doc} |
|
1361 | yield {'topic': c, 'summary': doc} | |
1361 |
|
1362 | |||
1362 | return tmpl('helptopics', topics=topics, earlycommands=earlycommands, |
|
1363 | return tmpl('helptopics', topics=topics, earlycommands=earlycommands, | |
1363 | othercommands=othercommands, title='Index') |
|
1364 | othercommands=othercommands, title='Index') | |
1364 |
|
1365 | |||
1365 | # Render an index of sub-topics. |
|
1366 | # Render an index of sub-topics. | |
1366 | if topicname in helpmod.subtopics: |
|
1367 | if topicname in helpmod.subtopics: | |
1367 | topics = [] |
|
1368 | topics = [] | |
1368 | for entries, summary, _doc in helpmod.subtopics[topicname]: |
|
1369 | for entries, summary, _doc in helpmod.subtopics[topicname]: | |
1369 | topics.append({ |
|
1370 | topics.append({ | |
1370 | 'topic': '%s.%s' % (topicname, entries[0]), |
|
1371 | 'topic': '%s.%s' % (topicname, entries[0]), | |
1371 | 'basename': entries[0], |
|
1372 | 'basename': entries[0], | |
1372 | 'summary': summary, |
|
1373 | 'summary': summary, | |
1373 | }) |
|
1374 | }) | |
1374 |
|
1375 | |||
1375 | return tmpl('helptopics', topics=topics, title=topicname, |
|
1376 | return tmpl('helptopics', topics=topics, title=topicname, | |
1376 | subindex=True) |
|
1377 | subindex=True) | |
1377 |
|
1378 | |||
1378 | u = webutil.wsgiui.load() |
|
1379 | u = webutil.wsgiui.load() | |
1379 | u.verbose = True |
|
1380 | u.verbose = True | |
1380 |
|
1381 | |||
1381 | # Render a page from a sub-topic. |
|
1382 | # Render a page from a sub-topic. | |
1382 | if '.' in topicname: |
|
1383 | if '.' in topicname: | |
1383 | # TODO implement support for rendering sections, like |
|
1384 | # TODO implement support for rendering sections, like | |
1384 | # `hg help` works. |
|
1385 | # `hg help` works. | |
1385 | topic, subtopic = topicname.split('.', 1) |
|
1386 | topic, subtopic = topicname.split('.', 1) | |
1386 | if topic not in helpmod.subtopics: |
|
1387 | if topic not in helpmod.subtopics: | |
1387 | raise ErrorResponse(HTTP_NOT_FOUND) |
|
1388 | raise ErrorResponse(HTTP_NOT_FOUND) | |
1388 | else: |
|
1389 | else: | |
1389 | topic = topicname |
|
1390 | topic = topicname | |
1390 | subtopic = None |
|
1391 | subtopic = None | |
1391 |
|
1392 | |||
1392 | try: |
|
1393 | try: | |
1393 | doc = helpmod.help_(u, commands, topic, subtopic=subtopic) |
|
1394 | doc = helpmod.help_(u, commands, topic, subtopic=subtopic) | |
1394 | except error.UnknownCommand: |
|
1395 | except error.UnknownCommand: | |
1395 | raise ErrorResponse(HTTP_NOT_FOUND) |
|
1396 | raise ErrorResponse(HTTP_NOT_FOUND) | |
1396 | return tmpl('help', topic=topicname, doc=doc) |
|
1397 | return tmpl('help', topic=topicname, doc=doc) | |
1397 |
|
1398 | |||
1398 | # tell hggettext to extract docstrings from these functions: |
|
1399 | # tell hggettext to extract docstrings from these functions: | |
1399 | i18nfunctions = commands.values() |
|
1400 | i18nfunctions = commands.values() |
@@ -1,75 +1,102 | |||||
1 | from __future__ import absolute_import |
|
1 | from __future__ import absolute_import | |
2 | from __future__ import print_function |
|
2 | from __future__ import print_function | |
3 |
|
3 | |||
4 | import unittest |
|
4 | import unittest | |
5 |
|
5 | |||
6 | from mercurial import ( |
|
6 | from mercurial import ( | |
7 | mdiff, |
|
7 | mdiff, | |
8 | ) |
|
8 | ) | |
9 | from mercurial.context import ( |
|
9 | from mercurial.context import ( | |
|
10 | annotateline, | |||
10 | _annotatepair, |
|
11 | _annotatepair, | |
11 | ) |
|
12 | ) | |
12 |
|
13 | |||
13 | class AnnotateTests(unittest.TestCase): |
|
14 | class AnnotateTests(unittest.TestCase): | |
14 | """Unit tests for annotate code.""" |
|
15 | """Unit tests for annotate code.""" | |
15 |
|
16 | |||
16 | def testannotatepair(self): |
|
17 | def testannotatepair(self): | |
17 | self.maxDiff = None # camelcase-required |
|
18 | self.maxDiff = None # camelcase-required | |
18 |
|
19 | |||
19 | oldfctx = b'old' |
|
20 | oldfctx = b'old' | |
20 | p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c' |
|
21 | p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c' | |
21 | olddata = b'a\nb\n' |
|
22 | olddata = b'a\nb\n' | |
22 | p1data = b'a\nb\nc\n' |
|
23 | p1data = b'a\nb\nc\n' | |
23 | p2data = b'a\nc\nd\n' |
|
24 | p2data = b'a\nc\nd\n' | |
24 | childdata = b'a\nb2\nc\nc2\nd\n' |
|
25 | childdata = b'a\nb2\nc\nc2\nd\n' | |
25 | diffopts = mdiff.diffopts() |
|
26 | diffopts = mdiff.diffopts() | |
26 |
|
27 | |||
27 | def decorate(text, rev): |
|
28 | def decorate(text, rev): | |
28 | return ([(rev, i) for i in xrange(1, text.count(b'\n') + 1)], text) |
|
29 | return ([annotateline(fctx=rev, lineno=i) | |
|
30 | for i in xrange(1, text.count(b'\n') + 1)], | |||
|
31 | text) | |||
29 |
|
32 | |||
30 | # Basic usage |
|
33 | # Basic usage | |
31 |
|
34 | |||
32 | oldann = decorate(olddata, oldfctx) |
|
35 | oldann = decorate(olddata, oldfctx) | |
33 | p1ann = decorate(p1data, p1fctx) |
|
36 | p1ann = decorate(p1data, p1fctx) | |
34 | p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
|
37 | p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) | |
35 |
self.assertEqual(p1ann[0], [ |
|
38 | self.assertEqual(p1ann[0], [ | |
|
39 | annotateline('old', 1), | |||
|
40 | annotateline('old', 2), | |||
|
41 | annotateline('p1', 3), | |||
|
42 | ]) | |||
36 |
|
43 | |||
37 | p2ann = decorate(p2data, p2fctx) |
|
44 | p2ann = decorate(p2data, p2fctx) | |
38 | p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
|
45 | p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) | |
39 |
self.assertEqual(p2ann[0], [ |
|
46 | self.assertEqual(p2ann[0], [ | |
|
47 | annotateline('old', 1), | |||
|
48 | annotateline('p2', 2), | |||
|
49 | annotateline('p2', 3), | |||
|
50 | ]) | |||
40 |
|
51 | |||
41 | # Test with multiple parents (note the difference caused by ordering) |
|
52 | # Test with multiple parents (note the difference caused by ordering) | |
42 |
|
53 | |||
43 | childann = decorate(childdata, childfctx) |
|
54 | childann = decorate(childdata, childfctx) | |
44 | childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, |
|
55 | childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, | |
45 | diffopts) |
|
56 | diffopts) | |
46 | self.assertEqual(childann[0], |
|
57 | self.assertEqual(childann[0], [ | |
47 | [('old', 1), ('c', 2), ('p2', 2), ('c', 4), ('p2', 3)] |
|
58 | annotateline('old', 1), | |
48 | ) |
|
59 | annotateline('c', 2), | |
|
60 | annotateline('p2', 2), | |||
|
61 | annotateline('c', 4), | |||
|
62 | annotateline('p2', 3), | |||
|
63 | ]) | |||
49 |
|
64 | |||
50 | childann = decorate(childdata, childfctx) |
|
65 | childann = decorate(childdata, childfctx) | |
51 | childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, |
|
66 | childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, | |
52 | diffopts) |
|
67 | diffopts) | |
53 | self.assertEqual(childann[0], |
|
68 | self.assertEqual(childann[0], [ | |
54 | [('old', 1), ('c', 2), ('p1', 3), ('c', 4), ('p2', 3)] |
|
69 | annotateline('old', 1), | |
55 | ) |
|
70 | annotateline('c', 2), | |
|
71 | annotateline('p1', 3), | |||
|
72 | annotateline('c', 4), | |||
|
73 | annotateline('p2', 3), | |||
|
74 | ]) | |||
56 |
|
75 | |||
57 | # Test with skipchild (note the difference caused by ordering) |
|
76 | # Test with skipchild (note the difference caused by ordering) | |
58 |
|
77 | |||
59 | childann = decorate(childdata, childfctx) |
|
78 | childann = decorate(childdata, childfctx) | |
60 | childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, |
|
79 | childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, | |
61 | diffopts) |
|
80 | diffopts) | |
62 | self.assertEqual(childann[0], |
|
81 | self.assertEqual(childann[0], [ | |
63 | [('old', 1), ('old', 2), ('p2', 2), ('p2', 2), ('p2', 3)] |
|
82 | annotateline('old', 1), | |
64 | ) |
|
83 | annotateline('old', 2), | |
|
84 | annotateline('p2', 2), | |||
|
85 | annotateline('p2', 2), | |||
|
86 | annotateline('p2', 3), | |||
|
87 | ]) | |||
65 |
|
88 | |||
66 | childann = decorate(childdata, childfctx) |
|
89 | childann = decorate(childdata, childfctx) | |
67 | childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, |
|
90 | childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, | |
68 | diffopts) |
|
91 | diffopts) | |
69 | self.assertEqual(childann[0], |
|
92 | self.assertEqual(childann[0], [ | |
70 | [('old', 1), ('old', 2), ('p1', 3), ('p1', 3), ('p2', 3)] |
|
93 | annotateline('old', 1), | |
71 | ) |
|
94 | annotateline('old', 2), | |
|
95 | annotateline('p1', 3), | |||
|
96 | annotateline('p1', 3), | |||
|
97 | annotateline('p2', 3), | |||
|
98 | ]) | |||
72 |
|
99 | |||
73 | if __name__ == '__main__': |
|
100 | if __name__ == '__main__': | |
74 | import silenttestrunner |
|
101 | import silenttestrunner | |
75 | silenttestrunner.main(__name__) |
|
102 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now