Show More
@@ -1,282 +1,286 b'' | |||
|
1 | 1 | # convert.py Foreign SCM converter |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''import revisions from foreign VCS repositories into Mercurial''' |
|
9 | 9 | |
|
10 | 10 | import convcmd |
|
11 | 11 | import cvsps |
|
12 | 12 | import subversion |
|
13 | 13 | from mercurial import commands |
|
14 | 14 | from mercurial.i18n import _ |
|
15 | 15 | |
|
16 | 16 | # Commands definition was moved elsewhere to ease demandload job. |
|
17 | 17 | |
|
18 | 18 | def convert(ui, src, dest=None, revmapfile=None, **opts): |
|
19 | 19 | """convert a foreign SCM repository to a Mercurial one. |
|
20 | 20 | |
|
21 | 21 | Accepted source formats [identifiers]: |
|
22 | ||
|
22 | 23 | - Mercurial [hg] |
|
23 | 24 | - CVS [cvs] |
|
24 | 25 | - Darcs [darcs] |
|
25 | 26 | - git [git] |
|
26 | 27 | - Subversion [svn] |
|
27 | 28 | - Monotone [mtn] |
|
28 | 29 | - GNU Arch [gnuarch] |
|
29 | 30 | - Bazaar [bzr] |
|
30 | 31 | - Perforce [p4] |
|
31 | 32 | |
|
32 | 33 | Accepted destination formats [identifiers]: |
|
34 | ||
|
33 | 35 | - Mercurial [hg] |
|
34 | 36 | - Subversion [svn] (history on branches is not preserved) |
|
35 | 37 | |
|
36 | 38 | If no revision is given, all revisions will be converted. Otherwise, |
|
37 | 39 | convert will only import up to the named revision (given in a format |
|
38 | 40 | understood by the source). |
|
39 | 41 | |
|
40 | 42 | If no destination directory name is specified, it defaults to the basename |
|
41 | 43 | of the source with '-hg' appended. If the destination repository doesn't |
|
42 | 44 | exist, it will be created. |
|
43 | 45 | |
|
44 | 46 | By default, all sources except Mercurial will use --branchsort. Mercurial |
|
45 | 47 | uses --sourcesort to preserve original revision numbers order. Sort modes |
|
46 | 48 | have the following effects: |
|
47 | 49 | |
|
48 |
--branchsort |
|
|
49 |
means branches are usually converted one after the other. It |
|
|
50 | more compact repositories. | |
|
51 | --datesort: sort revisions by date. Converted repositories have | |
|
52 | good-looking changelogs but are often an order of magnitude larger than | |
|
53 | the same ones generated by --branchsort. | |
|
54 | --sourcesort: try to preserve source revisions order, only supported by | |
|
55 | Mercurial sources. | |
|
50 | --branchsort convert from parent to child revision when possible, which | |
|
51 | means branches are usually converted one after the other. It | |
|
52 | generates more compact repositories. | |
|
53 | ||
|
54 | --datesort sort revisions by date. Converted repositories have | |
|
55 | good-looking changelogs but are often an order of magnitude | |
|
56 | larger than the same ones generated by --branchsort. | |
|
57 | ||
|
58 | --sourcesort try to preserve source revisions order, only supported by | |
|
59 | Mercurial sources. | |
|
56 | 60 | |
|
57 | 61 | If <REVMAP> isn't given, it will be put in a default location |
|
58 | 62 | (<dest>/.hg/shamap by default). The <REVMAP> is a simple text file that |
|
59 | 63 | maps each source commit ID to the destination ID for that revision, like |
|
60 | so: | |
|
64 | so:: | |
|
61 | 65 | |
|
62 | <source ID> <destination ID> | |
|
66 | <source ID> <destination ID> | |
|
63 | 67 | |
|
64 | 68 | If the file doesn't exist, it's automatically created. It's updated on |
|
65 | 69 | each commit copied, so convert-repo can be interrupted and can be run |
|
66 | 70 | repeatedly to copy new commits. |
|
67 | 71 | |
|
68 | 72 | The [username mapping] file is a simple text file that maps each source |
|
69 | 73 | commit author to a destination commit author. It is handy for source SCMs |
|
70 | 74 | that use unix logins to identify authors (eg: CVS). One line per author |
|
71 | 75 | mapping and the line format is: srcauthor=whatever string you want |
|
72 | 76 | |
|
73 | 77 | The filemap is a file that allows filtering and remapping of files and |
|
74 | 78 | directories. Comment lines start with '#'. Each line can contain one of |
|
75 | the following directives: | |
|
79 | the following directives:: | |
|
76 | 80 | |
|
77 | 81 | include path/to/file |
|
78 | 82 | |
|
79 | 83 | exclude path/to/file |
|
80 | 84 | |
|
81 | 85 | rename from/file to/file |
|
82 | 86 | |
|
83 | 87 | The 'include' directive causes a file, or all files under a directory, to |
|
84 | 88 | be included in the destination repository, and the exclusion of all other |
|
85 | 89 | files and directories not explicitly included. The 'exclude' directive |
|
86 | 90 | causes files or directories to be omitted. The 'rename' directive renames |
|
87 | 91 | a file or directory. To rename from a subdirectory into the root of the |
|
88 | 92 | repository, use '.' as the path to rename to. |
|
89 | 93 | |
|
90 | 94 | The splicemap is a file that allows insertion of synthetic history, |
|
91 | 95 | letting you specify the parents of a revision. This is useful if you want |
|
92 | 96 | to e.g. give a Subversion merge two parents, or graft two disconnected |
|
93 | 97 | series of history together. Each entry contains a key, followed by a |
|
94 | 98 | space, followed by one or two comma-separated values. The key is the |
|
95 | 99 | revision ID in the source revision control system whose parents should be |
|
96 | 100 | modified (same format as a key in .hg/shamap). The values are the revision |
|
97 | 101 | IDs (in either the source or destination revision control system) that |
|
98 | 102 | should be used as the new parents for that node. |
|
99 | 103 | |
|
100 | 104 | The branchmap is a file that allows you to rename a branch when it is |
|
101 | 105 | being brought in from whatever external repository. When used in |
|
102 | 106 | conjunction with a splicemap, it allows for a powerful combination to help |
|
103 | 107 | fix even the most badly mismanaged repositories and turn them into nicely |
|
104 | 108 | structured Mercurial repositories. The branchmap contains lines of the |
|
105 | 109 | form "original_branch_name new_branch_name". "original_branch_name" is the |
|
106 | 110 | name of the branch in the source repository, and "new_branch_name" is the |
|
107 | 111 | name of the branch is the destination repository. This can be used to (for |
|
108 | 112 | instance) move code in one repository from "default" to a named branch. |
|
109 | 113 | |
|
110 | 114 | Mercurial Source |
|
111 | 115 | ---------------- |
|
112 | 116 | |
|
113 | 117 | --config convert.hg.ignoreerrors=False (boolean) |
|
114 | 118 | ignore integrity errors when reading. Use it to fix Mercurial |
|
115 | 119 | repositories with missing revlogs, by converting from and to |
|
116 | 120 | Mercurial. |
|
117 | 121 | --config convert.hg.saverev=False (boolean) |
|
118 | 122 | store original revision ID in changeset (forces target IDs to change) |
|
119 | 123 | --config convert.hg.startrev=0 (hg revision identifier) |
|
120 | 124 | convert start revision and its descendants |
|
121 | 125 | |
|
122 | 126 | CVS Source |
|
123 | 127 | ---------- |
|
124 | 128 | |
|
125 | 129 | CVS source will use a sandbox (i.e. a checked-out copy) from CVS to |
|
126 | 130 | indicate the starting point of what will be converted. Direct access to |
|
127 | 131 | the repository files is not needed, unless of course the repository is |
|
128 | 132 | :local:. The conversion uses the top level directory in the sandbox to |
|
129 | 133 | find the CVS repository, and then uses CVS rlog commands to find files to |
|
130 | 134 | convert. This means that unless a filemap is given, all files under the |
|
131 | 135 | starting directory will be converted, and that any directory |
|
132 | 136 | reorganization in the CVS sandbox is ignored. |
|
133 | 137 | |
|
134 | 138 | Because CVS does not have changesets, it is necessary to collect |
|
135 | 139 | individual commits to CVS and merge them into changesets. CVS source uses |
|
136 | 140 | its internal changeset merging code by default but can be configured to |
|
137 | call the external 'cvsps' program by setting: | |
|
141 | call the external 'cvsps' program by setting:: | |
|
138 | 142 | |
|
139 | --config convert.cvsps='cvsps -A -u --cvs-direct -q' | |
|
143 | --config convert.cvsps='cvsps -A -u --cvs-direct -q' | |
|
140 | 144 | |
|
141 | 145 | This option is deprecated and will be removed in Mercurial 1.4. |
|
142 | 146 | |
|
143 | 147 | The options shown are the defaults. |
|
144 | 148 | |
|
145 | Internal cvsps is selected by setting | |
|
149 | Internal cvsps is selected by setting :: | |
|
146 | 150 | |
|
147 | --config convert.cvsps=builtin | |
|
151 | --config convert.cvsps=builtin | |
|
148 | 152 | |
|
149 | 153 | and has a few more configurable options: |
|
150 | 154 | |
|
151 | 155 | --config convert.cvsps.cache=True (boolean) |
|
152 | 156 | Set to False to disable remote log caching, for testing and debugging |
|
153 | 157 | purposes. |
|
154 | 158 | --config convert.cvsps.fuzz=60 (integer) |
|
155 | 159 | Specify the maximum time (in seconds) that is allowed between commits |
|
156 | 160 | with identical user and log message in a single changeset. When very |
|
157 | 161 | large files were checked in as part of a changeset then the default |
|
158 | 162 | may not be long enough. |
|
159 | 163 | --config convert.cvsps.mergeto='{{mergetobranch ([-\\w]+)}}' |
|
160 | 164 | Specify a regular expression to which commit log messages are matched. |
|
161 | 165 | If a match occurs, then the conversion process will insert a dummy |
|
162 | 166 | revision merging the branch on which this log message occurs to the |
|
163 | 167 | branch indicated in the regex. |
|
164 | 168 | --config convert.cvsps.mergefrom='{{mergefrombranch ([-\\w]+)}}' |
|
165 | 169 | Specify a regular expression to which commit log messages are matched. |
|
166 | 170 | If a match occurs, then the conversion process will add the most |
|
167 | 171 | recent revision on the branch indicated in the regex as the second |
|
168 | 172 | parent of the changeset. |
|
169 | 173 | |
|
170 | 174 | The hgext/convert/cvsps wrapper script allows the builtin changeset |
|
171 | 175 | merging code to be run without doing a conversion. Its parameters and |
|
172 | 176 | output are similar to that of cvsps 2.1. |
|
173 | 177 | |
|
174 | 178 | Subversion Source |
|
175 | 179 | ----------------- |
|
176 | 180 | |
|
177 | 181 | Subversion source detects classical trunk/branches/tags layouts. By |
|
178 | 182 | default, the supplied "svn://repo/path/" source URL is converted as a |
|
179 | 183 | single branch. If "svn://repo/path/trunk" exists it replaces the default |
|
180 | 184 | branch. If "svn://repo/path/branches" exists, its subdirectories are |
|
181 | 185 | listed as possible branches. If "svn://repo/path/tags" exists, it is |
|
182 | 186 | looked for tags referencing converted branches. Default "trunk", |
|
183 | 187 | "branches" and "tags" values can be overridden with following options. Set |
|
184 | 188 | them to paths relative to the source URL, or leave them blank to disable |
|
185 | 189 | auto detection. |
|
186 | 190 | |
|
187 | 191 | --config convert.svn.branches=branches (directory name) |
|
188 | 192 | specify the directory containing branches |
|
189 | 193 | --config convert.svn.tags=tags (directory name) |
|
190 | 194 | specify the directory containing tags |
|
191 | 195 | --config convert.svn.trunk=trunk (directory name) |
|
192 | 196 | specify the name of the trunk branch |
|
193 | 197 | |
|
194 | 198 | Source history can be retrieved starting at a specific revision, instead |
|
195 | 199 | of being integrally converted. Only single branch conversions are |
|
196 | 200 | supported. |
|
197 | 201 | |
|
198 | 202 | --config convert.svn.startrev=0 (svn revision number) |
|
199 | 203 | specify start Subversion revision. |
|
200 | 204 | |
|
201 | 205 | Perforce Source |
|
202 | 206 | --------------- |
|
203 | 207 | |
|
204 | 208 | The Perforce (P4) importer can be given a p4 depot path or a client |
|
205 | 209 | specification as source. It will convert all files in the source to a flat |
|
206 | 210 | Mercurial repository, ignoring labels, branches and integrations. Note |
|
207 | 211 | that when a depot path is given you then usually should specify a target |
|
208 | 212 | directory, because otherwise the target may be named ...-hg. |
|
209 | 213 | |
|
210 | 214 | It is possible to limit the amount of source history to be converted by |
|
211 | 215 | specifying an initial Perforce revision. |
|
212 | 216 | |
|
213 | 217 | --config convert.p4.startrev=0 (perforce changelist number) |
|
214 | 218 | specify initial Perforce revision. |
|
215 | 219 | |
|
216 | 220 | Mercurial Destination |
|
217 | 221 | --------------------- |
|
218 | 222 | |
|
219 | 223 | --config convert.hg.clonebranches=False (boolean) |
|
220 | 224 | dispatch source branches in separate clones. |
|
221 | 225 | --config convert.hg.tagsbranch=default (branch name) |
|
222 | 226 | tag revisions branch name |
|
223 | 227 | --config convert.hg.usebranchnames=True (boolean) |
|
224 | 228 | preserve branch names |
|
225 | 229 | |
|
226 | 230 | """ |
|
227 | 231 | return convcmd.convert(ui, src, dest, revmapfile, **opts) |
|
228 | 232 | |
|
229 | 233 | def debugsvnlog(ui, **opts): |
|
230 | 234 | return subversion.debugsvnlog(ui, **opts) |
|
231 | 235 | |
|
232 | 236 | def debugcvsps(ui, *args, **opts): |
|
233 | 237 | '''create changeset information from CVS |
|
234 | 238 | |
|
235 | 239 | This command is intended as a debugging tool for the CVS to Mercurial |
|
236 | 240 | converter, and can be used as a direct replacement for cvsps. |
|
237 | 241 | |
|
238 | 242 | Hg debugcvsps reads the CVS rlog for current directory (or any named |
|
239 | 243 | directory) in the CVS repository, and converts the log to a series of |
|
240 | 244 | changesets based on matching commit log entries and dates. |
|
241 | 245 | ''' |
|
242 | 246 | return cvsps.debugcvsps(ui, *args, **opts) |
|
243 | 247 | |
|
244 | 248 | commands.norepo += " convert debugsvnlog debugcvsps" |
|
245 | 249 | |
|
246 | 250 | cmdtable = { |
|
247 | 251 | "convert": |
|
248 | 252 | (convert, |
|
249 | 253 | [('A', 'authors', '', _('username mapping filename')), |
|
250 | 254 | ('d', 'dest-type', '', _('destination repository type')), |
|
251 | 255 | ('', 'filemap', '', _('remap file names using contents of file')), |
|
252 | 256 | ('r', 'rev', '', _('import up to target revision REV')), |
|
253 | 257 | ('s', 'source-type', '', _('source repository type')), |
|
254 | 258 | ('', 'splicemap', '', _('splice synthesized history into place')), |
|
255 | 259 | ('', 'branchmap', '', _('change branch names while converting')), |
|
256 | 260 | ('', 'branchsort', None, _('try to sort changesets by branches')), |
|
257 | 261 | ('', 'datesort', None, _('try to sort changesets by date')), |
|
258 | 262 | ('', 'sourcesort', None, _('preserve source changesets order'))], |
|
259 | 263 | _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')), |
|
260 | 264 | "debugsvnlog": |
|
261 | 265 | (debugsvnlog, |
|
262 | 266 | [], |
|
263 | 267 | 'hg debugsvnlog'), |
|
264 | 268 | "debugcvsps": |
|
265 | 269 | (debugcvsps, |
|
266 | 270 | [ |
|
267 | 271 | # Main options shared with cvsps-2.1 |
|
268 | 272 | ('b', 'branches', [], _('only return changes on specified branches')), |
|
269 | 273 | ('p', 'prefix', '', _('prefix to remove from file names')), |
|
270 | 274 | ('r', 'revisions', [], _('only return changes after or between specified tags')), |
|
271 | 275 | ('u', 'update-cache', None, _("update cvs log cache")), |
|
272 | 276 | ('x', 'new-cache', None, _("create new cvs log cache")), |
|
273 | 277 | ('z', 'fuzz', 60, _('set commit time fuzz in seconds')), |
|
274 | 278 | ('', 'root', '', _('specify cvsroot')), |
|
275 | 279 | # Options specific to builtin cvsps |
|
276 | 280 | ('', 'parents', '', _('show parent changesets')), |
|
277 | 281 | ('', 'ancestors', '', _('show current changeset in ancestor branches')), |
|
278 | 282 | # Options that are ignored for compatibility with cvsps-2.1 |
|
279 | 283 | ('A', 'cvs-direct', None, _('ignored for compatibility')), |
|
280 | 284 | ], |
|
281 | 285 | _('hg debugcvsps [OPTION]... [PATH]...')), |
|
282 | 286 | } |
@@ -1,543 +1,543 b'' | |||
|
1 | 1 | # keyword.py - $Keyword$ expansion for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2007, 2008 Christian Ebert <blacktrash@gmx.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | # |
|
8 | 8 | # $Id$ |
|
9 | 9 | # |
|
10 | 10 | # Keyword expansion hack against the grain of a DSCM |
|
11 | 11 | # |
|
12 | 12 | # There are many good reasons why this is not needed in a distributed |
|
13 | 13 | # SCM, still it may be useful in very small projects based on single |
|
14 | 14 | # files (like LaTeX packages), that are mostly addressed to an |
|
15 | 15 | # audience not running a version control system. |
|
16 | 16 | # |
|
17 | 17 | # For in-depth discussion refer to |
|
18 | 18 | # <http://mercurial.selenic.com/wiki/KeywordPlan>. |
|
19 | 19 | # |
|
20 | 20 | # Keyword expansion is based on Mercurial's changeset template mappings. |
|
21 | 21 | # |
|
22 | 22 | # Binary files are not touched. |
|
23 | 23 | # |
|
24 | 24 | # Files to act upon/ignore are specified in the [keyword] section. |
|
25 | 25 | # Customized keyword template mappings in the [keywordmaps] section. |
|
26 | 26 | # |
|
27 | 27 | # Run "hg help keyword" and "hg kwdemo" to get info on configuration. |
|
28 | 28 | |
|
29 | 29 | '''expand keywords in tracked files |
|
30 | 30 | |
|
31 | 31 | This extension expands RCS/CVS-like or self-customized $Keywords$ in tracked |
|
32 | 32 | text files selected by your configuration. |
|
33 | 33 | |
|
34 | 34 | Keywords are only expanded in local repositories and not stored in the change |
|
35 | 35 | history. The mechanism can be regarded as a convenience for the current user |
|
36 | 36 | or for archive distribution. |
|
37 | 37 | |
|
38 | 38 | Configuration is done in the [keyword] and [keywordmaps] sections of hgrc |
|
39 | 39 | files. |
|
40 | 40 | |
|
41 | Example: | |
|
41 | Example:: | |
|
42 | 42 | |
|
43 | 43 | [keyword] |
|
44 | 44 | # expand keywords in every python file except those matching "x*" |
|
45 | 45 | **.py = |
|
46 | 46 | x* = ignore |
|
47 | 47 | |
|
48 | 48 | NOTE: the more specific you are in your filename patterns the less you lose |
|
49 | 49 | speed in huge repositories. |
|
50 | 50 | |
|
51 | 51 | For [keywordmaps] template mapping and expansion demonstration and control run |
|
52 | 52 | "hg kwdemo". |
|
53 | 53 | |
|
54 | 54 | An additional date template filter {date|utcdate} is provided. |
|
55 | 55 | |
|
56 | 56 | The default template mappings (view with "hg kwdemo -d") can be replaced with |
|
57 | 57 | customized keywords and templates. Again, run "hg kwdemo" to control the |
|
58 | 58 | results of your config changes. |
|
59 | 59 | |
|
60 | 60 | Before changing/disabling active keywords, run "hg kwshrink" to avoid the risk |
|
61 | 61 | of inadvertently storing expanded keywords in the change history. |
|
62 | 62 | |
|
63 | 63 | To force expansion after enabling it, or a configuration change, run "hg |
|
64 | 64 | kwexpand". |
|
65 | 65 | |
|
66 | 66 | Also, when committing with the record extension or using mq's qrecord, be |
|
67 | 67 | aware that keywords cannot be updated. Again, run "hg kwexpand" on the files |
|
68 | 68 | in question to update keyword expansions after all changes have been checked |
|
69 | 69 | in. |
|
70 | 70 | |
|
71 | 71 | Expansions spanning more than one line and incremental expansions, like CVS' |
|
72 | 72 | $Log$, are not supported. A keyword template map "Log = {desc}" expands to the |
|
73 | 73 | first line of the changeset description. |
|
74 | 74 | ''' |
|
75 | 75 | |
|
76 | 76 | from mercurial import commands, cmdutil, dispatch, filelog, revlog, extensions |
|
77 | 77 | from mercurial import patch, localrepo, templater, templatefilters, util, match |
|
78 | 78 | from mercurial.hgweb import webcommands |
|
79 | 79 | from mercurial.lock import release |
|
80 | 80 | from mercurial.node import nullid |
|
81 | 81 | from mercurial.i18n import _ |
|
82 | 82 | import re, shutil, tempfile, time |
|
83 | 83 | |
|
84 | 84 | commands.optionalrepo += ' kwdemo' |
|
85 | 85 | |
|
86 | 86 | # hg commands that do not act on keywords |
|
87 | 87 | nokwcommands = ('add addremove annotate bundle copy export grep incoming init' |
|
88 | 88 | ' log outgoing push rename rollback tip verify' |
|
89 | 89 | ' convert email glog') |
|
90 | 90 | |
|
91 | 91 | # hg commands that trigger expansion only when writing to working dir, |
|
92 | 92 | # not when reading filelog, and unexpand when reading from working dir |
|
93 | 93 | restricted = 'merge record resolve qfold qimport qnew qpush qrefresh qrecord' |
|
94 | 94 | |
|
95 | 95 | def utcdate(date): |
|
96 | 96 | '''Returns hgdate in cvs-like UTC format.''' |
|
97 | 97 | return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0])) |
|
98 | 98 | |
|
99 | 99 | # make keyword tools accessible |
|
100 | 100 | kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']} |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | class kwtemplater(object): |
|
104 | 104 | ''' |
|
105 | 105 | Sets up keyword templates, corresponding keyword regex, and |
|
106 | 106 | provides keyword substitution functions. |
|
107 | 107 | ''' |
|
108 | 108 | templates = { |
|
109 | 109 | 'Revision': '{node|short}', |
|
110 | 110 | 'Author': '{author|user}', |
|
111 | 111 | 'Date': '{date|utcdate}', |
|
112 | 112 | 'RCSFile': '{file|basename},v', |
|
113 | 113 | 'Source': '{root}/{file},v', |
|
114 | 114 | 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', |
|
115 | 115 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | def __init__(self, ui, repo): |
|
119 | 119 | self.ui = ui |
|
120 | 120 | self.repo = repo |
|
121 | 121 | self.match = match.match(repo.root, '', [], |
|
122 | 122 | kwtools['inc'], kwtools['exc']) |
|
123 | 123 | self.restrict = kwtools['hgcmd'] in restricted.split() |
|
124 | 124 | |
|
125 | 125 | kwmaps = self.ui.configitems('keywordmaps') |
|
126 | 126 | if kwmaps: # override default templates |
|
127 | 127 | self.templates = dict((k, templater.parsestring(v, False)) |
|
128 | 128 | for k, v in kwmaps) |
|
129 | 129 | escaped = map(re.escape, self.templates.keys()) |
|
130 | 130 | kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped) |
|
131 | 131 | self.re_kw = re.compile(kwpat) |
|
132 | 132 | |
|
133 | 133 | templatefilters.filters['utcdate'] = utcdate |
|
134 | 134 | self.ct = cmdutil.changeset_templater(self.ui, self.repo, |
|
135 | 135 | False, None, '', False) |
|
136 | 136 | |
|
137 | 137 | def substitute(self, data, path, ctx, subfunc): |
|
138 | 138 | '''Replaces keywords in data with expanded template.''' |
|
139 | 139 | def kwsub(mobj): |
|
140 | 140 | kw = mobj.group(1) |
|
141 | 141 | self.ct.use_template(self.templates[kw]) |
|
142 | 142 | self.ui.pushbuffer() |
|
143 | 143 | self.ct.show(ctx, root=self.repo.root, file=path) |
|
144 | 144 | ekw = templatefilters.firstline(self.ui.popbuffer()) |
|
145 | 145 | return '$%s: %s $' % (kw, ekw) |
|
146 | 146 | return subfunc(kwsub, data) |
|
147 | 147 | |
|
148 | 148 | def expand(self, path, node, data): |
|
149 | 149 | '''Returns data with keywords expanded.''' |
|
150 | 150 | if not self.restrict and self.match(path) and not util.binary(data): |
|
151 | 151 | ctx = self.repo.filectx(path, fileid=node).changectx() |
|
152 | 152 | return self.substitute(data, path, ctx, self.re_kw.sub) |
|
153 | 153 | return data |
|
154 | 154 | |
|
155 | 155 | def iskwfile(self, path, flagfunc): |
|
156 | 156 | '''Returns true if path matches [keyword] pattern |
|
157 | 157 | and is not a symbolic link. |
|
158 | 158 | Caveat: localrepository._link fails on Windows.''' |
|
159 | 159 | return self.match(path) and not 'l' in flagfunc(path) |
|
160 | 160 | |
|
161 | 161 | def overwrite(self, node, expand, files): |
|
162 | 162 | '''Overwrites selected files expanding/shrinking keywords.''' |
|
163 | 163 | ctx = self.repo[node] |
|
164 | 164 | mf = ctx.manifest() |
|
165 | 165 | if node is not None: # commit |
|
166 | 166 | files = [f for f in ctx.files() if f in mf] |
|
167 | 167 | notify = self.ui.debug |
|
168 | 168 | else: # kwexpand/kwshrink |
|
169 | 169 | notify = self.ui.note |
|
170 | 170 | candidates = [f for f in files if self.iskwfile(f, ctx.flags)] |
|
171 | 171 | if candidates: |
|
172 | 172 | self.restrict = True # do not expand when reading |
|
173 | 173 | msg = (expand and _('overwriting %s expanding keywords\n') |
|
174 | 174 | or _('overwriting %s shrinking keywords\n')) |
|
175 | 175 | for f in candidates: |
|
176 | 176 | fp = self.repo.file(f) |
|
177 | 177 | data = fp.read(mf[f]) |
|
178 | 178 | if util.binary(data): |
|
179 | 179 | continue |
|
180 | 180 | if expand: |
|
181 | 181 | if node is None: |
|
182 | 182 | ctx = self.repo.filectx(f, fileid=mf[f]).changectx() |
|
183 | 183 | data, found = self.substitute(data, f, ctx, |
|
184 | 184 | self.re_kw.subn) |
|
185 | 185 | else: |
|
186 | 186 | found = self.re_kw.search(data) |
|
187 | 187 | if found: |
|
188 | 188 | notify(msg % f) |
|
189 | 189 | self.repo.wwrite(f, data, mf.flags(f)) |
|
190 | 190 | if node is None: |
|
191 | 191 | self.repo.dirstate.normal(f) |
|
192 | 192 | self.restrict = False |
|
193 | 193 | |
|
194 | 194 | def shrinktext(self, text): |
|
195 | 195 | '''Unconditionally removes all keyword substitutions from text.''' |
|
196 | 196 | return self.re_kw.sub(r'$\1$', text) |
|
197 | 197 | |
|
198 | 198 | def shrink(self, fname, text): |
|
199 | 199 | '''Returns text with all keyword substitutions removed.''' |
|
200 | 200 | if self.match(fname) and not util.binary(text): |
|
201 | 201 | return self.shrinktext(text) |
|
202 | 202 | return text |
|
203 | 203 | |
|
204 | 204 | def shrinklines(self, fname, lines): |
|
205 | 205 | '''Returns lines with keyword substitutions removed.''' |
|
206 | 206 | if self.match(fname): |
|
207 | 207 | text = ''.join(lines) |
|
208 | 208 | if not util.binary(text): |
|
209 | 209 | return self.shrinktext(text).splitlines(True) |
|
210 | 210 | return lines |
|
211 | 211 | |
|
212 | 212 | def wread(self, fname, data): |
|
213 | 213 | '''If in restricted mode returns data read from wdir with |
|
214 | 214 | keyword substitutions removed.''' |
|
215 | 215 | return self.restrict and self.shrink(fname, data) or data |
|
216 | 216 | |
|
217 | 217 | class kwfilelog(filelog.filelog): |
|
218 | 218 | ''' |
|
219 | 219 | Subclass of filelog to hook into its read, add, cmp methods. |
|
220 | 220 | Keywords are "stored" unexpanded, and processed on reading. |
|
221 | 221 | ''' |
|
222 | 222 | def __init__(self, opener, kwt, path): |
|
223 | 223 | super(kwfilelog, self).__init__(opener, path) |
|
224 | 224 | self.kwt = kwt |
|
225 | 225 | self.path = path |
|
226 | 226 | |
|
227 | 227 | def read(self, node): |
|
228 | 228 | '''Expands keywords when reading filelog.''' |
|
229 | 229 | data = super(kwfilelog, self).read(node) |
|
230 | 230 | return self.kwt.expand(self.path, node, data) |
|
231 | 231 | |
|
232 | 232 | def add(self, text, meta, tr, link, p1=None, p2=None): |
|
233 | 233 | '''Removes keyword substitutions when adding to filelog.''' |
|
234 | 234 | text = self.kwt.shrink(self.path, text) |
|
235 | 235 | return super(kwfilelog, self).add(text, meta, tr, link, p1, p2) |
|
236 | 236 | |
|
237 | 237 | def cmp(self, node, text): |
|
238 | 238 | '''Removes keyword substitutions for comparison.''' |
|
239 | 239 | text = self.kwt.shrink(self.path, text) |
|
240 | 240 | if self.renamed(node): |
|
241 | 241 | t2 = super(kwfilelog, self).read(node) |
|
242 | 242 | return t2 != text |
|
243 | 243 | return revlog.revlog.cmp(self, node, text) |
|
244 | 244 | |
|
245 | 245 | def _status(ui, repo, kwt, unknown, *pats, **opts): |
|
246 | 246 | '''Bails out if [keyword] configuration is not active. |
|
247 | 247 | Returns status of working directory.''' |
|
248 | 248 | if kwt: |
|
249 | 249 | match = cmdutil.match(repo, pats, opts) |
|
250 | 250 | return repo.status(match=match, unknown=unknown, clean=True) |
|
251 | 251 | if ui.configitems('keyword'): |
|
252 | 252 | raise util.Abort(_('[keyword] patterns cannot match')) |
|
253 | 253 | raise util.Abort(_('no [keyword] patterns configured')) |
|
254 | 254 | |
|
255 | 255 | def _kwfwrite(ui, repo, expand, *pats, **opts): |
|
256 | 256 | '''Selects files and passes them to kwtemplater.overwrite.''' |
|
257 | 257 | if repo.dirstate.parents()[1] != nullid: |
|
258 | 258 | raise util.Abort(_('outstanding uncommitted merge')) |
|
259 | 259 | kwt = kwtools['templater'] |
|
260 | 260 | status = _status(ui, repo, kwt, False, *pats, **opts) |
|
261 | 261 | modified, added, removed, deleted = status[:4] |
|
262 | 262 | if modified or added or removed or deleted: |
|
263 | 263 | raise util.Abort(_('outstanding uncommitted changes')) |
|
264 | 264 | wlock = lock = None |
|
265 | 265 | try: |
|
266 | 266 | wlock = repo.wlock() |
|
267 | 267 | lock = repo.lock() |
|
268 | 268 | kwt.overwrite(None, expand, status[6]) |
|
269 | 269 | finally: |
|
270 | 270 | release(lock, wlock) |
|
271 | 271 | |
|
272 | 272 | def demo(ui, repo, *args, **opts): |
|
273 | 273 | '''print [keywordmaps] configuration and an expansion example |
|
274 | 274 | |
|
275 | 275 | Show current, custom, or default keyword template maps and their |
|
276 | 276 | expansions. |
|
277 | 277 | |
|
278 | 278 | Extend current configuration by specifying maps as arguments and |
|
279 | 279 | optionally by reading from an additional hgrc file. |
|
280 | 280 | |
|
281 | 281 | Override current keyword template maps with "default" option. |
|
282 | 282 | ''' |
|
283 | 283 | def demoitems(section, items): |
|
284 | 284 | ui.write('[%s]\n' % section) |
|
285 | 285 | for k, v in items: |
|
286 | 286 | ui.write('%s = %s\n' % (k, v)) |
|
287 | 287 | |
|
288 | 288 | msg = 'hg keyword config and expansion example' |
|
289 | 289 | kwstatus = 'current' |
|
290 | 290 | fn = 'demo.txt' |
|
291 | 291 | branchname = 'demobranch' |
|
292 | 292 | tmpdir = tempfile.mkdtemp('', 'kwdemo.') |
|
293 | 293 | ui.note(_('creating temporary repository at %s\n') % tmpdir) |
|
294 | 294 | repo = localrepo.localrepository(ui, tmpdir, True) |
|
295 | 295 | ui.setconfig('keyword', fn, '') |
|
296 | 296 | if args or opts.get('rcfile'): |
|
297 | 297 | kwstatus = 'custom' |
|
298 | 298 | if opts.get('rcfile'): |
|
299 | 299 | ui.readconfig(opts.get('rcfile')) |
|
300 | 300 | if opts.get('default'): |
|
301 | 301 | kwstatus = 'default' |
|
302 | 302 | kwmaps = kwtemplater.templates |
|
303 | 303 | if ui.configitems('keywordmaps'): |
|
304 | 304 | # override maps from optional rcfile |
|
305 | 305 | for k, v in kwmaps.iteritems(): |
|
306 | 306 | ui.setconfig('keywordmaps', k, v) |
|
307 | 307 | elif args: |
|
308 | 308 | # simulate hgrc parsing |
|
309 | 309 | rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args] |
|
310 | 310 | fp = repo.opener('hgrc', 'w') |
|
311 | 311 | fp.writelines(rcmaps) |
|
312 | 312 | fp.close() |
|
313 | 313 | ui.readconfig(repo.join('hgrc')) |
|
314 | 314 | if not opts.get('default'): |
|
315 | 315 | kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates |
|
316 | 316 | uisetup(ui) |
|
317 | 317 | reposetup(ui, repo) |
|
318 | 318 | for k, v in ui.configitems('extensions'): |
|
319 | 319 | if k.endswith('keyword'): |
|
320 | 320 | extension = '%s = %s' % (k, v) |
|
321 | 321 | break |
|
322 | 322 | ui.status(_('\n\tconfig using %s keyword template maps\n') % kwstatus) |
|
323 | 323 | ui.write('[extensions]\n%s\n' % extension) |
|
324 | 324 | demoitems('keyword', ui.configitems('keyword')) |
|
325 | 325 | demoitems('keywordmaps', kwmaps.iteritems()) |
|
326 | 326 | keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n' |
|
327 | 327 | repo.wopener(fn, 'w').write(keywords) |
|
328 | 328 | repo.add([fn]) |
|
329 | 329 | path = repo.wjoin(fn) |
|
330 | 330 | ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path)) |
|
331 | 331 | ui.note(keywords) |
|
332 | 332 | ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname)) |
|
333 | 333 | # silence branch command if not verbose |
|
334 | 334 | quiet = ui.quiet |
|
335 | 335 | ui.quiet = not ui.verbose |
|
336 | 336 | commands.branch(ui, repo, branchname) |
|
337 | 337 | ui.quiet = quiet |
|
338 | 338 | for name, cmd in ui.configitems('hooks'): |
|
339 | 339 | if name.split('.', 1)[0].find('commit') > -1: |
|
340 | 340 | repo.ui.setconfig('hooks', name, '') |
|
341 | 341 | ui.note(_('unhooked all commit hooks\n')) |
|
342 | 342 | ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg)) |
|
343 | 343 | repo.commit(text=msg) |
|
344 | 344 | fmt = ui.verbose and ' in %s' % path or '' |
|
345 | 345 | ui.status(_('\n\t%s keywords expanded%s\n') % (kwstatus, fmt)) |
|
346 | 346 | ui.write(repo.wread(fn)) |
|
347 | 347 | ui.debug(_('\nremoving temporary repository %s\n') % tmpdir) |
|
348 | 348 | shutil.rmtree(tmpdir, ignore_errors=True) |
|
349 | 349 | |
|
350 | 350 | def expand(ui, repo, *pats, **opts): |
|
351 | 351 | '''expand keywords in the working directory |
|
352 | 352 | |
|
353 | 353 | Run after (re)enabling keyword expansion. |
|
354 | 354 | |
|
355 | 355 | kwexpand refuses to run if given files contain local changes. |
|
356 | 356 | ''' |
|
357 | 357 | # 3rd argument sets expansion to True |
|
358 | 358 | _kwfwrite(ui, repo, True, *pats, **opts) |
|
359 | 359 | |
|
360 | 360 | def files(ui, repo, *pats, **opts): |
|
361 | 361 | '''show files configured for keyword expansion |
|
362 | 362 | |
|
363 | 363 | List which files in the working directory are matched by the [keyword] |
|
364 | 364 | configuration patterns. |
|
365 | 365 | |
|
366 | 366 | Useful to prevent inadvertent keyword expansion and to speed up execution |
|
367 | 367 | by including only files that are actual candidates for expansion. |
|
368 | 368 | |
|
369 | 369 | See "hg help keyword" on how to construct patterns both for inclusion and |
|
370 | 370 | exclusion of files. |
|
371 | 371 | |
|
372 | 372 | Use -u/--untracked to list untracked files as well. |
|
373 | 373 | |
|
374 | 374 | With -a/--all and -v/--verbose the codes used to show the status of files |
|
375 | 375 | are: |
|
376 | 376 | K = keyword expansion candidate |
|
377 | 377 | k = keyword expansion candidate (untracked) |
|
378 | 378 | I = ignored |
|
379 | 379 | i = ignored (untracked) |
|
380 | 380 | ''' |
|
381 | 381 | kwt = kwtools['templater'] |
|
382 | 382 | status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts) |
|
383 | 383 | modified, added, removed, deleted, unknown, ignored, clean = status |
|
384 | 384 | files = sorted(modified + added + clean) |
|
385 | 385 | wctx = repo[None] |
|
386 | 386 | kwfiles = [f for f in files if kwt.iskwfile(f, wctx.flags)] |
|
387 | 387 | kwuntracked = [f for f in unknown if kwt.iskwfile(f, wctx.flags)] |
|
388 | 388 | cwd = pats and repo.getcwd() or '' |
|
389 | 389 | kwfstats = (not opts.get('ignore') and |
|
390 | 390 | (('K', kwfiles), ('k', kwuntracked),) or ()) |
|
391 | 391 | if opts.get('all') or opts.get('ignore'): |
|
392 | 392 | kwfstats += (('I', [f for f in files if f not in kwfiles]), |
|
393 | 393 | ('i', [f for f in unknown if f not in kwuntracked]),) |
|
394 | 394 | for char, filenames in kwfstats: |
|
395 | 395 | fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n' |
|
396 | 396 | for f in filenames: |
|
397 | 397 | ui.write(fmt % repo.pathto(f, cwd)) |
|
398 | 398 | |
|
399 | 399 | def shrink(ui, repo, *pats, **opts): |
|
400 | 400 | '''revert expanded keywords in the working directory |
|
401 | 401 | |
|
402 | 402 | Run before changing/disabling active keywords or if you experience |
|
403 | 403 | problems with "hg import" or "hg merge". |
|
404 | 404 | |
|
405 | 405 | kwshrink refuses to run if given files contain local changes. |
|
406 | 406 | ''' |
|
407 | 407 | # 3rd argument sets expansion to False |
|
408 | 408 | _kwfwrite(ui, repo, False, *pats, **opts) |
|
409 | 409 | |
|
410 | 410 | |
|
411 | 411 | def uisetup(ui): |
|
412 | 412 | '''Collects [keyword] config in kwtools. |
|
413 | 413 | Monkeypatches dispatch._parse if needed.''' |
|
414 | 414 | |
|
415 | 415 | for pat, opt in ui.configitems('keyword'): |
|
416 | 416 | if opt != 'ignore': |
|
417 | 417 | kwtools['inc'].append(pat) |
|
418 | 418 | else: |
|
419 | 419 | kwtools['exc'].append(pat) |
|
420 | 420 | |
|
421 | 421 | if kwtools['inc']: |
|
422 | 422 | def kwdispatch_parse(orig, ui, args): |
|
423 | 423 | '''Monkeypatch dispatch._parse to obtain running hg command.''' |
|
424 | 424 | cmd, func, args, options, cmdoptions = orig(ui, args) |
|
425 | 425 | kwtools['hgcmd'] = cmd |
|
426 | 426 | return cmd, func, args, options, cmdoptions |
|
427 | 427 | |
|
428 | 428 | extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
|
429 | 429 | |
|
430 | 430 | def reposetup(ui, repo): |
|
431 | 431 | '''Sets up repo as kwrepo for keyword substitution. |
|
432 | 432 | Overrides file method to return kwfilelog instead of filelog |
|
433 | 433 | if file matches user configuration. |
|
434 | 434 | Wraps commit to overwrite configured files with updated |
|
435 | 435 | keyword substitutions. |
|
436 | 436 | Monkeypatches patch and webcommands.''' |
|
437 | 437 | |
|
438 | 438 | try: |
|
439 | 439 | if (not repo.local() or not kwtools['inc'] |
|
440 | 440 | or kwtools['hgcmd'] in nokwcommands.split() |
|
441 | 441 | or '.hg' in util.splitpath(repo.root) |
|
442 | 442 | or repo._url.startswith('bundle:')): |
|
443 | 443 | return |
|
444 | 444 | except AttributeError: |
|
445 | 445 | pass |
|
446 | 446 | |
|
447 | 447 | kwtools['templater'] = kwt = kwtemplater(ui, repo) |
|
448 | 448 | |
|
449 | 449 | class kwrepo(repo.__class__): |
|
450 | 450 | def file(self, f): |
|
451 | 451 | if f[0] == '/': |
|
452 | 452 | f = f[1:] |
|
453 | 453 | return kwfilelog(self.sopener, kwt, f) |
|
454 | 454 | |
|
455 | 455 | def wread(self, filename): |
|
456 | 456 | data = super(kwrepo, self).wread(filename) |
|
457 | 457 | return kwt.wread(filename, data) |
|
458 | 458 | |
|
459 | 459 | def commit(self, *args, **opts): |
|
460 | 460 | # use custom commitctx for user commands |
|
461 | 461 | # other extensions can still wrap repo.commitctx directly |
|
462 | 462 | self.commitctx = self.kwcommitctx |
|
463 | 463 | try: |
|
464 | 464 | return super(kwrepo, self).commit(*args, **opts) |
|
465 | 465 | finally: |
|
466 | 466 | del self.commitctx |
|
467 | 467 | |
|
468 | 468 | def kwcommitctx(self, ctx, error=False): |
|
469 | 469 | wlock = lock = None |
|
470 | 470 | try: |
|
471 | 471 | wlock = self.wlock() |
|
472 | 472 | lock = self.lock() |
|
473 | 473 | # store and postpone commit hooks |
|
474 | 474 | commithooks = {} |
|
475 | 475 | for name, cmd in ui.configitems('hooks'): |
|
476 | 476 | if name.split('.', 1)[0] == 'commit': |
|
477 | 477 | commithooks[name] = cmd |
|
478 | 478 | ui.setconfig('hooks', name, None) |
|
479 | 479 | if commithooks: |
|
480 | 480 | # store parents for commit hooks |
|
481 | 481 | p1, p2 = ctx.p1(), ctx.p2() |
|
482 | 482 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
483 | 483 | |
|
484 | 484 | n = super(kwrepo, self).commitctx(ctx, error) |
|
485 | 485 | |
|
486 | 486 | kwt.overwrite(n, True, None) |
|
487 | 487 | if commithooks: |
|
488 | 488 | for name, cmd in commithooks.iteritems(): |
|
489 | 489 | ui.setconfig('hooks', name, cmd) |
|
490 | 490 | self.hook('commit', node=n, parent1=xp1, parent2=xp2) |
|
491 | 491 | return n |
|
492 | 492 | finally: |
|
493 | 493 | release(lock, wlock) |
|
494 | 494 | |
|
495 | 495 | # monkeypatches |
|
496 | 496 | def kwpatchfile_init(orig, self, ui, fname, opener, |
|
497 | 497 | missing=False, eol=None): |
|
498 | 498 | '''Monkeypatch/wrap patch.patchfile.__init__ to avoid |
|
499 | 499 | rejects or conflicts due to expanded keywords in working dir.''' |
|
500 | 500 | orig(self, ui, fname, opener, missing, eol) |
|
501 | 501 | # shrink keywords read from working dir |
|
502 | 502 | self.lines = kwt.shrinklines(self.fname, self.lines) |
|
503 | 503 | |
|
504 | 504 | def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None, |
|
505 | 505 | opts=None): |
|
506 | 506 | '''Monkeypatch patch.diff to avoid expansion except when |
|
507 | 507 | comparing against working dir.''' |
|
508 | 508 | if node2 is not None: |
|
509 | 509 | kwt.match = util.never |
|
510 | 510 | elif node1 is not None and node1 != repo['.'].node(): |
|
511 | 511 | kwt.restrict = True |
|
512 | 512 | return orig(repo, node1, node2, match, changes, opts) |
|
513 | 513 | |
|
514 | 514 | def kwweb_skip(orig, web, req, tmpl): |
|
515 | 515 | '''Wraps webcommands.x turning off keyword expansion.''' |
|
516 | 516 | kwt.match = util.never |
|
517 | 517 | return orig(web, req, tmpl) |
|
518 | 518 | |
|
519 | 519 | repo.__class__ = kwrepo |
|
520 | 520 | |
|
521 | 521 | extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |
|
522 | 522 | extensions.wrapfunction(patch, 'diff', kw_diff) |
|
523 | 523 | for c in 'annotate changeset rev filediff diff'.split(): |
|
524 | 524 | extensions.wrapfunction(webcommands, c, kwweb_skip) |
|
525 | 525 | |
|
526 | 526 | cmdtable = { |
|
527 | 527 | 'kwdemo': |
|
528 | 528 | (demo, |
|
529 | 529 | [('d', 'default', None, _('show default keyword template maps')), |
|
530 | 530 | ('f', 'rcfile', [], _('read maps from rcfile'))], |
|
531 | 531 | _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')), |
|
532 | 532 | 'kwexpand': (expand, commands.walkopts, |
|
533 | 533 | _('hg kwexpand [OPTION]... [FILE]...')), |
|
534 | 534 | 'kwfiles': |
|
535 | 535 | (files, |
|
536 | 536 | [('a', 'all', None, _('show keyword status flags of all files')), |
|
537 | 537 | ('i', 'ignore', None, _('show files excluded from expansion')), |
|
538 | 538 | ('u', 'untracked', None, _('additionally show untracked files')), |
|
539 | 539 | ] + commands.walkopts, |
|
540 | 540 | _('hg kwfiles [OPTION]... [FILE]...')), |
|
541 | 541 | 'kwshrink': (shrink, commands.walkopts, |
|
542 | 542 | _('hg kwshrink [OPTION]... [FILE]...')), |
|
543 | 543 | } |
@@ -1,2618 +1,2618 b'' | |||
|
1 | 1 | # mq.py - patch queues for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''manage a stack of patches |
|
9 | 9 | |
|
10 | 10 | This extension lets you work with a stack of patches in a Mercurial |
|
11 | 11 | repository. It manages two stacks of patches - all known patches, and applied |
|
12 | 12 | patches (subset of known patches). |
|
13 | 13 | |
|
14 | 14 | Known patches are represented as patch files in the .hg/patches directory. |
|
15 | 15 | Applied patches are both patch files and changesets. |
|
16 | 16 | |
|
17 | Common tasks (use "hg help command" for more details): | |
|
17 | Common tasks (use "hg help command" for more details):: | |
|
18 | 18 | |
|
19 | prepare repository to work with patches qinit | |
|
20 | create new patch qnew | |
|
21 | import existing patch qimport | |
|
19 | prepare repository to work with patches qinit | |
|
20 | create new patch qnew | |
|
21 | import existing patch qimport | |
|
22 | 22 | |
|
23 | print patch series qseries | |
|
24 | print applied patches qapplied | |
|
25 | print name of top applied patch qtop | |
|
23 | print patch series qseries | |
|
24 | print applied patches qapplied | |
|
25 | print name of top applied patch qtop | |
|
26 | 26 | |
|
27 | add known patch to applied stack qpush | |
|
28 | remove patch from applied stack qpop | |
|
29 | refresh contents of top applied patch qrefresh | |
|
27 | add known patch to applied stack qpush | |
|
28 | remove patch from applied stack qpop | |
|
29 | refresh contents of top applied patch qrefresh | |
|
30 | 30 | ''' |
|
31 | 31 | |
|
32 | 32 | from mercurial.i18n import _ |
|
33 | 33 | from mercurial.node import bin, hex, short, nullid, nullrev |
|
34 | 34 | from mercurial.lock import release |
|
35 | 35 | from mercurial import commands, cmdutil, hg, patch, util |
|
36 | 36 | from mercurial import repair, extensions, url, error |
|
37 | 37 | import os, sys, re, errno |
|
38 | 38 | |
|
39 | 39 | commands.norepo += " qclone" |
|
40 | 40 | |
|
41 | 41 | # Patch names looks like unix-file names. |
|
42 | 42 | # They must be joinable with queue directory and result in the patch path. |
|
43 | 43 | normname = util.normpath |
|
44 | 44 | |
|
45 | 45 | class statusentry(object): |
|
46 | 46 | def __init__(self, rev, name=None): |
|
47 | 47 | if not name: |
|
48 | 48 | fields = rev.split(':', 1) |
|
49 | 49 | if len(fields) == 2: |
|
50 | 50 | self.rev, self.name = fields |
|
51 | 51 | else: |
|
52 | 52 | self.rev, self.name = None, None |
|
53 | 53 | else: |
|
54 | 54 | self.rev, self.name = rev, name |
|
55 | 55 | |
|
56 | 56 | def __str__(self): |
|
57 | 57 | return self.rev + ':' + self.name |
|
58 | 58 | |
|
59 | 59 | class patchheader(object): |
|
60 | 60 | def __init__(self, pf): |
|
61 | 61 | def eatdiff(lines): |
|
62 | 62 | while lines: |
|
63 | 63 | l = lines[-1] |
|
64 | 64 | if (l.startswith("diff -") or |
|
65 | 65 | l.startswith("Index:") or |
|
66 | 66 | l.startswith("===========")): |
|
67 | 67 | del lines[-1] |
|
68 | 68 | else: |
|
69 | 69 | break |
|
70 | 70 | def eatempty(lines): |
|
71 | 71 | while lines: |
|
72 | 72 | l = lines[-1] |
|
73 | 73 | if re.match('\s*$', l): |
|
74 | 74 | del lines[-1] |
|
75 | 75 | else: |
|
76 | 76 | break |
|
77 | 77 | |
|
78 | 78 | message = [] |
|
79 | 79 | comments = [] |
|
80 | 80 | user = None |
|
81 | 81 | date = None |
|
82 | 82 | format = None |
|
83 | 83 | subject = None |
|
84 | 84 | diffstart = 0 |
|
85 | 85 | |
|
86 | 86 | for line in file(pf): |
|
87 | 87 | line = line.rstrip() |
|
88 | 88 | if line.startswith('diff --git'): |
|
89 | 89 | diffstart = 2 |
|
90 | 90 | break |
|
91 | 91 | if diffstart: |
|
92 | 92 | if line.startswith('+++ '): |
|
93 | 93 | diffstart = 2 |
|
94 | 94 | break |
|
95 | 95 | if line.startswith("--- "): |
|
96 | 96 | diffstart = 1 |
|
97 | 97 | continue |
|
98 | 98 | elif format == "hgpatch": |
|
99 | 99 | # parse values when importing the result of an hg export |
|
100 | 100 | if line.startswith("# User "): |
|
101 | 101 | user = line[7:] |
|
102 | 102 | elif line.startswith("# Date "): |
|
103 | 103 | date = line[7:] |
|
104 | 104 | elif not line.startswith("# ") and line: |
|
105 | 105 | message.append(line) |
|
106 | 106 | format = None |
|
107 | 107 | elif line == '# HG changeset patch': |
|
108 | 108 | format = "hgpatch" |
|
109 | 109 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
110 | 110 | line.startswith("subject: "))): |
|
111 | 111 | subject = line[9:] |
|
112 | 112 | format = "tag" |
|
113 | 113 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
114 | 114 | line.startswith("from: "))): |
|
115 | 115 | user = line[6:] |
|
116 | 116 | format = "tag" |
|
117 | 117 | elif format == "tag" and line == "": |
|
118 | 118 | # when looking for tags (subject: from: etc) they |
|
119 | 119 | # end once you find a blank line in the source |
|
120 | 120 | format = "tagdone" |
|
121 | 121 | elif message or line: |
|
122 | 122 | message.append(line) |
|
123 | 123 | comments.append(line) |
|
124 | 124 | |
|
125 | 125 | eatdiff(message) |
|
126 | 126 | eatdiff(comments) |
|
127 | 127 | eatempty(message) |
|
128 | 128 | eatempty(comments) |
|
129 | 129 | |
|
130 | 130 | # make sure message isn't empty |
|
131 | 131 | if format and format.startswith("tag") and subject: |
|
132 | 132 | message.insert(0, "") |
|
133 | 133 | message.insert(0, subject) |
|
134 | 134 | |
|
135 | 135 | self.message = message |
|
136 | 136 | self.comments = comments |
|
137 | 137 | self.user = user |
|
138 | 138 | self.date = date |
|
139 | 139 | self.haspatch = diffstart > 1 |
|
140 | 140 | |
|
141 | 141 | def setuser(self, user): |
|
142 | 142 | if not self.updateheader(['From: ', '# User '], user): |
|
143 | 143 | try: |
|
144 | 144 | patchheaderat = self.comments.index('# HG changeset patch') |
|
145 | 145 | self.comments.insert(patchheaderat + 1,'# User ' + user) |
|
146 | 146 | except ValueError: |
|
147 | 147 | self.comments = ['From: ' + user, ''] + self.comments |
|
148 | 148 | self.user = user |
|
149 | 149 | |
|
150 | 150 | def setdate(self, date): |
|
151 | 151 | if self.updateheader(['# Date '], date): |
|
152 | 152 | self.date = date |
|
153 | 153 | |
|
154 | 154 | def setmessage(self, message): |
|
155 | 155 | if self.comments: |
|
156 | 156 | self._delmsg() |
|
157 | 157 | self.message = [message] |
|
158 | 158 | self.comments += self.message |
|
159 | 159 | |
|
160 | 160 | def updateheader(self, prefixes, new): |
|
161 | 161 | '''Update all references to a field in the patch header. |
|
162 | 162 | Return whether the field is present.''' |
|
163 | 163 | res = False |
|
164 | 164 | for prefix in prefixes: |
|
165 | 165 | for i in xrange(len(self.comments)): |
|
166 | 166 | if self.comments[i].startswith(prefix): |
|
167 | 167 | self.comments[i] = prefix + new |
|
168 | 168 | res = True |
|
169 | 169 | break |
|
170 | 170 | return res |
|
171 | 171 | |
|
172 | 172 | def __str__(self): |
|
173 | 173 | if not self.comments: |
|
174 | 174 | return '' |
|
175 | 175 | return '\n'.join(self.comments) + '\n\n' |
|
176 | 176 | |
|
177 | 177 | def _delmsg(self): |
|
178 | 178 | '''Remove existing message, keeping the rest of the comments fields. |
|
179 | 179 | If comments contains 'subject: ', message will prepend |
|
180 | 180 | the field and a blank line.''' |
|
181 | 181 | if self.message: |
|
182 | 182 | subj = 'subject: ' + self.message[0].lower() |
|
183 | 183 | for i in xrange(len(self.comments)): |
|
184 | 184 | if subj == self.comments[i].lower(): |
|
185 | 185 | del self.comments[i] |
|
186 | 186 | self.message = self.message[2:] |
|
187 | 187 | break |
|
188 | 188 | ci = 0 |
|
189 | 189 | for mi in self.message: |
|
190 | 190 | while mi != self.comments[ci]: |
|
191 | 191 | ci += 1 |
|
192 | 192 | del self.comments[ci] |
|
193 | 193 | |
|
194 | 194 | class queue(object): |
|
195 | 195 | def __init__(self, ui, path, patchdir=None): |
|
196 | 196 | self.basepath = path |
|
197 | 197 | self.path = patchdir or os.path.join(path, "patches") |
|
198 | 198 | self.opener = util.opener(self.path) |
|
199 | 199 | self.ui = ui |
|
200 | 200 | self.applied_dirty = 0 |
|
201 | 201 | self.series_dirty = 0 |
|
202 | 202 | self.series_path = "series" |
|
203 | 203 | self.status_path = "status" |
|
204 | 204 | self.guards_path = "guards" |
|
205 | 205 | self.active_guards = None |
|
206 | 206 | self.guards_dirty = False |
|
207 | 207 | self._diffopts = None |
|
208 | 208 | |
|
209 | 209 | @util.propertycache |
|
210 | 210 | def applied(self): |
|
211 | 211 | if os.path.exists(self.join(self.status_path)): |
|
212 | 212 | lines = self.opener(self.status_path).read().splitlines() |
|
213 | 213 | return [statusentry(l) for l in lines] |
|
214 | 214 | return [] |
|
215 | 215 | |
|
216 | 216 | @util.propertycache |
|
217 | 217 | def full_series(self): |
|
218 | 218 | if os.path.exists(self.join(self.series_path)): |
|
219 | 219 | return self.opener(self.series_path).read().splitlines() |
|
220 | 220 | return [] |
|
221 | 221 | |
|
222 | 222 | @util.propertycache |
|
223 | 223 | def series(self): |
|
224 | 224 | self.parse_series() |
|
225 | 225 | return self.series |
|
226 | 226 | |
|
227 | 227 | @util.propertycache |
|
228 | 228 | def series_guards(self): |
|
229 | 229 | self.parse_series() |
|
230 | 230 | return self.series_guards |
|
231 | 231 | |
|
232 | 232 | def invalidate(self): |
|
233 | 233 | for a in 'applied full_series series series_guards'.split(): |
|
234 | 234 | if a in self.__dict__: |
|
235 | 235 | delattr(self, a) |
|
236 | 236 | self.applied_dirty = 0 |
|
237 | 237 | self.series_dirty = 0 |
|
238 | 238 | self.guards_dirty = False |
|
239 | 239 | self.active_guards = None |
|
240 | 240 | |
|
241 | 241 | def diffopts(self): |
|
242 | 242 | if self._diffopts is None: |
|
243 | 243 | self._diffopts = patch.diffopts(self.ui) |
|
244 | 244 | return self._diffopts |
|
245 | 245 | |
|
246 | 246 | def join(self, *p): |
|
247 | 247 | return os.path.join(self.path, *p) |
|
248 | 248 | |
|
249 | 249 | def find_series(self, patch): |
|
250 | 250 | pre = re.compile("(\s*)([^#]+)") |
|
251 | 251 | index = 0 |
|
252 | 252 | for l in self.full_series: |
|
253 | 253 | m = pre.match(l) |
|
254 | 254 | if m: |
|
255 | 255 | s = m.group(2) |
|
256 | 256 | s = s.rstrip() |
|
257 | 257 | if s == patch: |
|
258 | 258 | return index |
|
259 | 259 | index += 1 |
|
260 | 260 | return None |
|
261 | 261 | |
|
262 | 262 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
263 | 263 | |
|
264 | 264 | def parse_series(self): |
|
265 | 265 | self.series = [] |
|
266 | 266 | self.series_guards = [] |
|
267 | 267 | for l in self.full_series: |
|
268 | 268 | h = l.find('#') |
|
269 | 269 | if h == -1: |
|
270 | 270 | patch = l |
|
271 | 271 | comment = '' |
|
272 | 272 | elif h == 0: |
|
273 | 273 | continue |
|
274 | 274 | else: |
|
275 | 275 | patch = l[:h] |
|
276 | 276 | comment = l[h:] |
|
277 | 277 | patch = patch.strip() |
|
278 | 278 | if patch: |
|
279 | 279 | if patch in self.series: |
|
280 | 280 | raise util.Abort(_('%s appears more than once in %s') % |
|
281 | 281 | (patch, self.join(self.series_path))) |
|
282 | 282 | self.series.append(patch) |
|
283 | 283 | self.series_guards.append(self.guard_re.findall(comment)) |
|
284 | 284 | |
|
285 | 285 | def check_guard(self, guard): |
|
286 | 286 | if not guard: |
|
287 | 287 | return _('guard cannot be an empty string') |
|
288 | 288 | bad_chars = '# \t\r\n\f' |
|
289 | 289 | first = guard[0] |
|
290 | 290 | if first in '-+': |
|
291 | 291 | return (_('guard %r starts with invalid character: %r') % |
|
292 | 292 | (guard, first)) |
|
293 | 293 | for c in bad_chars: |
|
294 | 294 | if c in guard: |
|
295 | 295 | return _('invalid character in guard %r: %r') % (guard, c) |
|
296 | 296 | |
|
297 | 297 | def set_active(self, guards): |
|
298 | 298 | for guard in guards: |
|
299 | 299 | bad = self.check_guard(guard) |
|
300 | 300 | if bad: |
|
301 | 301 | raise util.Abort(bad) |
|
302 | 302 | guards = sorted(set(guards)) |
|
303 | 303 | self.ui.debug(_('active guards: %s\n') % ' '.join(guards)) |
|
304 | 304 | self.active_guards = guards |
|
305 | 305 | self.guards_dirty = True |
|
306 | 306 | |
|
307 | 307 | def active(self): |
|
308 | 308 | if self.active_guards is None: |
|
309 | 309 | self.active_guards = [] |
|
310 | 310 | try: |
|
311 | 311 | guards = self.opener(self.guards_path).read().split() |
|
312 | 312 | except IOError, err: |
|
313 | 313 | if err.errno != errno.ENOENT: raise |
|
314 | 314 | guards = [] |
|
315 | 315 | for i, guard in enumerate(guards): |
|
316 | 316 | bad = self.check_guard(guard) |
|
317 | 317 | if bad: |
|
318 | 318 | self.ui.warn('%s:%d: %s\n' % |
|
319 | 319 | (self.join(self.guards_path), i + 1, bad)) |
|
320 | 320 | else: |
|
321 | 321 | self.active_guards.append(guard) |
|
322 | 322 | return self.active_guards |
|
323 | 323 | |
|
324 | 324 | def set_guards(self, idx, guards): |
|
325 | 325 | for g in guards: |
|
326 | 326 | if len(g) < 2: |
|
327 | 327 | raise util.Abort(_('guard %r too short') % g) |
|
328 | 328 | if g[0] not in '-+': |
|
329 | 329 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
330 | 330 | bad = self.check_guard(g[1:]) |
|
331 | 331 | if bad: |
|
332 | 332 | raise util.Abort(bad) |
|
333 | 333 | drop = self.guard_re.sub('', self.full_series[idx]) |
|
334 | 334 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) |
|
335 | 335 | self.parse_series() |
|
336 | 336 | self.series_dirty = True |
|
337 | 337 | |
|
338 | 338 | def pushable(self, idx): |
|
339 | 339 | if isinstance(idx, str): |
|
340 | 340 | idx = self.series.index(idx) |
|
341 | 341 | patchguards = self.series_guards[idx] |
|
342 | 342 | if not patchguards: |
|
343 | 343 | return True, None |
|
344 | 344 | guards = self.active() |
|
345 | 345 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
346 | 346 | if exactneg: |
|
347 | 347 | return False, exactneg[0] |
|
348 | 348 | pos = [g for g in patchguards if g[0] == '+'] |
|
349 | 349 | exactpos = [g for g in pos if g[1:] in guards] |
|
350 | 350 | if pos: |
|
351 | 351 | if exactpos: |
|
352 | 352 | return True, exactpos[0] |
|
353 | 353 | return False, pos |
|
354 | 354 | return True, '' |
|
355 | 355 | |
|
356 | 356 | def explain_pushable(self, idx, all_patches=False): |
|
357 | 357 | write = all_patches and self.ui.write or self.ui.warn |
|
358 | 358 | if all_patches or self.ui.verbose: |
|
359 | 359 | if isinstance(idx, str): |
|
360 | 360 | idx = self.series.index(idx) |
|
361 | 361 | pushable, why = self.pushable(idx) |
|
362 | 362 | if all_patches and pushable: |
|
363 | 363 | if why is None: |
|
364 | 364 | write(_('allowing %s - no guards in effect\n') % |
|
365 | 365 | self.series[idx]) |
|
366 | 366 | else: |
|
367 | 367 | if not why: |
|
368 | 368 | write(_('allowing %s - no matching negative guards\n') % |
|
369 | 369 | self.series[idx]) |
|
370 | 370 | else: |
|
371 | 371 | write(_('allowing %s - guarded by %r\n') % |
|
372 | 372 | (self.series[idx], why)) |
|
373 | 373 | if not pushable: |
|
374 | 374 | if why: |
|
375 | 375 | write(_('skipping %s - guarded by %r\n') % |
|
376 | 376 | (self.series[idx], why)) |
|
377 | 377 | else: |
|
378 | 378 | write(_('skipping %s - no matching guards\n') % |
|
379 | 379 | self.series[idx]) |
|
380 | 380 | |
|
381 | 381 | def save_dirty(self): |
|
382 | 382 | def write_list(items, path): |
|
383 | 383 | fp = self.opener(path, 'w') |
|
384 | 384 | for i in items: |
|
385 | 385 | fp.write("%s\n" % i) |
|
386 | 386 | fp.close() |
|
387 | 387 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) |
|
388 | 388 | if self.series_dirty: write_list(self.full_series, self.series_path) |
|
389 | 389 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) |
|
390 | 390 | |
|
391 | 391 | def removeundo(self, repo): |
|
392 | 392 | undo = repo.sjoin('undo') |
|
393 | 393 | if not os.path.exists(undo): |
|
394 | 394 | return |
|
395 | 395 | try: |
|
396 | 396 | os.unlink(undo) |
|
397 | 397 | except OSError, inst: |
|
398 | 398 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
|
399 | 399 | |
|
400 | 400 | def printdiff(self, repo, node1, node2=None, files=None, |
|
401 | 401 | fp=None, changes=None, opts={}): |
|
402 | 402 | m = cmdutil.match(repo, files, opts) |
|
403 | 403 | chunks = patch.diff(repo, node1, node2, m, changes, self.diffopts()) |
|
404 | 404 | write = fp is None and repo.ui.write or fp.write |
|
405 | 405 | for chunk in chunks: |
|
406 | 406 | write(chunk) |
|
407 | 407 | |
|
408 | 408 | def mergeone(self, repo, mergeq, head, patch, rev): |
|
409 | 409 | # first try just applying the patch |
|
410 | 410 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
411 | 411 | strict=True, merge=rev) |
|
412 | 412 | |
|
413 | 413 | if err == 0: |
|
414 | 414 | return (err, n) |
|
415 | 415 | |
|
416 | 416 | if n is None: |
|
417 | 417 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
418 | 418 | |
|
419 | 419 | self.ui.warn(_("patch didn't work out, merging %s\n") % patch) |
|
420 | 420 | |
|
421 | 421 | # apply failed, strip away that rev and merge. |
|
422 | 422 | hg.clean(repo, head) |
|
423 | 423 | self.strip(repo, n, update=False, backup='strip') |
|
424 | 424 | |
|
425 | 425 | ctx = repo[rev] |
|
426 | 426 | ret = hg.merge(repo, rev) |
|
427 | 427 | if ret: |
|
428 | 428 | raise util.Abort(_("update returned %d") % ret) |
|
429 | 429 | n = repo.commit(ctx.description(), ctx.user(), force=True) |
|
430 | 430 | if n is None: |
|
431 | 431 | raise util.Abort(_("repo commit failed")) |
|
432 | 432 | try: |
|
433 | 433 | ph = patchheader(mergeq.join(patch)) |
|
434 | 434 | except: |
|
435 | 435 | raise util.Abort(_("unable to read %s") % patch) |
|
436 | 436 | |
|
437 | 437 | patchf = self.opener(patch, "w") |
|
438 | 438 | comments = str(ph) |
|
439 | 439 | if comments: |
|
440 | 440 | patchf.write(comments) |
|
441 | 441 | self.printdiff(repo, head, n, fp=patchf) |
|
442 | 442 | patchf.close() |
|
443 | 443 | self.removeundo(repo) |
|
444 | 444 | return (0, n) |
|
445 | 445 | |
|
446 | 446 | def qparents(self, repo, rev=None): |
|
447 | 447 | if rev is None: |
|
448 | 448 | (p1, p2) = repo.dirstate.parents() |
|
449 | 449 | if p2 == nullid: |
|
450 | 450 | return p1 |
|
451 | 451 | if len(self.applied) == 0: |
|
452 | 452 | return None |
|
453 | 453 | return bin(self.applied[-1].rev) |
|
454 | 454 | pp = repo.changelog.parents(rev) |
|
455 | 455 | if pp[1] != nullid: |
|
456 | 456 | arevs = [ x.rev for x in self.applied ] |
|
457 | 457 | p0 = hex(pp[0]) |
|
458 | 458 | p1 = hex(pp[1]) |
|
459 | 459 | if p0 in arevs: |
|
460 | 460 | return pp[0] |
|
461 | 461 | if p1 in arevs: |
|
462 | 462 | return pp[1] |
|
463 | 463 | return pp[0] |
|
464 | 464 | |
|
465 | 465 | def mergepatch(self, repo, mergeq, series): |
|
466 | 466 | if len(self.applied) == 0: |
|
467 | 467 | # each of the patches merged in will have two parents. This |
|
468 | 468 | # can confuse the qrefresh, qdiff, and strip code because it |
|
469 | 469 | # needs to know which parent is actually in the patch queue. |
|
470 | 470 | # so, we insert a merge marker with only one parent. This way |
|
471 | 471 | # the first patch in the queue is never a merge patch |
|
472 | 472 | # |
|
473 | 473 | pname = ".hg.patches.merge.marker" |
|
474 | 474 | n = repo.commit('[mq]: merge marker', force=True) |
|
475 | 475 | self.removeundo(repo) |
|
476 | 476 | self.applied.append(statusentry(hex(n), pname)) |
|
477 | 477 | self.applied_dirty = 1 |
|
478 | 478 | |
|
479 | 479 | head = self.qparents(repo) |
|
480 | 480 | |
|
481 | 481 | for patch in series: |
|
482 | 482 | patch = mergeq.lookup(patch, strict=True) |
|
483 | 483 | if not patch: |
|
484 | 484 | self.ui.warn(_("patch %s does not exist\n") % patch) |
|
485 | 485 | return (1, None) |
|
486 | 486 | pushable, reason = self.pushable(patch) |
|
487 | 487 | if not pushable: |
|
488 | 488 | self.explain_pushable(patch, all_patches=True) |
|
489 | 489 | continue |
|
490 | 490 | info = mergeq.isapplied(patch) |
|
491 | 491 | if not info: |
|
492 | 492 | self.ui.warn(_("patch %s is not applied\n") % patch) |
|
493 | 493 | return (1, None) |
|
494 | 494 | rev = bin(info[1]) |
|
495 | 495 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev) |
|
496 | 496 | if head: |
|
497 | 497 | self.applied.append(statusentry(hex(head), patch)) |
|
498 | 498 | self.applied_dirty = 1 |
|
499 | 499 | if err: |
|
500 | 500 | return (err, head) |
|
501 | 501 | self.save_dirty() |
|
502 | 502 | return (0, head) |
|
503 | 503 | |
|
504 | 504 | def patch(self, repo, patchfile): |
|
505 | 505 | '''Apply patchfile to the working directory. |
|
506 | 506 | patchfile: name of patch file''' |
|
507 | 507 | files = {} |
|
508 | 508 | try: |
|
509 | 509 | fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root, |
|
510 | 510 | files=files, eolmode=None) |
|
511 | 511 | except Exception, inst: |
|
512 | 512 | self.ui.note(str(inst) + '\n') |
|
513 | 513 | if not self.ui.verbose: |
|
514 | 514 | self.ui.warn(_("patch failed, unable to continue (try -v)\n")) |
|
515 | 515 | return (False, files, False) |
|
516 | 516 | |
|
517 | 517 | return (True, files, fuzz) |
|
518 | 518 | |
|
519 | 519 | def apply(self, repo, series, list=False, update_status=True, |
|
520 | 520 | strict=False, patchdir=None, merge=None, all_files={}): |
|
521 | 521 | wlock = lock = tr = None |
|
522 | 522 | try: |
|
523 | 523 | wlock = repo.wlock() |
|
524 | 524 | lock = repo.lock() |
|
525 | 525 | tr = repo.transaction() |
|
526 | 526 | try: |
|
527 | 527 | ret = self._apply(repo, series, list, update_status, |
|
528 | 528 | strict, patchdir, merge, all_files=all_files) |
|
529 | 529 | tr.close() |
|
530 | 530 | self.save_dirty() |
|
531 | 531 | return ret |
|
532 | 532 | except: |
|
533 | 533 | try: |
|
534 | 534 | tr.abort() |
|
535 | 535 | finally: |
|
536 | 536 | repo.invalidate() |
|
537 | 537 | repo.dirstate.invalidate() |
|
538 | 538 | raise |
|
539 | 539 | finally: |
|
540 | 540 | del tr |
|
541 | 541 | release(lock, wlock) |
|
542 | 542 | self.removeundo(repo) |
|
543 | 543 | |
|
544 | 544 | def _apply(self, repo, series, list=False, update_status=True, |
|
545 | 545 | strict=False, patchdir=None, merge=None, all_files={}): |
|
546 | 546 | '''returns (error, hash) |
|
547 | 547 | error = 1 for unable to read, 2 for patch failed, 3 for patch fuzz''' |
|
548 | 548 | # TODO unify with commands.py |
|
549 | 549 | if not patchdir: |
|
550 | 550 | patchdir = self.path |
|
551 | 551 | err = 0 |
|
552 | 552 | n = None |
|
553 | 553 | for patchname in series: |
|
554 | 554 | pushable, reason = self.pushable(patchname) |
|
555 | 555 | if not pushable: |
|
556 | 556 | self.explain_pushable(patchname, all_patches=True) |
|
557 | 557 | continue |
|
558 | 558 | self.ui.status(_("applying %s\n") % patchname) |
|
559 | 559 | pf = os.path.join(patchdir, patchname) |
|
560 | 560 | |
|
561 | 561 | try: |
|
562 | 562 | ph = patchheader(self.join(patchname)) |
|
563 | 563 | except: |
|
564 | 564 | self.ui.warn(_("unable to read %s\n") % patchname) |
|
565 | 565 | err = 1 |
|
566 | 566 | break |
|
567 | 567 | |
|
568 | 568 | message = ph.message |
|
569 | 569 | if not message: |
|
570 | 570 | message = _("imported patch %s\n") % patchname |
|
571 | 571 | else: |
|
572 | 572 | if list: |
|
573 | 573 | message.append(_("\nimported patch %s") % patchname) |
|
574 | 574 | message = '\n'.join(message) |
|
575 | 575 | |
|
576 | 576 | if ph.haspatch: |
|
577 | 577 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
578 | 578 | all_files.update(files) |
|
579 | 579 | patcherr = not patcherr |
|
580 | 580 | else: |
|
581 | 581 | self.ui.warn(_("patch %s is empty\n") % patchname) |
|
582 | 582 | patcherr, files, fuzz = 0, [], 0 |
|
583 | 583 | |
|
584 | 584 | if merge and files: |
|
585 | 585 | # Mark as removed/merged and update dirstate parent info |
|
586 | 586 | removed = [] |
|
587 | 587 | merged = [] |
|
588 | 588 | for f in files: |
|
589 | 589 | if os.path.exists(repo.wjoin(f)): |
|
590 | 590 | merged.append(f) |
|
591 | 591 | else: |
|
592 | 592 | removed.append(f) |
|
593 | 593 | for f in removed: |
|
594 | 594 | repo.dirstate.remove(f) |
|
595 | 595 | for f in merged: |
|
596 | 596 | repo.dirstate.merge(f) |
|
597 | 597 | p1, p2 = repo.dirstate.parents() |
|
598 | 598 | repo.dirstate.setparents(p1, merge) |
|
599 | 599 | |
|
600 | 600 | files = patch.updatedir(self.ui, repo, files) |
|
601 | 601 | match = cmdutil.matchfiles(repo, files or []) |
|
602 | 602 | n = repo.commit(message, ph.user, ph.date, match=match, force=True) |
|
603 | 603 | |
|
604 | 604 | if n is None: |
|
605 | 605 | raise util.Abort(_("repo commit failed")) |
|
606 | 606 | |
|
607 | 607 | if update_status: |
|
608 | 608 | self.applied.append(statusentry(hex(n), patchname)) |
|
609 | 609 | |
|
610 | 610 | if patcherr: |
|
611 | 611 | self.ui.warn(_("patch failed, rejects left in working dir\n")) |
|
612 | 612 | err = 2 |
|
613 | 613 | break |
|
614 | 614 | |
|
615 | 615 | if fuzz and strict: |
|
616 | 616 | self.ui.warn(_("fuzz found when applying patch, stopping\n")) |
|
617 | 617 | err = 3 |
|
618 | 618 | break |
|
619 | 619 | return (err, n) |
|
620 | 620 | |
|
621 | 621 | def _cleanup(self, patches, numrevs, keep=False): |
|
622 | 622 | if not keep: |
|
623 | 623 | r = self.qrepo() |
|
624 | 624 | if r: |
|
625 | 625 | r.remove(patches, True) |
|
626 | 626 | else: |
|
627 | 627 | for p in patches: |
|
628 | 628 | os.unlink(self.join(p)) |
|
629 | 629 | |
|
630 | 630 | if numrevs: |
|
631 | 631 | del self.applied[:numrevs] |
|
632 | 632 | self.applied_dirty = 1 |
|
633 | 633 | |
|
634 | 634 | for i in sorted([self.find_series(p) for p in patches], reverse=True): |
|
635 | 635 | del self.full_series[i] |
|
636 | 636 | self.parse_series() |
|
637 | 637 | self.series_dirty = 1 |
|
638 | 638 | |
|
639 | 639 | def _revpatches(self, repo, revs): |
|
640 | 640 | firstrev = repo[self.applied[0].rev].rev() |
|
641 | 641 | patches = [] |
|
642 | 642 | for i, rev in enumerate(revs): |
|
643 | 643 | |
|
644 | 644 | if rev < firstrev: |
|
645 | 645 | raise util.Abort(_('revision %d is not managed') % rev) |
|
646 | 646 | |
|
647 | 647 | ctx = repo[rev] |
|
648 | 648 | base = bin(self.applied[i].rev) |
|
649 | 649 | if ctx.node() != base: |
|
650 | 650 | msg = _('cannot delete revision %d above applied patches') |
|
651 | 651 | raise util.Abort(msg % rev) |
|
652 | 652 | |
|
653 | 653 | patch = self.applied[i].name |
|
654 | 654 | for fmt in ('[mq]: %s', 'imported patch %s'): |
|
655 | 655 | if ctx.description() == fmt % patch: |
|
656 | 656 | msg = _('patch %s finalized without changeset message\n') |
|
657 | 657 | repo.ui.status(msg % patch) |
|
658 | 658 | break |
|
659 | 659 | |
|
660 | 660 | patches.append(patch) |
|
661 | 661 | return patches |
|
662 | 662 | |
|
663 | 663 | def finish(self, repo, revs): |
|
664 | 664 | patches = self._revpatches(repo, sorted(revs)) |
|
665 | 665 | self._cleanup(patches, len(patches)) |
|
666 | 666 | |
|
667 | 667 | def delete(self, repo, patches, opts): |
|
668 | 668 | if not patches and not opts.get('rev'): |
|
669 | 669 | raise util.Abort(_('qdelete requires at least one revision or ' |
|
670 | 670 | 'patch name')) |
|
671 | 671 | |
|
672 | 672 | realpatches = [] |
|
673 | 673 | for patch in patches: |
|
674 | 674 | patch = self.lookup(patch, strict=True) |
|
675 | 675 | info = self.isapplied(patch) |
|
676 | 676 | if info: |
|
677 | 677 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
678 | 678 | if patch not in self.series: |
|
679 | 679 | raise util.Abort(_("patch %s not in series file") % patch) |
|
680 | 680 | realpatches.append(patch) |
|
681 | 681 | |
|
682 | 682 | numrevs = 0 |
|
683 | 683 | if opts.get('rev'): |
|
684 | 684 | if not self.applied: |
|
685 | 685 | raise util.Abort(_('no patches applied')) |
|
686 | 686 | revs = cmdutil.revrange(repo, opts['rev']) |
|
687 | 687 | if len(revs) > 1 and revs[0] > revs[1]: |
|
688 | 688 | revs.reverse() |
|
689 | 689 | revpatches = self._revpatches(repo, revs) |
|
690 | 690 | realpatches += revpatches |
|
691 | 691 | numrevs = len(revpatches) |
|
692 | 692 | |
|
693 | 693 | self._cleanup(realpatches, numrevs, opts.get('keep')) |
|
694 | 694 | |
|
695 | 695 | def check_toppatch(self, repo): |
|
696 | 696 | if len(self.applied) > 0: |
|
697 | 697 | top = bin(self.applied[-1].rev) |
|
698 | 698 | pp = repo.dirstate.parents() |
|
699 | 699 | if top not in pp: |
|
700 | 700 | raise util.Abort(_("working directory revision is not qtip")) |
|
701 | 701 | return top |
|
702 | 702 | return None |
|
703 | 703 | def check_localchanges(self, repo, force=False, refresh=True): |
|
704 | 704 | m, a, r, d = repo.status()[:4] |
|
705 | 705 | if m or a or r or d: |
|
706 | 706 | if not force: |
|
707 | 707 | if refresh: |
|
708 | 708 | raise util.Abort(_("local changes found, refresh first")) |
|
709 | 709 | else: |
|
710 | 710 | raise util.Abort(_("local changes found")) |
|
711 | 711 | return m, a, r, d |
|
712 | 712 | |
|
713 | 713 | _reserved = ('series', 'status', 'guards') |
|
714 | 714 | def check_reserved_name(self, name): |
|
715 | 715 | if (name in self._reserved or name.startswith('.hg') |
|
716 | 716 | or name.startswith('.mq')): |
|
717 | 717 | raise util.Abort(_('"%s" cannot be used as the name of a patch') |
|
718 | 718 | % name) |
|
719 | 719 | |
|
720 | 720 | def new(self, repo, patchfn, *pats, **opts): |
|
721 | 721 | """options: |
|
722 | 722 | msg: a string or a no-argument function returning a string |
|
723 | 723 | """ |
|
724 | 724 | msg = opts.get('msg') |
|
725 | 725 | force = opts.get('force') |
|
726 | 726 | user = opts.get('user') |
|
727 | 727 | date = opts.get('date') |
|
728 | 728 | if date: |
|
729 | 729 | date = util.parsedate(date) |
|
730 | 730 | self.check_reserved_name(patchfn) |
|
731 | 731 | if os.path.exists(self.join(patchfn)): |
|
732 | 732 | raise util.Abort(_('patch "%s" already exists') % patchfn) |
|
733 | 733 | if opts.get('include') or opts.get('exclude') or pats: |
|
734 | 734 | match = cmdutil.match(repo, pats, opts) |
|
735 | 735 | # detect missing files in pats |
|
736 | 736 | def badfn(f, msg): |
|
737 | 737 | raise util.Abort('%s: %s' % (f, msg)) |
|
738 | 738 | match.bad = badfn |
|
739 | 739 | m, a, r, d = repo.status(match=match)[:4] |
|
740 | 740 | else: |
|
741 | 741 | m, a, r, d = self.check_localchanges(repo, force) |
|
742 | 742 | match = cmdutil.matchfiles(repo, m + a + r) |
|
743 | 743 | commitfiles = m + a + r |
|
744 | 744 | self.check_toppatch(repo) |
|
745 | 745 | insert = self.full_series_end() |
|
746 | 746 | wlock = repo.wlock() |
|
747 | 747 | try: |
|
748 | 748 | # if patch file write fails, abort early |
|
749 | 749 | p = self.opener(patchfn, "w") |
|
750 | 750 | try: |
|
751 | 751 | if date: |
|
752 | 752 | p.write("# HG changeset patch\n") |
|
753 | 753 | if user: |
|
754 | 754 | p.write("# User " + user + "\n") |
|
755 | 755 | p.write("# Date %d %d\n\n" % date) |
|
756 | 756 | elif user: |
|
757 | 757 | p.write("From: " + user + "\n\n") |
|
758 | 758 | |
|
759 | 759 | if hasattr(msg, '__call__'): |
|
760 | 760 | msg = msg() |
|
761 | 761 | commitmsg = msg and msg or ("[mq]: %s" % patchfn) |
|
762 | 762 | n = repo.commit(commitmsg, user, date, match=match, force=True) |
|
763 | 763 | if n is None: |
|
764 | 764 | raise util.Abort(_("repo commit failed")) |
|
765 | 765 | try: |
|
766 | 766 | self.full_series[insert:insert] = [patchfn] |
|
767 | 767 | self.applied.append(statusentry(hex(n), patchfn)) |
|
768 | 768 | self.parse_series() |
|
769 | 769 | self.series_dirty = 1 |
|
770 | 770 | self.applied_dirty = 1 |
|
771 | 771 | if msg: |
|
772 | 772 | msg = msg + "\n\n" |
|
773 | 773 | p.write(msg) |
|
774 | 774 | if commitfiles: |
|
775 | 775 | diffopts = self.diffopts() |
|
776 | 776 | if opts.get('git'): diffopts.git = True |
|
777 | 777 | parent = self.qparents(repo, n) |
|
778 | 778 | chunks = patch.diff(repo, node1=parent, node2=n, |
|
779 | 779 | match=match, opts=diffopts) |
|
780 | 780 | for chunk in chunks: |
|
781 | 781 | p.write(chunk) |
|
782 | 782 | p.close() |
|
783 | 783 | wlock.release() |
|
784 | 784 | wlock = None |
|
785 | 785 | r = self.qrepo() |
|
786 | 786 | if r: r.add([patchfn]) |
|
787 | 787 | except: |
|
788 | 788 | repo.rollback() |
|
789 | 789 | raise |
|
790 | 790 | except Exception: |
|
791 | 791 | patchpath = self.join(patchfn) |
|
792 | 792 | try: |
|
793 | 793 | os.unlink(patchpath) |
|
794 | 794 | except: |
|
795 | 795 | self.ui.warn(_('error unlinking %s\n') % patchpath) |
|
796 | 796 | raise |
|
797 | 797 | self.removeundo(repo) |
|
798 | 798 | finally: |
|
799 | 799 | release(wlock) |
|
800 | 800 | |
|
801 | 801 | def strip(self, repo, rev, update=True, backup="all", force=None): |
|
802 | 802 | wlock = lock = None |
|
803 | 803 | try: |
|
804 | 804 | wlock = repo.wlock() |
|
805 | 805 | lock = repo.lock() |
|
806 | 806 | |
|
807 | 807 | if update: |
|
808 | 808 | self.check_localchanges(repo, force=force, refresh=False) |
|
809 | 809 | urev = self.qparents(repo, rev) |
|
810 | 810 | hg.clean(repo, urev) |
|
811 | 811 | repo.dirstate.write() |
|
812 | 812 | |
|
813 | 813 | self.removeundo(repo) |
|
814 | 814 | repair.strip(self.ui, repo, rev, backup) |
|
815 | 815 | # strip may have unbundled a set of backed up revisions after |
|
816 | 816 | # the actual strip |
|
817 | 817 | self.removeundo(repo) |
|
818 | 818 | finally: |
|
819 | 819 | release(lock, wlock) |
|
820 | 820 | |
|
821 | 821 | def isapplied(self, patch): |
|
822 | 822 | """returns (index, rev, patch)""" |
|
823 | 823 | for i, a in enumerate(self.applied): |
|
824 | 824 | if a.name == patch: |
|
825 | 825 | return (i, a.rev, a.name) |
|
826 | 826 | return None |
|
827 | 827 | |
|
828 | 828 | # if the exact patch name does not exist, we try a few |
|
829 | 829 | # variations. If strict is passed, we try only #1 |
|
830 | 830 | # |
|
831 | 831 | # 1) a number to indicate an offset in the series file |
|
832 | 832 | # 2) a unique substring of the patch name was given |
|
833 | 833 | # 3) patchname[-+]num to indicate an offset in the series file |
|
834 | 834 | def lookup(self, patch, strict=False): |
|
835 | 835 | patch = patch and str(patch) |
|
836 | 836 | |
|
837 | 837 | def partial_name(s): |
|
838 | 838 | if s in self.series: |
|
839 | 839 | return s |
|
840 | 840 | matches = [x for x in self.series if s in x] |
|
841 | 841 | if len(matches) > 1: |
|
842 | 842 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
843 | 843 | for m in matches: |
|
844 | 844 | self.ui.warn(' %s\n' % m) |
|
845 | 845 | return None |
|
846 | 846 | if matches: |
|
847 | 847 | return matches[0] |
|
848 | 848 | if len(self.series) > 0 and len(self.applied) > 0: |
|
849 | 849 | if s == 'qtip': |
|
850 | 850 | return self.series[self.series_end(True)-1] |
|
851 | 851 | if s == 'qbase': |
|
852 | 852 | return self.series[0] |
|
853 | 853 | return None |
|
854 | 854 | |
|
855 | 855 | if patch is None: |
|
856 | 856 | return None |
|
857 | 857 | if patch in self.series: |
|
858 | 858 | return patch |
|
859 | 859 | |
|
860 | 860 | if not os.path.isfile(self.join(patch)): |
|
861 | 861 | try: |
|
862 | 862 | sno = int(patch) |
|
863 | 863 | except(ValueError, OverflowError): |
|
864 | 864 | pass |
|
865 | 865 | else: |
|
866 | 866 | if -len(self.series) <= sno < len(self.series): |
|
867 | 867 | return self.series[sno] |
|
868 | 868 | |
|
869 | 869 | if not strict: |
|
870 | 870 | res = partial_name(patch) |
|
871 | 871 | if res: |
|
872 | 872 | return res |
|
873 | 873 | minus = patch.rfind('-') |
|
874 | 874 | if minus >= 0: |
|
875 | 875 | res = partial_name(patch[:minus]) |
|
876 | 876 | if res: |
|
877 | 877 | i = self.series.index(res) |
|
878 | 878 | try: |
|
879 | 879 | off = int(patch[minus+1:] or 1) |
|
880 | 880 | except(ValueError, OverflowError): |
|
881 | 881 | pass |
|
882 | 882 | else: |
|
883 | 883 | if i - off >= 0: |
|
884 | 884 | return self.series[i - off] |
|
885 | 885 | plus = patch.rfind('+') |
|
886 | 886 | if plus >= 0: |
|
887 | 887 | res = partial_name(patch[:plus]) |
|
888 | 888 | if res: |
|
889 | 889 | i = self.series.index(res) |
|
890 | 890 | try: |
|
891 | 891 | off = int(patch[plus+1:] or 1) |
|
892 | 892 | except(ValueError, OverflowError): |
|
893 | 893 | pass |
|
894 | 894 | else: |
|
895 | 895 | if i + off < len(self.series): |
|
896 | 896 | return self.series[i + off] |
|
897 | 897 | raise util.Abort(_("patch %s not in series") % patch) |
|
898 | 898 | |
|
899 | 899 | def push(self, repo, patch=None, force=False, list=False, |
|
900 | 900 | mergeq=None, all=False): |
|
901 | 901 | wlock = repo.wlock() |
|
902 | 902 | try: |
|
903 | 903 | if repo.dirstate.parents()[0] not in repo.heads(): |
|
904 | 904 | self.ui.status(_("(working directory not at a head)\n")) |
|
905 | 905 | |
|
906 | 906 | if not self.series: |
|
907 | 907 | self.ui.warn(_('no patches in series\n')) |
|
908 | 908 | return 0 |
|
909 | 909 | |
|
910 | 910 | patch = self.lookup(patch) |
|
911 | 911 | # Suppose our series file is: A B C and the current 'top' |
|
912 | 912 | # patch is B. qpush C should be performed (moving forward) |
|
913 | 913 | # qpush B is a NOP (no change) qpush A is an error (can't |
|
914 | 914 | # go backwards with qpush) |
|
915 | 915 | if patch: |
|
916 | 916 | info = self.isapplied(patch) |
|
917 | 917 | if info: |
|
918 | 918 | if info[0] < len(self.applied) - 1: |
|
919 | 919 | raise util.Abort( |
|
920 | 920 | _("cannot push to a previous patch: %s") % patch) |
|
921 | 921 | self.ui.warn( |
|
922 | 922 | _('qpush: %s is already at the top\n') % patch) |
|
923 | 923 | return |
|
924 | 924 | pushable, reason = self.pushable(patch) |
|
925 | 925 | if not pushable: |
|
926 | 926 | if reason: |
|
927 | 927 | reason = _('guarded by %r') % reason |
|
928 | 928 | else: |
|
929 | 929 | reason = _('no matching guards') |
|
930 | 930 | self.ui.warn(_("cannot push '%s' - %s\n") % (patch, reason)) |
|
931 | 931 | return 1 |
|
932 | 932 | elif all: |
|
933 | 933 | patch = self.series[-1] |
|
934 | 934 | if self.isapplied(patch): |
|
935 | 935 | self.ui.warn(_('all patches are currently applied\n')) |
|
936 | 936 | return 0 |
|
937 | 937 | |
|
938 | 938 | # Following the above example, starting at 'top' of B: |
|
939 | 939 | # qpush should be performed (pushes C), but a subsequent |
|
940 | 940 | # qpush without an argument is an error (nothing to |
|
941 | 941 | # apply). This allows a loop of "...while hg qpush..." to |
|
942 | 942 | # work as it detects an error when done |
|
943 | 943 | start = self.series_end() |
|
944 | 944 | if start == len(self.series): |
|
945 | 945 | self.ui.warn(_('patch series already fully applied\n')) |
|
946 | 946 | return 1 |
|
947 | 947 | if not force: |
|
948 | 948 | self.check_localchanges(repo) |
|
949 | 949 | |
|
950 | 950 | self.applied_dirty = 1 |
|
951 | 951 | if start > 0: |
|
952 | 952 | self.check_toppatch(repo) |
|
953 | 953 | if not patch: |
|
954 | 954 | patch = self.series[start] |
|
955 | 955 | end = start + 1 |
|
956 | 956 | else: |
|
957 | 957 | end = self.series.index(patch, start) + 1 |
|
958 | 958 | |
|
959 | 959 | s = self.series[start:end] |
|
960 | 960 | all_files = {} |
|
961 | 961 | try: |
|
962 | 962 | if mergeq: |
|
963 | 963 | ret = self.mergepatch(repo, mergeq, s) |
|
964 | 964 | else: |
|
965 | 965 | ret = self.apply(repo, s, list, all_files=all_files) |
|
966 | 966 | except: |
|
967 | 967 | self.ui.warn(_('cleaning up working directory...')) |
|
968 | 968 | node = repo.dirstate.parents()[0] |
|
969 | 969 | hg.revert(repo, node, None) |
|
970 | 970 | unknown = repo.status(unknown=True)[4] |
|
971 | 971 | # only remove unknown files that we know we touched or |
|
972 | 972 | # created while patching |
|
973 | 973 | for f in unknown: |
|
974 | 974 | if f in all_files: |
|
975 | 975 | util.unlink(repo.wjoin(f)) |
|
976 | 976 | self.ui.warn(_('done\n')) |
|
977 | 977 | raise |
|
978 | 978 | |
|
979 | 979 | top = self.applied[-1].name |
|
980 | 980 | if ret[0] and ret[0] > 1: |
|
981 | 981 | msg = _("errors during apply, please fix and refresh %s\n") |
|
982 | 982 | self.ui.write(msg % top) |
|
983 | 983 | else: |
|
984 | 984 | self.ui.write(_("now at: %s\n") % top) |
|
985 | 985 | return ret[0] |
|
986 | 986 | |
|
987 | 987 | finally: |
|
988 | 988 | wlock.release() |
|
989 | 989 | |
|
990 | 990 | def pop(self, repo, patch=None, force=False, update=True, all=False): |
|
991 | 991 | def getfile(f, rev, flags): |
|
992 | 992 | t = repo.file(f).read(rev) |
|
993 | 993 | repo.wwrite(f, t, flags) |
|
994 | 994 | |
|
995 | 995 | wlock = repo.wlock() |
|
996 | 996 | try: |
|
997 | 997 | if patch: |
|
998 | 998 | # index, rev, patch |
|
999 | 999 | info = self.isapplied(patch) |
|
1000 | 1000 | if not info: |
|
1001 | 1001 | patch = self.lookup(patch) |
|
1002 | 1002 | info = self.isapplied(patch) |
|
1003 | 1003 | if not info: |
|
1004 | 1004 | raise util.Abort(_("patch %s is not applied") % patch) |
|
1005 | 1005 | |
|
1006 | 1006 | if len(self.applied) == 0: |
|
1007 | 1007 | # Allow qpop -a to work repeatedly, |
|
1008 | 1008 | # but not qpop without an argument |
|
1009 | 1009 | self.ui.warn(_("no patches applied\n")) |
|
1010 | 1010 | return not all |
|
1011 | 1011 | |
|
1012 | 1012 | if all: |
|
1013 | 1013 | start = 0 |
|
1014 | 1014 | elif patch: |
|
1015 | 1015 | start = info[0] + 1 |
|
1016 | 1016 | else: |
|
1017 | 1017 | start = len(self.applied) - 1 |
|
1018 | 1018 | |
|
1019 | 1019 | if start >= len(self.applied): |
|
1020 | 1020 | self.ui.warn(_("qpop: %s is already at the top\n") % patch) |
|
1021 | 1021 | return |
|
1022 | 1022 | |
|
1023 | 1023 | if not update: |
|
1024 | 1024 | parents = repo.dirstate.parents() |
|
1025 | 1025 | rr = [ bin(x.rev) for x in self.applied ] |
|
1026 | 1026 | for p in parents: |
|
1027 | 1027 | if p in rr: |
|
1028 | 1028 | self.ui.warn(_("qpop: forcing dirstate update\n")) |
|
1029 | 1029 | update = True |
|
1030 | 1030 | else: |
|
1031 | 1031 | parents = [p.hex() for p in repo[None].parents()] |
|
1032 | 1032 | needupdate = False |
|
1033 | 1033 | for entry in self.applied[start:]: |
|
1034 | 1034 | if entry.rev in parents: |
|
1035 | 1035 | needupdate = True |
|
1036 | 1036 | break |
|
1037 | 1037 | update = needupdate |
|
1038 | 1038 | |
|
1039 | 1039 | if not force and update: |
|
1040 | 1040 | self.check_localchanges(repo) |
|
1041 | 1041 | |
|
1042 | 1042 | self.applied_dirty = 1 |
|
1043 | 1043 | end = len(self.applied) |
|
1044 | 1044 | rev = bin(self.applied[start].rev) |
|
1045 | 1045 | if update: |
|
1046 | 1046 | top = self.check_toppatch(repo) |
|
1047 | 1047 | |
|
1048 | 1048 | try: |
|
1049 | 1049 | heads = repo.changelog.heads(rev) |
|
1050 | 1050 | except error.LookupError: |
|
1051 | 1051 | node = short(rev) |
|
1052 | 1052 | raise util.Abort(_('trying to pop unknown node %s') % node) |
|
1053 | 1053 | |
|
1054 | 1054 | if heads != [bin(self.applied[-1].rev)]: |
|
1055 | 1055 | raise util.Abort(_("popping would remove a revision not " |
|
1056 | 1056 | "managed by this patch queue")) |
|
1057 | 1057 | |
|
1058 | 1058 | # we know there are no local changes, so we can make a simplified |
|
1059 | 1059 | # form of hg.update. |
|
1060 | 1060 | if update: |
|
1061 | 1061 | qp = self.qparents(repo, rev) |
|
1062 | 1062 | changes = repo.changelog.read(qp) |
|
1063 | 1063 | mmap = repo.manifest.read(changes[0]) |
|
1064 | 1064 | m, a, r, d = repo.status(qp, top)[:4] |
|
1065 | 1065 | if d: |
|
1066 | 1066 | raise util.Abort(_("deletions found between repo revs")) |
|
1067 | 1067 | for f in m: |
|
1068 | 1068 | getfile(f, mmap[f], mmap.flags(f)) |
|
1069 | 1069 | for f in r: |
|
1070 | 1070 | getfile(f, mmap[f], mmap.flags(f)) |
|
1071 | 1071 | for f in m + r: |
|
1072 | 1072 | repo.dirstate.normal(f) |
|
1073 | 1073 | for f in a: |
|
1074 | 1074 | try: |
|
1075 | 1075 | os.unlink(repo.wjoin(f)) |
|
1076 | 1076 | except OSError, e: |
|
1077 | 1077 | if e.errno != errno.ENOENT: |
|
1078 | 1078 | raise |
|
1079 | 1079 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
1080 | 1080 | except: pass |
|
1081 | 1081 | repo.dirstate.forget(f) |
|
1082 | 1082 | repo.dirstate.setparents(qp, nullid) |
|
1083 | 1083 | for patch in reversed(self.applied[start:end]): |
|
1084 | 1084 | self.ui.status(_("popping %s\n") % patch.name) |
|
1085 | 1085 | del self.applied[start:end] |
|
1086 | 1086 | self.strip(repo, rev, update=False, backup='strip') |
|
1087 | 1087 | if len(self.applied): |
|
1088 | 1088 | self.ui.write(_("now at: %s\n") % self.applied[-1].name) |
|
1089 | 1089 | else: |
|
1090 | 1090 | self.ui.write(_("patch queue now empty\n")) |
|
1091 | 1091 | finally: |
|
1092 | 1092 | wlock.release() |
|
1093 | 1093 | |
|
1094 | 1094 | def diff(self, repo, pats, opts): |
|
1095 | 1095 | top = self.check_toppatch(repo) |
|
1096 | 1096 | if not top: |
|
1097 | 1097 | self.ui.write(_("no patches applied\n")) |
|
1098 | 1098 | return |
|
1099 | 1099 | qp = self.qparents(repo, top) |
|
1100 | 1100 | self._diffopts = patch.diffopts(self.ui, opts) |
|
1101 | 1101 | self.printdiff(repo, qp, files=pats, opts=opts) |
|
1102 | 1102 | |
|
1103 | 1103 | def refresh(self, repo, pats=None, **opts): |
|
1104 | 1104 | if len(self.applied) == 0: |
|
1105 | 1105 | self.ui.write(_("no patches applied\n")) |
|
1106 | 1106 | return 1 |
|
1107 | 1107 | msg = opts.get('msg', '').rstrip() |
|
1108 | 1108 | newuser = opts.get('user') |
|
1109 | 1109 | newdate = opts.get('date') |
|
1110 | 1110 | if newdate: |
|
1111 | 1111 | newdate = '%d %d' % util.parsedate(newdate) |
|
1112 | 1112 | wlock = repo.wlock() |
|
1113 | 1113 | try: |
|
1114 | 1114 | self.check_toppatch(repo) |
|
1115 | 1115 | (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name) |
|
1116 | 1116 | top = bin(top) |
|
1117 | 1117 | if repo.changelog.heads(top) != [top]: |
|
1118 | 1118 | raise util.Abort(_("cannot refresh a revision with children")) |
|
1119 | 1119 | cparents = repo.changelog.parents(top) |
|
1120 | 1120 | patchparent = self.qparents(repo, top) |
|
1121 | 1121 | ph = patchheader(self.join(patchfn)) |
|
1122 | 1122 | |
|
1123 | 1123 | patchf = self.opener(patchfn, 'r') |
|
1124 | 1124 | |
|
1125 | 1125 | # if the patch was a git patch, refresh it as a git patch |
|
1126 | 1126 | for line in patchf: |
|
1127 | 1127 | if line.startswith('diff --git'): |
|
1128 | 1128 | self.diffopts().git = True |
|
1129 | 1129 | break |
|
1130 | 1130 | |
|
1131 | 1131 | if msg: |
|
1132 | 1132 | ph.setmessage(msg) |
|
1133 | 1133 | if newuser: |
|
1134 | 1134 | ph.setuser(newuser) |
|
1135 | 1135 | if newdate: |
|
1136 | 1136 | ph.setdate(newdate) |
|
1137 | 1137 | |
|
1138 | 1138 | # only commit new patch when write is complete |
|
1139 | 1139 | patchf = self.opener(patchfn, 'w', atomictemp=True) |
|
1140 | 1140 | |
|
1141 | 1141 | patchf.seek(0) |
|
1142 | 1142 | patchf.truncate() |
|
1143 | 1143 | |
|
1144 | 1144 | comments = str(ph) |
|
1145 | 1145 | if comments: |
|
1146 | 1146 | patchf.write(comments) |
|
1147 | 1147 | |
|
1148 | 1148 | if opts.get('git'): |
|
1149 | 1149 | self.diffopts().git = True |
|
1150 | 1150 | tip = repo.changelog.tip() |
|
1151 | 1151 | if top == tip: |
|
1152 | 1152 | # if the top of our patch queue is also the tip, there is an |
|
1153 | 1153 | # optimization here. We update the dirstate in place and strip |
|
1154 | 1154 | # off the tip commit. Then just commit the current directory |
|
1155 | 1155 | # tree. We can also send repo.commit the list of files |
|
1156 | 1156 | # changed to speed up the diff |
|
1157 | 1157 | # |
|
1158 | 1158 | # in short mode, we only diff the files included in the |
|
1159 | 1159 | # patch already plus specified files |
|
1160 | 1160 | # |
|
1161 | 1161 | # this should really read: |
|
1162 | 1162 | # mm, dd, aa, aa2 = repo.status(tip, patchparent)[:4] |
|
1163 | 1163 | # but we do it backwards to take advantage of manifest/chlog |
|
1164 | 1164 | # caching against the next repo.status call |
|
1165 | 1165 | # |
|
1166 | 1166 | mm, aa, dd, aa2 = repo.status(patchparent, tip)[:4] |
|
1167 | 1167 | changes = repo.changelog.read(tip) |
|
1168 | 1168 | man = repo.manifest.read(changes[0]) |
|
1169 | 1169 | aaa = aa[:] |
|
1170 | 1170 | matchfn = cmdutil.match(repo, pats, opts) |
|
1171 | 1171 | if opts.get('short'): |
|
1172 | 1172 | # if amending a patch, we start with existing |
|
1173 | 1173 | # files plus specified files - unfiltered |
|
1174 | 1174 | match = cmdutil.matchfiles(repo, mm + aa + dd + matchfn.files()) |
|
1175 | 1175 | # filter with inc/exl options |
|
1176 | 1176 | matchfn = cmdutil.match(repo, opts=opts) |
|
1177 | 1177 | else: |
|
1178 | 1178 | match = cmdutil.matchall(repo) |
|
1179 | 1179 | m, a, r, d = repo.status(match=match)[:4] |
|
1180 | 1180 | |
|
1181 | 1181 | # we might end up with files that were added between |
|
1182 | 1182 | # tip and the dirstate parent, but then changed in the |
|
1183 | 1183 | # local dirstate. in this case, we want them to only |
|
1184 | 1184 | # show up in the added section |
|
1185 | 1185 | for x in m: |
|
1186 | 1186 | if x not in aa: |
|
1187 | 1187 | mm.append(x) |
|
1188 | 1188 | # we might end up with files added by the local dirstate that |
|
1189 | 1189 | # were deleted by the patch. In this case, they should only |
|
1190 | 1190 | # show up in the changed section. |
|
1191 | 1191 | for x in a: |
|
1192 | 1192 | if x in dd: |
|
1193 | 1193 | del dd[dd.index(x)] |
|
1194 | 1194 | mm.append(x) |
|
1195 | 1195 | else: |
|
1196 | 1196 | aa.append(x) |
|
1197 | 1197 | # make sure any files deleted in the local dirstate |
|
1198 | 1198 | # are not in the add or change column of the patch |
|
1199 | 1199 | forget = [] |
|
1200 | 1200 | for x in d + r: |
|
1201 | 1201 | if x in aa: |
|
1202 | 1202 | del aa[aa.index(x)] |
|
1203 | 1203 | forget.append(x) |
|
1204 | 1204 | continue |
|
1205 | 1205 | elif x in mm: |
|
1206 | 1206 | del mm[mm.index(x)] |
|
1207 | 1207 | dd.append(x) |
|
1208 | 1208 | |
|
1209 | 1209 | m = list(set(mm)) |
|
1210 | 1210 | r = list(set(dd)) |
|
1211 | 1211 | a = list(set(aa)) |
|
1212 | 1212 | c = [filter(matchfn, l) for l in (m, a, r)] |
|
1213 | 1213 | match = cmdutil.matchfiles(repo, set(c[0] + c[1] + c[2])) |
|
1214 | 1214 | chunks = patch.diff(repo, patchparent, match=match, |
|
1215 | 1215 | changes=c, opts=self.diffopts()) |
|
1216 | 1216 | for chunk in chunks: |
|
1217 | 1217 | patchf.write(chunk) |
|
1218 | 1218 | |
|
1219 | 1219 | try: |
|
1220 | 1220 | if self.diffopts().git: |
|
1221 | 1221 | copies = {} |
|
1222 | 1222 | for dst in a: |
|
1223 | 1223 | src = repo.dirstate.copied(dst) |
|
1224 | 1224 | # during qfold, the source file for copies may |
|
1225 | 1225 | # be removed. Treat this as a simple add. |
|
1226 | 1226 | if src is not None and src in repo.dirstate: |
|
1227 | 1227 | copies.setdefault(src, []).append(dst) |
|
1228 | 1228 | repo.dirstate.add(dst) |
|
1229 | 1229 | # remember the copies between patchparent and tip |
|
1230 | 1230 | for dst in aaa: |
|
1231 | 1231 | f = repo.file(dst) |
|
1232 | 1232 | src = f.renamed(man[dst]) |
|
1233 | 1233 | if src: |
|
1234 | 1234 | copies.setdefault(src[0], []).extend(copies.get(dst, [])) |
|
1235 | 1235 | if dst in a: |
|
1236 | 1236 | copies[src[0]].append(dst) |
|
1237 | 1237 | # we can't copy a file created by the patch itself |
|
1238 | 1238 | if dst in copies: |
|
1239 | 1239 | del copies[dst] |
|
1240 | 1240 | for src, dsts in copies.iteritems(): |
|
1241 | 1241 | for dst in dsts: |
|
1242 | 1242 | repo.dirstate.copy(src, dst) |
|
1243 | 1243 | else: |
|
1244 | 1244 | for dst in a: |
|
1245 | 1245 | repo.dirstate.add(dst) |
|
1246 | 1246 | # Drop useless copy information |
|
1247 | 1247 | for f in list(repo.dirstate.copies()): |
|
1248 | 1248 | repo.dirstate.copy(None, f) |
|
1249 | 1249 | for f in r: |
|
1250 | 1250 | repo.dirstate.remove(f) |
|
1251 | 1251 | # if the patch excludes a modified file, mark that |
|
1252 | 1252 | # file with mtime=0 so status can see it. |
|
1253 | 1253 | mm = [] |
|
1254 | 1254 | for i in xrange(len(m)-1, -1, -1): |
|
1255 | 1255 | if not matchfn(m[i]): |
|
1256 | 1256 | mm.append(m[i]) |
|
1257 | 1257 | del m[i] |
|
1258 | 1258 | for f in m: |
|
1259 | 1259 | repo.dirstate.normal(f) |
|
1260 | 1260 | for f in mm: |
|
1261 | 1261 | repo.dirstate.normallookup(f) |
|
1262 | 1262 | for f in forget: |
|
1263 | 1263 | repo.dirstate.forget(f) |
|
1264 | 1264 | |
|
1265 | 1265 | if not msg: |
|
1266 | 1266 | if not ph.message: |
|
1267 | 1267 | message = "[mq]: %s\n" % patchfn |
|
1268 | 1268 | else: |
|
1269 | 1269 | message = "\n".join(ph.message) |
|
1270 | 1270 | else: |
|
1271 | 1271 | message = msg |
|
1272 | 1272 | |
|
1273 | 1273 | user = ph.user or changes[1] |
|
1274 | 1274 | |
|
1275 | 1275 | # assumes strip can roll itself back if interrupted |
|
1276 | 1276 | repo.dirstate.setparents(*cparents) |
|
1277 | 1277 | self.applied.pop() |
|
1278 | 1278 | self.applied_dirty = 1 |
|
1279 | 1279 | self.strip(repo, top, update=False, |
|
1280 | 1280 | backup='strip') |
|
1281 | 1281 | except: |
|
1282 | 1282 | repo.dirstate.invalidate() |
|
1283 | 1283 | raise |
|
1284 | 1284 | |
|
1285 | 1285 | try: |
|
1286 | 1286 | # might be nice to attempt to roll back strip after this |
|
1287 | 1287 | patchf.rename() |
|
1288 | 1288 | n = repo.commit(message, user, ph.date, match=match, |
|
1289 | 1289 | force=True) |
|
1290 | 1290 | self.applied.append(statusentry(hex(n), patchfn)) |
|
1291 | 1291 | except: |
|
1292 | 1292 | ctx = repo[cparents[0]] |
|
1293 | 1293 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
1294 | 1294 | self.save_dirty() |
|
1295 | 1295 | self.ui.warn(_('refresh interrupted while patch was popped! ' |
|
1296 | 1296 | '(revert --all, qpush to recover)\n')) |
|
1297 | 1297 | raise |
|
1298 | 1298 | else: |
|
1299 | 1299 | self.printdiff(repo, patchparent, fp=patchf) |
|
1300 | 1300 | patchf.rename() |
|
1301 | 1301 | added = repo.status()[1] |
|
1302 | 1302 | for a in added: |
|
1303 | 1303 | f = repo.wjoin(a) |
|
1304 | 1304 | try: |
|
1305 | 1305 | os.unlink(f) |
|
1306 | 1306 | except OSError, e: |
|
1307 | 1307 | if e.errno != errno.ENOENT: |
|
1308 | 1308 | raise |
|
1309 | 1309 | try: os.removedirs(os.path.dirname(f)) |
|
1310 | 1310 | except: pass |
|
1311 | 1311 | # forget the file copies in the dirstate |
|
1312 | 1312 | # push should readd the files later on |
|
1313 | 1313 | repo.dirstate.forget(a) |
|
1314 | 1314 | self.pop(repo, force=True) |
|
1315 | 1315 | self.push(repo, force=True) |
|
1316 | 1316 | finally: |
|
1317 | 1317 | wlock.release() |
|
1318 | 1318 | self.removeundo(repo) |
|
1319 | 1319 | |
|
1320 | 1320 | def init(self, repo, create=False): |
|
1321 | 1321 | if not create and os.path.isdir(self.path): |
|
1322 | 1322 | raise util.Abort(_("patch queue directory already exists")) |
|
1323 | 1323 | try: |
|
1324 | 1324 | os.mkdir(self.path) |
|
1325 | 1325 | except OSError, inst: |
|
1326 | 1326 | if inst.errno != errno.EEXIST or not create: |
|
1327 | 1327 | raise |
|
1328 | 1328 | if create: |
|
1329 | 1329 | return self.qrepo(create=True) |
|
1330 | 1330 | |
|
1331 | 1331 | def unapplied(self, repo, patch=None): |
|
1332 | 1332 | if patch and patch not in self.series: |
|
1333 | 1333 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1334 | 1334 | if not patch: |
|
1335 | 1335 | start = self.series_end() |
|
1336 | 1336 | else: |
|
1337 | 1337 | start = self.series.index(patch) + 1 |
|
1338 | 1338 | unapplied = [] |
|
1339 | 1339 | for i in xrange(start, len(self.series)): |
|
1340 | 1340 | pushable, reason = self.pushable(i) |
|
1341 | 1341 | if pushable: |
|
1342 | 1342 | unapplied.append((i, self.series[i])) |
|
1343 | 1343 | self.explain_pushable(i) |
|
1344 | 1344 | return unapplied |
|
1345 | 1345 | |
|
1346 | 1346 | def qseries(self, repo, missing=None, start=0, length=None, status=None, |
|
1347 | 1347 | summary=False): |
|
1348 | 1348 | def displayname(pfx, patchname): |
|
1349 | 1349 | if summary: |
|
1350 | 1350 | ph = patchheader(self.join(patchname)) |
|
1351 | 1351 | msg = ph.message |
|
1352 | 1352 | msg = msg and ': ' + msg[0] or ': ' |
|
1353 | 1353 | else: |
|
1354 | 1354 | msg = '' |
|
1355 | 1355 | msg = "%s%s%s" % (pfx, patchname, msg) |
|
1356 | 1356 | if self.ui.interactive(): |
|
1357 | 1357 | msg = util.ellipsis(msg, util.termwidth()) |
|
1358 | 1358 | self.ui.write(msg + '\n') |
|
1359 | 1359 | |
|
1360 | 1360 | applied = set([p.name for p in self.applied]) |
|
1361 | 1361 | if length is None: |
|
1362 | 1362 | length = len(self.series) - start |
|
1363 | 1363 | if not missing: |
|
1364 | 1364 | if self.ui.verbose: |
|
1365 | 1365 | idxwidth = len(str(start+length - 1)) |
|
1366 | 1366 | for i in xrange(start, start+length): |
|
1367 | 1367 | patch = self.series[i] |
|
1368 | 1368 | if patch in applied: |
|
1369 | 1369 | stat = 'A' |
|
1370 | 1370 | elif self.pushable(i)[0]: |
|
1371 | 1371 | stat = 'U' |
|
1372 | 1372 | else: |
|
1373 | 1373 | stat = 'G' |
|
1374 | 1374 | pfx = '' |
|
1375 | 1375 | if self.ui.verbose: |
|
1376 | 1376 | pfx = '%*d %s ' % (idxwidth, i, stat) |
|
1377 | 1377 | elif status and status != stat: |
|
1378 | 1378 | continue |
|
1379 | 1379 | displayname(pfx, patch) |
|
1380 | 1380 | else: |
|
1381 | 1381 | msng_list = [] |
|
1382 | 1382 | for root, dirs, files in os.walk(self.path): |
|
1383 | 1383 | d = root[len(self.path) + 1:] |
|
1384 | 1384 | for f in files: |
|
1385 | 1385 | fl = os.path.join(d, f) |
|
1386 | 1386 | if (fl not in self.series and |
|
1387 | 1387 | fl not in (self.status_path, self.series_path, |
|
1388 | 1388 | self.guards_path) |
|
1389 | 1389 | and not fl.startswith('.')): |
|
1390 | 1390 | msng_list.append(fl) |
|
1391 | 1391 | for x in sorted(msng_list): |
|
1392 | 1392 | pfx = self.ui.verbose and ('D ') or '' |
|
1393 | 1393 | displayname(pfx, x) |
|
1394 | 1394 | |
|
1395 | 1395 | def issaveline(self, l): |
|
1396 | 1396 | if l.name == '.hg.patches.save.line': |
|
1397 | 1397 | return True |
|
1398 | 1398 | |
|
1399 | 1399 | def qrepo(self, create=False): |
|
1400 | 1400 | if create or os.path.isdir(self.join(".hg")): |
|
1401 | 1401 | return hg.repository(self.ui, path=self.path, create=create) |
|
1402 | 1402 | |
|
1403 | 1403 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1404 | 1404 | c = repo.changelog.read(rev) |
|
1405 | 1405 | desc = c[4].strip() |
|
1406 | 1406 | lines = desc.splitlines() |
|
1407 | 1407 | i = 0 |
|
1408 | 1408 | datastart = None |
|
1409 | 1409 | series = [] |
|
1410 | 1410 | applied = [] |
|
1411 | 1411 | qpp = None |
|
1412 | 1412 | for i, line in enumerate(lines): |
|
1413 | 1413 | if line == 'Patch Data:': |
|
1414 | 1414 | datastart = i + 1 |
|
1415 | 1415 | elif line.startswith('Dirstate:'): |
|
1416 | 1416 | l = line.rstrip() |
|
1417 | 1417 | l = l[10:].split(' ') |
|
1418 | 1418 | qpp = [ bin(x) for x in l ] |
|
1419 | 1419 | elif datastart != None: |
|
1420 | 1420 | l = line.rstrip() |
|
1421 | 1421 | se = statusentry(l) |
|
1422 | 1422 | file_ = se.name |
|
1423 | 1423 | if se.rev: |
|
1424 | 1424 | applied.append(se) |
|
1425 | 1425 | else: |
|
1426 | 1426 | series.append(file_) |
|
1427 | 1427 | if datastart is None: |
|
1428 | 1428 | self.ui.warn(_("No saved patch data found\n")) |
|
1429 | 1429 | return 1 |
|
1430 | 1430 | self.ui.warn(_("restoring status: %s\n") % lines[0]) |
|
1431 | 1431 | self.full_series = series |
|
1432 | 1432 | self.applied = applied |
|
1433 | 1433 | self.parse_series() |
|
1434 | 1434 | self.series_dirty = 1 |
|
1435 | 1435 | self.applied_dirty = 1 |
|
1436 | 1436 | heads = repo.changelog.heads() |
|
1437 | 1437 | if delete: |
|
1438 | 1438 | if rev not in heads: |
|
1439 | 1439 | self.ui.warn(_("save entry has children, leaving it alone\n")) |
|
1440 | 1440 | else: |
|
1441 | 1441 | self.ui.warn(_("removing save entry %s\n") % short(rev)) |
|
1442 | 1442 | pp = repo.dirstate.parents() |
|
1443 | 1443 | if rev in pp: |
|
1444 | 1444 | update = True |
|
1445 | 1445 | else: |
|
1446 | 1446 | update = False |
|
1447 | 1447 | self.strip(repo, rev, update=update, backup='strip') |
|
1448 | 1448 | if qpp: |
|
1449 | 1449 | self.ui.warn(_("saved queue repository parents: %s %s\n") % |
|
1450 | 1450 | (short(qpp[0]), short(qpp[1]))) |
|
1451 | 1451 | if qupdate: |
|
1452 | 1452 | self.ui.status(_("queue directory updating\n")) |
|
1453 | 1453 | r = self.qrepo() |
|
1454 | 1454 | if not r: |
|
1455 | 1455 | self.ui.warn(_("Unable to load queue repository\n")) |
|
1456 | 1456 | return 1 |
|
1457 | 1457 | hg.clean(r, qpp[0]) |
|
1458 | 1458 | |
|
1459 | 1459 | def save(self, repo, msg=None): |
|
1460 | 1460 | if len(self.applied) == 0: |
|
1461 | 1461 | self.ui.warn(_("save: no patches applied, exiting\n")) |
|
1462 | 1462 | return 1 |
|
1463 | 1463 | if self.issaveline(self.applied[-1]): |
|
1464 | 1464 | self.ui.warn(_("status is already saved\n")) |
|
1465 | 1465 | return 1 |
|
1466 | 1466 | |
|
1467 | 1467 | ar = [ ':' + x for x in self.full_series ] |
|
1468 | 1468 | if not msg: |
|
1469 | 1469 | msg = _("hg patches saved state") |
|
1470 | 1470 | else: |
|
1471 | 1471 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1472 | 1472 | r = self.qrepo() |
|
1473 | 1473 | if r: |
|
1474 | 1474 | pp = r.dirstate.parents() |
|
1475 | 1475 | msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1])) |
|
1476 | 1476 | msg += "\n\nPatch Data:\n" |
|
1477 | 1477 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and |
|
1478 | 1478 | "\n".join(ar) + '\n' or "") |
|
1479 | 1479 | n = repo.commit(text, force=True) |
|
1480 | 1480 | if not n: |
|
1481 | 1481 | self.ui.warn(_("repo commit failed\n")) |
|
1482 | 1482 | return 1 |
|
1483 | 1483 | self.applied.append(statusentry(hex(n),'.hg.patches.save.line')) |
|
1484 | 1484 | self.applied_dirty = 1 |
|
1485 | 1485 | self.removeundo(repo) |
|
1486 | 1486 | |
|
1487 | 1487 | def full_series_end(self): |
|
1488 | 1488 | if len(self.applied) > 0: |
|
1489 | 1489 | p = self.applied[-1].name |
|
1490 | 1490 | end = self.find_series(p) |
|
1491 | 1491 | if end is None: |
|
1492 | 1492 | return len(self.full_series) |
|
1493 | 1493 | return end + 1 |
|
1494 | 1494 | return 0 |
|
1495 | 1495 | |
|
1496 | 1496 | def series_end(self, all_patches=False): |
|
1497 | 1497 | """If all_patches is False, return the index of the next pushable patch |
|
1498 | 1498 | in the series, or the series length. If all_patches is True, return the |
|
1499 | 1499 | index of the first patch past the last applied one. |
|
1500 | 1500 | """ |
|
1501 | 1501 | end = 0 |
|
1502 | 1502 | def next(start): |
|
1503 | 1503 | if all_patches: |
|
1504 | 1504 | return start |
|
1505 | 1505 | i = start |
|
1506 | 1506 | while i < len(self.series): |
|
1507 | 1507 | p, reason = self.pushable(i) |
|
1508 | 1508 | if p: |
|
1509 | 1509 | break |
|
1510 | 1510 | self.explain_pushable(i) |
|
1511 | 1511 | i += 1 |
|
1512 | 1512 | return i |
|
1513 | 1513 | if len(self.applied) > 0: |
|
1514 | 1514 | p = self.applied[-1].name |
|
1515 | 1515 | try: |
|
1516 | 1516 | end = self.series.index(p) |
|
1517 | 1517 | except ValueError: |
|
1518 | 1518 | return 0 |
|
1519 | 1519 | return next(end + 1) |
|
1520 | 1520 | return next(end) |
|
1521 | 1521 | |
|
1522 | 1522 | def appliedname(self, index): |
|
1523 | 1523 | pname = self.applied[index].name |
|
1524 | 1524 | if not self.ui.verbose: |
|
1525 | 1525 | p = pname |
|
1526 | 1526 | else: |
|
1527 | 1527 | p = str(self.series.index(pname)) + " " + pname |
|
1528 | 1528 | return p |
|
1529 | 1529 | |
|
1530 | 1530 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
|
1531 | 1531 | force=None, git=False): |
|
1532 | 1532 | def checkseries(patchname): |
|
1533 | 1533 | if patchname in self.series: |
|
1534 | 1534 | raise util.Abort(_('patch %s is already in the series file') |
|
1535 | 1535 | % patchname) |
|
1536 | 1536 | def checkfile(patchname): |
|
1537 | 1537 | if not force and os.path.exists(self.join(patchname)): |
|
1538 | 1538 | raise util.Abort(_('patch "%s" already exists') |
|
1539 | 1539 | % patchname) |
|
1540 | 1540 | |
|
1541 | 1541 | if rev: |
|
1542 | 1542 | if files: |
|
1543 | 1543 | raise util.Abort(_('option "-r" not valid when importing ' |
|
1544 | 1544 | 'files')) |
|
1545 | 1545 | rev = cmdutil.revrange(repo, rev) |
|
1546 | 1546 | rev.sort(reverse=True) |
|
1547 | 1547 | if (len(files) > 1 or len(rev) > 1) and patchname: |
|
1548 | 1548 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1549 | 1549 | 'patches')) |
|
1550 | 1550 | i = 0 |
|
1551 | 1551 | added = [] |
|
1552 | 1552 | if rev: |
|
1553 | 1553 | # If mq patches are applied, we can only import revisions |
|
1554 | 1554 | # that form a linear path to qbase. |
|
1555 | 1555 | # Otherwise, they should form a linear path to a head. |
|
1556 | 1556 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) |
|
1557 | 1557 | if len(heads) > 1: |
|
1558 | 1558 | raise util.Abort(_('revision %d is the root of more than one ' |
|
1559 | 1559 | 'branch') % rev[-1]) |
|
1560 | 1560 | if self.applied: |
|
1561 | 1561 | base = hex(repo.changelog.node(rev[0])) |
|
1562 | 1562 | if base in [n.rev for n in self.applied]: |
|
1563 | 1563 | raise util.Abort(_('revision %d is already managed') |
|
1564 | 1564 | % rev[0]) |
|
1565 | 1565 | if heads != [bin(self.applied[-1].rev)]: |
|
1566 | 1566 | raise util.Abort(_('revision %d is not the parent of ' |
|
1567 | 1567 | 'the queue') % rev[0]) |
|
1568 | 1568 | base = repo.changelog.rev(bin(self.applied[0].rev)) |
|
1569 | 1569 | lastparent = repo.changelog.parentrevs(base)[0] |
|
1570 | 1570 | else: |
|
1571 | 1571 | if heads != [repo.changelog.node(rev[0])]: |
|
1572 | 1572 | raise util.Abort(_('revision %d has unmanaged children') |
|
1573 | 1573 | % rev[0]) |
|
1574 | 1574 | lastparent = None |
|
1575 | 1575 | |
|
1576 | 1576 | if git: |
|
1577 | 1577 | self.diffopts().git = True |
|
1578 | 1578 | |
|
1579 | 1579 | for r in rev: |
|
1580 | 1580 | p1, p2 = repo.changelog.parentrevs(r) |
|
1581 | 1581 | n = repo.changelog.node(r) |
|
1582 | 1582 | if p2 != nullrev: |
|
1583 | 1583 | raise util.Abort(_('cannot import merge revision %d') % r) |
|
1584 | 1584 | if lastparent and lastparent != r: |
|
1585 | 1585 | raise util.Abort(_('revision %d is not the parent of %d') |
|
1586 | 1586 | % (r, lastparent)) |
|
1587 | 1587 | lastparent = p1 |
|
1588 | 1588 | |
|
1589 | 1589 | if not patchname: |
|
1590 | 1590 | patchname = normname('%d.diff' % r) |
|
1591 | 1591 | self.check_reserved_name(patchname) |
|
1592 | 1592 | checkseries(patchname) |
|
1593 | 1593 | checkfile(patchname) |
|
1594 | 1594 | self.full_series.insert(0, patchname) |
|
1595 | 1595 | |
|
1596 | 1596 | patchf = self.opener(patchname, "w") |
|
1597 | 1597 | patch.export(repo, [n], fp=patchf, opts=self.diffopts()) |
|
1598 | 1598 | patchf.close() |
|
1599 | 1599 | |
|
1600 | 1600 | se = statusentry(hex(n), patchname) |
|
1601 | 1601 | self.applied.insert(0, se) |
|
1602 | 1602 | |
|
1603 | 1603 | added.append(patchname) |
|
1604 | 1604 | patchname = None |
|
1605 | 1605 | self.parse_series() |
|
1606 | 1606 | self.applied_dirty = 1 |
|
1607 | 1607 | |
|
1608 | 1608 | for filename in files: |
|
1609 | 1609 | if existing: |
|
1610 | 1610 | if filename == '-': |
|
1611 | 1611 | raise util.Abort(_('-e is incompatible with import from -')) |
|
1612 | 1612 | if not patchname: |
|
1613 | 1613 | patchname = normname(filename) |
|
1614 | 1614 | self.check_reserved_name(patchname) |
|
1615 | 1615 | if not os.path.isfile(self.join(patchname)): |
|
1616 | 1616 | raise util.Abort(_("patch %s does not exist") % patchname) |
|
1617 | 1617 | else: |
|
1618 | 1618 | try: |
|
1619 | 1619 | if filename == '-': |
|
1620 | 1620 | if not patchname: |
|
1621 | 1621 | raise util.Abort(_('need --name to import a patch from -')) |
|
1622 | 1622 | text = sys.stdin.read() |
|
1623 | 1623 | else: |
|
1624 | 1624 | text = url.open(self.ui, filename).read() |
|
1625 | 1625 | except (OSError, IOError): |
|
1626 | 1626 | raise util.Abort(_("unable to read %s") % filename) |
|
1627 | 1627 | if not patchname: |
|
1628 | 1628 | patchname = normname(os.path.basename(filename)) |
|
1629 | 1629 | self.check_reserved_name(patchname) |
|
1630 | 1630 | checkfile(patchname) |
|
1631 | 1631 | patchf = self.opener(patchname, "w") |
|
1632 | 1632 | patchf.write(text) |
|
1633 | 1633 | if not force: |
|
1634 | 1634 | checkseries(patchname) |
|
1635 | 1635 | if patchname not in self.series: |
|
1636 | 1636 | index = self.full_series_end() + i |
|
1637 | 1637 | self.full_series[index:index] = [patchname] |
|
1638 | 1638 | self.parse_series() |
|
1639 | 1639 | self.ui.warn(_("adding %s to series file\n") % patchname) |
|
1640 | 1640 | i += 1 |
|
1641 | 1641 | added.append(patchname) |
|
1642 | 1642 | patchname = None |
|
1643 | 1643 | self.series_dirty = 1 |
|
1644 | 1644 | qrepo = self.qrepo() |
|
1645 | 1645 | if qrepo: |
|
1646 | 1646 | qrepo.add(added) |
|
1647 | 1647 | |
|
1648 | 1648 | def delete(ui, repo, *patches, **opts): |
|
1649 | 1649 | """remove patches from queue |
|
1650 | 1650 | |
|
1651 | 1651 | The patches must not be applied, and at least one patch is required. With |
|
1652 | 1652 | -k/--keep, the patch files are preserved in the patch directory. |
|
1653 | 1653 | |
|
1654 | 1654 | To stop managing a patch and move it into permanent history, |
|
1655 | 1655 | use the qfinish command.""" |
|
1656 | 1656 | q = repo.mq |
|
1657 | 1657 | q.delete(repo, patches, opts) |
|
1658 | 1658 | q.save_dirty() |
|
1659 | 1659 | return 0 |
|
1660 | 1660 | |
|
1661 | 1661 | def applied(ui, repo, patch=None, **opts): |
|
1662 | 1662 | """print the patches already applied""" |
|
1663 | 1663 | q = repo.mq |
|
1664 | 1664 | if patch: |
|
1665 | 1665 | if patch not in q.series: |
|
1666 | 1666 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1667 | 1667 | end = q.series.index(patch) + 1 |
|
1668 | 1668 | else: |
|
1669 | 1669 | end = q.series_end(True) |
|
1670 | 1670 | return q.qseries(repo, length=end, status='A', summary=opts.get('summary')) |
|
1671 | 1671 | |
|
1672 | 1672 | def unapplied(ui, repo, patch=None, **opts): |
|
1673 | 1673 | """print the patches not yet applied""" |
|
1674 | 1674 | q = repo.mq |
|
1675 | 1675 | if patch: |
|
1676 | 1676 | if patch not in q.series: |
|
1677 | 1677 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1678 | 1678 | start = q.series.index(patch) + 1 |
|
1679 | 1679 | else: |
|
1680 | 1680 | start = q.series_end(True) |
|
1681 | 1681 | q.qseries(repo, start=start, status='U', summary=opts.get('summary')) |
|
1682 | 1682 | |
|
1683 | 1683 | def qimport(ui, repo, *filename, **opts): |
|
1684 | 1684 | """import a patch |
|
1685 | 1685 | |
|
1686 | 1686 | The patch is inserted into the series after the last applied patch. If no |
|
1687 | 1687 | patches have been applied, qimport prepends the patch to the series. |
|
1688 | 1688 | |
|
1689 | 1689 | The patch will have the same name as its source file unless you give it a |
|
1690 | 1690 | new one with -n/--name. |
|
1691 | 1691 | |
|
1692 | 1692 | You can register an existing patch inside the patch directory with the |
|
1693 | 1693 | -e/--existing flag. |
|
1694 | 1694 | |
|
1695 | 1695 | With -f/--force, an existing patch of the same name will be overwritten. |
|
1696 | 1696 | |
|
1697 | 1697 | An existing changeset may be placed under mq control with -r/--rev (e.g. |
|
1698 | 1698 | qimport --rev tip -n patch will place tip under mq control). With |
|
1699 | 1699 | -g/--git, patches imported with --rev will use the git diff format. See |
|
1700 | 1700 | the diffs help topic for information on why this is important for |
|
1701 | 1701 | preserving rename/copy information and permission changes. |
|
1702 | 1702 | |
|
1703 | 1703 | To import a patch from standard input, pass - as the patch file. When |
|
1704 | 1704 | importing from standard input, a patch name must be specified using the |
|
1705 | 1705 | --name flag. |
|
1706 | 1706 | """ |
|
1707 | 1707 | q = repo.mq |
|
1708 | 1708 | q.qimport(repo, filename, patchname=opts['name'], |
|
1709 | 1709 | existing=opts['existing'], force=opts['force'], rev=opts['rev'], |
|
1710 | 1710 | git=opts['git']) |
|
1711 | 1711 | q.save_dirty() |
|
1712 | 1712 | |
|
1713 | 1713 | if opts.get('push') and not opts.get('rev'): |
|
1714 | 1714 | return q.push(repo, None) |
|
1715 | 1715 | return 0 |
|
1716 | 1716 | |
|
1717 | 1717 | def init(ui, repo, **opts): |
|
1718 | 1718 | """init a new queue repository |
|
1719 | 1719 | |
|
1720 | 1720 | The queue repository is unversioned by default. If -c/--create-repo is |
|
1721 | 1721 | specified, qinit will create a separate nested repository for patches |
|
1722 | 1722 | (qinit -c may also be run later to convert an unversioned patch repository |
|
1723 | 1723 | into a versioned one). You can use qcommit to commit changes to this queue |
|
1724 | 1724 | repository. |
|
1725 | 1725 | """ |
|
1726 | 1726 | q = repo.mq |
|
1727 | 1727 | r = q.init(repo, create=opts['create_repo']) |
|
1728 | 1728 | q.save_dirty() |
|
1729 | 1729 | if r: |
|
1730 | 1730 | if not os.path.exists(r.wjoin('.hgignore')): |
|
1731 | 1731 | fp = r.wopener('.hgignore', 'w') |
|
1732 | 1732 | fp.write('^\\.hg\n') |
|
1733 | 1733 | fp.write('^\\.mq\n') |
|
1734 | 1734 | fp.write('syntax: glob\n') |
|
1735 | 1735 | fp.write('status\n') |
|
1736 | 1736 | fp.write('guards\n') |
|
1737 | 1737 | fp.close() |
|
1738 | 1738 | if not os.path.exists(r.wjoin('series')): |
|
1739 | 1739 | r.wopener('series', 'w').close() |
|
1740 | 1740 | r.add(['.hgignore', 'series']) |
|
1741 | 1741 | commands.add(ui, r) |
|
1742 | 1742 | return 0 |
|
1743 | 1743 | |
|
1744 | 1744 | def clone(ui, source, dest=None, **opts): |
|
1745 | 1745 | '''clone main and patch repository at same time |
|
1746 | 1746 | |
|
1747 | 1747 | If source is local, destination will have no patches applied. If source is |
|
1748 | 1748 | remote, this command can not check if patches are applied in source, so |
|
1749 | 1749 | cannot guarantee that patches are not applied in destination. If you clone |
|
1750 | 1750 | remote repository, be sure before that it has no patches applied. |
|
1751 | 1751 | |
|
1752 | 1752 | Source patch repository is looked for in <src>/.hg/patches by default. Use |
|
1753 | 1753 | -p <url> to change. |
|
1754 | 1754 | |
|
1755 | 1755 | The patch directory must be a nested Mercurial repository, as would be |
|
1756 | 1756 | created by qinit -c. |
|
1757 | 1757 | ''' |
|
1758 | 1758 | def patchdir(repo): |
|
1759 | 1759 | url = repo.url() |
|
1760 | 1760 | if url.endswith('/'): |
|
1761 | 1761 | url = url[:-1] |
|
1762 | 1762 | return url + '/.hg/patches' |
|
1763 | 1763 | if dest is None: |
|
1764 | 1764 | dest = hg.defaultdest(source) |
|
1765 | 1765 | sr = hg.repository(cmdutil.remoteui(ui, opts), ui.expandpath(source)) |
|
1766 | 1766 | if opts['patches']: |
|
1767 | 1767 | patchespath = ui.expandpath(opts['patches']) |
|
1768 | 1768 | else: |
|
1769 | 1769 | patchespath = patchdir(sr) |
|
1770 | 1770 | try: |
|
1771 | 1771 | hg.repository(ui, patchespath) |
|
1772 | 1772 | except error.RepoError: |
|
1773 | 1773 | raise util.Abort(_('versioned patch repository not found' |
|
1774 | 1774 | ' (see qinit -c)')) |
|
1775 | 1775 | qbase, destrev = None, None |
|
1776 | 1776 | if sr.local(): |
|
1777 | 1777 | if sr.mq.applied: |
|
1778 | 1778 | qbase = bin(sr.mq.applied[0].rev) |
|
1779 | 1779 | if not hg.islocal(dest): |
|
1780 | 1780 | heads = set(sr.heads()) |
|
1781 | 1781 | destrev = list(heads.difference(sr.heads(qbase))) |
|
1782 | 1782 | destrev.append(sr.changelog.parents(qbase)[0]) |
|
1783 | 1783 | elif sr.capable('lookup'): |
|
1784 | 1784 | try: |
|
1785 | 1785 | qbase = sr.lookup('qbase') |
|
1786 | 1786 | except error.RepoError: |
|
1787 | 1787 | pass |
|
1788 | 1788 | ui.note(_('cloning main repository\n')) |
|
1789 | 1789 | sr, dr = hg.clone(ui, sr.url(), dest, |
|
1790 | 1790 | pull=opts['pull'], |
|
1791 | 1791 | rev=destrev, |
|
1792 | 1792 | update=False, |
|
1793 | 1793 | stream=opts['uncompressed']) |
|
1794 | 1794 | ui.note(_('cloning patch repository\n')) |
|
1795 | 1795 | hg.clone(ui, opts['patches'] or patchdir(sr), patchdir(dr), |
|
1796 | 1796 | pull=opts['pull'], update=not opts['noupdate'], |
|
1797 | 1797 | stream=opts['uncompressed']) |
|
1798 | 1798 | if dr.local(): |
|
1799 | 1799 | if qbase: |
|
1800 | 1800 | ui.note(_('stripping applied patches from destination ' |
|
1801 | 1801 | 'repository\n')) |
|
1802 | 1802 | dr.mq.strip(dr, qbase, update=False, backup=None) |
|
1803 | 1803 | if not opts['noupdate']: |
|
1804 | 1804 | ui.note(_('updating destination repository\n')) |
|
1805 | 1805 | hg.update(dr, dr.changelog.tip()) |
|
1806 | 1806 | |
|
1807 | 1807 | def commit(ui, repo, *pats, **opts): |
|
1808 | 1808 | """commit changes in the queue repository""" |
|
1809 | 1809 | q = repo.mq |
|
1810 | 1810 | r = q.qrepo() |
|
1811 | 1811 | if not r: raise util.Abort('no queue repository') |
|
1812 | 1812 | commands.commit(r.ui, r, *pats, **opts) |
|
1813 | 1813 | |
|
1814 | 1814 | def series(ui, repo, **opts): |
|
1815 | 1815 | """print the entire series file""" |
|
1816 | 1816 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
|
1817 | 1817 | return 0 |
|
1818 | 1818 | |
|
1819 | 1819 | def top(ui, repo, **opts): |
|
1820 | 1820 | """print the name of the current patch""" |
|
1821 | 1821 | q = repo.mq |
|
1822 | 1822 | t = q.applied and q.series_end(True) or 0 |
|
1823 | 1823 | if t: |
|
1824 | 1824 | return q.qseries(repo, start=t-1, length=1, status='A', |
|
1825 | 1825 | summary=opts.get('summary')) |
|
1826 | 1826 | else: |
|
1827 | 1827 | ui.write(_("no patches applied\n")) |
|
1828 | 1828 | return 1 |
|
1829 | 1829 | |
|
1830 | 1830 | def next(ui, repo, **opts): |
|
1831 | 1831 | """print the name of the next patch""" |
|
1832 | 1832 | q = repo.mq |
|
1833 | 1833 | end = q.series_end() |
|
1834 | 1834 | if end == len(q.series): |
|
1835 | 1835 | ui.write(_("all patches applied\n")) |
|
1836 | 1836 | return 1 |
|
1837 | 1837 | return q.qseries(repo, start=end, length=1, summary=opts.get('summary')) |
|
1838 | 1838 | |
|
1839 | 1839 | def prev(ui, repo, **opts): |
|
1840 | 1840 | """print the name of the previous patch""" |
|
1841 | 1841 | q = repo.mq |
|
1842 | 1842 | l = len(q.applied) |
|
1843 | 1843 | if l == 1: |
|
1844 | 1844 | ui.write(_("only one patch applied\n")) |
|
1845 | 1845 | return 1 |
|
1846 | 1846 | if not l: |
|
1847 | 1847 | ui.write(_("no patches applied\n")) |
|
1848 | 1848 | return 1 |
|
1849 | 1849 | return q.qseries(repo, start=l-2, length=1, status='A', |
|
1850 | 1850 | summary=opts.get('summary')) |
|
1851 | 1851 | |
|
1852 | 1852 | def setupheaderopts(ui, opts): |
|
1853 | 1853 | def do(opt,val): |
|
1854 | 1854 | if not opts[opt] and opts['current' + opt]: |
|
1855 | 1855 | opts[opt] = val |
|
1856 | 1856 | do('user', ui.username()) |
|
1857 | 1857 | do('date', "%d %d" % util.makedate()) |
|
1858 | 1858 | |
|
1859 | 1859 | def new(ui, repo, patch, *args, **opts): |
|
1860 | 1860 | """create a new patch |
|
1861 | 1861 | |
|
1862 | 1862 | qnew creates a new patch on top of the currently-applied patch (if any). |
|
1863 | 1863 | It will refuse to run if there are any outstanding changes unless |
|
1864 | 1864 | -f/--force is specified, in which case the patch will be initialized with |
|
1865 | 1865 | them. You may also use -I/--include, -X/--exclude, and/or a list of files |
|
1866 | 1866 | after the patch name to add only changes to matching files to the new |
|
1867 | 1867 | patch, leaving the rest as uncommitted modifications. |
|
1868 | 1868 | |
|
1869 | 1869 | -u/--user and -d/--date can be used to set the (given) user and date, |
|
1870 | 1870 | respectively. -U/--currentuser and -D/--currentdate set user to current |
|
1871 | 1871 | user and date to current date. |
|
1872 | 1872 | |
|
1873 | 1873 | -e/--edit, -m/--message or -l/--logfile set the patch header as well as |
|
1874 | 1874 | the commit message. If none is specified, the header is empty and the |
|
1875 | 1875 | commit message is '[mq]: PATCH'. |
|
1876 | 1876 | |
|
1877 | 1877 | Use the -g/--git option to keep the patch in the git extended diff format. |
|
1878 | 1878 | Read the diffs help topic for more information on why this is important |
|
1879 | 1879 | for preserving permission changes and copy/rename information. |
|
1880 | 1880 | """ |
|
1881 | 1881 | msg = cmdutil.logmessage(opts) |
|
1882 | 1882 | def getmsg(): return ui.edit(msg, ui.username()) |
|
1883 | 1883 | q = repo.mq |
|
1884 | 1884 | opts['msg'] = msg |
|
1885 | 1885 | if opts.get('edit'): |
|
1886 | 1886 | opts['msg'] = getmsg |
|
1887 | 1887 | else: |
|
1888 | 1888 | opts['msg'] = msg |
|
1889 | 1889 | setupheaderopts(ui, opts) |
|
1890 | 1890 | q.new(repo, patch, *args, **opts) |
|
1891 | 1891 | q.save_dirty() |
|
1892 | 1892 | return 0 |
|
1893 | 1893 | |
|
1894 | 1894 | def refresh(ui, repo, *pats, **opts): |
|
1895 | 1895 | """update the current patch |
|
1896 | 1896 | |
|
1897 | 1897 | If any file patterns are provided, the refreshed patch will contain only |
|
1898 | 1898 | the modifications that match those patterns; the remaining modifications |
|
1899 | 1899 | will remain in the working directory. |
|
1900 | 1900 | |
|
1901 | 1901 | If -s/--short is specified, files currently included in the patch will be |
|
1902 | 1902 | refreshed just like matched files and remain in the patch. |
|
1903 | 1903 | |
|
1904 | 1904 | hg add/remove/copy/rename work as usual, though you might want to use |
|
1905 | 1905 | git-style patches (-g/--git or [diff] git=1) to track copies and renames. |
|
1906 | 1906 | See the diffs help topic for more information on the git diff format. |
|
1907 | 1907 | """ |
|
1908 | 1908 | q = repo.mq |
|
1909 | 1909 | message = cmdutil.logmessage(opts) |
|
1910 | 1910 | if opts['edit']: |
|
1911 | 1911 | if not q.applied: |
|
1912 | 1912 | ui.write(_("no patches applied\n")) |
|
1913 | 1913 | return 1 |
|
1914 | 1914 | if message: |
|
1915 | 1915 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1916 | 1916 | patch = q.applied[-1].name |
|
1917 | 1917 | ph = patchheader(q.join(patch)) |
|
1918 | 1918 | message = ui.edit('\n'.join(ph.message), ph.user or ui.username()) |
|
1919 | 1919 | setupheaderopts(ui, opts) |
|
1920 | 1920 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
1921 | 1921 | q.save_dirty() |
|
1922 | 1922 | return ret |
|
1923 | 1923 | |
|
1924 | 1924 | def diff(ui, repo, *pats, **opts): |
|
1925 | 1925 | """diff of the current patch and subsequent modifications |
|
1926 | 1926 | |
|
1927 | 1927 | Shows a diff which includes the current patch as well as any changes which |
|
1928 | 1928 | have been made in the working directory since the last refresh (thus |
|
1929 | 1929 | showing what the current patch would become after a qrefresh). |
|
1930 | 1930 | |
|
1931 | 1931 | Use 'hg diff' if you only want to see the changes made since the last |
|
1932 | 1932 | qrefresh, or 'hg export qtip' if you want to see changes made by the |
|
1933 | 1933 | current patch without including changes made since the qrefresh. |
|
1934 | 1934 | """ |
|
1935 | 1935 | repo.mq.diff(repo, pats, opts) |
|
1936 | 1936 | return 0 |
|
1937 | 1937 | |
|
1938 | 1938 | def fold(ui, repo, *files, **opts): |
|
1939 | 1939 | """fold the named patches into the current patch |
|
1940 | 1940 | |
|
1941 | 1941 | Patches must not yet be applied. Each patch will be successively applied |
|
1942 | 1942 | to the current patch in the order given. If all the patches apply |
|
1943 | 1943 | successfully, the current patch will be refreshed with the new cumulative |
|
1944 | 1944 | patch, and the folded patches will be deleted. With -k/--keep, the folded |
|
1945 | 1945 | patch files will not be removed afterwards. |
|
1946 | 1946 | |
|
1947 | 1947 | The header for each folded patch will be concatenated with the current |
|
1948 | 1948 | patch header, separated by a line of '* * *'. |
|
1949 | 1949 | """ |
|
1950 | 1950 | |
|
1951 | 1951 | q = repo.mq |
|
1952 | 1952 | |
|
1953 | 1953 | if not files: |
|
1954 | 1954 | raise util.Abort(_('qfold requires at least one patch name')) |
|
1955 | 1955 | if not q.check_toppatch(repo): |
|
1956 | 1956 | raise util.Abort(_('No patches applied')) |
|
1957 | 1957 | q.check_localchanges(repo) |
|
1958 | 1958 | |
|
1959 | 1959 | message = cmdutil.logmessage(opts) |
|
1960 | 1960 | if opts['edit']: |
|
1961 | 1961 | if message: |
|
1962 | 1962 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1963 | 1963 | |
|
1964 | 1964 | parent = q.lookup('qtip') |
|
1965 | 1965 | patches = [] |
|
1966 | 1966 | messages = [] |
|
1967 | 1967 | for f in files: |
|
1968 | 1968 | p = q.lookup(f) |
|
1969 | 1969 | if p in patches or p == parent: |
|
1970 | 1970 | ui.warn(_('Skipping already folded patch %s') % p) |
|
1971 | 1971 | if q.isapplied(p): |
|
1972 | 1972 | raise util.Abort(_('qfold cannot fold already applied patch %s') % p) |
|
1973 | 1973 | patches.append(p) |
|
1974 | 1974 | |
|
1975 | 1975 | for p in patches: |
|
1976 | 1976 | if not message: |
|
1977 | 1977 | ph = patchheader(q.join(p)) |
|
1978 | 1978 | if ph.message: |
|
1979 | 1979 | messages.append(ph.message) |
|
1980 | 1980 | pf = q.join(p) |
|
1981 | 1981 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1982 | 1982 | if not patchsuccess: |
|
1983 | 1983 | raise util.Abort(_('Error folding patch %s') % p) |
|
1984 | 1984 | patch.updatedir(ui, repo, files) |
|
1985 | 1985 | |
|
1986 | 1986 | if not message: |
|
1987 | 1987 | ph = patchheader(q.join(parent)) |
|
1988 | 1988 | message, user = ph.message, ph.user |
|
1989 | 1989 | for msg in messages: |
|
1990 | 1990 | message.append('* * *') |
|
1991 | 1991 | message.extend(msg) |
|
1992 | 1992 | message = '\n'.join(message) |
|
1993 | 1993 | |
|
1994 | 1994 | if opts['edit']: |
|
1995 | 1995 | message = ui.edit(message, user or ui.username()) |
|
1996 | 1996 | |
|
1997 | 1997 | q.refresh(repo, msg=message) |
|
1998 | 1998 | q.delete(repo, patches, opts) |
|
1999 | 1999 | q.save_dirty() |
|
2000 | 2000 | |
|
2001 | 2001 | def goto(ui, repo, patch, **opts): |
|
2002 | 2002 | '''push or pop patches until named patch is at top of stack''' |
|
2003 | 2003 | q = repo.mq |
|
2004 | 2004 | patch = q.lookup(patch) |
|
2005 | 2005 | if q.isapplied(patch): |
|
2006 | 2006 | ret = q.pop(repo, patch, force=opts['force']) |
|
2007 | 2007 | else: |
|
2008 | 2008 | ret = q.push(repo, patch, force=opts['force']) |
|
2009 | 2009 | q.save_dirty() |
|
2010 | 2010 | return ret |
|
2011 | 2011 | |
|
2012 | 2012 | def guard(ui, repo, *args, **opts): |
|
2013 | 2013 | '''set or print guards for a patch |
|
2014 | 2014 | |
|
2015 | 2015 | Guards control whether a patch can be pushed. A patch with no guards is |
|
2016 | 2016 | always pushed. A patch with a positive guard ("+foo") is pushed only if |
|
2017 | 2017 | the qselect command has activated it. A patch with a negative guard |
|
2018 | 2018 | ("-foo") is never pushed if the qselect command has activated it. |
|
2019 | 2019 | |
|
2020 | 2020 | With no arguments, print the currently active guards. With arguments, set |
|
2021 | 2021 | guards for the named patch. |
|
2022 | 2022 | NOTE: Specifying negative guards now requires '--'. |
|
2023 | 2023 | |
|
2024 | 2024 | To set guards on another patch: |
|
2025 | 2025 | hg qguard -- other.patch +2.6.17 -stable |
|
2026 | 2026 | ''' |
|
2027 | 2027 | def status(idx): |
|
2028 | 2028 | guards = q.series_guards[idx] or ['unguarded'] |
|
2029 | 2029 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) |
|
2030 | 2030 | q = repo.mq |
|
2031 | 2031 | patch = None |
|
2032 | 2032 | args = list(args) |
|
2033 | 2033 | if opts['list']: |
|
2034 | 2034 | if args or opts['none']: |
|
2035 | 2035 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) |
|
2036 | 2036 | for i in xrange(len(q.series)): |
|
2037 | 2037 | status(i) |
|
2038 | 2038 | return |
|
2039 | 2039 | if not args or args[0][0:1] in '-+': |
|
2040 | 2040 | if not q.applied: |
|
2041 | 2041 | raise util.Abort(_('no patches applied')) |
|
2042 | 2042 | patch = q.applied[-1].name |
|
2043 | 2043 | if patch is None and args[0][0:1] not in '-+': |
|
2044 | 2044 | patch = args.pop(0) |
|
2045 | 2045 | if patch is None: |
|
2046 | 2046 | raise util.Abort(_('no patch to work with')) |
|
2047 | 2047 | if args or opts['none']: |
|
2048 | 2048 | idx = q.find_series(patch) |
|
2049 | 2049 | if idx is None: |
|
2050 | 2050 | raise util.Abort(_('no patch named %s') % patch) |
|
2051 | 2051 | q.set_guards(idx, args) |
|
2052 | 2052 | q.save_dirty() |
|
2053 | 2053 | else: |
|
2054 | 2054 | status(q.series.index(q.lookup(patch))) |
|
2055 | 2055 | |
|
2056 | 2056 | def header(ui, repo, patch=None): |
|
2057 | 2057 | """print the header of the topmost or specified patch""" |
|
2058 | 2058 | q = repo.mq |
|
2059 | 2059 | |
|
2060 | 2060 | if patch: |
|
2061 | 2061 | patch = q.lookup(patch) |
|
2062 | 2062 | else: |
|
2063 | 2063 | if not q.applied: |
|
2064 | 2064 | ui.write('no patches applied\n') |
|
2065 | 2065 | return 1 |
|
2066 | 2066 | patch = q.lookup('qtip') |
|
2067 | 2067 | ph = patchheader(repo.mq.join(patch)) |
|
2068 | 2068 | |
|
2069 | 2069 | ui.write('\n'.join(ph.message) + '\n') |
|
2070 | 2070 | |
|
2071 | 2071 | def lastsavename(path): |
|
2072 | 2072 | (directory, base) = os.path.split(path) |
|
2073 | 2073 | names = os.listdir(directory) |
|
2074 | 2074 | namere = re.compile("%s.([0-9]+)" % base) |
|
2075 | 2075 | maxindex = None |
|
2076 | 2076 | maxname = None |
|
2077 | 2077 | for f in names: |
|
2078 | 2078 | m = namere.match(f) |
|
2079 | 2079 | if m: |
|
2080 | 2080 | index = int(m.group(1)) |
|
2081 | 2081 | if maxindex is None or index > maxindex: |
|
2082 | 2082 | maxindex = index |
|
2083 | 2083 | maxname = f |
|
2084 | 2084 | if maxname: |
|
2085 | 2085 | return (os.path.join(directory, maxname), maxindex) |
|
2086 | 2086 | return (None, None) |
|
2087 | 2087 | |
|
2088 | 2088 | def savename(path): |
|
2089 | 2089 | (last, index) = lastsavename(path) |
|
2090 | 2090 | if last is None: |
|
2091 | 2091 | index = 0 |
|
2092 | 2092 | newpath = path + ".%d" % (index + 1) |
|
2093 | 2093 | return newpath |
|
2094 | 2094 | |
|
2095 | 2095 | def push(ui, repo, patch=None, **opts): |
|
2096 | 2096 | """push the next patch onto the stack |
|
2097 | 2097 | |
|
2098 | 2098 | When -f/--force is applied, all local changes in patched files will be |
|
2099 | 2099 | lost. |
|
2100 | 2100 | """ |
|
2101 | 2101 | q = repo.mq |
|
2102 | 2102 | mergeq = None |
|
2103 | 2103 | |
|
2104 | 2104 | if opts['merge']: |
|
2105 | 2105 | if opts['name']: |
|
2106 | 2106 | newpath = repo.join(opts['name']) |
|
2107 | 2107 | else: |
|
2108 | 2108 | newpath, i = lastsavename(q.path) |
|
2109 | 2109 | if not newpath: |
|
2110 | 2110 | ui.warn(_("no saved queues found, please use -n\n")) |
|
2111 | 2111 | return 1 |
|
2112 | 2112 | mergeq = queue(ui, repo.join(""), newpath) |
|
2113 | 2113 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) |
|
2114 | 2114 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
2115 | 2115 | mergeq=mergeq, all=opts.get('all')) |
|
2116 | 2116 | return ret |
|
2117 | 2117 | |
|
2118 | 2118 | def pop(ui, repo, patch=None, **opts): |
|
2119 | 2119 | """pop the current patch off the stack |
|
2120 | 2120 | |
|
2121 | 2121 | By default, pops off the top of the patch stack. If given a patch name, |
|
2122 | 2122 | keeps popping off patches until the named patch is at the top of the |
|
2123 | 2123 | stack. |
|
2124 | 2124 | """ |
|
2125 | 2125 | localupdate = True |
|
2126 | 2126 | if opts['name']: |
|
2127 | 2127 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
2128 | 2128 | ui.warn(_('using patch queue: %s\n') % q.path) |
|
2129 | 2129 | localupdate = False |
|
2130 | 2130 | else: |
|
2131 | 2131 | q = repo.mq |
|
2132 | 2132 | ret = q.pop(repo, patch, force=opts['force'], update=localupdate, |
|
2133 | 2133 | all=opts['all']) |
|
2134 | 2134 | q.save_dirty() |
|
2135 | 2135 | return ret |
|
2136 | 2136 | |
|
2137 | 2137 | def rename(ui, repo, patch, name=None, **opts): |
|
2138 | 2138 | """rename a patch |
|
2139 | 2139 | |
|
2140 | 2140 | With one argument, renames the current patch to PATCH1. |
|
2141 | 2141 | With two arguments, renames PATCH1 to PATCH2.""" |
|
2142 | 2142 | |
|
2143 | 2143 | q = repo.mq |
|
2144 | 2144 | |
|
2145 | 2145 | if not name: |
|
2146 | 2146 | name = patch |
|
2147 | 2147 | patch = None |
|
2148 | 2148 | |
|
2149 | 2149 | if patch: |
|
2150 | 2150 | patch = q.lookup(patch) |
|
2151 | 2151 | else: |
|
2152 | 2152 | if not q.applied: |
|
2153 | 2153 | ui.write(_('no patches applied\n')) |
|
2154 | 2154 | return |
|
2155 | 2155 | patch = q.lookup('qtip') |
|
2156 | 2156 | absdest = q.join(name) |
|
2157 | 2157 | if os.path.isdir(absdest): |
|
2158 | 2158 | name = normname(os.path.join(name, os.path.basename(patch))) |
|
2159 | 2159 | absdest = q.join(name) |
|
2160 | 2160 | if os.path.exists(absdest): |
|
2161 | 2161 | raise util.Abort(_('%s already exists') % absdest) |
|
2162 | 2162 | |
|
2163 | 2163 | if name in q.series: |
|
2164 | 2164 | raise util.Abort(_('A patch named %s already exists in the series file') % name) |
|
2165 | 2165 | |
|
2166 | 2166 | if ui.verbose: |
|
2167 | 2167 | ui.write('renaming %s to %s\n' % (patch, name)) |
|
2168 | 2168 | i = q.find_series(patch) |
|
2169 | 2169 | guards = q.guard_re.findall(q.full_series[i]) |
|
2170 | 2170 | q.full_series[i] = name + ''.join([' #' + g for g in guards]) |
|
2171 | 2171 | q.parse_series() |
|
2172 | 2172 | q.series_dirty = 1 |
|
2173 | 2173 | |
|
2174 | 2174 | info = q.isapplied(patch) |
|
2175 | 2175 | if info: |
|
2176 | 2176 | q.applied[info[0]] = statusentry(info[1], name) |
|
2177 | 2177 | q.applied_dirty = 1 |
|
2178 | 2178 | |
|
2179 | 2179 | util.rename(q.join(patch), absdest) |
|
2180 | 2180 | r = q.qrepo() |
|
2181 | 2181 | if r: |
|
2182 | 2182 | wlock = r.wlock() |
|
2183 | 2183 | try: |
|
2184 | 2184 | if r.dirstate[patch] == 'a': |
|
2185 | 2185 | r.dirstate.forget(patch) |
|
2186 | 2186 | r.dirstate.add(name) |
|
2187 | 2187 | else: |
|
2188 | 2188 | if r.dirstate[name] == 'r': |
|
2189 | 2189 | r.undelete([name]) |
|
2190 | 2190 | r.copy(patch, name) |
|
2191 | 2191 | r.remove([patch], False) |
|
2192 | 2192 | finally: |
|
2193 | 2193 | wlock.release() |
|
2194 | 2194 | |
|
2195 | 2195 | q.save_dirty() |
|
2196 | 2196 | |
|
2197 | 2197 | def restore(ui, repo, rev, **opts): |
|
2198 | 2198 | """restore the queue state saved by a revision""" |
|
2199 | 2199 | rev = repo.lookup(rev) |
|
2200 | 2200 | q = repo.mq |
|
2201 | 2201 | q.restore(repo, rev, delete=opts['delete'], |
|
2202 | 2202 | qupdate=opts['update']) |
|
2203 | 2203 | q.save_dirty() |
|
2204 | 2204 | return 0 |
|
2205 | 2205 | |
|
2206 | 2206 | def save(ui, repo, **opts): |
|
2207 | 2207 | """save current queue state""" |
|
2208 | 2208 | q = repo.mq |
|
2209 | 2209 | message = cmdutil.logmessage(opts) |
|
2210 | 2210 | ret = q.save(repo, msg=message) |
|
2211 | 2211 | if ret: |
|
2212 | 2212 | return ret |
|
2213 | 2213 | q.save_dirty() |
|
2214 | 2214 | if opts['copy']: |
|
2215 | 2215 | path = q.path |
|
2216 | 2216 | if opts['name']: |
|
2217 | 2217 | newpath = os.path.join(q.basepath, opts['name']) |
|
2218 | 2218 | if os.path.exists(newpath): |
|
2219 | 2219 | if not os.path.isdir(newpath): |
|
2220 | 2220 | raise util.Abort(_('destination %s exists and is not ' |
|
2221 | 2221 | 'a directory') % newpath) |
|
2222 | 2222 | if not opts['force']: |
|
2223 | 2223 | raise util.Abort(_('destination %s exists, ' |
|
2224 | 2224 | 'use -f to force') % newpath) |
|
2225 | 2225 | else: |
|
2226 | 2226 | newpath = savename(path) |
|
2227 | 2227 | ui.warn(_("copy %s to %s\n") % (path, newpath)) |
|
2228 | 2228 | util.copyfiles(path, newpath) |
|
2229 | 2229 | if opts['empty']: |
|
2230 | 2230 | try: |
|
2231 | 2231 | os.unlink(q.join(q.status_path)) |
|
2232 | 2232 | except: |
|
2233 | 2233 | pass |
|
2234 | 2234 | return 0 |
|
2235 | 2235 | |
|
2236 | 2236 | def strip(ui, repo, rev, **opts): |
|
2237 | 2237 | """strip a revision and all its descendants from the repository |
|
2238 | 2238 | |
|
2239 | 2239 | If one of the working directory's parent revisions is stripped, the |
|
2240 | 2240 | working directory will be updated to the parent of the stripped revision. |
|
2241 | 2241 | """ |
|
2242 | 2242 | backup = 'all' |
|
2243 | 2243 | if opts['backup']: |
|
2244 | 2244 | backup = 'strip' |
|
2245 | 2245 | elif opts['nobackup']: |
|
2246 | 2246 | backup = 'none' |
|
2247 | 2247 | |
|
2248 | 2248 | rev = repo.lookup(rev) |
|
2249 | 2249 | p = repo.dirstate.parents() |
|
2250 | 2250 | cl = repo.changelog |
|
2251 | 2251 | update = True |
|
2252 | 2252 | if p[0] == nullid: |
|
2253 | 2253 | update = False |
|
2254 | 2254 | elif p[1] == nullid and rev != cl.ancestor(p[0], rev): |
|
2255 | 2255 | update = False |
|
2256 | 2256 | elif rev not in (cl.ancestor(p[0], rev), cl.ancestor(p[1], rev)): |
|
2257 | 2257 | update = False |
|
2258 | 2258 | |
|
2259 | 2259 | repo.mq.strip(repo, rev, backup=backup, update=update, force=opts['force']) |
|
2260 | 2260 | return 0 |
|
2261 | 2261 | |
|
2262 | 2262 | def select(ui, repo, *args, **opts): |
|
2263 | 2263 | '''set or print guarded patches to push |
|
2264 | 2264 | |
|
2265 | 2265 | Use the qguard command to set or print guards on patch, then use qselect |
|
2266 | 2266 | to tell mq which guards to use. A patch will be pushed if it has no guards |
|
2267 | 2267 | or any positive guards match the currently selected guard, but will not be |
|
2268 | 2268 | pushed if any negative guards match the current guard. For example: |
|
2269 | 2269 | |
|
2270 | 2270 | qguard foo.patch -stable (negative guard) |
|
2271 | 2271 | qguard bar.patch +stable (positive guard) |
|
2272 | 2272 | qselect stable |
|
2273 | 2273 | |
|
2274 | 2274 | This activates the "stable" guard. mq will skip foo.patch (because it has |
|
2275 | 2275 | a negative match) but push bar.patch (because it has a positive match). |
|
2276 | 2276 | |
|
2277 | 2277 | With no arguments, prints the currently active guards. With one argument, |
|
2278 | 2278 | sets the active guard. |
|
2279 | 2279 | |
|
2280 | 2280 | Use -n/--none to deactivate guards (no other arguments needed). When no |
|
2281 | 2281 | guards are active, patches with positive guards are skipped and patches |
|
2282 | 2282 | with negative guards are pushed. |
|
2283 | 2283 | |
|
2284 | 2284 | qselect can change the guards on applied patches. It does not pop guarded |
|
2285 | 2285 | patches by default. Use --pop to pop back to the last applied patch that |
|
2286 | 2286 | is not guarded. Use --reapply (which implies --pop) to push back to the |
|
2287 | 2287 | current patch afterwards, but skip guarded patches. |
|
2288 | 2288 | |
|
2289 | 2289 | Use -s/--series to print a list of all guards in the series file (no other |
|
2290 | 2290 | arguments needed). Use -v for more information. |
|
2291 | 2291 | ''' |
|
2292 | 2292 | |
|
2293 | 2293 | q = repo.mq |
|
2294 | 2294 | guards = q.active() |
|
2295 | 2295 | if args or opts['none']: |
|
2296 | 2296 | old_unapplied = q.unapplied(repo) |
|
2297 | 2297 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
2298 | 2298 | not q.pushable(i)[0]] |
|
2299 | 2299 | q.set_active(args) |
|
2300 | 2300 | q.save_dirty() |
|
2301 | 2301 | if not args: |
|
2302 | 2302 | ui.status(_('guards deactivated\n')) |
|
2303 | 2303 | if not opts['pop'] and not opts['reapply']: |
|
2304 | 2304 | unapplied = q.unapplied(repo) |
|
2305 | 2305 | guarded = [i for i in xrange(len(q.applied)) |
|
2306 | 2306 | if not q.pushable(i)[0]] |
|
2307 | 2307 | if len(unapplied) != len(old_unapplied): |
|
2308 | 2308 | ui.status(_('number of unguarded, unapplied patches has ' |
|
2309 | 2309 | 'changed from %d to %d\n') % |
|
2310 | 2310 | (len(old_unapplied), len(unapplied))) |
|
2311 | 2311 | if len(guarded) != len(old_guarded): |
|
2312 | 2312 | ui.status(_('number of guarded, applied patches has changed ' |
|
2313 | 2313 | 'from %d to %d\n') % |
|
2314 | 2314 | (len(old_guarded), len(guarded))) |
|
2315 | 2315 | elif opts['series']: |
|
2316 | 2316 | guards = {} |
|
2317 | 2317 | noguards = 0 |
|
2318 | 2318 | for gs in q.series_guards: |
|
2319 | 2319 | if not gs: |
|
2320 | 2320 | noguards += 1 |
|
2321 | 2321 | for g in gs: |
|
2322 | 2322 | guards.setdefault(g, 0) |
|
2323 | 2323 | guards[g] += 1 |
|
2324 | 2324 | if ui.verbose: |
|
2325 | 2325 | guards['NONE'] = noguards |
|
2326 | 2326 | guards = guards.items() |
|
2327 | 2327 | guards.sort(key=lambda x: x[0][1:]) |
|
2328 | 2328 | if guards: |
|
2329 | 2329 | ui.note(_('guards in series file:\n')) |
|
2330 | 2330 | for guard, count in guards: |
|
2331 | 2331 | ui.note('%2d ' % count) |
|
2332 | 2332 | ui.write(guard, '\n') |
|
2333 | 2333 | else: |
|
2334 | 2334 | ui.note(_('no guards in series file\n')) |
|
2335 | 2335 | else: |
|
2336 | 2336 | if guards: |
|
2337 | 2337 | ui.note(_('active guards:\n')) |
|
2338 | 2338 | for g in guards: |
|
2339 | 2339 | ui.write(g, '\n') |
|
2340 | 2340 | else: |
|
2341 | 2341 | ui.write(_('no active guards\n')) |
|
2342 | 2342 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) |
|
2343 | 2343 | popped = False |
|
2344 | 2344 | if opts['pop'] or opts['reapply']: |
|
2345 | 2345 | for i in xrange(len(q.applied)): |
|
2346 | 2346 | pushable, reason = q.pushable(i) |
|
2347 | 2347 | if not pushable: |
|
2348 | 2348 | ui.status(_('popping guarded patches\n')) |
|
2349 | 2349 | popped = True |
|
2350 | 2350 | if i == 0: |
|
2351 | 2351 | q.pop(repo, all=True) |
|
2352 | 2352 | else: |
|
2353 | 2353 | q.pop(repo, i-1) |
|
2354 | 2354 | break |
|
2355 | 2355 | if popped: |
|
2356 | 2356 | try: |
|
2357 | 2357 | if reapply: |
|
2358 | 2358 | ui.status(_('reapplying unguarded patches\n')) |
|
2359 | 2359 | q.push(repo, reapply) |
|
2360 | 2360 | finally: |
|
2361 | 2361 | q.save_dirty() |
|
2362 | 2362 | |
|
2363 | 2363 | def finish(ui, repo, *revrange, **opts): |
|
2364 | 2364 | """move applied patches into repository history |
|
2365 | 2365 | |
|
2366 | 2366 | Finishes the specified revisions (corresponding to applied patches) by |
|
2367 | 2367 | moving them out of mq control into regular repository history. |
|
2368 | 2368 | |
|
2369 | 2369 | Accepts a revision range or the -a/--applied option. If --applied is |
|
2370 | 2370 | specified, all applied mq revisions are removed from mq control. |
|
2371 | 2371 | Otherwise, the given revisions must be at the base of the stack of applied |
|
2372 | 2372 | patches. |
|
2373 | 2373 | |
|
2374 | 2374 | This can be especially useful if your changes have been applied to an |
|
2375 | 2375 | upstream repository, or if you are about to push your changes to upstream. |
|
2376 | 2376 | """ |
|
2377 | 2377 | if not opts['applied'] and not revrange: |
|
2378 | 2378 | raise util.Abort(_('no revisions specified')) |
|
2379 | 2379 | elif opts['applied']: |
|
2380 | 2380 | revrange = ('qbase:qtip',) + revrange |
|
2381 | 2381 | |
|
2382 | 2382 | q = repo.mq |
|
2383 | 2383 | if not q.applied: |
|
2384 | 2384 | ui.status(_('no patches applied\n')) |
|
2385 | 2385 | return 0 |
|
2386 | 2386 | |
|
2387 | 2387 | revs = cmdutil.revrange(repo, revrange) |
|
2388 | 2388 | q.finish(repo, revs) |
|
2389 | 2389 | q.save_dirty() |
|
2390 | 2390 | return 0 |
|
2391 | 2391 | |
|
2392 | 2392 | def reposetup(ui, repo): |
|
2393 | 2393 | class mqrepo(repo.__class__): |
|
2394 | 2394 | @util.propertycache |
|
2395 | 2395 | def mq(self): |
|
2396 | 2396 | return queue(self.ui, self.join("")) |
|
2397 | 2397 | |
|
2398 | 2398 | def abort_if_wdir_patched(self, errmsg, force=False): |
|
2399 | 2399 | if self.mq.applied and not force: |
|
2400 | 2400 | parent = hex(self.dirstate.parents()[0]) |
|
2401 | 2401 | if parent in [s.rev for s in self.mq.applied]: |
|
2402 | 2402 | raise util.Abort(errmsg) |
|
2403 | 2403 | |
|
2404 | 2404 | def commit(self, text="", user=None, date=None, match=None, |
|
2405 | 2405 | force=False, editor=False, extra={}): |
|
2406 | 2406 | self.abort_if_wdir_patched( |
|
2407 | 2407 | _('cannot commit over an applied mq patch'), |
|
2408 | 2408 | force) |
|
2409 | 2409 | |
|
2410 | 2410 | return super(mqrepo, self).commit(text, user, date, match, force, |
|
2411 | 2411 | editor, extra) |
|
2412 | 2412 | |
|
2413 | 2413 | def push(self, remote, force=False, revs=None): |
|
2414 | 2414 | if self.mq.applied and not force and not revs: |
|
2415 | 2415 | raise util.Abort(_('source has mq patches applied')) |
|
2416 | 2416 | return super(mqrepo, self).push(remote, force, revs) |
|
2417 | 2417 | |
|
2418 | 2418 | def tags(self): |
|
2419 | 2419 | if self.tagscache: |
|
2420 | 2420 | return self.tagscache |
|
2421 | 2421 | |
|
2422 | 2422 | tagscache = super(mqrepo, self).tags() |
|
2423 | 2423 | |
|
2424 | 2424 | q = self.mq |
|
2425 | 2425 | if not q.applied: |
|
2426 | 2426 | return tagscache |
|
2427 | 2427 | |
|
2428 | 2428 | mqtags = [(bin(patch.rev), patch.name) for patch in q.applied] |
|
2429 | 2429 | |
|
2430 | 2430 | if mqtags[-1][0] not in self.changelog.nodemap: |
|
2431 | 2431 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
2432 | 2432 | % short(mqtags[-1][0])) |
|
2433 | 2433 | return tagscache |
|
2434 | 2434 | |
|
2435 | 2435 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
2436 | 2436 | mqtags.append((mqtags[0][0], 'qbase')) |
|
2437 | 2437 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) |
|
2438 | 2438 | for patch in mqtags: |
|
2439 | 2439 | if patch[1] in tagscache: |
|
2440 | 2440 | self.ui.warn(_('Tag %s overrides mq patch of the same name\n') |
|
2441 | 2441 | % patch[1]) |
|
2442 | 2442 | else: |
|
2443 | 2443 | tagscache[patch[1]] = patch[0] |
|
2444 | 2444 | |
|
2445 | 2445 | return tagscache |
|
2446 | 2446 | |
|
2447 | 2447 | def _branchtags(self, partial, lrev): |
|
2448 | 2448 | q = self.mq |
|
2449 | 2449 | if not q.applied: |
|
2450 | 2450 | return super(mqrepo, self)._branchtags(partial, lrev) |
|
2451 | 2451 | |
|
2452 | 2452 | cl = self.changelog |
|
2453 | 2453 | qbasenode = bin(q.applied[0].rev) |
|
2454 | 2454 | if qbasenode not in cl.nodemap: |
|
2455 | 2455 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
2456 | 2456 | % short(qbasenode)) |
|
2457 | 2457 | return super(mqrepo, self)._branchtags(partial, lrev) |
|
2458 | 2458 | |
|
2459 | 2459 | qbase = cl.rev(qbasenode) |
|
2460 | 2460 | start = lrev + 1 |
|
2461 | 2461 | if start < qbase: |
|
2462 | 2462 | # update the cache (excluding the patches) and save it |
|
2463 | 2463 | self._updatebranchcache(partial, lrev+1, qbase) |
|
2464 | 2464 | self._writebranchcache(partial, cl.node(qbase-1), qbase-1) |
|
2465 | 2465 | start = qbase |
|
2466 | 2466 | # if start = qbase, the cache is as updated as it should be. |
|
2467 | 2467 | # if start > qbase, the cache includes (part of) the patches. |
|
2468 | 2468 | # we might as well use it, but we won't save it. |
|
2469 | 2469 | |
|
2470 | 2470 | # update the cache up to the tip |
|
2471 | 2471 | self._updatebranchcache(partial, start, len(cl)) |
|
2472 | 2472 | |
|
2473 | 2473 | return partial |
|
2474 | 2474 | |
|
2475 | 2475 | if repo.local(): |
|
2476 | 2476 | repo.__class__ = mqrepo |
|
2477 | 2477 | |
|
2478 | 2478 | def mqimport(orig, ui, repo, *args, **kwargs): |
|
2479 | 2479 | if hasattr(repo, 'abort_if_wdir_patched'): |
|
2480 | 2480 | repo.abort_if_wdir_patched(_('cannot import over an applied patch'), |
|
2481 | 2481 | kwargs.get('force')) |
|
2482 | 2482 | return orig(ui, repo, *args, **kwargs) |
|
2483 | 2483 | |
|
2484 | 2484 | def uisetup(ui): |
|
2485 | 2485 | extensions.wrapcommand(commands.table, 'import', mqimport) |
|
2486 | 2486 | |
|
2487 | 2487 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] |
|
2488 | 2488 | |
|
2489 | 2489 | cmdtable = { |
|
2490 | 2490 | "qapplied": (applied, [] + seriesopts, _('hg qapplied [-s] [PATCH]')), |
|
2491 | 2491 | "qclone": |
|
2492 | 2492 | (clone, |
|
2493 | 2493 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2494 | 2494 | ('U', 'noupdate', None, _('do not update the new working directories')), |
|
2495 | 2495 | ('', 'uncompressed', None, |
|
2496 | 2496 | _('use uncompressed transfer (fast over LAN)')), |
|
2497 | 2497 | ('p', 'patches', '', _('location of source patch repository')), |
|
2498 | 2498 | ] + commands.remoteopts, |
|
2499 | 2499 | _('hg qclone [OPTION]... SOURCE [DEST]')), |
|
2500 | 2500 | "qcommit|qci": |
|
2501 | 2501 | (commit, |
|
2502 | 2502 | commands.table["^commit|ci"][1], |
|
2503 | 2503 | _('hg qcommit [OPTION]... [FILE]...')), |
|
2504 | 2504 | "^qdiff": |
|
2505 | 2505 | (diff, |
|
2506 | 2506 | commands.diffopts + commands.diffopts2 + commands.walkopts, |
|
2507 | 2507 | _('hg qdiff [OPTION]... [FILE]...')), |
|
2508 | 2508 | "qdelete|qremove|qrm": |
|
2509 | 2509 | (delete, |
|
2510 | 2510 | [('k', 'keep', None, _('keep patch file')), |
|
2511 | 2511 | ('r', 'rev', [], _('stop managing a revision (DEPRECATED)'))], |
|
2512 | 2512 | _('hg qdelete [-k] [-r REV]... [PATCH]...')), |
|
2513 | 2513 | 'qfold': |
|
2514 | 2514 | (fold, |
|
2515 | 2515 | [('e', 'edit', None, _('edit patch header')), |
|
2516 | 2516 | ('k', 'keep', None, _('keep folded patch files')), |
|
2517 | 2517 | ] + commands.commitopts, |
|
2518 | 2518 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...')), |
|
2519 | 2519 | 'qgoto': |
|
2520 | 2520 | (goto, |
|
2521 | 2521 | [('f', 'force', None, _('overwrite any local changes'))], |
|
2522 | 2522 | _('hg qgoto [OPTION]... PATCH')), |
|
2523 | 2523 | 'qguard': |
|
2524 | 2524 | (guard, |
|
2525 | 2525 | [('l', 'list', None, _('list all patches and guards')), |
|
2526 | 2526 | ('n', 'none', None, _('drop all guards'))], |
|
2527 | 2527 | _('hg qguard [-l] [-n] -- [PATCH] [+GUARD]... [-GUARD]...')), |
|
2528 | 2528 | 'qheader': (header, [], _('hg qheader [PATCH]')), |
|
2529 | 2529 | "^qimport": |
|
2530 | 2530 | (qimport, |
|
2531 | 2531 | [('e', 'existing', None, _('import file in patch directory')), |
|
2532 | 2532 | ('n', 'name', '', _('name of patch file')), |
|
2533 | 2533 | ('f', 'force', None, _('overwrite existing files')), |
|
2534 | 2534 | ('r', 'rev', [], _('place existing revisions under mq control')), |
|
2535 | 2535 | ('g', 'git', None, _('use git extended diff format')), |
|
2536 | 2536 | ('P', 'push', None, _('qpush after importing'))], |
|
2537 | 2537 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-P] [-r REV]... FILE...')), |
|
2538 | 2538 | "^qinit": |
|
2539 | 2539 | (init, |
|
2540 | 2540 | [('c', 'create-repo', None, _('create queue repository'))], |
|
2541 | 2541 | _('hg qinit [-c]')), |
|
2542 | 2542 | "qnew": |
|
2543 | 2543 | (new, |
|
2544 | 2544 | [('e', 'edit', None, _('edit commit message')), |
|
2545 | 2545 | ('f', 'force', None, _('import uncommitted changes into patch')), |
|
2546 | 2546 | ('g', 'git', None, _('use git extended diff format')), |
|
2547 | 2547 | ('U', 'currentuser', None, _('add "From: <current user>" to patch')), |
|
2548 | 2548 | ('u', 'user', '', _('add "From: <given user>" to patch')), |
|
2549 | 2549 | ('D', 'currentdate', None, _('add "Date: <current date>" to patch')), |
|
2550 | 2550 | ('d', 'date', '', _('add "Date: <given date>" to patch')) |
|
2551 | 2551 | ] + commands.walkopts + commands.commitopts, |
|
2552 | 2552 | _('hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH [FILE]...')), |
|
2553 | 2553 | "qnext": (next, [] + seriesopts, _('hg qnext [-s]')), |
|
2554 | 2554 | "qprev": (prev, [] + seriesopts, _('hg qprev [-s]')), |
|
2555 | 2555 | "^qpop": |
|
2556 | 2556 | (pop, |
|
2557 | 2557 | [('a', 'all', None, _('pop all patches')), |
|
2558 | 2558 | ('n', 'name', '', _('queue name to pop')), |
|
2559 | 2559 | ('f', 'force', None, _('forget any local changes'))], |
|
2560 | 2560 | _('hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]')), |
|
2561 | 2561 | "^qpush": |
|
2562 | 2562 | (push, |
|
2563 | 2563 | [('f', 'force', None, _('apply if the patch has rejects')), |
|
2564 | 2564 | ('l', 'list', None, _('list patch name in commit text')), |
|
2565 | 2565 | ('a', 'all', None, _('apply all patches')), |
|
2566 | 2566 | ('m', 'merge', None, _('merge from another queue')), |
|
2567 | 2567 | ('n', 'name', '', _('merge queue name'))], |
|
2568 | 2568 | _('hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]')), |
|
2569 | 2569 | "^qrefresh": |
|
2570 | 2570 | (refresh, |
|
2571 | 2571 | [('e', 'edit', None, _('edit commit message')), |
|
2572 | 2572 | ('g', 'git', None, _('use git extended diff format')), |
|
2573 | 2573 | ('s', 'short', None, _('refresh only files already in the patch and specified files')), |
|
2574 | 2574 | ('U', 'currentuser', None, _('add/update "From: <current user>" in patch')), |
|
2575 | 2575 | ('u', 'user', '', _('add/update "From: <given user>" in patch')), |
|
2576 | 2576 | ('D', 'currentdate', None, _('update "Date: <current date>" in patch (if present)')), |
|
2577 | 2577 | ('d', 'date', '', _('update "Date: <given date>" in patch (if present)')) |
|
2578 | 2578 | ] + commands.walkopts + commands.commitopts, |
|
2579 | 2579 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')), |
|
2580 | 2580 | 'qrename|qmv': |
|
2581 | 2581 | (rename, [], _('hg qrename PATCH1 [PATCH2]')), |
|
2582 | 2582 | "qrestore": |
|
2583 | 2583 | (restore, |
|
2584 | 2584 | [('d', 'delete', None, _('delete save entry')), |
|
2585 | 2585 | ('u', 'update', None, _('update queue working directory'))], |
|
2586 | 2586 | _('hg qrestore [-d] [-u] REV')), |
|
2587 | 2587 | "qsave": |
|
2588 | 2588 | (save, |
|
2589 | 2589 | [('c', 'copy', None, _('copy patch directory')), |
|
2590 | 2590 | ('n', 'name', '', _('copy directory name')), |
|
2591 | 2591 | ('e', 'empty', None, _('clear queue status file')), |
|
2592 | 2592 | ('f', 'force', None, _('force copy'))] + commands.commitopts, |
|
2593 | 2593 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]')), |
|
2594 | 2594 | "qselect": |
|
2595 | 2595 | (select, |
|
2596 | 2596 | [('n', 'none', None, _('disable all guards')), |
|
2597 | 2597 | ('s', 'series', None, _('list all guards in series file')), |
|
2598 | 2598 | ('', 'pop', None, _('pop to before first guarded applied patch')), |
|
2599 | 2599 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
2600 | 2600 | _('hg qselect [OPTION]... [GUARD]...')), |
|
2601 | 2601 | "qseries": |
|
2602 | 2602 | (series, |
|
2603 | 2603 | [('m', 'missing', None, _('print patches not in series')), |
|
2604 | 2604 | ] + seriesopts, |
|
2605 | 2605 | _('hg qseries [-ms]')), |
|
2606 | 2606 | "^strip": |
|
2607 | 2607 | (strip, |
|
2608 | 2608 | [('f', 'force', None, _('force removal with local changes')), |
|
2609 | 2609 | ('b', 'backup', None, _('bundle unrelated changesets')), |
|
2610 | 2610 | ('n', 'nobackup', None, _('no backups'))], |
|
2611 | 2611 | _('hg strip [-f] [-b] [-n] REV')), |
|
2612 | 2612 | "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), |
|
2613 | 2613 | "qunapplied": (unapplied, [] + seriesopts, _('hg qunapplied [-s] [PATCH]')), |
|
2614 | 2614 | "qfinish": |
|
2615 | 2615 | (finish, |
|
2616 | 2616 | [('a', 'applied', None, _('finish all applied changesets'))], |
|
2617 | 2617 | _('hg qfinish [-a] [REV]...')), |
|
2618 | 2618 | } |
@@ -1,289 +1,291 b'' | |||
|
1 | 1 | # notify.py - email notifications for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''hooks for sending email notifications at commit/push time |
|
9 | 9 | |
|
10 | 10 | Subscriptions can be managed through a hgrc file. Default mode is to print |
|
11 | 11 | messages to stdout, for testing and configuring. |
|
12 | 12 | |
|
13 | To use, configure the notify extension and enable it in hgrc like this: | |
|
13 | To use, configure the notify extension and enable it in hgrc like this:: | |
|
14 | 14 | |
|
15 | 15 | [extensions] |
|
16 | 16 | hgext.notify = |
|
17 | 17 | |
|
18 | 18 | [hooks] |
|
19 | 19 | # one email for each incoming changeset |
|
20 | 20 | incoming.notify = python:hgext.notify.hook |
|
21 | 21 | # batch emails when many changesets incoming at one time |
|
22 | 22 | changegroup.notify = python:hgext.notify.hook |
|
23 | 23 | |
|
24 | 24 | [notify] |
|
25 | 25 | # config items go here |
|
26 | 26 | |
|
27 | Required configuration items: | |
|
27 | Required configuration items:: | |
|
28 | 28 | |
|
29 | 29 | config = /path/to/file # file containing subscriptions |
|
30 | 30 | |
|
31 | Optional configuration items: | |
|
31 | Optional configuration items:: | |
|
32 | 32 | |
|
33 | 33 | test = True # print messages to stdout for testing |
|
34 | 34 | strip = 3 # number of slashes to strip for url paths |
|
35 | 35 | domain = example.com # domain to use if committer missing domain |
|
36 | 36 | style = ... # style file to use when formatting email |
|
37 | 37 | template = ... # template to use when formatting email |
|
38 | 38 | incoming = ... # template to use when run as incoming hook |
|
39 | 39 | changegroup = ... # template when run as changegroup hook |
|
40 | 40 | maxdiff = 300 # max lines of diffs to include (0=none, -1=all) |
|
41 | 41 | maxsubject = 67 # truncate subject line longer than this |
|
42 | 42 | diffstat = True # add a diffstat before the diff content |
|
43 | 43 | sources = serve # notify if source of incoming changes in this list |
|
44 | 44 | # (serve == ssh or http, push, pull, bundle) |
|
45 | 45 | [email] |
|
46 | 46 | from = user@host.com # email address to send as if none given |
|
47 | 47 | [web] |
|
48 | 48 | baseurl = http://hgserver/... # root of hg web site for browsing commits |
|
49 | 49 | |
|
50 | 50 | The notify config file has same format as a regular hgrc file. It has two |
|
51 | 51 | sections so you can express subscriptions in whatever way is handier for you. |
|
52 | 52 | |
|
53 | :: | |
|
54 | ||
|
53 | 55 | [usersubs] |
|
54 | 56 | # key is subscriber email, value is ","-separated list of glob patterns |
|
55 | 57 | user@host = pattern |
|
56 | 58 | |
|
57 | 59 | [reposubs] |
|
58 | 60 | # key is glob pattern, value is ","-separated list of subscriber emails |
|
59 | 61 | pattern = user@host |
|
60 | 62 | |
|
61 | 63 | Glob patterns are matched against path to repository root. |
|
62 | 64 | |
|
63 | 65 | If you like, you can put notify config file in repository that users can push |
|
64 | 66 | changes to, they can manage their own subscriptions. |
|
65 | 67 | ''' |
|
66 | 68 | |
|
67 | 69 | from mercurial.i18n import _ |
|
68 | 70 | from mercurial import patch, cmdutil, templater, util, mail |
|
69 | 71 | import email.Parser, fnmatch, socket, time |
|
70 | 72 | |
|
71 | 73 | # template for single changeset can include email headers. |
|
72 | 74 | single_template = ''' |
|
73 | 75 | Subject: changeset in {webroot}: {desc|firstline|strip} |
|
74 | 76 | From: {author} |
|
75 | 77 | |
|
76 | 78 | changeset {node|short} in {root} |
|
77 | 79 | details: {baseurl}{webroot}?cmd=changeset;node={node|short} |
|
78 | 80 | description: |
|
79 | 81 | \t{desc|tabindent|strip} |
|
80 | 82 | '''.lstrip() |
|
81 | 83 | |
|
82 | 84 | # template for multiple changesets should not contain email headers, |
|
83 | 85 | # because only first set of headers will be used and result will look |
|
84 | 86 | # strange. |
|
85 | 87 | multiple_template = ''' |
|
86 | 88 | changeset {node|short} in {root} |
|
87 | 89 | details: {baseurl}{webroot}?cmd=changeset;node={node|short} |
|
88 | 90 | summary: {desc|firstline} |
|
89 | 91 | ''' |
|
90 | 92 | |
|
91 | 93 | deftemplates = { |
|
92 | 94 | 'changegroup': multiple_template, |
|
93 | 95 | } |
|
94 | 96 | |
|
95 | 97 | class notifier(object): |
|
96 | 98 | '''email notification class.''' |
|
97 | 99 | |
|
98 | 100 | def __init__(self, ui, repo, hooktype): |
|
99 | 101 | self.ui = ui |
|
100 | 102 | cfg = self.ui.config('notify', 'config') |
|
101 | 103 | if cfg: |
|
102 | 104 | self.ui.readconfig(cfg, sections=['usersubs', 'reposubs']) |
|
103 | 105 | self.repo = repo |
|
104 | 106 | self.stripcount = int(self.ui.config('notify', 'strip', 0)) |
|
105 | 107 | self.root = self.strip(self.repo.root) |
|
106 | 108 | self.domain = self.ui.config('notify', 'domain') |
|
107 | 109 | self.test = self.ui.configbool('notify', 'test', True) |
|
108 | 110 | self.charsets = mail._charsets(self.ui) |
|
109 | 111 | self.subs = self.subscribers() |
|
110 | 112 | |
|
111 | 113 | mapfile = self.ui.config('notify', 'style') |
|
112 | 114 | template = (self.ui.config('notify', hooktype) or |
|
113 | 115 | self.ui.config('notify', 'template')) |
|
114 | 116 | self.t = cmdutil.changeset_templater(self.ui, self.repo, |
|
115 | 117 | False, None, mapfile, False) |
|
116 | 118 | if not mapfile and not template: |
|
117 | 119 | template = deftemplates.get(hooktype) or single_template |
|
118 | 120 | if template: |
|
119 | 121 | template = templater.parsestring(template, quoted=False) |
|
120 | 122 | self.t.use_template(template) |
|
121 | 123 | |
|
122 | 124 | def strip(self, path): |
|
123 | 125 | '''strip leading slashes from local path, turn into web-safe path.''' |
|
124 | 126 | |
|
125 | 127 | path = util.pconvert(path) |
|
126 | 128 | count = self.stripcount |
|
127 | 129 | while count > 0: |
|
128 | 130 | c = path.find('/') |
|
129 | 131 | if c == -1: |
|
130 | 132 | break |
|
131 | 133 | path = path[c+1:] |
|
132 | 134 | count -= 1 |
|
133 | 135 | return path |
|
134 | 136 | |
|
135 | 137 | def fixmail(self, addr): |
|
136 | 138 | '''try to clean up email addresses.''' |
|
137 | 139 | |
|
138 | 140 | addr = util.email(addr.strip()) |
|
139 | 141 | if self.domain: |
|
140 | 142 | a = addr.find('@localhost') |
|
141 | 143 | if a != -1: |
|
142 | 144 | addr = addr[:a] |
|
143 | 145 | if '@' not in addr: |
|
144 | 146 | return addr + '@' + self.domain |
|
145 | 147 | return addr |
|
146 | 148 | |
|
147 | 149 | def subscribers(self): |
|
148 | 150 | '''return list of email addresses of subscribers to this repo.''' |
|
149 | 151 | subs = set() |
|
150 | 152 | for user, pats in self.ui.configitems('usersubs'): |
|
151 | 153 | for pat in pats.split(','): |
|
152 | 154 | if fnmatch.fnmatch(self.repo.root, pat.strip()): |
|
153 | 155 | subs.add(self.fixmail(user)) |
|
154 | 156 | for pat, users in self.ui.configitems('reposubs'): |
|
155 | 157 | if fnmatch.fnmatch(self.repo.root, pat): |
|
156 | 158 | for user in users.split(','): |
|
157 | 159 | subs.add(self.fixmail(user)) |
|
158 | 160 | return [mail.addressencode(self.ui, s, self.charsets, self.test) |
|
159 | 161 | for s in sorted(subs)] |
|
160 | 162 | |
|
161 | 163 | def url(self, path=None): |
|
162 | 164 | return self.ui.config('web', 'baseurl') + (path or self.root) |
|
163 | 165 | |
|
164 | 166 | def node(self, ctx): |
|
165 | 167 | '''format one changeset.''' |
|
166 | 168 | self.t.show(ctx, changes=ctx.changeset(), |
|
167 | 169 | baseurl=self.ui.config('web', 'baseurl'), |
|
168 | 170 | root=self.repo.root, webroot=self.root) |
|
169 | 171 | |
|
170 | 172 | def skipsource(self, source): |
|
171 | 173 | '''true if incoming changes from this source should be skipped.''' |
|
172 | 174 | ok_sources = self.ui.config('notify', 'sources', 'serve').split() |
|
173 | 175 | return source not in ok_sources |
|
174 | 176 | |
|
175 | 177 | def send(self, ctx, count, data): |
|
176 | 178 | '''send message.''' |
|
177 | 179 | |
|
178 | 180 | p = email.Parser.Parser() |
|
179 | 181 | msg = p.parsestr(data) |
|
180 | 182 | |
|
181 | 183 | # store sender and subject |
|
182 | 184 | sender, subject = msg['From'], msg['Subject'] |
|
183 | 185 | del msg['From'], msg['Subject'] |
|
184 | 186 | # store remaining headers |
|
185 | 187 | headers = msg.items() |
|
186 | 188 | # create fresh mime message from msg body |
|
187 | 189 | text = msg.get_payload() |
|
188 | 190 | # for notification prefer readability over data precision |
|
189 | 191 | msg = mail.mimeencode(self.ui, text, self.charsets, self.test) |
|
190 | 192 | # reinstate custom headers |
|
191 | 193 | for k, v in headers: |
|
192 | 194 | msg[k] = v |
|
193 | 195 | |
|
194 | 196 | msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
|
195 | 197 | |
|
196 | 198 | # try to make subject line exist and be useful |
|
197 | 199 | if not subject: |
|
198 | 200 | if count > 1: |
|
199 | 201 | subject = _('%s: %d new changesets') % (self.root, count) |
|
200 | 202 | else: |
|
201 | 203 | s = ctx.description().lstrip().split('\n', 1)[0].rstrip() |
|
202 | 204 | subject = '%s: %s' % (self.root, s) |
|
203 | 205 | maxsubject = int(self.ui.config('notify', 'maxsubject', 67)) |
|
204 | 206 | if maxsubject and len(subject) > maxsubject: |
|
205 | 207 | subject = subject[:maxsubject-3] + '...' |
|
206 | 208 | msg['Subject'] = mail.headencode(self.ui, subject, |
|
207 | 209 | self.charsets, self.test) |
|
208 | 210 | |
|
209 | 211 | # try to make message have proper sender |
|
210 | 212 | if not sender: |
|
211 | 213 | sender = self.ui.config('email', 'from') or self.ui.username() |
|
212 | 214 | if '@' not in sender or '@localhost' in sender: |
|
213 | 215 | sender = self.fixmail(sender) |
|
214 | 216 | msg['From'] = mail.addressencode(self.ui, sender, |
|
215 | 217 | self.charsets, self.test) |
|
216 | 218 | |
|
217 | 219 | msg['X-Hg-Notification'] = 'changeset %s' % ctx |
|
218 | 220 | if not msg['Message-Id']: |
|
219 | 221 | msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' % |
|
220 | 222 | (ctx, int(time.time()), |
|
221 | 223 | hash(self.repo.root), socket.getfqdn())) |
|
222 | 224 | msg['To'] = ', '.join(self.subs) |
|
223 | 225 | |
|
224 | 226 | msgtext = msg.as_string() |
|
225 | 227 | if self.test: |
|
226 | 228 | self.ui.write(msgtext) |
|
227 | 229 | if not msgtext.endswith('\n'): |
|
228 | 230 | self.ui.write('\n') |
|
229 | 231 | else: |
|
230 | 232 | self.ui.status(_('notify: sending %d subscribers %d changes\n') % |
|
231 | 233 | (len(self.subs), count)) |
|
232 | 234 | mail.sendmail(self.ui, util.email(msg['From']), |
|
233 | 235 | self.subs, msgtext) |
|
234 | 236 | |
|
235 | 237 | def diff(self, ctx, ref=None): |
|
236 | 238 | |
|
237 | 239 | maxdiff = int(self.ui.config('notify', 'maxdiff', 300)) |
|
238 | 240 | prev = ctx.parents()[0].node() |
|
239 | 241 | ref = ref and ref.node() or ctx.node() |
|
240 | 242 | chunks = patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui)) |
|
241 | 243 | difflines = ''.join(chunks).splitlines() |
|
242 | 244 | |
|
243 | 245 | if self.ui.configbool('notify', 'diffstat', True): |
|
244 | 246 | s = patch.diffstat(difflines) |
|
245 | 247 | # s may be nil, don't include the header if it is |
|
246 | 248 | if s: |
|
247 | 249 | self.ui.write('\ndiffstat:\n\n%s' % s) |
|
248 | 250 | |
|
249 | 251 | if maxdiff == 0: |
|
250 | 252 | return |
|
251 | 253 | elif maxdiff > 0 and len(difflines) > maxdiff: |
|
252 | 254 | msg = _('\ndiffs (truncated from %d to %d lines):\n\n') |
|
253 | 255 | self.ui.write(msg % (len(difflines), maxdiff)) |
|
254 | 256 | difflines = difflines[:maxdiff] |
|
255 | 257 | elif difflines: |
|
256 | 258 | self.ui.write(_('\ndiffs (%d lines):\n\n') % len(difflines)) |
|
257 | 259 | |
|
258 | 260 | self.ui.write("\n".join(difflines)) |
|
259 | 261 | |
|
260 | 262 | def hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
|
261 | 263 | '''send email notifications to interested subscribers. |
|
262 | 264 | |
|
263 | 265 | if used as changegroup hook, send one email for all changesets in |
|
264 | 266 | changegroup. else send one email per changeset.''' |
|
265 | 267 | |
|
266 | 268 | n = notifier(ui, repo, hooktype) |
|
267 | 269 | ctx = repo[node] |
|
268 | 270 | |
|
269 | 271 | if not n.subs: |
|
270 | 272 | ui.debug(_('notify: no subscribers to repository %s\n') % n.root) |
|
271 | 273 | return |
|
272 | 274 | if n.skipsource(source): |
|
273 | 275 | ui.debug(_('notify: changes have source "%s" - skipping\n') % source) |
|
274 | 276 | return |
|
275 | 277 | |
|
276 | 278 | ui.pushbuffer() |
|
277 | 279 | if hooktype == 'changegroup': |
|
278 | 280 | start, end = ctx.rev(), len(repo) |
|
279 | 281 | count = end - start |
|
280 | 282 | for rev in xrange(start, end): |
|
281 | 283 | n.node(repo[rev]) |
|
282 | 284 | n.diff(ctx, repo['tip']) |
|
283 | 285 | else: |
|
284 | 286 | count = 1 |
|
285 | 287 | n.node(ctx) |
|
286 | 288 | n.diff(ctx) |
|
287 | 289 | |
|
288 | 290 | data = ui.popbuffer() |
|
289 | 291 | n.send(ctx, count, data) |
@@ -1,549 +1,549 b'' | |||
|
1 | 1 | # record.py |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | '''commands to interactively select changes for commit/qrefresh''' |
|
9 | 9 | |
|
10 | 10 | from mercurial.i18n import gettext, _ |
|
11 | 11 | from mercurial import cmdutil, commands, extensions, hg, mdiff, patch |
|
12 | 12 | from mercurial import util |
|
13 | 13 | import copy, cStringIO, errno, operator, os, re, tempfile |
|
14 | 14 | |
|
15 | 15 | lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)') |
|
16 | 16 | |
|
17 | 17 | def scanpatch(fp): |
|
18 | 18 | """like patch.iterhunks, but yield different events |
|
19 | 19 | |
|
20 | 20 | - ('file', [header_lines + fromfile + tofile]) |
|
21 | 21 | - ('context', [context_lines]) |
|
22 | 22 | - ('hunk', [hunk_lines]) |
|
23 | 23 | - ('range', (-start,len, +start,len, diffp)) |
|
24 | 24 | """ |
|
25 | 25 | lr = patch.linereader(fp) |
|
26 | 26 | |
|
27 | 27 | def scanwhile(first, p): |
|
28 | 28 | """scan lr while predicate holds""" |
|
29 | 29 | lines = [first] |
|
30 | 30 | while True: |
|
31 | 31 | line = lr.readline() |
|
32 | 32 | if not line: |
|
33 | 33 | break |
|
34 | 34 | if p(line): |
|
35 | 35 | lines.append(line) |
|
36 | 36 | else: |
|
37 | 37 | lr.push(line) |
|
38 | 38 | break |
|
39 | 39 | return lines |
|
40 | 40 | |
|
41 | 41 | while True: |
|
42 | 42 | line = lr.readline() |
|
43 | 43 | if not line: |
|
44 | 44 | break |
|
45 | 45 | if line.startswith('diff --git a/'): |
|
46 | 46 | def notheader(line): |
|
47 | 47 | s = line.split(None, 1) |
|
48 | 48 | return not s or s[0] not in ('---', 'diff') |
|
49 | 49 | header = scanwhile(line, notheader) |
|
50 | 50 | fromfile = lr.readline() |
|
51 | 51 | if fromfile.startswith('---'): |
|
52 | 52 | tofile = lr.readline() |
|
53 | 53 | header += [fromfile, tofile] |
|
54 | 54 | else: |
|
55 | 55 | lr.push(fromfile) |
|
56 | 56 | yield 'file', header |
|
57 | 57 | elif line[0] == ' ': |
|
58 | 58 | yield 'context', scanwhile(line, lambda l: l[0] in ' \\') |
|
59 | 59 | elif line[0] in '-+': |
|
60 | 60 | yield 'hunk', scanwhile(line, lambda l: l[0] in '-+\\') |
|
61 | 61 | else: |
|
62 | 62 | m = lines_re.match(line) |
|
63 | 63 | if m: |
|
64 | 64 | yield 'range', m.groups() |
|
65 | 65 | else: |
|
66 | 66 | raise patch.PatchError('unknown patch content: %r' % line) |
|
67 | 67 | |
|
68 | 68 | class header(object): |
|
69 | 69 | """patch header |
|
70 | 70 | |
|
71 | 71 | XXX shoudn't we move this to mercurial/patch.py ? |
|
72 | 72 | """ |
|
73 | 73 | diff_re = re.compile('diff --git a/(.*) b/(.*)$') |
|
74 | 74 | allhunks_re = re.compile('(?:index|new file|deleted file) ') |
|
75 | 75 | pretty_re = re.compile('(?:new file|deleted file) ') |
|
76 | 76 | special_re = re.compile('(?:index|new|deleted|copy|rename) ') |
|
77 | 77 | |
|
78 | 78 | def __init__(self, header): |
|
79 | 79 | self.header = header |
|
80 | 80 | self.hunks = [] |
|
81 | 81 | |
|
82 | 82 | def binary(self): |
|
83 | 83 | for h in self.header: |
|
84 | 84 | if h.startswith('index '): |
|
85 | 85 | return True |
|
86 | 86 | |
|
87 | 87 | def pretty(self, fp): |
|
88 | 88 | for h in self.header: |
|
89 | 89 | if h.startswith('index '): |
|
90 | 90 | fp.write(_('this modifies a binary file (all or nothing)\n')) |
|
91 | 91 | break |
|
92 | 92 | if self.pretty_re.match(h): |
|
93 | 93 | fp.write(h) |
|
94 | 94 | if self.binary(): |
|
95 | 95 | fp.write(_('this is a binary file\n')) |
|
96 | 96 | break |
|
97 | 97 | if h.startswith('---'): |
|
98 | 98 | fp.write(_('%d hunks, %d lines changed\n') % |
|
99 | 99 | (len(self.hunks), |
|
100 | 100 | sum([h.added + h.removed for h in self.hunks]))) |
|
101 | 101 | break |
|
102 | 102 | fp.write(h) |
|
103 | 103 | |
|
104 | 104 | def write(self, fp): |
|
105 | 105 | fp.write(''.join(self.header)) |
|
106 | 106 | |
|
107 | 107 | def allhunks(self): |
|
108 | 108 | for h in self.header: |
|
109 | 109 | if self.allhunks_re.match(h): |
|
110 | 110 | return True |
|
111 | 111 | |
|
112 | 112 | def files(self): |
|
113 | 113 | fromfile, tofile = self.diff_re.match(self.header[0]).groups() |
|
114 | 114 | if fromfile == tofile: |
|
115 | 115 | return [fromfile] |
|
116 | 116 | return [fromfile, tofile] |
|
117 | 117 | |
|
118 | 118 | def filename(self): |
|
119 | 119 | return self.files()[-1] |
|
120 | 120 | |
|
121 | 121 | def __repr__(self): |
|
122 | 122 | return '<header %s>' % (' '.join(map(repr, self.files()))) |
|
123 | 123 | |
|
124 | 124 | def special(self): |
|
125 | 125 | for h in self.header: |
|
126 | 126 | if self.special_re.match(h): |
|
127 | 127 | return True |
|
128 | 128 | |
|
129 | 129 | def countchanges(hunk): |
|
130 | 130 | """hunk -> (n+,n-)""" |
|
131 | 131 | add = len([h for h in hunk if h[0] == '+']) |
|
132 | 132 | rem = len([h for h in hunk if h[0] == '-']) |
|
133 | 133 | return add, rem |
|
134 | 134 | |
|
135 | 135 | class hunk(object): |
|
136 | 136 | """patch hunk |
|
137 | 137 | |
|
138 | 138 | XXX shouldn't we merge this with patch.hunk ? |
|
139 | 139 | """ |
|
140 | 140 | maxcontext = 3 |
|
141 | 141 | |
|
142 | 142 | def __init__(self, header, fromline, toline, proc, before, hunk, after): |
|
143 | 143 | def trimcontext(number, lines): |
|
144 | 144 | delta = len(lines) - self.maxcontext |
|
145 | 145 | if False and delta > 0: |
|
146 | 146 | return number + delta, lines[:self.maxcontext] |
|
147 | 147 | return number, lines |
|
148 | 148 | |
|
149 | 149 | self.header = header |
|
150 | 150 | self.fromline, self.before = trimcontext(fromline, before) |
|
151 | 151 | self.toline, self.after = trimcontext(toline, after) |
|
152 | 152 | self.proc = proc |
|
153 | 153 | self.hunk = hunk |
|
154 | 154 | self.added, self.removed = countchanges(self.hunk) |
|
155 | 155 | |
|
156 | 156 | def write(self, fp): |
|
157 | 157 | delta = len(self.before) + len(self.after) |
|
158 | 158 | if self.after and self.after[-1] == '\\ No newline at end of file\n': |
|
159 | 159 | delta -= 1 |
|
160 | 160 | fromlen = delta + self.removed |
|
161 | 161 | tolen = delta + self.added |
|
162 | 162 | fp.write('@@ -%d,%d +%d,%d @@%s\n' % |
|
163 | 163 | (self.fromline, fromlen, self.toline, tolen, |
|
164 | 164 | self.proc and (' ' + self.proc))) |
|
165 | 165 | fp.write(''.join(self.before + self.hunk + self.after)) |
|
166 | 166 | |
|
167 | 167 | pretty = write |
|
168 | 168 | |
|
169 | 169 | def filename(self): |
|
170 | 170 | return self.header.filename() |
|
171 | 171 | |
|
172 | 172 | def __repr__(self): |
|
173 | 173 | return '<hunk %r@%d>' % (self.filename(), self.fromline) |
|
174 | 174 | |
|
175 | 175 | def parsepatch(fp): |
|
176 | 176 | """patch -> [] of hunks """ |
|
177 | 177 | class parser(object): |
|
178 | 178 | """patch parsing state machine""" |
|
179 | 179 | def __init__(self): |
|
180 | 180 | self.fromline = 0 |
|
181 | 181 | self.toline = 0 |
|
182 | 182 | self.proc = '' |
|
183 | 183 | self.header = None |
|
184 | 184 | self.context = [] |
|
185 | 185 | self.before = [] |
|
186 | 186 | self.hunk = [] |
|
187 | 187 | self.stream = [] |
|
188 | 188 | |
|
189 | 189 | def addrange(self, (fromstart, fromend, tostart, toend, proc)): |
|
190 | 190 | self.fromline = int(fromstart) |
|
191 | 191 | self.toline = int(tostart) |
|
192 | 192 | self.proc = proc |
|
193 | 193 | |
|
194 | 194 | def addcontext(self, context): |
|
195 | 195 | if self.hunk: |
|
196 | 196 | h = hunk(self.header, self.fromline, self.toline, self.proc, |
|
197 | 197 | self.before, self.hunk, context) |
|
198 | 198 | self.header.hunks.append(h) |
|
199 | 199 | self.stream.append(h) |
|
200 | 200 | self.fromline += len(self.before) + h.removed |
|
201 | 201 | self.toline += len(self.before) + h.added |
|
202 | 202 | self.before = [] |
|
203 | 203 | self.hunk = [] |
|
204 | 204 | self.proc = '' |
|
205 | 205 | self.context = context |
|
206 | 206 | |
|
207 | 207 | def addhunk(self, hunk): |
|
208 | 208 | if self.context: |
|
209 | 209 | self.before = self.context |
|
210 | 210 | self.context = [] |
|
211 | 211 | self.hunk = hunk |
|
212 | 212 | |
|
213 | 213 | def newfile(self, hdr): |
|
214 | 214 | self.addcontext([]) |
|
215 | 215 | h = header(hdr) |
|
216 | 216 | self.stream.append(h) |
|
217 | 217 | self.header = h |
|
218 | 218 | |
|
219 | 219 | def finished(self): |
|
220 | 220 | self.addcontext([]) |
|
221 | 221 | return self.stream |
|
222 | 222 | |
|
223 | 223 | transitions = { |
|
224 | 224 | 'file': {'context': addcontext, |
|
225 | 225 | 'file': newfile, |
|
226 | 226 | 'hunk': addhunk, |
|
227 | 227 | 'range': addrange}, |
|
228 | 228 | 'context': {'file': newfile, |
|
229 | 229 | 'hunk': addhunk, |
|
230 | 230 | 'range': addrange}, |
|
231 | 231 | 'hunk': {'context': addcontext, |
|
232 | 232 | 'file': newfile, |
|
233 | 233 | 'range': addrange}, |
|
234 | 234 | 'range': {'context': addcontext, |
|
235 | 235 | 'hunk': addhunk}, |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | p = parser() |
|
239 | 239 | |
|
240 | 240 | state = 'context' |
|
241 | 241 | for newstate, data in scanpatch(fp): |
|
242 | 242 | try: |
|
243 | 243 | p.transitions[state][newstate](p, data) |
|
244 | 244 | except KeyError: |
|
245 | 245 | raise patch.PatchError('unhandled transition: %s -> %s' % |
|
246 | 246 | (state, newstate)) |
|
247 | 247 | state = newstate |
|
248 | 248 | return p.finished() |
|
249 | 249 | |
|
250 | 250 | def filterpatch(ui, chunks): |
|
251 | 251 | """Interactively filter patch chunks into applied-only chunks""" |
|
252 | 252 | chunks = list(chunks) |
|
253 | 253 | chunks.reverse() |
|
254 | 254 | seen = set() |
|
255 | 255 | def consumefile(): |
|
256 | 256 | """fetch next portion from chunks until a 'header' is seen |
|
257 | 257 | NB: header == new-file mark |
|
258 | 258 | """ |
|
259 | 259 | consumed = [] |
|
260 | 260 | while chunks: |
|
261 | 261 | if isinstance(chunks[-1], header): |
|
262 | 262 | break |
|
263 | 263 | else: |
|
264 | 264 | consumed.append(chunks.pop()) |
|
265 | 265 | return consumed |
|
266 | 266 | |
|
267 | 267 | resp_all = [None] # this two are changed from inside prompt, |
|
268 | 268 | resp_file = [None] # so can't be usual variables |
|
269 | 269 | applied = {} # 'filename' -> [] of chunks |
|
270 | 270 | def prompt(query): |
|
271 | 271 | """prompt query, and process base inputs |
|
272 | 272 | |
|
273 | 273 | - y/n for the rest of file |
|
274 | 274 | - y/n for the rest |
|
275 | 275 | - ? (help) |
|
276 | 276 | - q (quit) |
|
277 | 277 | |
|
278 | 278 | else, input is returned to the caller. |
|
279 | 279 | """ |
|
280 | 280 | if resp_all[0] is not None: |
|
281 | 281 | return resp_all[0] |
|
282 | 282 | if resp_file[0] is not None: |
|
283 | 283 | return resp_file[0] |
|
284 | 284 | while True: |
|
285 | 285 | resps = _('[Ynsfdaq?]') |
|
286 | 286 | choices = (_('&Yes, record this change'), |
|
287 | 287 | _('&No, skip this change'), |
|
288 | 288 | _('&Skip remaining changes to this file'), |
|
289 | 289 | _('Record remaining changes to this &file'), |
|
290 | 290 | _('&Done, skip remaining changes and files'), |
|
291 | 291 | _('Record &all changes to all remaining files'), |
|
292 | 292 | _('&Quit, recording no changes'), |
|
293 | 293 | _('&?')) |
|
294 | 294 | r = ui.promptchoice("%s %s " % (query, resps), choices) |
|
295 | 295 | if r == 7: # ? |
|
296 | 296 | doc = gettext(record.__doc__) |
|
297 | 297 | c = doc.find(_('y - record this change')) |
|
298 | 298 | for l in doc[c:].splitlines(): |
|
299 | 299 | if l: ui.write(l.strip(), '\n') |
|
300 | 300 | continue |
|
301 | 301 | elif r == 0: # yes |
|
302 | 302 | ret = 'y' |
|
303 | 303 | elif r == 1: # no |
|
304 | 304 | ret = 'n' |
|
305 | 305 | elif r == 2: # Skip |
|
306 | 306 | ret = resp_file[0] = 'n' |
|
307 | 307 | elif r == 3: # file (Record remaining) |
|
308 | 308 | ret = resp_file[0] = 'y' |
|
309 | 309 | elif r == 4: # done, skip remaining |
|
310 | 310 | ret = resp_all[0] = 'n' |
|
311 | 311 | elif r == 5: # all |
|
312 | 312 | ret = resp_all[0] = 'y' |
|
313 | 313 | elif r == 6: # quit |
|
314 | 314 | raise util.Abort(_('user quit')) |
|
315 | 315 | return ret |
|
316 | 316 | pos, total = 0, len(chunks) - 1 |
|
317 | 317 | while chunks: |
|
318 | 318 | chunk = chunks.pop() |
|
319 | 319 | if isinstance(chunk, header): |
|
320 | 320 | # new-file mark |
|
321 | 321 | resp_file = [None] |
|
322 | 322 | fixoffset = 0 |
|
323 | 323 | hdr = ''.join(chunk.header) |
|
324 | 324 | if hdr in seen: |
|
325 | 325 | consumefile() |
|
326 | 326 | continue |
|
327 | 327 | seen.add(hdr) |
|
328 | 328 | if resp_all[0] is None: |
|
329 | 329 | chunk.pretty(ui) |
|
330 | 330 | r = prompt(_('examine changes to %s?') % |
|
331 | 331 | _(' and ').join(map(repr, chunk.files()))) |
|
332 | 332 | if r == _('y'): |
|
333 | 333 | applied[chunk.filename()] = [chunk] |
|
334 | 334 | if chunk.allhunks(): |
|
335 | 335 | applied[chunk.filename()] += consumefile() |
|
336 | 336 | else: |
|
337 | 337 | consumefile() |
|
338 | 338 | else: |
|
339 | 339 | # new hunk |
|
340 | 340 | if resp_file[0] is None and resp_all[0] is None: |
|
341 | 341 | chunk.pretty(ui) |
|
342 | 342 | r = total == 1 and prompt(_('record this change to %r?') % |
|
343 | 343 | chunk.filename()) \ |
|
344 | 344 | or prompt(_('record change %d/%d to %r?') % |
|
345 | 345 | (pos, total, chunk.filename())) |
|
346 | 346 | if r == _('y'): |
|
347 | 347 | if fixoffset: |
|
348 | 348 | chunk = copy.copy(chunk) |
|
349 | 349 | chunk.toline += fixoffset |
|
350 | 350 | applied[chunk.filename()].append(chunk) |
|
351 | 351 | else: |
|
352 | 352 | fixoffset += chunk.removed - chunk.added |
|
353 | 353 | pos = pos + 1 |
|
354 | 354 | return reduce(operator.add, [h for h in applied.itervalues() |
|
355 | 355 | if h[0].special() or len(h) > 1], []) |
|
356 | 356 | |
|
357 | 357 | def record(ui, repo, *pats, **opts): |
|
358 | 358 | '''interactively select changes to commit |
|
359 | 359 | |
|
360 | 360 | If a list of files is omitted, all changes reported by "hg status" will be |
|
361 | 361 | candidates for recording. |
|
362 | 362 | |
|
363 | 363 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
364 | 364 | |
|
365 | 365 | You will be prompted for whether to record changes to each modified file, |
|
366 | 366 | and for files with multiple changes, for each change to use. For each |
|
367 | query, the following responses are possible: | |
|
367 | query, the following responses are possible:: | |
|
368 | 368 | |
|
369 | y - record this change | |
|
370 | n - skip this change | |
|
369 | y - record this change | |
|
370 | n - skip this change | |
|
371 | 371 | |
|
372 | s - skip remaining changes to this file | |
|
373 | f - record remaining changes to this file | |
|
372 | s - skip remaining changes to this file | |
|
373 | f - record remaining changes to this file | |
|
374 | 374 | |
|
375 | d - done, skip remaining changes and files | |
|
376 | a - record all changes to all remaining files | |
|
377 | q - quit, recording no changes | |
|
375 | d - done, skip remaining changes and files | |
|
376 | a - record all changes to all remaining files | |
|
377 | q - quit, recording no changes | |
|
378 | 378 | |
|
379 | ? - display help''' | |
|
379 | ? - display help''' | |
|
380 | 380 | |
|
381 | 381 | def record_committer(ui, repo, pats, opts): |
|
382 | 382 | commands.commit(ui, repo, *pats, **opts) |
|
383 | 383 | |
|
384 | 384 | dorecord(ui, repo, record_committer, *pats, **opts) |
|
385 | 385 | |
|
386 | 386 | |
|
387 | 387 | def qrecord(ui, repo, patch, *pats, **opts): |
|
388 | 388 | '''interactively record a new patch |
|
389 | 389 | |
|
390 | 390 | See 'hg help qnew' & 'hg help record' for more information and usage. |
|
391 | 391 | ''' |
|
392 | 392 | |
|
393 | 393 | try: |
|
394 | 394 | mq = extensions.find('mq') |
|
395 | 395 | except KeyError: |
|
396 | 396 | raise util.Abort(_("'mq' extension not loaded")) |
|
397 | 397 | |
|
398 | 398 | def qrecord_committer(ui, repo, pats, opts): |
|
399 | 399 | mq.new(ui, repo, patch, *pats, **opts) |
|
400 | 400 | |
|
401 | 401 | opts = opts.copy() |
|
402 | 402 | opts['force'] = True # always 'qnew -f' |
|
403 | 403 | dorecord(ui, repo, qrecord_committer, *pats, **opts) |
|
404 | 404 | |
|
405 | 405 | |
|
406 | 406 | def dorecord(ui, repo, committer, *pats, **opts): |
|
407 | 407 | if not ui.interactive(): |
|
408 | 408 | raise util.Abort(_('running non-interactively, use commit instead')) |
|
409 | 409 | |
|
410 | 410 | def recordfunc(ui, repo, message, match, opts): |
|
411 | 411 | """This is generic record driver. |
|
412 | 412 | |
|
413 | 413 | Its job is to interactively filter local changes, and accordingly |
|
414 | 414 | prepare working dir into a state, where the job can be delegated to |
|
415 | 415 | non-interactive commit command such as 'commit' or 'qrefresh'. |
|
416 | 416 | |
|
417 | 417 | After the actual job is done by non-interactive command, working dir |
|
418 | 418 | state is restored to original. |
|
419 | 419 | |
|
420 | 420 | In the end we'll record intresting changes, and everything else will be |
|
421 | 421 | left in place, so the user can continue his work. |
|
422 | 422 | """ |
|
423 | 423 | |
|
424 | 424 | changes = repo.status(match=match)[:3] |
|
425 | 425 | diffopts = mdiff.diffopts(git=True, nodates=True) |
|
426 | 426 | chunks = patch.diff(repo, changes=changes, opts=diffopts) |
|
427 | 427 | fp = cStringIO.StringIO() |
|
428 | 428 | fp.write(''.join(chunks)) |
|
429 | 429 | fp.seek(0) |
|
430 | 430 | |
|
431 | 431 | # 1. filter patch, so we have intending-to apply subset of it |
|
432 | 432 | chunks = filterpatch(ui, parsepatch(fp)) |
|
433 | 433 | del fp |
|
434 | 434 | |
|
435 | 435 | contenders = set() |
|
436 | 436 | for h in chunks: |
|
437 | 437 | try: contenders.update(set(h.files())) |
|
438 | 438 | except AttributeError: pass |
|
439 | 439 | |
|
440 | 440 | changed = changes[0] + changes[1] + changes[2] |
|
441 | 441 | newfiles = [f for f in changed if f in contenders] |
|
442 | 442 | if not newfiles: |
|
443 | 443 | ui.status(_('no changes to record\n')) |
|
444 | 444 | return 0 |
|
445 | 445 | |
|
446 | 446 | modified = set(changes[0]) |
|
447 | 447 | |
|
448 | 448 | # 2. backup changed files, so we can restore them in the end |
|
449 | 449 | backups = {} |
|
450 | 450 | backupdir = repo.join('record-backups') |
|
451 | 451 | try: |
|
452 | 452 | os.mkdir(backupdir) |
|
453 | 453 | except OSError, err: |
|
454 | 454 | if err.errno != errno.EEXIST: |
|
455 | 455 | raise |
|
456 | 456 | try: |
|
457 | 457 | # backup continues |
|
458 | 458 | for f in newfiles: |
|
459 | 459 | if f not in modified: |
|
460 | 460 | continue |
|
461 | 461 | fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', |
|
462 | 462 | dir=backupdir) |
|
463 | 463 | os.close(fd) |
|
464 | 464 | ui.debug(_('backup %r as %r\n') % (f, tmpname)) |
|
465 | 465 | util.copyfile(repo.wjoin(f), tmpname) |
|
466 | 466 | backups[f] = tmpname |
|
467 | 467 | |
|
468 | 468 | fp = cStringIO.StringIO() |
|
469 | 469 | for c in chunks: |
|
470 | 470 | if c.filename() in backups: |
|
471 | 471 | c.write(fp) |
|
472 | 472 | dopatch = fp.tell() |
|
473 | 473 | fp.seek(0) |
|
474 | 474 | |
|
475 | 475 | # 3a. apply filtered patch to clean repo (clean) |
|
476 | 476 | if backups: |
|
477 | 477 | hg.revert(repo, repo.dirstate.parents()[0], backups.has_key) |
|
478 | 478 | |
|
479 | 479 | # 3b. (apply) |
|
480 | 480 | if dopatch: |
|
481 | 481 | try: |
|
482 | 482 | ui.debug(_('applying patch\n')) |
|
483 | 483 | ui.debug(fp.getvalue()) |
|
484 | 484 | pfiles = {} |
|
485 | 485 | patch.internalpatch(fp, ui, 1, repo.root, files=pfiles, |
|
486 | 486 | eolmode=None) |
|
487 | 487 | patch.updatedir(ui, repo, pfiles) |
|
488 | 488 | except patch.PatchError, err: |
|
489 | 489 | s = str(err) |
|
490 | 490 | if s: |
|
491 | 491 | raise util.Abort(s) |
|
492 | 492 | else: |
|
493 | 493 | raise util.Abort(_('patch failed to apply')) |
|
494 | 494 | del fp |
|
495 | 495 | |
|
496 | 496 | # 4. We prepared working directory according to filtered patch. |
|
497 | 497 | # Now is the time to delegate the job to commit/qrefresh or the like! |
|
498 | 498 | |
|
499 | 499 | # it is important to first chdir to repo root -- we'll call a |
|
500 | 500 | # highlevel command with list of pathnames relative to repo root |
|
501 | 501 | cwd = os.getcwd() |
|
502 | 502 | os.chdir(repo.root) |
|
503 | 503 | try: |
|
504 | 504 | committer(ui, repo, newfiles, opts) |
|
505 | 505 | finally: |
|
506 | 506 | os.chdir(cwd) |
|
507 | 507 | |
|
508 | 508 | return 0 |
|
509 | 509 | finally: |
|
510 | 510 | # 5. finally restore backed-up files |
|
511 | 511 | try: |
|
512 | 512 | for realname, tmpname in backups.iteritems(): |
|
513 | 513 | ui.debug(_('restoring %r to %r\n') % (tmpname, realname)) |
|
514 | 514 | util.copyfile(tmpname, repo.wjoin(realname)) |
|
515 | 515 | os.unlink(tmpname) |
|
516 | 516 | os.rmdir(backupdir) |
|
517 | 517 | except OSError: |
|
518 | 518 | pass |
|
519 | 519 | return cmdutil.commit(ui, repo, recordfunc, pats, opts) |
|
520 | 520 | |
|
521 | 521 | cmdtable = { |
|
522 | 522 | "record": |
|
523 | 523 | (record, |
|
524 | 524 | |
|
525 | 525 | # add commit options |
|
526 | 526 | commands.table['^commit|ci'][1], |
|
527 | 527 | |
|
528 | 528 | _('hg record [OPTION]... [FILE]...')), |
|
529 | 529 | } |
|
530 | 530 | |
|
531 | 531 | |
|
532 | 532 | def extsetup(): |
|
533 | 533 | try: |
|
534 | 534 | mq = extensions.find('mq') |
|
535 | 535 | except KeyError: |
|
536 | 536 | return |
|
537 | 537 | |
|
538 | 538 | qcmdtable = { |
|
539 | 539 | "qrecord": |
|
540 | 540 | (qrecord, |
|
541 | 541 | |
|
542 | 542 | # add qnew options, except '--force' |
|
543 | 543 | [opt for opt in mq.cmdtable['qnew'][1] if opt[1] != 'force'], |
|
544 | 544 | |
|
545 | 545 | _('hg qrecord [OPTION]... PATCH [FILE]...')), |
|
546 | 546 | } |
|
547 | 547 | |
|
548 | 548 | cmdtable.update(qcmdtable) |
|
549 | 549 |
@@ -1,3510 +1,3515 b'' | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from node import hex, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _, gettext |
|
11 | 11 | import os, re, sys, subprocess, difflib, time, tempfile |
|
12 | 12 | import hg, util, revlog, bundlerepo, extensions, copies, context, error |
|
13 | 13 | import patch, help, mdiff, url, encoding |
|
14 | 14 | import archival, changegroup, cmdutil, sshserver, hbisect |
|
15 | 15 | from hgweb import server |
|
16 | 16 | import merge as merge_ |
|
17 | import minirst | |
|
17 | 18 | |
|
18 | 19 | # Commands start here, listed alphabetically |
|
19 | 20 | |
|
20 | 21 | def add(ui, repo, *pats, **opts): |
|
21 | 22 | """add the specified files on the next commit |
|
22 | 23 | |
|
23 | 24 | Schedule files to be version controlled and added to the repository. |
|
24 | 25 | |
|
25 | 26 | The files will be added to the repository at the next commit. To undo an |
|
26 | 27 | add before that, see hg forget. |
|
27 | 28 | |
|
28 | 29 | If no names are given, add all files to the repository. |
|
29 | 30 | """ |
|
30 | 31 | |
|
31 | 32 | bad = [] |
|
32 | 33 | exacts = {} |
|
33 | 34 | names = [] |
|
34 | 35 | m = cmdutil.match(repo, pats, opts) |
|
35 | 36 | oldbad = m.bad |
|
36 | 37 | m.bad = lambda x,y: bad.append(x) or oldbad(x,y) |
|
37 | 38 | |
|
38 | 39 | for f in repo.walk(m): |
|
39 | 40 | exact = m.exact(f) |
|
40 | 41 | if exact or f not in repo.dirstate: |
|
41 | 42 | names.append(f) |
|
42 | 43 | if ui.verbose or not exact: |
|
43 | 44 | ui.status(_('adding %s\n') % m.rel(f)) |
|
44 | 45 | if not opts.get('dry_run'): |
|
45 | 46 | bad += [f for f in repo.add(names) if f in m.files()] |
|
46 | 47 | return bad and 1 or 0 |
|
47 | 48 | |
|
48 | 49 | def addremove(ui, repo, *pats, **opts): |
|
49 | 50 | """add all new files, delete all missing files |
|
50 | 51 | |
|
51 | 52 | Add all new files and remove all missing files from the repository. |
|
52 | 53 | |
|
53 | 54 | New files are ignored if they match any of the patterns in .hgignore. As |
|
54 | 55 | with add, these changes take effect at the next commit. |
|
55 | 56 | |
|
56 | 57 | Use the -s/--similarity option to detect renamed files. With a parameter |
|
57 | 58 | greater than 0, this compares every removed file with every added file and |
|
58 | 59 | records those similar enough as renames. This option takes a percentage |
|
59 | 60 | between 0 (disabled) and 100 (files must be identical) as its parameter. |
|
60 | 61 | Detecting renamed files this way can be expensive. |
|
61 | 62 | """ |
|
62 | 63 | try: |
|
63 | 64 | sim = float(opts.get('similarity') or 0) |
|
64 | 65 | except ValueError: |
|
65 | 66 | raise util.Abort(_('similarity must be a number')) |
|
66 | 67 | if sim < 0 or sim > 100: |
|
67 | 68 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
68 | 69 | return cmdutil.addremove(repo, pats, opts, similarity=sim/100.) |
|
69 | 70 | |
|
70 | 71 | def annotate(ui, repo, *pats, **opts): |
|
71 | 72 | """show changeset information by line for each file |
|
72 | 73 | |
|
73 | 74 | List changes in files, showing the revision id responsible for each line |
|
74 | 75 | |
|
75 | 76 | This command is useful for discovering when a change was made and by whom. |
|
76 | 77 | |
|
77 | 78 | Without the -a/--text option, annotate will avoid processing files it |
|
78 | 79 | detects as binary. With -a, annotate will annotate the file anyway, |
|
79 | 80 | although the results will probably be neither useful nor desirable. |
|
80 | 81 | """ |
|
81 | 82 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
82 | 83 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) |
|
83 | 84 | |
|
84 | 85 | if not pats: |
|
85 | 86 | raise util.Abort(_('at least one filename or pattern is required')) |
|
86 | 87 | |
|
87 | 88 | opmap = [('user', lambda x: ui.shortuser(x[0].user())), |
|
88 | 89 | ('number', lambda x: str(x[0].rev())), |
|
89 | 90 | ('changeset', lambda x: short(x[0].node())), |
|
90 | 91 | ('date', getdate), |
|
91 | 92 | ('follow', lambda x: x[0].path()), |
|
92 | 93 | ] |
|
93 | 94 | |
|
94 | 95 | if (not opts.get('user') and not opts.get('changeset') and not opts.get('date') |
|
95 | 96 | and not opts.get('follow')): |
|
96 | 97 | opts['number'] = 1 |
|
97 | 98 | |
|
98 | 99 | linenumber = opts.get('line_number') is not None |
|
99 | 100 | if (linenumber and (not opts.get('changeset')) and (not opts.get('number'))): |
|
100 | 101 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
101 | 102 | |
|
102 | 103 | funcmap = [func for op, func in opmap if opts.get(op)] |
|
103 | 104 | if linenumber: |
|
104 | 105 | lastfunc = funcmap[-1] |
|
105 | 106 | funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) |
|
106 | 107 | |
|
107 | 108 | ctx = repo[opts.get('rev')] |
|
108 | 109 | |
|
109 | 110 | m = cmdutil.match(repo, pats, opts) |
|
110 | 111 | for abs in ctx.walk(m): |
|
111 | 112 | fctx = ctx[abs] |
|
112 | 113 | if not opts.get('text') and util.binary(fctx.data()): |
|
113 | 114 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
114 | 115 | continue |
|
115 | 116 | |
|
116 | 117 | lines = fctx.annotate(follow=opts.get('follow'), |
|
117 | 118 | linenumber=linenumber) |
|
118 | 119 | pieces = [] |
|
119 | 120 | |
|
120 | 121 | for f in funcmap: |
|
121 | 122 | l = [f(n) for n, dummy in lines] |
|
122 | 123 | if l: |
|
123 | 124 | ml = max(map(len, l)) |
|
124 | 125 | pieces.append(["%*s" % (ml, x) for x in l]) |
|
125 | 126 | |
|
126 | 127 | if pieces: |
|
127 | 128 | for p, l in zip(zip(*pieces), lines): |
|
128 | 129 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
129 | 130 | |
|
130 | 131 | def archive(ui, repo, dest, **opts): |
|
131 | 132 | '''create an unversioned archive of a repository revision |
|
132 | 133 | |
|
133 | 134 | By default, the revision used is the parent of the working directory; use |
|
134 | 135 | -r/--rev to specify a different revision. |
|
135 | 136 | |
|
136 | To specify the type of archive to create, use -t/--type. Valid types are: | |
|
137 | ||
|
138 | "files" (default): a directory full of files | |
|
139 | "tar": tar archive, uncompressed | |
|
140 | "tbz2": tar archive, compressed using bzip2 | |
|
141 | "tgz": tar archive, compressed using gzip | |
|
142 | "uzip": zip archive, uncompressed | |
|
143 | "zip": zip archive, compressed using deflate | |
|
137 | To specify the type of archive to create, use -t/--type. Valid types are:: | |
|
138 | ||
|
139 | "files" (default): a directory full of files | |
|
140 | "tar": tar archive, uncompressed | |
|
141 | "tbz2": tar archive, compressed using bzip2 | |
|
142 | "tgz": tar archive, compressed using gzip | |
|
143 | "uzip": zip archive, uncompressed | |
|
144 | "zip": zip archive, compressed using deflate | |
|
144 | 145 | |
|
145 | 146 | The exact name of the destination archive or directory is given using a |
|
146 | 147 | format string; see 'hg help export' for details. |
|
147 | 148 | |
|
148 | 149 | Each member added to an archive file has a directory prefix prepended. Use |
|
149 | 150 | -p/--prefix to specify a format string for the prefix. The default is the |
|
150 | 151 | basename of the archive, with suffixes removed. |
|
151 | 152 | ''' |
|
152 | 153 | |
|
153 | 154 | ctx = repo[opts.get('rev')] |
|
154 | 155 | if not ctx: |
|
155 | 156 | raise util.Abort(_('no working directory: please specify a revision')) |
|
156 | 157 | node = ctx.node() |
|
157 | 158 | dest = cmdutil.make_filename(repo, dest, node) |
|
158 | 159 | if os.path.realpath(dest) == repo.root: |
|
159 | 160 | raise util.Abort(_('repository root cannot be destination')) |
|
160 | 161 | matchfn = cmdutil.match(repo, [], opts) |
|
161 | 162 | kind = opts.get('type') or 'files' |
|
162 | 163 | prefix = opts.get('prefix') |
|
163 | 164 | if dest == '-': |
|
164 | 165 | if kind == 'files': |
|
165 | 166 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
166 | 167 | dest = sys.stdout |
|
167 | 168 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' |
|
168 | 169 | prefix = cmdutil.make_filename(repo, prefix, node) |
|
169 | 170 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
170 | 171 | matchfn, prefix) |
|
171 | 172 | |
|
172 | 173 | def backout(ui, repo, node=None, rev=None, **opts): |
|
173 | 174 | '''reverse effect of earlier changeset |
|
174 | 175 | |
|
175 | 176 | Commit the backed out changes as a new changeset. The new changeset is a |
|
176 | 177 | child of the backed out changeset. |
|
177 | 178 | |
|
178 | 179 | If you backout a changeset other than the tip, a new head is created. This |
|
179 | 180 | head will be the new tip and you should merge this backout changeset with |
|
180 | 181 | another head. |
|
181 | 182 | |
|
182 | 183 | The --merge option remembers the parent of the working directory before |
|
183 | 184 | starting the backout, then merges the new head with that changeset |
|
184 | 185 | afterwards. This saves you from doing the merge by hand. The result of |
|
185 | 186 | this merge is not committed, as with a normal merge. |
|
186 | 187 | |
|
187 | 188 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
188 | 189 | ''' |
|
189 | 190 | if rev and node: |
|
190 | 191 | raise util.Abort(_("please specify just one revision")) |
|
191 | 192 | |
|
192 | 193 | if not rev: |
|
193 | 194 | rev = node |
|
194 | 195 | |
|
195 | 196 | if not rev: |
|
196 | 197 | raise util.Abort(_("please specify a revision to backout")) |
|
197 | 198 | |
|
198 | 199 | date = opts.get('date') |
|
199 | 200 | if date: |
|
200 | 201 | opts['date'] = util.parsedate(date) |
|
201 | 202 | |
|
202 | 203 | cmdutil.bail_if_changed(repo) |
|
203 | 204 | node = repo.lookup(rev) |
|
204 | 205 | |
|
205 | 206 | op1, op2 = repo.dirstate.parents() |
|
206 | 207 | a = repo.changelog.ancestor(op1, node) |
|
207 | 208 | if a != node: |
|
208 | 209 | raise util.Abort(_('cannot backout change on a different branch')) |
|
209 | 210 | |
|
210 | 211 | p1, p2 = repo.changelog.parents(node) |
|
211 | 212 | if p1 == nullid: |
|
212 | 213 | raise util.Abort(_('cannot backout a change with no parents')) |
|
213 | 214 | if p2 != nullid: |
|
214 | 215 | if not opts.get('parent'): |
|
215 | 216 | raise util.Abort(_('cannot backout a merge changeset without ' |
|
216 | 217 | '--parent')) |
|
217 | 218 | p = repo.lookup(opts['parent']) |
|
218 | 219 | if p not in (p1, p2): |
|
219 | 220 | raise util.Abort(_('%s is not a parent of %s') % |
|
220 | 221 | (short(p), short(node))) |
|
221 | 222 | parent = p |
|
222 | 223 | else: |
|
223 | 224 | if opts.get('parent'): |
|
224 | 225 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
225 | 226 | parent = p1 |
|
226 | 227 | |
|
227 | 228 | # the backout should appear on the same branch |
|
228 | 229 | branch = repo.dirstate.branch() |
|
229 | 230 | hg.clean(repo, node, show_stats=False) |
|
230 | 231 | repo.dirstate.setbranch(branch) |
|
231 | 232 | revert_opts = opts.copy() |
|
232 | 233 | revert_opts['date'] = None |
|
233 | 234 | revert_opts['all'] = True |
|
234 | 235 | revert_opts['rev'] = hex(parent) |
|
235 | 236 | revert_opts['no_backup'] = None |
|
236 | 237 | revert(ui, repo, **revert_opts) |
|
237 | 238 | commit_opts = opts.copy() |
|
238 | 239 | commit_opts['addremove'] = False |
|
239 | 240 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
240 | 241 | commit_opts['message'] = _("Backed out changeset %s") % (short(node)) |
|
241 | 242 | commit_opts['force_editor'] = True |
|
242 | 243 | commit(ui, repo, **commit_opts) |
|
243 | 244 | def nice(node): |
|
244 | 245 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
245 | 246 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
246 | 247 | (nice(repo.changelog.tip()), nice(node))) |
|
247 | 248 | if op1 != node: |
|
248 | 249 | hg.clean(repo, op1, show_stats=False) |
|
249 | 250 | if opts.get('merge'): |
|
250 | 251 | ui.status(_('merging with changeset %s\n') % nice(repo.changelog.tip())) |
|
251 | 252 | hg.merge(repo, hex(repo.changelog.tip())) |
|
252 | 253 | else: |
|
253 | 254 | ui.status(_('the backout changeset is a new head - ' |
|
254 | 255 | 'do not forget to merge\n')) |
|
255 | 256 | ui.status(_('(use "backout --merge" ' |
|
256 | 257 | 'if you want to auto-merge)\n')) |
|
257 | 258 | |
|
258 | 259 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
259 | 260 | reset=None, good=None, bad=None, skip=None, noupdate=None): |
|
260 | 261 | """subdivision search of changesets |
|
261 | 262 | |
|
262 | 263 | This command helps to find changesets which introduce problems. To use, |
|
263 | 264 | mark the earliest changeset you know exhibits the problem as bad, then |
|
264 | 265 | mark the latest changeset which is free from the problem as good. Bisect |
|
265 | 266 | will update your working directory to a revision for testing (unless the |
|
266 | 267 | -U/--noupdate option is specified). Once you have performed tests, mark |
|
267 | 268 | the working directory as good or bad, and bisect will either update to |
|
268 | 269 | another candidate changeset or announce that it has found the bad |
|
269 | 270 | revision. |
|
270 | 271 | |
|
271 | 272 | As a shortcut, you can also use the revision argument to mark a revision |
|
272 | 273 | as good or bad without checking it out first. |
|
273 | 274 | |
|
274 | 275 | If you supply a command, it will be used for automatic bisection. Its exit |
|
275 | 276 | status will be used to mark revisions as good or bad: status 0 means good, |
|
276 | 277 | 125 means to skip the revision, 127 (command not found) will abort the |
|
277 | 278 | bisection, and any other non-zero exit status means the revision is bad. |
|
278 | 279 | """ |
|
279 | 280 | def print_result(nodes, good): |
|
280 | 281 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
281 | 282 | if len(nodes) == 1: |
|
282 | 283 | # narrowed it down to a single revision |
|
283 | 284 | if good: |
|
284 | 285 | ui.write(_("The first good revision is:\n")) |
|
285 | 286 | else: |
|
286 | 287 | ui.write(_("The first bad revision is:\n")) |
|
287 | 288 | displayer.show(repo[nodes[0]]) |
|
288 | 289 | else: |
|
289 | 290 | # multiple possible revisions |
|
290 | 291 | if good: |
|
291 | 292 | ui.write(_("Due to skipped revisions, the first " |
|
292 | 293 | "good revision could be any of:\n")) |
|
293 | 294 | else: |
|
294 | 295 | ui.write(_("Due to skipped revisions, the first " |
|
295 | 296 | "bad revision could be any of:\n")) |
|
296 | 297 | for n in nodes: |
|
297 | 298 | displayer.show(repo[n]) |
|
298 | 299 | |
|
299 | 300 | def check_state(state, interactive=True): |
|
300 | 301 | if not state['good'] or not state['bad']: |
|
301 | 302 | if (good or bad or skip or reset) and interactive: |
|
302 | 303 | return |
|
303 | 304 | if not state['good']: |
|
304 | 305 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
305 | 306 | else: |
|
306 | 307 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
307 | 308 | return True |
|
308 | 309 | |
|
309 | 310 | # backward compatibility |
|
310 | 311 | if rev in "good bad reset init".split(): |
|
311 | 312 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
312 | 313 | cmd, rev, extra = rev, extra, None |
|
313 | 314 | if cmd == "good": |
|
314 | 315 | good = True |
|
315 | 316 | elif cmd == "bad": |
|
316 | 317 | bad = True |
|
317 | 318 | else: |
|
318 | 319 | reset = True |
|
319 | 320 | elif extra or good + bad + skip + reset + bool(command) > 1: |
|
320 | 321 | raise util.Abort(_('incompatible arguments')) |
|
321 | 322 | |
|
322 | 323 | if reset: |
|
323 | 324 | p = repo.join("bisect.state") |
|
324 | 325 | if os.path.exists(p): |
|
325 | 326 | os.unlink(p) |
|
326 | 327 | return |
|
327 | 328 | |
|
328 | 329 | state = hbisect.load_state(repo) |
|
329 | 330 | |
|
330 | 331 | if command: |
|
331 | 332 | commandpath = util.find_exe(command) |
|
332 | 333 | if commandpath is None: |
|
333 | 334 | raise util.Abort(_("cannot find executable: %s") % command) |
|
334 | 335 | changesets = 1 |
|
335 | 336 | try: |
|
336 | 337 | while changesets: |
|
337 | 338 | # update state |
|
338 | 339 | status = subprocess.call([commandpath]) |
|
339 | 340 | if status == 125: |
|
340 | 341 | transition = "skip" |
|
341 | 342 | elif status == 0: |
|
342 | 343 | transition = "good" |
|
343 | 344 | # status < 0 means process was killed |
|
344 | 345 | elif status == 127: |
|
345 | 346 | raise util.Abort(_("failed to execute %s") % command) |
|
346 | 347 | elif status < 0: |
|
347 | 348 | raise util.Abort(_("%s killed") % command) |
|
348 | 349 | else: |
|
349 | 350 | transition = "bad" |
|
350 | 351 | ctx = repo[rev or '.'] |
|
351 | 352 | state[transition].append(ctx.node()) |
|
352 | 353 | ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
353 | 354 | check_state(state, interactive=False) |
|
354 | 355 | # bisect |
|
355 | 356 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
356 | 357 | # update to next check |
|
357 | 358 | cmdutil.bail_if_changed(repo) |
|
358 | 359 | hg.clean(repo, nodes[0], show_stats=False) |
|
359 | 360 | finally: |
|
360 | 361 | hbisect.save_state(repo, state) |
|
361 | 362 | return print_result(nodes, not status) |
|
362 | 363 | |
|
363 | 364 | # update state |
|
364 | 365 | node = repo.lookup(rev or '.') |
|
365 | 366 | if good: |
|
366 | 367 | state['good'].append(node) |
|
367 | 368 | elif bad: |
|
368 | 369 | state['bad'].append(node) |
|
369 | 370 | elif skip: |
|
370 | 371 | state['skip'].append(node) |
|
371 | 372 | |
|
372 | 373 | hbisect.save_state(repo, state) |
|
373 | 374 | |
|
374 | 375 | if not check_state(state): |
|
375 | 376 | return |
|
376 | 377 | |
|
377 | 378 | # actually bisect |
|
378 | 379 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
379 | 380 | if changesets == 0: |
|
380 | 381 | print_result(nodes, good) |
|
381 | 382 | else: |
|
382 | 383 | assert len(nodes) == 1 # only a single node can be tested next |
|
383 | 384 | node = nodes[0] |
|
384 | 385 | # compute the approximate number of remaining tests |
|
385 | 386 | tests, size = 0, 2 |
|
386 | 387 | while size <= changesets: |
|
387 | 388 | tests, size = tests + 1, size * 2 |
|
388 | 389 | rev = repo.changelog.rev(node) |
|
389 | 390 | ui.write(_("Testing changeset %d:%s " |
|
390 | 391 | "(%d changesets remaining, ~%d tests)\n") |
|
391 | 392 | % (rev, short(node), changesets, tests)) |
|
392 | 393 | if not noupdate: |
|
393 | 394 | cmdutil.bail_if_changed(repo) |
|
394 | 395 | return hg.clean(repo, node) |
|
395 | 396 | |
|
396 | 397 | def branch(ui, repo, label=None, **opts): |
|
397 | 398 | """set or show the current branch name |
|
398 | 399 | |
|
399 | 400 | With no argument, show the current branch name. With one argument, set the |
|
400 | 401 | working directory branch name (the branch will not exist in the repository |
|
401 | 402 | until the next commit). Standard practice recommends that primary |
|
402 | 403 | development take place on the 'default' branch. |
|
403 | 404 | |
|
404 | 405 | Unless -f/--force is specified, branch will not let you set a branch name |
|
405 | 406 | that already exists, even if it's inactive. |
|
406 | 407 | |
|
407 | 408 | Use -C/--clean to reset the working directory branch to that of the parent |
|
408 | 409 | of the working directory, negating a previous branch change. |
|
409 | 410 | |
|
410 | 411 | Use the command 'hg update' to switch to an existing branch. Use 'hg |
|
411 | 412 | commit --close-branch' to mark this branch as closed. |
|
412 | 413 | """ |
|
413 | 414 | |
|
414 | 415 | if opts.get('clean'): |
|
415 | 416 | label = repo[None].parents()[0].branch() |
|
416 | 417 | repo.dirstate.setbranch(label) |
|
417 | 418 | ui.status(_('reset working directory to branch %s\n') % label) |
|
418 | 419 | elif label: |
|
419 | 420 | if not opts.get('force') and label in repo.branchtags(): |
|
420 | 421 | if label not in [p.branch() for p in repo.parents()]: |
|
421 | 422 | raise util.Abort(_('a branch of the same name already exists' |
|
422 | 423 | ' (use --force to override)')) |
|
423 | 424 | repo.dirstate.setbranch(encoding.fromlocal(label)) |
|
424 | 425 | ui.status(_('marked working directory as branch %s\n') % label) |
|
425 | 426 | else: |
|
426 | 427 | ui.write("%s\n" % encoding.tolocal(repo.dirstate.branch())) |
|
427 | 428 | |
|
428 | 429 | def branches(ui, repo, active=False, closed=False): |
|
429 | 430 | """list repository named branches |
|
430 | 431 | |
|
431 | 432 | List the repository's named branches, indicating which ones are inactive. |
|
432 | 433 | If -c/--closed is specified, also list branches which have been marked |
|
433 | 434 | closed (see hg commit --close-branch). |
|
434 | 435 | |
|
435 | 436 | If -a/--active is specified, only show active branches. A branch is |
|
436 | 437 | considered active if it contains repository heads. |
|
437 | 438 | |
|
438 | 439 | Use the command 'hg update' to switch to an existing branch. |
|
439 | 440 | """ |
|
440 | 441 | |
|
441 | 442 | hexfunc = ui.debugflag and hex or short |
|
442 | 443 | activebranches = [encoding.tolocal(repo[n].branch()) |
|
443 | 444 | for n in repo.heads()] |
|
444 | 445 | def testactive(tag, node): |
|
445 | 446 | realhead = tag in activebranches |
|
446 | 447 | open = node in repo.branchheads(tag, closed=False) |
|
447 | 448 | return realhead and open |
|
448 | 449 | branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) |
|
449 | 450 | for tag, node in repo.branchtags().items()], |
|
450 | 451 | reverse=True) |
|
451 | 452 | |
|
452 | 453 | for isactive, node, tag in branches: |
|
453 | 454 | if (not active) or isactive: |
|
454 | 455 | if ui.quiet: |
|
455 | 456 | ui.write("%s\n" % tag) |
|
456 | 457 | else: |
|
457 | 458 | hn = repo.lookup(node) |
|
458 | 459 | if isactive: |
|
459 | 460 | notice = '' |
|
460 | 461 | elif hn not in repo.branchheads(tag, closed=False): |
|
461 | 462 | if not closed: |
|
462 | 463 | continue |
|
463 | 464 | notice = ' (closed)' |
|
464 | 465 | else: |
|
465 | 466 | notice = ' (inactive)' |
|
466 | 467 | rev = str(node).rjust(31 - encoding.colwidth(tag)) |
|
467 | 468 | data = tag, rev, hexfunc(hn), notice |
|
468 | 469 | ui.write("%s %s:%s%s\n" % data) |
|
469 | 470 | |
|
470 | 471 | def bundle(ui, repo, fname, dest=None, **opts): |
|
471 | 472 | """create a changegroup file |
|
472 | 473 | |
|
473 | 474 | Generate a compressed changegroup file collecting changesets not known to |
|
474 | 475 | be in another repository. |
|
475 | 476 | |
|
476 | 477 | If no destination repository is specified the destination is assumed to |
|
477 | 478 | have all the nodes specified by one or more --base parameters. To create a |
|
478 | 479 | bundle containing all changesets, use -a/--all (or --base null). |
|
479 | 480 | |
|
480 | 481 | You can change compression method with the -t/--type option. The available |
|
481 | 482 | compression methods are: none, bzip2, and gzip (by default, bundles are |
|
482 | 483 | compressed using bzip2). |
|
483 | 484 | |
|
484 | 485 | The bundle file can then be transferred using conventional means and |
|
485 | 486 | applied to another repository with the unbundle or pull command. This is |
|
486 | 487 | useful when direct push and pull are not available or when exporting an |
|
487 | 488 | entire repository is undesirable. |
|
488 | 489 | |
|
489 | 490 | Applying bundles preserves all changeset contents including permissions, |
|
490 | 491 | copy/rename information, and revision history. |
|
491 | 492 | """ |
|
492 | 493 | revs = opts.get('rev') or None |
|
493 | 494 | if revs: |
|
494 | 495 | revs = [repo.lookup(rev) for rev in revs] |
|
495 | 496 | if opts.get('all'): |
|
496 | 497 | base = ['null'] |
|
497 | 498 | else: |
|
498 | 499 | base = opts.get('base') |
|
499 | 500 | if base: |
|
500 | 501 | if dest: |
|
501 | 502 | raise util.Abort(_("--base is incompatible with specifying " |
|
502 | 503 | "a destination")) |
|
503 | 504 | base = [repo.lookup(rev) for rev in base] |
|
504 | 505 | # create the right base |
|
505 | 506 | # XXX: nodesbetween / changegroup* should be "fixed" instead |
|
506 | 507 | o = [] |
|
507 | 508 | has = set((nullid,)) |
|
508 | 509 | for n in base: |
|
509 | 510 | has.update(repo.changelog.reachable(n)) |
|
510 | 511 | if revs: |
|
511 | 512 | visit = list(revs) |
|
512 | 513 | else: |
|
513 | 514 | visit = repo.changelog.heads() |
|
514 | 515 | seen = {} |
|
515 | 516 | while visit: |
|
516 | 517 | n = visit.pop(0) |
|
517 | 518 | parents = [p for p in repo.changelog.parents(n) if p not in has] |
|
518 | 519 | if len(parents) == 0: |
|
519 | 520 | o.insert(0, n) |
|
520 | 521 | else: |
|
521 | 522 | for p in parents: |
|
522 | 523 | if p not in seen: |
|
523 | 524 | seen[p] = 1 |
|
524 | 525 | visit.append(p) |
|
525 | 526 | else: |
|
526 | 527 | dest, revs, checkout = hg.parseurl( |
|
527 | 528 | ui.expandpath(dest or 'default-push', dest or 'default'), revs) |
|
528 | 529 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
529 | 530 | o = repo.findoutgoing(other, force=opts.get('force')) |
|
530 | 531 | |
|
531 | 532 | if revs: |
|
532 | 533 | cg = repo.changegroupsubset(o, revs, 'bundle') |
|
533 | 534 | else: |
|
534 | 535 | cg = repo.changegroup(o, 'bundle') |
|
535 | 536 | |
|
536 | 537 | bundletype = opts.get('type', 'bzip2').lower() |
|
537 | 538 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
538 | 539 | bundletype = btypes.get(bundletype) |
|
539 | 540 | if bundletype not in changegroup.bundletypes: |
|
540 | 541 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
541 | 542 | |
|
542 | 543 | changegroup.writebundle(cg, fname, bundletype) |
|
543 | 544 | |
|
544 | 545 | def cat(ui, repo, file1, *pats, **opts): |
|
545 | 546 | """output the current or given revision of files |
|
546 | 547 | |
|
547 | 548 | Print the specified files as they were at the given revision. If no |
|
548 | 549 | revision is given, the parent of the working directory is used, or tip if |
|
549 | 550 | no revision is checked out. |
|
550 | 551 | |
|
551 | 552 | Output may be to a file, in which case the name of the file is given using |
|
552 | 553 | a format string. The formatting rules are the same as for the export |
|
553 | command, with the following additions: | |
|
554 | ||
|
555 | %s basename of file being printed | |
|
556 | %d dirname of file being printed, or '.' if in repository root | |
|
557 | %p root-relative path name of file being printed | |
|
554 | command, with the following additions:: | |
|
555 | ||
|
556 | %s basename of file being printed | |
|
557 | %d dirname of file being printed, or '.' if in repository root | |
|
558 | %p root-relative path name of file being printed | |
|
558 | 559 | """ |
|
559 | 560 | ctx = repo[opts.get('rev')] |
|
560 | 561 | err = 1 |
|
561 | 562 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
562 | 563 | for abs in ctx.walk(m): |
|
563 | 564 | fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs) |
|
564 | 565 | data = ctx[abs].data() |
|
565 | 566 | if opts.get('decode'): |
|
566 | 567 | data = repo.wwritedata(abs, data) |
|
567 | 568 | fp.write(data) |
|
568 | 569 | err = 0 |
|
569 | 570 | return err |
|
570 | 571 | |
|
571 | 572 | def clone(ui, source, dest=None, **opts): |
|
572 | 573 | """make a copy of an existing repository |
|
573 | 574 | |
|
574 | 575 | Create a copy of an existing repository in a new directory. |
|
575 | 576 | |
|
576 | 577 | If no destination directory name is specified, it defaults to the basename |
|
577 | 578 | of the source. |
|
578 | 579 | |
|
579 | 580 | The location of the source is added to the new repository's .hg/hgrc file, |
|
580 | 581 | as the default to be used for future pulls. |
|
581 | 582 | |
|
582 | 583 | If you use the -r/--rev option to clone up to a specific revision, no |
|
583 | 584 | subsequent revisions (including subsequent tags) will be present in the |
|
584 | 585 | cloned repository. This option implies --pull, even on local repositories. |
|
585 | 586 | |
|
586 | 587 | By default, clone will check out the head of the 'default' branch. If the |
|
587 | 588 | -U/--noupdate option is used, the new clone will contain only a repository |
|
588 | 589 | (.hg) and no working copy (the working copy parent is the null revision). |
|
589 | 590 | |
|
590 | 591 | See 'hg help urls' for valid source format details. |
|
591 | 592 | |
|
592 | 593 | It is possible to specify an ssh:// URL as the destination, but no |
|
593 | 594 | .hg/hgrc and working directory will be created on the remote side. Please |
|
594 | 595 | see 'hg help urls' for important details about ssh:// URLs. |
|
595 | 596 | |
|
596 | 597 | For efficiency, hardlinks are used for cloning whenever the source and |
|
597 | 598 | destination are on the same filesystem (note this applies only to the |
|
598 | 599 | repository data, not to the checked out files). Some filesystems, such as |
|
599 | 600 | AFS, implement hardlinking incorrectly, but do not report errors. In these |
|
600 | 601 | cases, use the --pull option to avoid hardlinking. |
|
601 | 602 | |
|
602 | 603 | In some cases, you can clone repositories and checked out files using full |
|
603 | hardlinks with | |
|
604 | hardlinks with :: | |
|
604 | 605 | |
|
605 | 606 | $ cp -al REPO REPOCLONE |
|
606 | 607 | |
|
607 | 608 | This is the fastest way to clone, but it is not always safe. The operation |
|
608 | 609 | is not atomic (making sure REPO is not modified during the operation is up |
|
609 | 610 | to you) and you have to make sure your editor breaks hardlinks (Emacs and |
|
610 | 611 | most Linux Kernel tools do so). Also, this is not compatible with certain |
|
611 | 612 | extensions that place their metadata under the .hg directory, such as mq. |
|
612 | 613 | """ |
|
613 | 614 | hg.clone(cmdutil.remoteui(ui, opts), source, dest, |
|
614 | 615 | pull=opts.get('pull'), |
|
615 | 616 | stream=opts.get('uncompressed'), |
|
616 | 617 | rev=opts.get('rev'), |
|
617 | 618 | update=not opts.get('noupdate')) |
|
618 | 619 | |
|
619 | 620 | def commit(ui, repo, *pats, **opts): |
|
620 | 621 | """commit the specified files or all outstanding changes |
|
621 | 622 | |
|
622 | 623 | Commit changes to the given files into the repository. Unlike a |
|
623 | 624 | centralized RCS, this operation is a local operation. See hg push for a |
|
624 | 625 | way to actively distribute your changes. |
|
625 | 626 | |
|
626 | 627 | If a list of files is omitted, all changes reported by "hg status" will be |
|
627 | 628 | committed. |
|
628 | 629 | |
|
629 | 630 | If you are committing the result of a merge, do not provide any filenames |
|
630 | 631 | or -I/-X filters. |
|
631 | 632 | |
|
632 | 633 | If no commit message is specified, the configured editor is started to |
|
633 | 634 | prompt you for a message. |
|
634 | 635 | |
|
635 | 636 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
636 | 637 | """ |
|
637 | 638 | extra = {} |
|
638 | 639 | if opts.get('close_branch'): |
|
639 | 640 | extra['close'] = 1 |
|
640 | 641 | e = cmdutil.commiteditor |
|
641 | 642 | if opts.get('force_editor'): |
|
642 | 643 | e = cmdutil.commitforceeditor |
|
643 | 644 | |
|
644 | 645 | def commitfunc(ui, repo, message, match, opts): |
|
645 | 646 | return repo.commit(message, opts.get('user'), opts.get('date'), match, |
|
646 | 647 | editor=e, extra=extra) |
|
647 | 648 | |
|
648 | 649 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
649 | 650 | if not node: |
|
650 | 651 | ui.status(_("nothing changed\n")) |
|
651 | 652 | return |
|
652 | 653 | cl = repo.changelog |
|
653 | 654 | rev = cl.rev(node) |
|
654 | 655 | parents = cl.parentrevs(rev) |
|
655 | 656 | if rev - 1 in parents: |
|
656 | 657 | # one of the parents was the old tip |
|
657 | 658 | pass |
|
658 | 659 | elif (parents == (nullrev, nullrev) or |
|
659 | 660 | len(cl.heads(cl.node(parents[0]))) > 1 and |
|
660 | 661 | (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)): |
|
661 | 662 | ui.status(_('created new head\n')) |
|
662 | 663 | |
|
663 | 664 | if ui.debugflag: |
|
664 | 665 | ui.write(_('committed changeset %d:%s\n') % (rev,hex(node))) |
|
665 | 666 | elif ui.verbose: |
|
666 | 667 | ui.write(_('committed changeset %d:%s\n') % (rev,short(node))) |
|
667 | 668 | |
|
668 | 669 | def copy(ui, repo, *pats, **opts): |
|
669 | 670 | """mark files as copied for the next commit |
|
670 | 671 | |
|
671 | 672 | Mark dest as having copies of source files. If dest is a directory, copies |
|
672 | 673 | are put in that directory. If dest is a file, the source must be a single |
|
673 | 674 | file. |
|
674 | 675 | |
|
675 | 676 | By default, this command copies the contents of files as they exist in the |
|
676 | 677 | working directory. If invoked with -A/--after, the operation is recorded, |
|
677 | 678 | but no copying is performed. |
|
678 | 679 | |
|
679 | 680 | This command takes effect with the next commit. To undo a copy before |
|
680 | 681 | that, see hg revert. |
|
681 | 682 | """ |
|
682 | 683 | wlock = repo.wlock(False) |
|
683 | 684 | try: |
|
684 | 685 | return cmdutil.copy(ui, repo, pats, opts) |
|
685 | 686 | finally: |
|
686 | 687 | wlock.release() |
|
687 | 688 | |
|
688 | 689 | def debugancestor(ui, repo, *args): |
|
689 | 690 | """find the ancestor revision of two revisions in a given index""" |
|
690 | 691 | if len(args) == 3: |
|
691 | 692 | index, rev1, rev2 = args |
|
692 | 693 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index) |
|
693 | 694 | lookup = r.lookup |
|
694 | 695 | elif len(args) == 2: |
|
695 | 696 | if not repo: |
|
696 | 697 | raise util.Abort(_("There is no Mercurial repository here " |
|
697 | 698 | "(.hg not found)")) |
|
698 | 699 | rev1, rev2 = args |
|
699 | 700 | r = repo.changelog |
|
700 | 701 | lookup = repo.lookup |
|
701 | 702 | else: |
|
702 | 703 | raise util.Abort(_('either two or three arguments required')) |
|
703 | 704 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
704 | 705 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
705 | 706 | |
|
706 | 707 | def debugcommands(ui, cmd='', *args): |
|
707 | 708 | for cmd, vals in sorted(table.iteritems()): |
|
708 | 709 | cmd = cmd.split('|')[0].strip('^') |
|
709 | 710 | opts = ', '.join([i[1] for i in vals[1]]) |
|
710 | 711 | ui.write('%s: %s\n' % (cmd, opts)) |
|
711 | 712 | |
|
712 | 713 | def debugcomplete(ui, cmd='', **opts): |
|
713 | 714 | """returns the completion list associated with the given command""" |
|
714 | 715 | |
|
715 | 716 | if opts.get('options'): |
|
716 | 717 | options = [] |
|
717 | 718 | otables = [globalopts] |
|
718 | 719 | if cmd: |
|
719 | 720 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
720 | 721 | otables.append(entry[1]) |
|
721 | 722 | for t in otables: |
|
722 | 723 | for o in t: |
|
723 | 724 | if o[0]: |
|
724 | 725 | options.append('-%s' % o[0]) |
|
725 | 726 | options.append('--%s' % o[1]) |
|
726 | 727 | ui.write("%s\n" % "\n".join(options)) |
|
727 | 728 | return |
|
728 | 729 | |
|
729 | 730 | cmdlist = cmdutil.findpossible(cmd, table) |
|
730 | 731 | if ui.verbose: |
|
731 | 732 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
732 | 733 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
733 | 734 | |
|
734 | 735 | def debugfsinfo(ui, path = "."): |
|
735 | 736 | open('.debugfsinfo', 'w').write('') |
|
736 | 737 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) |
|
737 | 738 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) |
|
738 | 739 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') |
|
739 | 740 | and 'yes' or 'no')) |
|
740 | 741 | os.unlink('.debugfsinfo') |
|
741 | 742 | |
|
742 | 743 | def debugrebuildstate(ui, repo, rev="tip"): |
|
743 | 744 | """rebuild the dirstate as it would look like for the given revision""" |
|
744 | 745 | ctx = repo[rev] |
|
745 | 746 | wlock = repo.wlock() |
|
746 | 747 | try: |
|
747 | 748 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
748 | 749 | finally: |
|
749 | 750 | wlock.release() |
|
750 | 751 | |
|
751 | 752 | def debugcheckstate(ui, repo): |
|
752 | 753 | """validate the correctness of the current dirstate""" |
|
753 | 754 | parent1, parent2 = repo.dirstate.parents() |
|
754 | 755 | m1 = repo[parent1].manifest() |
|
755 | 756 | m2 = repo[parent2].manifest() |
|
756 | 757 | errors = 0 |
|
757 | 758 | for f in repo.dirstate: |
|
758 | 759 | state = repo.dirstate[f] |
|
759 | 760 | if state in "nr" and f not in m1: |
|
760 | 761 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
761 | 762 | errors += 1 |
|
762 | 763 | if state in "a" and f in m1: |
|
763 | 764 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
764 | 765 | errors += 1 |
|
765 | 766 | if state in "m" and f not in m1 and f not in m2: |
|
766 | 767 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
767 | 768 | (f, state)) |
|
768 | 769 | errors += 1 |
|
769 | 770 | for f in m1: |
|
770 | 771 | state = repo.dirstate[f] |
|
771 | 772 | if state not in "nrm": |
|
772 | 773 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
773 | 774 | errors += 1 |
|
774 | 775 | if errors: |
|
775 | 776 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
776 | 777 | raise util.Abort(error) |
|
777 | 778 | |
|
778 | 779 | def showconfig(ui, repo, *values, **opts): |
|
779 | 780 | """show combined config settings from all hgrc files |
|
780 | 781 | |
|
781 | 782 | With no arguments, print names and values of all config items. |
|
782 | 783 | |
|
783 | 784 | With one argument of the form section.name, print just the value of that |
|
784 | 785 | config item. |
|
785 | 786 | |
|
786 | 787 | With multiple arguments, print names and values of all config items with |
|
787 | 788 | matching section names. |
|
788 | 789 | |
|
789 | 790 | With --debug, the source (filename and line number) is printed for each |
|
790 | 791 | config item. |
|
791 | 792 | """ |
|
792 | 793 | |
|
793 | 794 | untrusted = bool(opts.get('untrusted')) |
|
794 | 795 | if values: |
|
795 | 796 | if len([v for v in values if '.' in v]) > 1: |
|
796 | 797 | raise util.Abort(_('only one config item permitted')) |
|
797 | 798 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
798 | 799 | sectname = section + '.' + name |
|
799 | 800 | if values: |
|
800 | 801 | for v in values: |
|
801 | 802 | if v == section: |
|
802 | 803 | ui.debug('%s: ' % |
|
803 | 804 | ui.configsource(section, name, untrusted)) |
|
804 | 805 | ui.write('%s=%s\n' % (sectname, value)) |
|
805 | 806 | elif v == sectname: |
|
806 | 807 | ui.debug('%s: ' % |
|
807 | 808 | ui.configsource(section, name, untrusted)) |
|
808 | 809 | ui.write(value, '\n') |
|
809 | 810 | else: |
|
810 | 811 | ui.debug('%s: ' % |
|
811 | 812 | ui.configsource(section, name, untrusted)) |
|
812 | 813 | ui.write('%s=%s\n' % (sectname, value)) |
|
813 | 814 | |
|
814 | 815 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
815 | 816 | """manually set the parents of the current working directory |
|
816 | 817 | |
|
817 | 818 | This is useful for writing repository conversion tools, but should be used |
|
818 | 819 | with care. |
|
819 | 820 | """ |
|
820 | 821 | |
|
821 | 822 | if not rev2: |
|
822 | 823 | rev2 = hex(nullid) |
|
823 | 824 | |
|
824 | 825 | wlock = repo.wlock() |
|
825 | 826 | try: |
|
826 | 827 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
827 | 828 | finally: |
|
828 | 829 | wlock.release() |
|
829 | 830 | |
|
830 | 831 | def debugstate(ui, repo, nodates=None): |
|
831 | 832 | """show the contents of the current dirstate""" |
|
832 | 833 | timestr = "" |
|
833 | 834 | showdate = not nodates |
|
834 | 835 | for file_, ent in sorted(repo.dirstate._map.iteritems()): |
|
835 | 836 | if showdate: |
|
836 | 837 | if ent[3] == -1: |
|
837 | 838 | # Pad or slice to locale representation |
|
838 | 839 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0))) |
|
839 | 840 | timestr = 'unset' |
|
840 | 841 | timestr = timestr[:locale_len] + ' '*(locale_len - len(timestr)) |
|
841 | 842 | else: |
|
842 | 843 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])) |
|
843 | 844 | if ent[1] & 020000: |
|
844 | 845 | mode = 'lnk' |
|
845 | 846 | else: |
|
846 | 847 | mode = '%3o' % (ent[1] & 0777) |
|
847 | 848 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
848 | 849 | for f in repo.dirstate.copies(): |
|
849 | 850 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
850 | 851 | |
|
851 | 852 | def debugsub(ui, repo, rev=None): |
|
852 | 853 | if rev == '': |
|
853 | 854 | rev = None |
|
854 | 855 | for k,v in sorted(repo[rev].substate.items()): |
|
855 | 856 | ui.write('path %s\n' % k) |
|
856 | 857 | ui.write(' source %s\n' % v[0]) |
|
857 | 858 | ui.write(' revision %s\n' % v[1]) |
|
858 | 859 | |
|
859 | 860 | def debugdata(ui, file_, rev): |
|
860 | 861 | """dump the contents of a data file revision""" |
|
861 | 862 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_[:-2] + ".i") |
|
862 | 863 | try: |
|
863 | 864 | ui.write(r.revision(r.lookup(rev))) |
|
864 | 865 | except KeyError: |
|
865 | 866 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
866 | 867 | |
|
867 | 868 | def debugdate(ui, date, range=None, **opts): |
|
868 | 869 | """parse and display a date""" |
|
869 | 870 | if opts["extended"]: |
|
870 | 871 | d = util.parsedate(date, util.extendeddateformats) |
|
871 | 872 | else: |
|
872 | 873 | d = util.parsedate(date) |
|
873 | 874 | ui.write("internal: %s %s\n" % d) |
|
874 | 875 | ui.write("standard: %s\n" % util.datestr(d)) |
|
875 | 876 | if range: |
|
876 | 877 | m = util.matchdate(range) |
|
877 | 878 | ui.write("match: %s\n" % m(d[0])) |
|
878 | 879 | |
|
879 | 880 | def debugindex(ui, file_): |
|
880 | 881 | """dump the contents of an index file""" |
|
881 | 882 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) |
|
882 | 883 | ui.write(" rev offset length base linkrev" |
|
883 | 884 | " nodeid p1 p2\n") |
|
884 | 885 | for i in r: |
|
885 | 886 | node = r.node(i) |
|
886 | 887 | try: |
|
887 | 888 | pp = r.parents(node) |
|
888 | 889 | except: |
|
889 | 890 | pp = [nullid, nullid] |
|
890 | 891 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
891 | 892 | i, r.start(i), r.length(i), r.base(i), r.linkrev(i), |
|
892 | 893 | short(node), short(pp[0]), short(pp[1]))) |
|
893 | 894 | |
|
894 | 895 | def debugindexdot(ui, file_): |
|
895 | 896 | """dump an index DAG as a graphviz dot file""" |
|
896 | 897 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_) |
|
897 | 898 | ui.write("digraph G {\n") |
|
898 | 899 | for i in r: |
|
899 | 900 | node = r.node(i) |
|
900 | 901 | pp = r.parents(node) |
|
901 | 902 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
902 | 903 | if pp[1] != nullid: |
|
903 | 904 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
904 | 905 | ui.write("}\n") |
|
905 | 906 | |
|
906 | 907 | def debuginstall(ui): |
|
907 | 908 | '''test Mercurial installation''' |
|
908 | 909 | |
|
909 | 910 | def writetemp(contents): |
|
910 | 911 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
911 | 912 | f = os.fdopen(fd, "wb") |
|
912 | 913 | f.write(contents) |
|
913 | 914 | f.close() |
|
914 | 915 | return name |
|
915 | 916 | |
|
916 | 917 | problems = 0 |
|
917 | 918 | |
|
918 | 919 | # encoding |
|
919 | 920 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) |
|
920 | 921 | try: |
|
921 | 922 | encoding.fromlocal("test") |
|
922 | 923 | except util.Abort, inst: |
|
923 | 924 | ui.write(" %s\n" % inst) |
|
924 | 925 | ui.write(_(" (check that your locale is properly set)\n")) |
|
925 | 926 | problems += 1 |
|
926 | 927 | |
|
927 | 928 | # compiled modules |
|
928 | 929 | ui.status(_("Checking extensions...\n")) |
|
929 | 930 | try: |
|
930 | 931 | import bdiff, mpatch, base85 |
|
931 | 932 | except Exception, inst: |
|
932 | 933 | ui.write(" %s\n" % inst) |
|
933 | 934 | ui.write(_(" One or more extensions could not be found")) |
|
934 | 935 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
935 | 936 | problems += 1 |
|
936 | 937 | |
|
937 | 938 | # templates |
|
938 | 939 | ui.status(_("Checking templates...\n")) |
|
939 | 940 | try: |
|
940 | 941 | import templater |
|
941 | 942 | templater.templater(templater.templatepath("map-cmdline.default")) |
|
942 | 943 | except Exception, inst: |
|
943 | 944 | ui.write(" %s\n" % inst) |
|
944 | 945 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
945 | 946 | problems += 1 |
|
946 | 947 | |
|
947 | 948 | # patch |
|
948 | 949 | ui.status(_("Checking patch...\n")) |
|
949 | 950 | patchproblems = 0 |
|
950 | 951 | a = "1\n2\n3\n4\n" |
|
951 | 952 | b = "1\n2\n3\ninsert\n4\n" |
|
952 | 953 | fa = writetemp(a) |
|
953 | 954 | d = mdiff.unidiff(a, None, b, None, os.path.basename(fa), |
|
954 | 955 | os.path.basename(fa)) |
|
955 | 956 | fd = writetemp(d) |
|
956 | 957 | |
|
957 | 958 | files = {} |
|
958 | 959 | try: |
|
959 | 960 | patch.patch(fd, ui, cwd=os.path.dirname(fa), files=files) |
|
960 | 961 | except util.Abort, e: |
|
961 | 962 | ui.write(_(" patch call failed:\n")) |
|
962 | 963 | ui.write(" " + str(e) + "\n") |
|
963 | 964 | patchproblems += 1 |
|
964 | 965 | else: |
|
965 | 966 | if list(files) != [os.path.basename(fa)]: |
|
966 | 967 | ui.write(_(" unexpected patch output!\n")) |
|
967 | 968 | patchproblems += 1 |
|
968 | 969 | a = open(fa).read() |
|
969 | 970 | if a != b: |
|
970 | 971 | ui.write(_(" patch test failed!\n")) |
|
971 | 972 | patchproblems += 1 |
|
972 | 973 | |
|
973 | 974 | if patchproblems: |
|
974 | 975 | if ui.config('ui', 'patch'): |
|
975 | 976 | ui.write(_(" (Current patch tool may be incompatible with patch," |
|
976 | 977 | " or misconfigured. Please check your .hgrc file)\n")) |
|
977 | 978 | else: |
|
978 | 979 | ui.write(_(" Internal patcher failure, please report this error" |
|
979 | 980 | " to http://mercurial.selenic.com/bts/\n")) |
|
980 | 981 | problems += patchproblems |
|
981 | 982 | |
|
982 | 983 | os.unlink(fa) |
|
983 | 984 | os.unlink(fd) |
|
984 | 985 | |
|
985 | 986 | # editor |
|
986 | 987 | ui.status(_("Checking commit editor...\n")) |
|
987 | 988 | editor = ui.geteditor() |
|
988 | 989 | cmdpath = util.find_exe(editor) or util.find_exe(editor.split()[0]) |
|
989 | 990 | if not cmdpath: |
|
990 | 991 | if editor == 'vi': |
|
991 | 992 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
992 | 993 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
993 | 994 | else: |
|
994 | 995 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
995 | 996 | ui.write(_(" (specify a commit editor in your .hgrc file)\n")) |
|
996 | 997 | problems += 1 |
|
997 | 998 | |
|
998 | 999 | # check username |
|
999 | 1000 | ui.status(_("Checking username...\n")) |
|
1000 | 1001 | user = os.environ.get("HGUSER") |
|
1001 | 1002 | if user is None: |
|
1002 | 1003 | user = ui.config("ui", "username") |
|
1003 | 1004 | if user is None: |
|
1004 | 1005 | user = os.environ.get("EMAIL") |
|
1005 | 1006 | if not user: |
|
1006 | 1007 | ui.warn(" ") |
|
1007 | 1008 | ui.username() |
|
1008 | 1009 | ui.write(_(" (specify a username in your .hgrc file)\n")) |
|
1009 | 1010 | |
|
1010 | 1011 | if not problems: |
|
1011 | 1012 | ui.status(_("No problems detected\n")) |
|
1012 | 1013 | else: |
|
1013 | 1014 | ui.write(_("%s problems detected," |
|
1014 | 1015 | " please check your install!\n") % problems) |
|
1015 | 1016 | |
|
1016 | 1017 | return problems |
|
1017 | 1018 | |
|
1018 | 1019 | def debugrename(ui, repo, file1, *pats, **opts): |
|
1019 | 1020 | """dump rename information""" |
|
1020 | 1021 | |
|
1021 | 1022 | ctx = repo[opts.get('rev')] |
|
1022 | 1023 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
1023 | 1024 | for abs in ctx.walk(m): |
|
1024 | 1025 | fctx = ctx[abs] |
|
1025 | 1026 | o = fctx.filelog().renamed(fctx.filenode()) |
|
1026 | 1027 | rel = m.rel(abs) |
|
1027 | 1028 | if o: |
|
1028 | 1029 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
1029 | 1030 | else: |
|
1030 | 1031 | ui.write(_("%s not renamed\n") % rel) |
|
1031 | 1032 | |
|
1032 | 1033 | def debugwalk(ui, repo, *pats, **opts): |
|
1033 | 1034 | """show how files match on given patterns""" |
|
1034 | 1035 | m = cmdutil.match(repo, pats, opts) |
|
1035 | 1036 | items = list(repo.walk(m)) |
|
1036 | 1037 | if not items: |
|
1037 | 1038 | return |
|
1038 | 1039 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
1039 | 1040 | max([len(abs) for abs in items]), |
|
1040 | 1041 | max([len(m.rel(abs)) for abs in items])) |
|
1041 | 1042 | for abs in items: |
|
1042 | 1043 | line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') |
|
1043 | 1044 | ui.write("%s\n" % line.rstrip()) |
|
1044 | 1045 | |
|
1045 | 1046 | def diff(ui, repo, *pats, **opts): |
|
1046 | 1047 | """diff repository (or selected files) |
|
1047 | 1048 | |
|
1048 | 1049 | Show differences between revisions for the specified files. |
|
1049 | 1050 | |
|
1050 | 1051 | Differences between files are shown using the unified diff format. |
|
1051 | 1052 | |
|
1052 | 1053 | NOTE: diff may generate unexpected results for merges, as it will default |
|
1053 | 1054 | to comparing against the working directory's first parent changeset if no |
|
1054 | 1055 | revisions are specified. |
|
1055 | 1056 | |
|
1056 | 1057 | When two revision arguments are given, then changes are shown between |
|
1057 | 1058 | those revisions. If only one revision is specified then that revision is |
|
1058 | 1059 | compared to the working directory, and, when no revisions are specified, |
|
1059 | 1060 | the working directory files are compared to its parent. |
|
1060 | 1061 | |
|
1061 | 1062 | Without the -a/--text option, diff will avoid generating diffs of files it |
|
1062 | 1063 | detects as binary. With -a, diff will generate a diff anyway, probably |
|
1063 | 1064 | with undesirable results. |
|
1064 | 1065 | |
|
1065 | 1066 | Use the -g/--git option to generate diffs in the git extended diff format. |
|
1066 | 1067 | For more information, read 'hg help diffs'. |
|
1067 | 1068 | """ |
|
1068 | 1069 | |
|
1069 | 1070 | revs = opts.get('rev') |
|
1070 | 1071 | change = opts.get('change') |
|
1071 | 1072 | |
|
1072 | 1073 | if revs and change: |
|
1073 | 1074 | msg = _('cannot specify --rev and --change at the same time') |
|
1074 | 1075 | raise util.Abort(msg) |
|
1075 | 1076 | elif change: |
|
1076 | 1077 | node2 = repo.lookup(change) |
|
1077 | 1078 | node1 = repo[node2].parents()[0].node() |
|
1078 | 1079 | else: |
|
1079 | 1080 | node1, node2 = cmdutil.revpair(repo, revs) |
|
1080 | 1081 | |
|
1081 | 1082 | m = cmdutil.match(repo, pats, opts) |
|
1082 | 1083 | it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts)) |
|
1083 | 1084 | for chunk in it: |
|
1084 | 1085 | ui.write(chunk) |
|
1085 | 1086 | |
|
1086 | 1087 | def export(ui, repo, *changesets, **opts): |
|
1087 | 1088 | """dump the header and diffs for one or more changesets |
|
1088 | 1089 | |
|
1089 | 1090 | Print the changeset header and diffs for one or more revisions. |
|
1090 | 1091 | |
|
1091 | 1092 | The information shown in the changeset header is: author, changeset hash, |
|
1092 | 1093 | parent(s) and commit comment. |
|
1093 | 1094 | |
|
1094 | 1095 | NOTE: export may generate unexpected diff output for merge changesets, as |
|
1095 | 1096 | it will compare the merge changeset against its first parent only. |
|
1096 | 1097 | |
|
1097 | 1098 | Output may be to a file, in which case the name of the file is given using |
|
1098 | a format string. The formatting rules are as follows: | |
|
1099 | ||
|
1100 | %% literal "%" character | |
|
1101 | %H changeset hash (40 bytes of hexadecimal) | |
|
1102 | %N number of patches being generated | |
|
1103 | %R changeset revision number | |
|
1104 | %b basename of the exporting repository | |
|
1105 | %h short-form changeset hash (12 bytes of hexadecimal) | |
|
1106 | %n zero-padded sequence number, starting at 1 | |
|
1107 | %r zero-padded changeset revision number | |
|
1099 | a format string. The formatting rules are as follows:: | |
|
1100 | ||
|
1101 | %% literal "%" character | |
|
1102 | %H changeset hash (40 bytes of hexadecimal) | |
|
1103 | %N number of patches being generated | |
|
1104 | %R changeset revision number | |
|
1105 | %b basename of the exporting repository | |
|
1106 | %h short-form changeset hash (12 bytes of hexadecimal) | |
|
1107 | %n zero-padded sequence number, starting at 1 | |
|
1108 | %r zero-padded changeset revision number | |
|
1108 | 1109 | |
|
1109 | 1110 | Without the -a/--text option, export will avoid generating diffs of files |
|
1110 | 1111 | it detects as binary. With -a, export will generate a diff anyway, |
|
1111 | 1112 | probably with undesirable results. |
|
1112 | 1113 | |
|
1113 | 1114 | Use the -g/--git option to generate diffs in the git extended diff format. |
|
1114 | 1115 | See 'hg help diffs' for more information. |
|
1115 | 1116 | |
|
1116 | 1117 | With the --switch-parent option, the diff will be against the second |
|
1117 | 1118 | parent. It can be useful to review a merge. |
|
1118 | 1119 | """ |
|
1119 | 1120 | if not changesets: |
|
1120 | 1121 | raise util.Abort(_("export requires at least one changeset")) |
|
1121 | 1122 | revs = cmdutil.revrange(repo, changesets) |
|
1122 | 1123 | if len(revs) > 1: |
|
1123 | 1124 | ui.note(_('exporting patches:\n')) |
|
1124 | 1125 | else: |
|
1125 | 1126 | ui.note(_('exporting patch:\n')) |
|
1126 | 1127 | patch.export(repo, revs, template=opts.get('output'), |
|
1127 | 1128 | switch_parent=opts.get('switch_parent'), |
|
1128 | 1129 | opts=patch.diffopts(ui, opts)) |
|
1129 | 1130 | |
|
1130 | 1131 | def forget(ui, repo, *pats, **opts): |
|
1131 | 1132 | """forget the specified files on the next commit |
|
1132 | 1133 | |
|
1133 | 1134 | Mark the specified files so they will no longer be tracked after the next |
|
1134 | 1135 | commit. |
|
1135 | 1136 | |
|
1136 | 1137 | This only removes files from the current branch, not from the entire |
|
1137 | 1138 | project history, and it does not delete them from the working directory. |
|
1138 | 1139 | |
|
1139 | 1140 | To undo a forget before the next commit, see hg add. |
|
1140 | 1141 | """ |
|
1141 | 1142 | |
|
1142 | 1143 | if not pats: |
|
1143 | 1144 | raise util.Abort(_('no files specified')) |
|
1144 | 1145 | |
|
1145 | 1146 | m = cmdutil.match(repo, pats, opts) |
|
1146 | 1147 | s = repo.status(match=m, clean=True) |
|
1147 | 1148 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
1148 | 1149 | |
|
1149 | 1150 | for f in m.files(): |
|
1150 | 1151 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
1151 | 1152 | ui.warn(_('not removing %s: file is already untracked\n') |
|
1152 | 1153 | % m.rel(f)) |
|
1153 | 1154 | |
|
1154 | 1155 | for f in forget: |
|
1155 | 1156 | if ui.verbose or not m.exact(f): |
|
1156 | 1157 | ui.status(_('removing %s\n') % m.rel(f)) |
|
1157 | 1158 | |
|
1158 | 1159 | repo.remove(forget, unlink=False) |
|
1159 | 1160 | |
|
1160 | 1161 | def grep(ui, repo, pattern, *pats, **opts): |
|
1161 | 1162 | """search for a pattern in specified files and revisions |
|
1162 | 1163 | |
|
1163 | 1164 | Search revisions of files for a regular expression. |
|
1164 | 1165 | |
|
1165 | 1166 | This command behaves differently than Unix grep. It only accepts |
|
1166 | 1167 | Python/Perl regexps. It searches repository history, not the working |
|
1167 | 1168 | directory. It always prints the revision number in which a match appears. |
|
1168 | 1169 | |
|
1169 | 1170 | By default, grep only prints output for the first revision of a file in |
|
1170 | 1171 | which it finds a match. To get it to print every revision that contains a |
|
1171 | 1172 | change in match status ("-" for a match that becomes a non-match, or "+" |
|
1172 | 1173 | for a non-match that becomes a match), use the --all flag. |
|
1173 | 1174 | """ |
|
1174 | 1175 | reflags = 0 |
|
1175 | 1176 | if opts.get('ignore_case'): |
|
1176 | 1177 | reflags |= re.I |
|
1177 | 1178 | try: |
|
1178 | 1179 | regexp = re.compile(pattern, reflags) |
|
1179 | 1180 | except Exception, inst: |
|
1180 | 1181 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
1181 | 1182 | return None |
|
1182 | 1183 | sep, eol = ':', '\n' |
|
1183 | 1184 | if opts.get('print0'): |
|
1184 | 1185 | sep = eol = '\0' |
|
1185 | 1186 | |
|
1186 | 1187 | getfile = util.lrucachefunc(repo.file) |
|
1187 | 1188 | |
|
1188 | 1189 | def matchlines(body): |
|
1189 | 1190 | begin = 0 |
|
1190 | 1191 | linenum = 0 |
|
1191 | 1192 | while True: |
|
1192 | 1193 | match = regexp.search(body, begin) |
|
1193 | 1194 | if not match: |
|
1194 | 1195 | break |
|
1195 | 1196 | mstart, mend = match.span() |
|
1196 | 1197 | linenum += body.count('\n', begin, mstart) + 1 |
|
1197 | 1198 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1198 | 1199 | begin = body.find('\n', mend) + 1 or len(body) |
|
1199 | 1200 | lend = begin - 1 |
|
1200 | 1201 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1201 | 1202 | |
|
1202 | 1203 | class linestate(object): |
|
1203 | 1204 | def __init__(self, line, linenum, colstart, colend): |
|
1204 | 1205 | self.line = line |
|
1205 | 1206 | self.linenum = linenum |
|
1206 | 1207 | self.colstart = colstart |
|
1207 | 1208 | self.colend = colend |
|
1208 | 1209 | |
|
1209 | 1210 | def __hash__(self): |
|
1210 | 1211 | return hash((self.linenum, self.line)) |
|
1211 | 1212 | |
|
1212 | 1213 | def __eq__(self, other): |
|
1213 | 1214 | return self.line == other.line |
|
1214 | 1215 | |
|
1215 | 1216 | matches = {} |
|
1216 | 1217 | copies = {} |
|
1217 | 1218 | def grepbody(fn, rev, body): |
|
1218 | 1219 | matches[rev].setdefault(fn, []) |
|
1219 | 1220 | m = matches[rev][fn] |
|
1220 | 1221 | for lnum, cstart, cend, line in matchlines(body): |
|
1221 | 1222 | s = linestate(line, lnum, cstart, cend) |
|
1222 | 1223 | m.append(s) |
|
1223 | 1224 | |
|
1224 | 1225 | def difflinestates(a, b): |
|
1225 | 1226 | sm = difflib.SequenceMatcher(None, a, b) |
|
1226 | 1227 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
1227 | 1228 | if tag == 'insert': |
|
1228 | 1229 | for i in xrange(blo, bhi): |
|
1229 | 1230 | yield ('+', b[i]) |
|
1230 | 1231 | elif tag == 'delete': |
|
1231 | 1232 | for i in xrange(alo, ahi): |
|
1232 | 1233 | yield ('-', a[i]) |
|
1233 | 1234 | elif tag == 'replace': |
|
1234 | 1235 | for i in xrange(alo, ahi): |
|
1235 | 1236 | yield ('-', a[i]) |
|
1236 | 1237 | for i in xrange(blo, bhi): |
|
1237 | 1238 | yield ('+', b[i]) |
|
1238 | 1239 | |
|
1239 | 1240 | def display(fn, r, pstates, states): |
|
1240 | 1241 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
1241 | 1242 | found = False |
|
1242 | 1243 | filerevmatches = {} |
|
1243 | 1244 | if opts.get('all'): |
|
1244 | 1245 | iter = difflinestates(pstates, states) |
|
1245 | 1246 | else: |
|
1246 | 1247 | iter = [('', l) for l in states] |
|
1247 | 1248 | for change, l in iter: |
|
1248 | 1249 | cols = [fn, str(r)] |
|
1249 | 1250 | if opts.get('line_number'): |
|
1250 | 1251 | cols.append(str(l.linenum)) |
|
1251 | 1252 | if opts.get('all'): |
|
1252 | 1253 | cols.append(change) |
|
1253 | 1254 | if opts.get('user'): |
|
1254 | 1255 | cols.append(ui.shortuser(get(r)[1])) |
|
1255 | 1256 | if opts.get('date'): |
|
1256 | 1257 | cols.append(datefunc(get(r)[2])) |
|
1257 | 1258 | if opts.get('files_with_matches'): |
|
1258 | 1259 | c = (fn, r) |
|
1259 | 1260 | if c in filerevmatches: |
|
1260 | 1261 | continue |
|
1261 | 1262 | filerevmatches[c] = 1 |
|
1262 | 1263 | else: |
|
1263 | 1264 | cols.append(l.line) |
|
1264 | 1265 | ui.write(sep.join(cols), eol) |
|
1265 | 1266 | found = True |
|
1266 | 1267 | return found |
|
1267 | 1268 | |
|
1268 | 1269 | skip = {} |
|
1269 | 1270 | revfiles = {} |
|
1270 | 1271 | get = util.cachefunc(lambda r: repo[r].changeset()) |
|
1271 | 1272 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1272 | 1273 | found = False |
|
1273 | 1274 | follow = opts.get('follow') |
|
1274 | 1275 | for st, rev, fns in changeiter: |
|
1275 | 1276 | if st == 'window': |
|
1276 | 1277 | matches.clear() |
|
1277 | 1278 | revfiles.clear() |
|
1278 | 1279 | elif st == 'add': |
|
1279 | 1280 | ctx = repo[rev] |
|
1280 | 1281 | pctx = ctx.parents()[0] |
|
1281 | 1282 | parent = pctx.rev() |
|
1282 | 1283 | matches.setdefault(rev, {}) |
|
1283 | 1284 | matches.setdefault(parent, {}) |
|
1284 | 1285 | files = revfiles.setdefault(rev, []) |
|
1285 | 1286 | for fn in fns: |
|
1286 | 1287 | flog = getfile(fn) |
|
1287 | 1288 | try: |
|
1288 | 1289 | fnode = ctx.filenode(fn) |
|
1289 | 1290 | except error.LookupError: |
|
1290 | 1291 | continue |
|
1291 | 1292 | |
|
1292 | 1293 | copied = flog.renamed(fnode) |
|
1293 | 1294 | copy = follow and copied and copied[0] |
|
1294 | 1295 | if copy: |
|
1295 | 1296 | copies.setdefault(rev, {})[fn] = copy |
|
1296 | 1297 | if fn in skip: |
|
1297 | 1298 | if copy: |
|
1298 | 1299 | skip[copy] = True |
|
1299 | 1300 | continue |
|
1300 | 1301 | files.append(fn) |
|
1301 | 1302 | |
|
1302 | 1303 | if not matches[rev].has_key(fn): |
|
1303 | 1304 | grepbody(fn, rev, flog.read(fnode)) |
|
1304 | 1305 | |
|
1305 | 1306 | pfn = copy or fn |
|
1306 | 1307 | if not matches[parent].has_key(pfn): |
|
1307 | 1308 | try: |
|
1308 | 1309 | fnode = pctx.filenode(pfn) |
|
1309 | 1310 | grepbody(pfn, parent, flog.read(fnode)) |
|
1310 | 1311 | except error.LookupError: |
|
1311 | 1312 | pass |
|
1312 | 1313 | elif st == 'iter': |
|
1313 | 1314 | parent = repo[rev].parents()[0].rev() |
|
1314 | 1315 | for fn in sorted(revfiles.get(rev, [])): |
|
1315 | 1316 | states = matches[rev][fn] |
|
1316 | 1317 | copy = copies.get(rev, {}).get(fn) |
|
1317 | 1318 | if fn in skip: |
|
1318 | 1319 | if copy: |
|
1319 | 1320 | skip[copy] = True |
|
1320 | 1321 | continue |
|
1321 | 1322 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
1322 | 1323 | if pstates or states: |
|
1323 | 1324 | r = display(fn, rev, pstates, states) |
|
1324 | 1325 | found = found or r |
|
1325 | 1326 | if r and not opts.get('all'): |
|
1326 | 1327 | skip[fn] = True |
|
1327 | 1328 | if copy: |
|
1328 | 1329 | skip[copy] = True |
|
1329 | 1330 | |
|
1330 | 1331 | def heads(ui, repo, *branchrevs, **opts): |
|
1331 | 1332 | """show current repository heads or show branch heads |
|
1332 | 1333 | |
|
1333 | 1334 | With no arguments, show all repository head changesets. |
|
1334 | 1335 | |
|
1335 | 1336 | Repository "heads" are changesets that don't have child changesets. They |
|
1336 | 1337 | are where development generally takes place and are the usual targets for |
|
1337 | 1338 | update and merge operations. |
|
1338 | 1339 | |
|
1339 | 1340 | If one or more REV is given, the "branch heads" will be shown for the |
|
1340 | 1341 | named branch associated with that revision. The name of the branch is |
|
1341 | 1342 | called the revision's branch tag. |
|
1342 | 1343 | |
|
1343 | 1344 | Branch heads are revisions on a given named branch that do not have any |
|
1344 | 1345 | descendants on the same branch. A branch head could be a true head or it |
|
1345 | 1346 | could be the last changeset on a branch before a new branch was created. |
|
1346 | 1347 | If none of the branch heads are true heads, the branch is considered |
|
1347 | 1348 | inactive. If -c/--closed is specified, also show branch heads marked |
|
1348 | 1349 | closed (see hg commit --close-branch). |
|
1349 | 1350 | |
|
1350 | 1351 | If STARTREV is specified only those heads (or branch heads) that are |
|
1351 | 1352 | descendants of STARTREV will be displayed. |
|
1352 | 1353 | """ |
|
1353 | 1354 | if opts.get('rev'): |
|
1354 | 1355 | start = repo.lookup(opts['rev']) |
|
1355 | 1356 | else: |
|
1356 | 1357 | start = None |
|
1357 | 1358 | closed = opts.get('closed') |
|
1358 | 1359 | hideinactive, _heads = opts.get('active'), None |
|
1359 | 1360 | if not branchrevs: |
|
1360 | 1361 | # Assume we're looking repo-wide heads if no revs were specified. |
|
1361 | 1362 | heads = repo.heads(start) |
|
1362 | 1363 | else: |
|
1363 | 1364 | if hideinactive: |
|
1364 | 1365 | _heads = repo.heads(start) |
|
1365 | 1366 | heads = [] |
|
1366 | 1367 | visitedset = set() |
|
1367 | 1368 | for branchrev in branchrevs: |
|
1368 | 1369 | branch = repo[branchrev].branch() |
|
1369 | 1370 | if branch in visitedset: |
|
1370 | 1371 | continue |
|
1371 | 1372 | visitedset.add(branch) |
|
1372 | 1373 | bheads = repo.branchheads(branch, start, closed=closed) |
|
1373 | 1374 | if not bheads: |
|
1374 | 1375 | if not opts.get('rev'): |
|
1375 | 1376 | ui.warn(_("no open branch heads on branch %s\n") % branch) |
|
1376 | 1377 | elif branch != branchrev: |
|
1377 | 1378 | ui.warn(_("no changes on branch %s containing %s are " |
|
1378 | 1379 | "reachable from %s\n") |
|
1379 | 1380 | % (branch, branchrev, opts.get('rev'))) |
|
1380 | 1381 | else: |
|
1381 | 1382 | ui.warn(_("no changes on branch %s are reachable from %s\n") |
|
1382 | 1383 | % (branch, opts.get('rev'))) |
|
1383 | 1384 | if hideinactive: |
|
1384 | 1385 | bheads = [bhead for bhead in bheads if bhead in _heads] |
|
1385 | 1386 | heads.extend(bheads) |
|
1386 | 1387 | if not heads: |
|
1387 | 1388 | return 1 |
|
1388 | 1389 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
1389 | 1390 | for n in heads: |
|
1390 | 1391 | displayer.show(repo[n]) |
|
1391 | 1392 | |
|
1392 | 1393 | def help_(ui, name=None, with_version=False): |
|
1393 | 1394 | """show help for a given topic or a help overview |
|
1394 | 1395 | |
|
1395 | 1396 | With no arguments, print a list of commands with short help messages. |
|
1396 | 1397 | |
|
1397 | 1398 | Given a topic, extension, or command name, print help for that topic. |
|
1398 | 1399 | """ |
|
1399 | 1400 | option_lists = [] |
|
1401 | textwidth = util.termwidth() - 2 | |
|
1400 | 1402 | |
|
1401 | 1403 | def addglobalopts(aliases): |
|
1402 | 1404 | if ui.verbose: |
|
1403 | 1405 | option_lists.append((_("global options:"), globalopts)) |
|
1404 | 1406 | if name == 'shortlist': |
|
1405 | 1407 | option_lists.append((_('use "hg help" for the full list ' |
|
1406 | 1408 | 'of commands'), ())) |
|
1407 | 1409 | else: |
|
1408 | 1410 | if name == 'shortlist': |
|
1409 | 1411 | msg = _('use "hg help" for the full list of commands ' |
|
1410 | 1412 | 'or "hg -v" for details') |
|
1411 | 1413 | elif aliases: |
|
1412 | 1414 | msg = _('use "hg -v help%s" to show aliases and ' |
|
1413 | 1415 | 'global options') % (name and " " + name or "") |
|
1414 | 1416 | else: |
|
1415 | 1417 | msg = _('use "hg -v help %s" to show global options') % name |
|
1416 | 1418 | option_lists.append((msg, ())) |
|
1417 | 1419 | |
|
1418 | 1420 | def helpcmd(name): |
|
1419 | 1421 | if with_version: |
|
1420 | 1422 | version_(ui) |
|
1421 | 1423 | ui.write('\n') |
|
1422 | 1424 | |
|
1423 | 1425 | try: |
|
1424 | 1426 | aliases, i = cmdutil.findcmd(name, table, False) |
|
1425 | 1427 | except error.AmbiguousCommand, inst: |
|
1426 | 1428 | # py3k fix: except vars can't be used outside the scope of the |
|
1427 | 1429 | # except block, nor can be used inside a lambda. python issue4617 |
|
1428 | 1430 | prefix = inst.args[0] |
|
1429 | 1431 | select = lambda c: c.lstrip('^').startswith(prefix) |
|
1430 | 1432 | helplist(_('list of commands:\n\n'), select) |
|
1431 | 1433 | return |
|
1432 | 1434 | |
|
1433 | 1435 | # synopsis |
|
1434 | 1436 | if len(i) > 2: |
|
1435 | 1437 | if i[2].startswith('hg'): |
|
1436 | 1438 | ui.write("%s\n" % i[2]) |
|
1437 | 1439 | else: |
|
1438 | 1440 | ui.write('hg %s %s\n' % (aliases[0], i[2])) |
|
1439 | 1441 | else: |
|
1440 | 1442 | ui.write('hg %s\n' % aliases[0]) |
|
1441 | 1443 | |
|
1442 | 1444 | # aliases |
|
1443 | 1445 | if not ui.quiet and len(aliases) > 1: |
|
1444 | 1446 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
1445 | 1447 | |
|
1446 | 1448 | # description |
|
1447 | 1449 | doc = gettext(i[0].__doc__) |
|
1448 | 1450 | if not doc: |
|
1449 | 1451 | doc = _("(no help text available)") |
|
1450 | 1452 | if ui.quiet: |
|
1451 | 1453 | doc = doc.splitlines()[0] |
|
1452 |
ui.write("\n%s\n" % doc |
|
|
1454 | ui.write("\n%s\n" % minirst.format(doc, textwidth)) | |
|
1453 | 1455 | |
|
1454 | 1456 | if not ui.quiet: |
|
1455 | 1457 | # options |
|
1456 | 1458 | if i[1]: |
|
1457 | 1459 | option_lists.append((_("options:\n"), i[1])) |
|
1458 | 1460 | |
|
1459 | 1461 | addglobalopts(False) |
|
1460 | 1462 | |
|
1461 | 1463 | def helplist(header, select=None): |
|
1462 | 1464 | h = {} |
|
1463 | 1465 | cmds = {} |
|
1464 | 1466 | for c, e in table.iteritems(): |
|
1465 | 1467 | f = c.split("|", 1)[0] |
|
1466 | 1468 | if select and not select(f): |
|
1467 | 1469 | continue |
|
1468 | 1470 | if (not select and name != 'shortlist' and |
|
1469 | 1471 | e[0].__module__ != __name__): |
|
1470 | 1472 | continue |
|
1471 | 1473 | if name == "shortlist" and not f.startswith("^"): |
|
1472 | 1474 | continue |
|
1473 | 1475 | f = f.lstrip("^") |
|
1474 | 1476 | if not ui.debugflag and f.startswith("debug"): |
|
1475 | 1477 | continue |
|
1476 | 1478 | doc = e[0].__doc__ |
|
1477 | 1479 | if doc and 'DEPRECATED' in doc and not ui.verbose: |
|
1478 | 1480 | continue |
|
1479 | 1481 | doc = gettext(doc) |
|
1480 | 1482 | if not doc: |
|
1481 | 1483 | doc = _("(no help text available)") |
|
1482 | 1484 | h[f] = doc.splitlines()[0].rstrip() |
|
1483 | 1485 | cmds[f] = c.lstrip("^") |
|
1484 | 1486 | |
|
1485 | 1487 | if not h: |
|
1486 | 1488 | ui.status(_('no commands defined\n')) |
|
1487 | 1489 | return |
|
1488 | 1490 | |
|
1489 | 1491 | ui.status(header) |
|
1490 | 1492 | fns = sorted(h) |
|
1491 | 1493 | m = max(map(len, fns)) |
|
1492 | 1494 | for f in fns: |
|
1493 | 1495 | if ui.verbose: |
|
1494 | 1496 | commands = cmds[f].replace("|",", ") |
|
1495 | 1497 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
1496 | 1498 | else: |
|
1497 | 1499 | ui.write(' %-*s %s\n' % (m, f, util.wrap(h[f], m + 4))) |
|
1498 | 1500 | |
|
1499 | 1501 | if name != 'shortlist': |
|
1500 | 1502 | exts, maxlength = extensions.enabled() |
|
1501 |
|
|
|
1503 | text = help.listexts(_('enabled extensions:'), exts, maxlength) | |
|
1504 | if text: | |
|
1505 | ui.write("\n%s\n" % minirst.format(text, textwidth)) | |
|
1502 | 1506 | |
|
1503 | 1507 | if not ui.quiet: |
|
1504 | 1508 | addglobalopts(True) |
|
1505 | 1509 | |
|
1506 | 1510 | def helptopic(name): |
|
1507 | 1511 | for names, header, doc in help.helptable: |
|
1508 | 1512 | if name in names: |
|
1509 | 1513 | break |
|
1510 | 1514 | else: |
|
1511 | 1515 | raise error.UnknownCommand(name) |
|
1512 | 1516 | |
|
1513 | 1517 | # description |
|
1514 | 1518 | if not doc: |
|
1515 | 1519 | doc = _("(no help text available)") |
|
1516 | 1520 | if hasattr(doc, '__call__'): |
|
1517 | 1521 | doc = doc() |
|
1518 | 1522 | |
|
1519 | ui.write("%s\n" % header) | |
|
1520 |
ui.write("%s\n" % doc |
|
|
1523 | ui.write("%s\n\n" % header) | |
|
1524 | ui.write("%s\n" % minirst.format(doc, textwidth)) | |
|
1521 | 1525 | |
|
1522 | 1526 | def helpext(name): |
|
1523 | 1527 | try: |
|
1524 | 1528 | mod = extensions.find(name) |
|
1525 | 1529 | except KeyError: |
|
1526 | 1530 | raise error.UnknownCommand(name) |
|
1527 | 1531 | |
|
1528 | 1532 | doc = gettext(mod.__doc__) or _('no help text available') |
|
1529 |
|
|
|
1530 |
ui.write(_('%s extension - %s\n') % (name.split('.')[-1], d |
|
|
1531 | for d in doc[1:]: | |
|
1532 | ui.write(d, '\n') | |
|
1533 | ||
|
1534 | ui.status('\n') | |
|
1533 | head, tail = doc.split('\n', 1) | |
|
1534 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) | |
|
1535 | if tail: | |
|
1536 | ui.write(minirst.format(tail, textwidth)) | |
|
1537 | ui.status('\n\n') | |
|
1535 | 1538 | |
|
1536 | 1539 | try: |
|
1537 | 1540 | ct = mod.cmdtable |
|
1538 | 1541 | except AttributeError: |
|
1539 | 1542 | ct = {} |
|
1540 | 1543 | |
|
1541 | 1544 | modcmds = set([c.split('|', 1)[0] for c in ct]) |
|
1542 | 1545 | helplist(_('list of commands:\n\n'), modcmds.__contains__) |
|
1543 | 1546 | |
|
1544 | 1547 | if name and name != 'shortlist': |
|
1545 | 1548 | i = None |
|
1546 | 1549 | for f in (helptopic, helpcmd, helpext): |
|
1547 | 1550 | try: |
|
1548 | 1551 | f(name) |
|
1549 | 1552 | i = None |
|
1550 | 1553 | break |
|
1551 | 1554 | except error.UnknownCommand, inst: |
|
1552 | 1555 | i = inst |
|
1553 | 1556 | if i: |
|
1554 | 1557 | raise i |
|
1555 | 1558 | |
|
1556 | 1559 | else: |
|
1557 | 1560 | # program name |
|
1558 | 1561 | if ui.verbose or with_version: |
|
1559 | 1562 | version_(ui) |
|
1560 | 1563 | else: |
|
1561 | 1564 | ui.status(_("Mercurial Distributed SCM\n")) |
|
1562 | 1565 | ui.status('\n') |
|
1563 | 1566 | |
|
1564 | 1567 | # list of commands |
|
1565 | 1568 | if name == "shortlist": |
|
1566 | 1569 | header = _('basic commands:\n\n') |
|
1567 | 1570 | else: |
|
1568 | 1571 | header = _('list of commands:\n\n') |
|
1569 | 1572 | |
|
1570 | 1573 | helplist(header) |
|
1571 | 1574 | |
|
1572 | 1575 | # list all option lists |
|
1573 | 1576 | opt_output = [] |
|
1574 | 1577 | for title, options in option_lists: |
|
1575 | 1578 | opt_output.append(("\n%s" % title, None)) |
|
1576 | 1579 | for shortopt, longopt, default, desc in options: |
|
1577 | 1580 | if "DEPRECATED" in desc and not ui.verbose: continue |
|
1578 | 1581 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
1579 | 1582 | longopt and " --%s" % longopt), |
|
1580 | 1583 | "%s%s" % (desc, |
|
1581 | 1584 | default |
|
1582 | 1585 | and _(" (default: %s)") % default |
|
1583 | 1586 | or ""))) |
|
1584 | 1587 | |
|
1585 | 1588 | if not name: |
|
1586 | 1589 | ui.write(_("\nadditional help topics:\n\n")) |
|
1587 | 1590 | topics = [] |
|
1588 | 1591 | for names, header, doc in help.helptable: |
|
1589 | 1592 | names = [(-len(name), name) for name in names] |
|
1590 | 1593 | names.sort() |
|
1591 | 1594 | topics.append((names[0][1], header)) |
|
1592 | 1595 | topics_len = max([len(s[0]) for s in topics]) |
|
1593 | 1596 | for t, desc in topics: |
|
1594 | 1597 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
|
1595 | 1598 | |
|
1596 | 1599 | if opt_output: |
|
1597 | 1600 | opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) |
|
1598 | 1601 | for first, second in opt_output: |
|
1599 | 1602 | if second: |
|
1600 | 1603 | second = util.wrap(second, opts_len + 3) |
|
1601 | 1604 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
1602 | 1605 | else: |
|
1603 | 1606 | ui.write("%s\n" % first) |
|
1604 | 1607 | |
|
1605 | 1608 | def identify(ui, repo, source=None, |
|
1606 | 1609 | rev=None, num=None, id=None, branch=None, tags=None): |
|
1607 | 1610 | """identify the working copy or specified revision |
|
1608 | 1611 | |
|
1609 | 1612 | With no revision, print a summary of the current state of the repository. |
|
1610 | 1613 | |
|
1611 | 1614 | Specifying a path to a repository root or Mercurial bundle will cause |
|
1612 | 1615 | lookup to operate on that repository/bundle. |
|
1613 | 1616 | |
|
1614 | 1617 | This summary identifies the repository state using one or two parent hash |
|
1615 | 1618 | identifiers, followed by a "+" if there are uncommitted changes in the |
|
1616 | 1619 | working directory, a list of tags for this revision and a branch name for |
|
1617 | 1620 | non-default branches. |
|
1618 | 1621 | """ |
|
1619 | 1622 | |
|
1620 | 1623 | if not repo and not source: |
|
1621 | 1624 | raise util.Abort(_("There is no Mercurial repository here " |
|
1622 | 1625 | "(.hg not found)")) |
|
1623 | 1626 | |
|
1624 | 1627 | hexfunc = ui.debugflag and hex or short |
|
1625 | 1628 | default = not (num or id or branch or tags) |
|
1626 | 1629 | output = [] |
|
1627 | 1630 | |
|
1628 | 1631 | revs = [] |
|
1629 | 1632 | if source: |
|
1630 | 1633 | source, revs, checkout = hg.parseurl(ui.expandpath(source), []) |
|
1631 | 1634 | repo = hg.repository(ui, source) |
|
1632 | 1635 | |
|
1633 | 1636 | if not repo.local(): |
|
1634 | 1637 | if not rev and revs: |
|
1635 | 1638 | rev = revs[0] |
|
1636 | 1639 | if not rev: |
|
1637 | 1640 | rev = "tip" |
|
1638 | 1641 | if num or branch or tags: |
|
1639 | 1642 | raise util.Abort( |
|
1640 | 1643 | "can't query remote revision number, branch, or tags") |
|
1641 | 1644 | output = [hexfunc(repo.lookup(rev))] |
|
1642 | 1645 | elif not rev: |
|
1643 | 1646 | ctx = repo[None] |
|
1644 | 1647 | parents = ctx.parents() |
|
1645 | 1648 | changed = False |
|
1646 | 1649 | if default or id or num: |
|
1647 | 1650 | changed = ctx.files() + ctx.deleted() |
|
1648 | 1651 | if default or id: |
|
1649 | 1652 | output = ["%s%s" % ('+'.join([hexfunc(p.node()) for p in parents]), |
|
1650 | 1653 | (changed) and "+" or "")] |
|
1651 | 1654 | if num: |
|
1652 | 1655 | output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]), |
|
1653 | 1656 | (changed) and "+" or "")) |
|
1654 | 1657 | else: |
|
1655 | 1658 | ctx = repo[rev] |
|
1656 | 1659 | if default or id: |
|
1657 | 1660 | output = [hexfunc(ctx.node())] |
|
1658 | 1661 | if num: |
|
1659 | 1662 | output.append(str(ctx.rev())) |
|
1660 | 1663 | |
|
1661 | 1664 | if repo.local() and default and not ui.quiet: |
|
1662 | 1665 | b = encoding.tolocal(ctx.branch()) |
|
1663 | 1666 | if b != 'default': |
|
1664 | 1667 | output.append("(%s)" % b) |
|
1665 | 1668 | |
|
1666 | 1669 | # multiple tags for a single parent separated by '/' |
|
1667 | 1670 | t = "/".join(ctx.tags()) |
|
1668 | 1671 | if t: |
|
1669 | 1672 | output.append(t) |
|
1670 | 1673 | |
|
1671 | 1674 | if branch: |
|
1672 | 1675 | output.append(encoding.tolocal(ctx.branch())) |
|
1673 | 1676 | |
|
1674 | 1677 | if tags: |
|
1675 | 1678 | output.extend(ctx.tags()) |
|
1676 | 1679 | |
|
1677 | 1680 | ui.write("%s\n" % ' '.join(output)) |
|
1678 | 1681 | |
|
1679 | 1682 | def import_(ui, repo, patch1, *patches, **opts): |
|
1680 | 1683 | """import an ordered set of patches |
|
1681 | 1684 | |
|
1682 | 1685 | Import a list of patches and commit them individually. |
|
1683 | 1686 | |
|
1684 | 1687 | If there are outstanding changes in the working directory, import will |
|
1685 | 1688 | abort unless given the -f/--force flag. |
|
1686 | 1689 | |
|
1687 | 1690 | You can import a patch straight from a mail message. Even patches as |
|
1688 | 1691 | attachments work (to use the body part, it must have type text/plain or |
|
1689 | 1692 | text/x-patch). From and Subject headers of email message are used as |
|
1690 | 1693 | default committer and commit message. All text/plain body parts before |
|
1691 | 1694 | first diff are added to commit message. |
|
1692 | 1695 | |
|
1693 | 1696 | If the imported patch was generated by hg export, user and description |
|
1694 | 1697 | from patch override values from message headers and body. Values given on |
|
1695 | 1698 | command line with -m/--message and -u/--user override these. |
|
1696 | 1699 | |
|
1697 | 1700 | If --exact is specified, import will set the working directory to the |
|
1698 | 1701 | parent of each patch before applying it, and will abort if the resulting |
|
1699 | 1702 | changeset has a different ID than the one recorded in the patch. This may |
|
1700 | 1703 | happen due to character set problems or other deficiencies in the text |
|
1701 | 1704 | patch format. |
|
1702 | 1705 | |
|
1703 | 1706 | With -s/--similarity, hg will attempt to discover renames and copies in |
|
1704 | 1707 | the patch in the same way as 'addremove'. |
|
1705 | 1708 | |
|
1706 | 1709 | To read a patch from standard input, use "-" as the patch name. If a URL |
|
1707 | 1710 | is specified, the patch will be downloaded from it. See 'hg help dates' |
|
1708 | 1711 | for a list of formats valid for -d/--date. |
|
1709 | 1712 | """ |
|
1710 | 1713 | patches = (patch1,) + patches |
|
1711 | 1714 | |
|
1712 | 1715 | date = opts.get('date') |
|
1713 | 1716 | if date: |
|
1714 | 1717 | opts['date'] = util.parsedate(date) |
|
1715 | 1718 | |
|
1716 | 1719 | try: |
|
1717 | 1720 | sim = float(opts.get('similarity') or 0) |
|
1718 | 1721 | except ValueError: |
|
1719 | 1722 | raise util.Abort(_('similarity must be a number')) |
|
1720 | 1723 | if sim < 0 or sim > 100: |
|
1721 | 1724 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
1722 | 1725 | |
|
1723 | 1726 | if opts.get('exact') or not opts.get('force'): |
|
1724 | 1727 | cmdutil.bail_if_changed(repo) |
|
1725 | 1728 | |
|
1726 | 1729 | d = opts["base"] |
|
1727 | 1730 | strip = opts["strip"] |
|
1728 | 1731 | wlock = lock = None |
|
1729 | 1732 | try: |
|
1730 | 1733 | wlock = repo.wlock() |
|
1731 | 1734 | lock = repo.lock() |
|
1732 | 1735 | for p in patches: |
|
1733 | 1736 | pf = os.path.join(d, p) |
|
1734 | 1737 | |
|
1735 | 1738 | if pf == '-': |
|
1736 | 1739 | ui.status(_("applying patch from stdin\n")) |
|
1737 | 1740 | pf = sys.stdin |
|
1738 | 1741 | else: |
|
1739 | 1742 | ui.status(_("applying %s\n") % p) |
|
1740 | 1743 | pf = url.open(ui, pf) |
|
1741 | 1744 | data = patch.extract(ui, pf) |
|
1742 | 1745 | tmpname, message, user, date, branch, nodeid, p1, p2 = data |
|
1743 | 1746 | |
|
1744 | 1747 | if tmpname is None: |
|
1745 | 1748 | raise util.Abort(_('no diffs found')) |
|
1746 | 1749 | |
|
1747 | 1750 | try: |
|
1748 | 1751 | cmdline_message = cmdutil.logmessage(opts) |
|
1749 | 1752 | if cmdline_message: |
|
1750 | 1753 | # pickup the cmdline msg |
|
1751 | 1754 | message = cmdline_message |
|
1752 | 1755 | elif message: |
|
1753 | 1756 | # pickup the patch msg |
|
1754 | 1757 | message = message.strip() |
|
1755 | 1758 | else: |
|
1756 | 1759 | # launch the editor |
|
1757 | 1760 | message = None |
|
1758 | 1761 | ui.debug(_('message:\n%s\n') % message) |
|
1759 | 1762 | |
|
1760 | 1763 | wp = repo.parents() |
|
1761 | 1764 | if opts.get('exact'): |
|
1762 | 1765 | if not nodeid or not p1: |
|
1763 | 1766 | raise util.Abort(_('not a Mercurial patch')) |
|
1764 | 1767 | p1 = repo.lookup(p1) |
|
1765 | 1768 | p2 = repo.lookup(p2 or hex(nullid)) |
|
1766 | 1769 | |
|
1767 | 1770 | if p1 != wp[0].node(): |
|
1768 | 1771 | hg.clean(repo, p1) |
|
1769 | 1772 | repo.dirstate.setparents(p1, p2) |
|
1770 | 1773 | elif p2: |
|
1771 | 1774 | try: |
|
1772 | 1775 | p1 = repo.lookup(p1) |
|
1773 | 1776 | p2 = repo.lookup(p2) |
|
1774 | 1777 | if p1 == wp[0].node(): |
|
1775 | 1778 | repo.dirstate.setparents(p1, p2) |
|
1776 | 1779 | except error.RepoError: |
|
1777 | 1780 | pass |
|
1778 | 1781 | if opts.get('exact') or opts.get('import_branch'): |
|
1779 | 1782 | repo.dirstate.setbranch(branch or 'default') |
|
1780 | 1783 | |
|
1781 | 1784 | files = {} |
|
1782 | 1785 | try: |
|
1783 | 1786 | patch.patch(tmpname, ui, strip=strip, cwd=repo.root, |
|
1784 | 1787 | files=files, eolmode=None) |
|
1785 | 1788 | finally: |
|
1786 | 1789 | files = patch.updatedir(ui, repo, files, similarity=sim/100.) |
|
1787 | 1790 | if not opts.get('no_commit'): |
|
1788 | 1791 | m = cmdutil.matchfiles(repo, files or []) |
|
1789 | 1792 | n = repo.commit(message, opts.get('user') or user, |
|
1790 | 1793 | opts.get('date') or date, match=m, |
|
1791 | 1794 | editor=cmdutil.commiteditor) |
|
1792 | 1795 | if opts.get('exact'): |
|
1793 | 1796 | if hex(n) != nodeid: |
|
1794 | 1797 | repo.rollback() |
|
1795 | 1798 | raise util.Abort(_('patch is damaged' |
|
1796 | 1799 | ' or loses information')) |
|
1797 | 1800 | # Force a dirstate write so that the next transaction |
|
1798 | 1801 | # backups an up-do-date file. |
|
1799 | 1802 | repo.dirstate.write() |
|
1800 | 1803 | finally: |
|
1801 | 1804 | os.unlink(tmpname) |
|
1802 | 1805 | finally: |
|
1803 | 1806 | release(lock, wlock) |
|
1804 | 1807 | |
|
1805 | 1808 | def incoming(ui, repo, source="default", **opts): |
|
1806 | 1809 | """show new changesets found in source |
|
1807 | 1810 | |
|
1808 | 1811 | Show new changesets found in the specified path/URL or the default pull |
|
1809 | 1812 | location. These are the changesets that would have been pulled if a pull |
|
1810 | 1813 | at the time you issued this command. |
|
1811 | 1814 | |
|
1812 | 1815 | For remote repository, using --bundle avoids downloading the changesets |
|
1813 | 1816 | twice if the incoming is followed by a pull. |
|
1814 | 1817 | |
|
1815 | 1818 | See pull for valid source format details. |
|
1816 | 1819 | """ |
|
1817 | 1820 | limit = cmdutil.loglimit(opts) |
|
1818 | 1821 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
|
1819 | 1822 | other = hg.repository(cmdutil.remoteui(repo, opts), source) |
|
1820 | 1823 | ui.status(_('comparing with %s\n') % url.hidepassword(source)) |
|
1821 | 1824 | if revs: |
|
1822 | 1825 | revs = [other.lookup(rev) for rev in revs] |
|
1823 | 1826 | common, incoming, rheads = repo.findcommonincoming(other, heads=revs, |
|
1824 | 1827 | force=opts["force"]) |
|
1825 | 1828 | if not incoming: |
|
1826 | 1829 | try: |
|
1827 | 1830 | os.unlink(opts["bundle"]) |
|
1828 | 1831 | except: |
|
1829 | 1832 | pass |
|
1830 | 1833 | ui.status(_("no changes found\n")) |
|
1831 | 1834 | return 1 |
|
1832 | 1835 | |
|
1833 | 1836 | cleanup = None |
|
1834 | 1837 | try: |
|
1835 | 1838 | fname = opts["bundle"] |
|
1836 | 1839 | if fname or not other.local(): |
|
1837 | 1840 | # create a bundle (uncompressed if other repo is not local) |
|
1838 | 1841 | |
|
1839 | 1842 | if revs is None and other.capable('changegroupsubset'): |
|
1840 | 1843 | revs = rheads |
|
1841 | 1844 | |
|
1842 | 1845 | if revs is None: |
|
1843 | 1846 | cg = other.changegroup(incoming, "incoming") |
|
1844 | 1847 | else: |
|
1845 | 1848 | cg = other.changegroupsubset(incoming, revs, 'incoming') |
|
1846 | 1849 | bundletype = other.local() and "HG10BZ" or "HG10UN" |
|
1847 | 1850 | fname = cleanup = changegroup.writebundle(cg, fname, bundletype) |
|
1848 | 1851 | # keep written bundle? |
|
1849 | 1852 | if opts["bundle"]: |
|
1850 | 1853 | cleanup = None |
|
1851 | 1854 | if not other.local(): |
|
1852 | 1855 | # use the created uncompressed bundlerepo |
|
1853 | 1856 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1854 | 1857 | |
|
1855 | 1858 | o = other.changelog.nodesbetween(incoming, revs)[0] |
|
1856 | 1859 | if opts.get('newest_first'): |
|
1857 | 1860 | o.reverse() |
|
1858 | 1861 | displayer = cmdutil.show_changeset(ui, other, opts) |
|
1859 | 1862 | count = 0 |
|
1860 | 1863 | for n in o: |
|
1861 | 1864 | if count >= limit: |
|
1862 | 1865 | break |
|
1863 | 1866 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1864 | 1867 | if opts.get('no_merges') and len(parents) == 2: |
|
1865 | 1868 | continue |
|
1866 | 1869 | count += 1 |
|
1867 | 1870 | displayer.show(other[n]) |
|
1868 | 1871 | finally: |
|
1869 | 1872 | if hasattr(other, 'close'): |
|
1870 | 1873 | other.close() |
|
1871 | 1874 | if cleanup: |
|
1872 | 1875 | os.unlink(cleanup) |
|
1873 | 1876 | |
|
1874 | 1877 | def init(ui, dest=".", **opts): |
|
1875 | 1878 | """create a new repository in the given directory |
|
1876 | 1879 | |
|
1877 | 1880 | Initialize a new repository in the given directory. If the given directory |
|
1878 | 1881 | does not exist, it will be created. |
|
1879 | 1882 | |
|
1880 | 1883 | If no directory is given, the current directory is used. |
|
1881 | 1884 | |
|
1882 | 1885 | It is possible to specify an ssh:// URL as the destination. See 'hg help |
|
1883 | 1886 | urls' for more information. |
|
1884 | 1887 | """ |
|
1885 | 1888 | hg.repository(cmdutil.remoteui(ui, opts), dest, create=1) |
|
1886 | 1889 | |
|
1887 | 1890 | def locate(ui, repo, *pats, **opts): |
|
1888 | 1891 | """locate files matching specific patterns |
|
1889 | 1892 | |
|
1890 | 1893 | Print files under Mercurial control in the working directory whose names |
|
1891 | 1894 | match the given patterns. |
|
1892 | 1895 | |
|
1893 | 1896 | By default, this command searches all directories in the working |
|
1894 | 1897 | directory. To search just the current directory and its subdirectories, |
|
1895 | 1898 | use "--include .". |
|
1896 | 1899 | |
|
1897 | 1900 | If no patterns are given to match, this command prints the names of all |
|
1898 | 1901 | files under Mercurial control in the working directory. |
|
1899 | 1902 | |
|
1900 | 1903 | If you want to feed the output of this command into the "xargs" command, |
|
1901 | 1904 | use the -0 option to both this command and "xargs". This will avoid the |
|
1902 | 1905 | problem of "xargs" treating single filenames that contain whitespace as |
|
1903 | 1906 | multiple filenames. |
|
1904 | 1907 | """ |
|
1905 | 1908 | end = opts.get('print0') and '\0' or '\n' |
|
1906 | 1909 | rev = opts.get('rev') or None |
|
1907 | 1910 | |
|
1908 | 1911 | ret = 1 |
|
1909 | 1912 | m = cmdutil.match(repo, pats, opts, default='relglob') |
|
1910 | 1913 | m.bad = lambda x,y: False |
|
1911 | 1914 | for abs in repo[rev].walk(m): |
|
1912 | 1915 | if not rev and abs not in repo.dirstate: |
|
1913 | 1916 | continue |
|
1914 | 1917 | if opts.get('fullpath'): |
|
1915 | 1918 | ui.write(repo.wjoin(abs), end) |
|
1916 | 1919 | else: |
|
1917 | 1920 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
1918 | 1921 | ret = 0 |
|
1919 | 1922 | |
|
1920 | 1923 | return ret |
|
1921 | 1924 | |
|
1922 | 1925 | def log(ui, repo, *pats, **opts): |
|
1923 | 1926 | """show revision history of entire repository or files |
|
1924 | 1927 | |
|
1925 | 1928 | Print the revision history of the specified files or the entire project. |
|
1926 | 1929 | |
|
1927 | 1930 | File history is shown without following rename or copy history of files. |
|
1928 | 1931 | Use -f/--follow with a filename to follow history across renames and |
|
1929 | 1932 | copies. --follow without a filename will only show ancestors or |
|
1930 | 1933 | descendants of the starting revision. --follow-first only follows the |
|
1931 | 1934 | first parent of merge revisions. |
|
1932 | 1935 | |
|
1933 | 1936 | If no revision range is specified, the default is tip:0 unless --follow is |
|
1934 | 1937 | set, in which case the working directory parent is used as the starting |
|
1935 | 1938 | revision. |
|
1936 | 1939 | |
|
1937 | 1940 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
1938 | 1941 | |
|
1939 | 1942 | By default this command prints revision number and changeset id, tags, |
|
1940 | 1943 | non-trivial parents, user, date and time, and a summary for each commit. |
|
1941 | 1944 | When the -v/--verbose switch is used, the list of changed files and full |
|
1942 | 1945 | commit message are shown. |
|
1943 | 1946 | |
|
1944 | 1947 | NOTE: log -p/--patch may generate unexpected diff output for merge |
|
1945 | 1948 | changesets, as it will only compare the merge changeset against its first |
|
1946 | 1949 | parent. Also, only files different from BOTH parents will appear in |
|
1947 | 1950 | files:. |
|
1948 | 1951 | """ |
|
1949 | 1952 | |
|
1950 | 1953 | get = util.cachefunc(lambda r: repo[r].changeset()) |
|
1951 | 1954 | changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts) |
|
1952 | 1955 | |
|
1953 | 1956 | limit = cmdutil.loglimit(opts) |
|
1954 | 1957 | count = 0 |
|
1955 | 1958 | |
|
1956 | 1959 | if opts.get('copies') and opts.get('rev'): |
|
1957 | 1960 | endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1 |
|
1958 | 1961 | else: |
|
1959 | 1962 | endrev = len(repo) |
|
1960 | 1963 | rcache = {} |
|
1961 | 1964 | ncache = {} |
|
1962 | 1965 | def getrenamed(fn, rev): |
|
1963 | 1966 | '''looks up all renames for a file (up to endrev) the first |
|
1964 | 1967 | time the file is given. It indexes on the changerev and only |
|
1965 | 1968 | parses the manifest if linkrev != changerev. |
|
1966 | 1969 | Returns rename info for fn at changerev rev.''' |
|
1967 | 1970 | if fn not in rcache: |
|
1968 | 1971 | rcache[fn] = {} |
|
1969 | 1972 | ncache[fn] = {} |
|
1970 | 1973 | fl = repo.file(fn) |
|
1971 | 1974 | for i in fl: |
|
1972 | 1975 | node = fl.node(i) |
|
1973 | 1976 | lr = fl.linkrev(i) |
|
1974 | 1977 | renamed = fl.renamed(node) |
|
1975 | 1978 | rcache[fn][lr] = renamed |
|
1976 | 1979 | if renamed: |
|
1977 | 1980 | ncache[fn][node] = renamed |
|
1978 | 1981 | if lr >= endrev: |
|
1979 | 1982 | break |
|
1980 | 1983 | if rev in rcache[fn]: |
|
1981 | 1984 | return rcache[fn][rev] |
|
1982 | 1985 | |
|
1983 | 1986 | # If linkrev != rev (i.e. rev not found in rcache) fallback to |
|
1984 | 1987 | # filectx logic. |
|
1985 | 1988 | |
|
1986 | 1989 | try: |
|
1987 | 1990 | return repo[rev][fn].renamed() |
|
1988 | 1991 | except error.LookupError: |
|
1989 | 1992 | pass |
|
1990 | 1993 | return None |
|
1991 | 1994 | |
|
1992 | 1995 | df = False |
|
1993 | 1996 | if opts["date"]: |
|
1994 | 1997 | df = util.matchdate(opts["date"]) |
|
1995 | 1998 | |
|
1996 | 1999 | only_branches = opts.get('only_branch') |
|
1997 | 2000 | |
|
1998 | 2001 | displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) |
|
1999 | 2002 | for st, rev, fns in changeiter: |
|
2000 | 2003 | if st == 'add': |
|
2001 | 2004 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
2002 | 2005 | if p != nullrev] |
|
2003 | 2006 | if opts.get('no_merges') and len(parents) == 2: |
|
2004 | 2007 | continue |
|
2005 | 2008 | if opts.get('only_merges') and len(parents) != 2: |
|
2006 | 2009 | continue |
|
2007 | 2010 | |
|
2008 | 2011 | if only_branches: |
|
2009 | 2012 | revbranch = get(rev)[5]['branch'] |
|
2010 | 2013 | if revbranch not in only_branches: |
|
2011 | 2014 | continue |
|
2012 | 2015 | |
|
2013 | 2016 | if df: |
|
2014 | 2017 | changes = get(rev) |
|
2015 | 2018 | if not df(changes[2][0]): |
|
2016 | 2019 | continue |
|
2017 | 2020 | |
|
2018 | 2021 | if opts.get('keyword'): |
|
2019 | 2022 | changes = get(rev) |
|
2020 | 2023 | miss = 0 |
|
2021 | 2024 | for k in [kw.lower() for kw in opts['keyword']]: |
|
2022 | 2025 | if not (k in changes[1].lower() or |
|
2023 | 2026 | k in changes[4].lower() or |
|
2024 | 2027 | k in " ".join(changes[3]).lower()): |
|
2025 | 2028 | miss = 1 |
|
2026 | 2029 | break |
|
2027 | 2030 | if miss: |
|
2028 | 2031 | continue |
|
2029 | 2032 | |
|
2030 | 2033 | if opts['user']: |
|
2031 | 2034 | changes = get(rev) |
|
2032 | 2035 | if not [k for k in opts['user'] if k in changes[1]]: |
|
2033 | 2036 | continue |
|
2034 | 2037 | |
|
2035 | 2038 | copies = [] |
|
2036 | 2039 | if opts.get('copies') and rev: |
|
2037 | 2040 | for fn in get(rev)[3]: |
|
2038 | 2041 | rename = getrenamed(fn, rev) |
|
2039 | 2042 | if rename: |
|
2040 | 2043 | copies.append((fn, rename[0])) |
|
2041 | 2044 | displayer.show(context.changectx(repo, rev), copies=copies) |
|
2042 | 2045 | elif st == 'iter': |
|
2043 | 2046 | if count == limit: break |
|
2044 | 2047 | if displayer.flush(rev): |
|
2045 | 2048 | count += 1 |
|
2046 | 2049 | |
|
2047 | 2050 | def manifest(ui, repo, node=None, rev=None): |
|
2048 | 2051 | """output the current or given revision of the project manifest |
|
2049 | 2052 | |
|
2050 | 2053 | Print a list of version controlled files for the given revision. If no |
|
2051 | 2054 | revision is given, the first parent of the working directory is used, or |
|
2052 | 2055 | the null revision if no revision is checked out. |
|
2053 | 2056 | |
|
2054 | 2057 | With -v, print file permissions, symlink and executable bits. |
|
2055 | 2058 | With --debug, print file revision hashes. |
|
2056 | 2059 | """ |
|
2057 | 2060 | |
|
2058 | 2061 | if rev and node: |
|
2059 | 2062 | raise util.Abort(_("please specify just one revision")) |
|
2060 | 2063 | |
|
2061 | 2064 | if not node: |
|
2062 | 2065 | node = rev |
|
2063 | 2066 | |
|
2064 | 2067 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
|
2065 | 2068 | ctx = repo[node] |
|
2066 | 2069 | for f in ctx: |
|
2067 | 2070 | if ui.debugflag: |
|
2068 | 2071 | ui.write("%40s " % hex(ctx.manifest()[f])) |
|
2069 | 2072 | if ui.verbose: |
|
2070 | 2073 | ui.write(decor[ctx.flags(f)]) |
|
2071 | 2074 | ui.write("%s\n" % f) |
|
2072 | 2075 | |
|
2073 | 2076 | def merge(ui, repo, node=None, **opts): |
|
2074 | 2077 | """merge working directory with another revision |
|
2075 | 2078 | |
|
2076 | 2079 | The current working directory is updated with all changes made in the |
|
2077 | 2080 | requested revision since the last common predecessor revision. |
|
2078 | 2081 | |
|
2079 | 2082 | Files that changed between either parent are marked as changed for the |
|
2080 | 2083 | next commit and a commit must be performed before any further updates to |
|
2081 | 2084 | the repository are allowed. The next commit will have two parents. |
|
2082 | 2085 | |
|
2083 | 2086 | If no revision is specified, the working directory's parent is a head |
|
2084 | 2087 | revision, and the current branch contains exactly one other head, the |
|
2085 | 2088 | other head is merged with by default. Otherwise, an explicit revision with |
|
2086 | 2089 | which to merge with must be provided. |
|
2087 | 2090 | """ |
|
2088 | 2091 | |
|
2089 | 2092 | if opts.get('rev') and node: |
|
2090 | 2093 | raise util.Abort(_("please specify just one revision")) |
|
2091 | 2094 | if not node: |
|
2092 | 2095 | node = opts.get('rev') |
|
2093 | 2096 | |
|
2094 | 2097 | if not node: |
|
2095 | 2098 | branch = repo.changectx(None).branch() |
|
2096 | 2099 | bheads = repo.branchheads(branch) |
|
2097 | 2100 | if len(bheads) > 2: |
|
2098 | 2101 | raise util.Abort(_("branch '%s' has %d heads - " |
|
2099 | 2102 | "please merge with an explicit rev") % |
|
2100 | 2103 | (branch, len(bheads))) |
|
2101 | 2104 | |
|
2102 | 2105 | parent = repo.dirstate.parents()[0] |
|
2103 | 2106 | if len(bheads) == 1: |
|
2104 | 2107 | if len(repo.heads()) > 1: |
|
2105 | 2108 | raise util.Abort(_("branch '%s' has one head - " |
|
2106 | 2109 | "please merge with an explicit rev") % |
|
2107 | 2110 | branch) |
|
2108 | 2111 | msg = _('there is nothing to merge') |
|
2109 | 2112 | if parent != repo.lookup(repo[None].branch()): |
|
2110 | 2113 | msg = _('%s - use "hg update" instead') % msg |
|
2111 | 2114 | raise util.Abort(msg) |
|
2112 | 2115 | |
|
2113 | 2116 | if parent not in bheads: |
|
2114 | 2117 | raise util.Abort(_('working dir not at a head rev - ' |
|
2115 | 2118 | 'use "hg update" or merge with an explicit rev')) |
|
2116 | 2119 | node = parent == bheads[0] and bheads[-1] or bheads[0] |
|
2117 | 2120 | |
|
2118 | 2121 | if opts.get('preview'): |
|
2119 | 2122 | p1 = repo['.'] |
|
2120 | 2123 | p2 = repo[node] |
|
2121 | 2124 | common = p1.ancestor(p2) |
|
2122 | 2125 | roots, heads = [common.node()], [p2.node()] |
|
2123 | 2126 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2124 | 2127 | for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]: |
|
2125 | 2128 | displayer.show(repo[node]) |
|
2126 | 2129 | return 0 |
|
2127 | 2130 | |
|
2128 | 2131 | return hg.merge(repo, node, force=opts.get('force')) |
|
2129 | 2132 | |
|
2130 | 2133 | def outgoing(ui, repo, dest=None, **opts): |
|
2131 | 2134 | """show changesets not found in destination |
|
2132 | 2135 | |
|
2133 | 2136 | Show changesets not found in the specified destination repository or the |
|
2134 | 2137 | default push location. These are the changesets that would be pushed if a |
|
2135 | 2138 | push was requested. |
|
2136 | 2139 | |
|
2137 | 2140 | See pull for valid destination format details. |
|
2138 | 2141 | """ |
|
2139 | 2142 | limit = cmdutil.loglimit(opts) |
|
2140 | 2143 | dest, revs, checkout = hg.parseurl( |
|
2141 | 2144 | ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev')) |
|
2142 | 2145 | if revs: |
|
2143 | 2146 | revs = [repo.lookup(rev) for rev in revs] |
|
2144 | 2147 | |
|
2145 | 2148 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
2146 | 2149 | ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
|
2147 | 2150 | o = repo.findoutgoing(other, force=opts.get('force')) |
|
2148 | 2151 | if not o: |
|
2149 | 2152 | ui.status(_("no changes found\n")) |
|
2150 | 2153 | return 1 |
|
2151 | 2154 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
2152 | 2155 | if opts.get('newest_first'): |
|
2153 | 2156 | o.reverse() |
|
2154 | 2157 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2155 | 2158 | count = 0 |
|
2156 | 2159 | for n in o: |
|
2157 | 2160 | if count >= limit: |
|
2158 | 2161 | break |
|
2159 | 2162 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2160 | 2163 | if opts.get('no_merges') and len(parents) == 2: |
|
2161 | 2164 | continue |
|
2162 | 2165 | count += 1 |
|
2163 | 2166 | displayer.show(repo[n]) |
|
2164 | 2167 | |
|
2165 | 2168 | def parents(ui, repo, file_=None, **opts): |
|
2166 | 2169 | """show the parents of the working directory or revision |
|
2167 | 2170 | |
|
2168 | 2171 | Print the working directory's parent revisions. If a revision is given via |
|
2169 | 2172 | -r/--rev, the parent of that revision will be printed. If a file argument |
|
2170 | 2173 | is given, the revision in which the file was last changed (before the |
|
2171 | 2174 | working directory revision or the argument to --rev if given) is printed. |
|
2172 | 2175 | """ |
|
2173 | 2176 | rev = opts.get('rev') |
|
2174 | 2177 | if rev: |
|
2175 | 2178 | ctx = repo[rev] |
|
2176 | 2179 | else: |
|
2177 | 2180 | ctx = repo[None] |
|
2178 | 2181 | |
|
2179 | 2182 | if file_: |
|
2180 | 2183 | m = cmdutil.match(repo, (file_,), opts) |
|
2181 | 2184 | if m.anypats() or len(m.files()) != 1: |
|
2182 | 2185 | raise util.Abort(_('can only specify an explicit filename')) |
|
2183 | 2186 | file_ = m.files()[0] |
|
2184 | 2187 | filenodes = [] |
|
2185 | 2188 | for cp in ctx.parents(): |
|
2186 | 2189 | if not cp: |
|
2187 | 2190 | continue |
|
2188 | 2191 | try: |
|
2189 | 2192 | filenodes.append(cp.filenode(file_)) |
|
2190 | 2193 | except error.LookupError: |
|
2191 | 2194 | pass |
|
2192 | 2195 | if not filenodes: |
|
2193 | 2196 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
2194 | 2197 | fl = repo.file(file_) |
|
2195 | 2198 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] |
|
2196 | 2199 | else: |
|
2197 | 2200 | p = [cp.node() for cp in ctx.parents()] |
|
2198 | 2201 | |
|
2199 | 2202 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2200 | 2203 | for n in p: |
|
2201 | 2204 | if n != nullid: |
|
2202 | 2205 | displayer.show(repo[n]) |
|
2203 | 2206 | |
|
2204 | 2207 | def paths(ui, repo, search=None): |
|
2205 | 2208 | """show aliases for remote repositories |
|
2206 | 2209 | |
|
2207 | 2210 | Show definition of symbolic path name NAME. If no name is given, show |
|
2208 | 2211 | definition of all available names. |
|
2209 | 2212 | |
|
2210 | 2213 | Path names are defined in the [paths] section of /etc/mercurial/hgrc and |
|
2211 | 2214 | $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2212 | 2215 | |
|
2213 | 2216 | See 'hg help urls' for more information. |
|
2214 | 2217 | """ |
|
2215 | 2218 | if search: |
|
2216 | 2219 | for name, path in ui.configitems("paths"): |
|
2217 | 2220 | if name == search: |
|
2218 | 2221 | ui.write("%s\n" % url.hidepassword(path)) |
|
2219 | 2222 | return |
|
2220 | 2223 | ui.warn(_("not found!\n")) |
|
2221 | 2224 | return 1 |
|
2222 | 2225 | else: |
|
2223 | 2226 | for name, path in ui.configitems("paths"): |
|
2224 | 2227 | ui.write("%s = %s\n" % (name, url.hidepassword(path))) |
|
2225 | 2228 | |
|
2226 | 2229 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
2227 | 2230 | if modheads == 0: |
|
2228 | 2231 | return |
|
2229 | 2232 | if optupdate: |
|
2230 | 2233 | if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout: |
|
2231 | 2234 | return hg.update(repo, checkout) |
|
2232 | 2235 | else: |
|
2233 | 2236 | ui.status(_("not updating, since new heads added\n")) |
|
2234 | 2237 | if modheads > 1: |
|
2235 | 2238 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2236 | 2239 | else: |
|
2237 | 2240 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2238 | 2241 | |
|
2239 | 2242 | def pull(ui, repo, source="default", **opts): |
|
2240 | 2243 | """pull changes from the specified source |
|
2241 | 2244 | |
|
2242 | 2245 | Pull changes from a remote repository to a local one. |
|
2243 | 2246 | |
|
2244 | 2247 | This finds all changes from the repository at the specified path or URL |
|
2245 | 2248 | and adds them to a local repository (the current one unless -R is |
|
2246 | 2249 | specified). By default, this does not update the copy of the project in |
|
2247 | 2250 | the working directory. |
|
2248 | 2251 | |
|
2249 | 2252 | Use hg incoming if you want to see what would have been added by a pull at |
|
2250 | 2253 | the time you issued this command. If you then decide to added those |
|
2251 | 2254 | changes to the repository, you should use pull -r X where X is the last |
|
2252 | 2255 | changeset listed by hg incoming. |
|
2253 | 2256 | |
|
2254 | 2257 | If SOURCE is omitted, the 'default' path will be used. See 'hg help urls' |
|
2255 | 2258 | for more information. |
|
2256 | 2259 | """ |
|
2257 | 2260 | source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev')) |
|
2258 | 2261 | other = hg.repository(cmdutil.remoteui(repo, opts), source) |
|
2259 | 2262 | ui.status(_('pulling from %s\n') % url.hidepassword(source)) |
|
2260 | 2263 | if revs: |
|
2261 | 2264 | try: |
|
2262 | 2265 | revs = [other.lookup(rev) for rev in revs] |
|
2263 | 2266 | except error.CapabilityError: |
|
2264 | 2267 | err = _("Other repository doesn't support revision lookup, " |
|
2265 | 2268 | "so a rev cannot be specified.") |
|
2266 | 2269 | raise util.Abort(err) |
|
2267 | 2270 | |
|
2268 | 2271 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) |
|
2269 | 2272 | return postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
2270 | 2273 | |
|
2271 | 2274 | def push(ui, repo, dest=None, **opts): |
|
2272 | 2275 | """push changes to the specified destination |
|
2273 | 2276 | |
|
2274 | 2277 | Push changes from the local repository to the given destination. |
|
2275 | 2278 | |
|
2276 | 2279 | This is the symmetrical operation for pull. It moves changes from the |
|
2277 | 2280 | current repository to a different one. If the destination is local this is |
|
2278 | 2281 | identical to a pull in that directory from the current one. |
|
2279 | 2282 | |
|
2280 | 2283 | By default, push will refuse to run if it detects the result would |
|
2281 | 2284 | increase the number of remote heads. This generally indicates the user |
|
2282 | 2285 | forgot to pull and merge before pushing. |
|
2283 | 2286 | |
|
2284 | 2287 | If -r/--rev is used, the named revision and all its ancestors will be |
|
2285 | 2288 | pushed to the remote repository. |
|
2286 | 2289 | |
|
2287 | 2290 | Please see 'hg help urls' for important details about ssh:// URLs. If |
|
2288 | 2291 | DESTINATION is omitted, a default path will be used. |
|
2289 | 2292 | """ |
|
2290 | 2293 | dest, revs, checkout = hg.parseurl( |
|
2291 | 2294 | ui.expandpath(dest or 'default-push', dest or 'default'), opts.get('rev')) |
|
2292 | 2295 | other = hg.repository(cmdutil.remoteui(repo, opts), dest) |
|
2293 | 2296 | ui.status(_('pushing to %s\n') % url.hidepassword(dest)) |
|
2294 | 2297 | if revs: |
|
2295 | 2298 | revs = [repo.lookup(rev) for rev in revs] |
|
2296 | 2299 | |
|
2297 | 2300 | # push subrepos depth-first for coherent ordering |
|
2298 | 2301 | c = repo[''] |
|
2299 | 2302 | subs = c.substate # only repos that are committed |
|
2300 | 2303 | for s in sorted(subs): |
|
2301 | 2304 | c.sub(s).push(opts.get('force')) |
|
2302 | 2305 | |
|
2303 | 2306 | r = repo.push(other, opts.get('force'), revs=revs) |
|
2304 | 2307 | return r == 0 |
|
2305 | 2308 | |
|
2306 | 2309 | def recover(ui, repo): |
|
2307 | 2310 | """roll back an interrupted transaction |
|
2308 | 2311 | |
|
2309 | 2312 | Recover from an interrupted commit or pull. |
|
2310 | 2313 | |
|
2311 | 2314 | This command tries to fix the repository status after an interrupted |
|
2312 | 2315 | operation. It should only be necessary when Mercurial suggests it. |
|
2313 | 2316 | """ |
|
2314 | 2317 | if repo.recover(): |
|
2315 | 2318 | return hg.verify(repo) |
|
2316 | 2319 | return 1 |
|
2317 | 2320 | |
|
2318 | 2321 | def remove(ui, repo, *pats, **opts): |
|
2319 | 2322 | """remove the specified files on the next commit |
|
2320 | 2323 | |
|
2321 | 2324 | Schedule the indicated files for removal from the repository. |
|
2322 | 2325 | |
|
2323 | 2326 | This only removes files from the current branch, not from the entire |
|
2324 | 2327 | project history. -A/--after can be used to remove only files that have |
|
2325 | 2328 | already been deleted, -f/--force can be used to force deletion, and -Af |
|
2326 | 2329 | can be used to remove files from the next revision without deleting them |
|
2327 | 2330 | from the working directory. |
|
2328 | 2331 | |
|
2329 | 2332 | The following table details the behavior of remove for different file |
|
2330 | 2333 | states (columns) and option combinations (rows). The file states are Added |
|
2331 | 2334 | [A], Clean [C], Modified [M] and Missing [!] (as reported by hg status). |
|
2332 |
The actions are Warn, Remove (from branch) and Delete (from disk) |
|
|
2333 | ||
|
2334 | A C M ! | |
|
2335 | none W RD W R | |
|
2336 | -f R RD RD R | |
|
2337 | -A W W W R | |
|
2338 | -Af R R R R | |
|
2335 | The actions are Warn, Remove (from branch) and Delete (from disk):: | |
|
2336 | ||
|
2337 | A C M ! | |
|
2338 | none W RD W R | |
|
2339 | -f R RD RD R | |
|
2340 | -A W W W R | |
|
2341 | -Af R R R R | |
|
2339 | 2342 | |
|
2340 | 2343 | This command schedules the files to be removed at the next commit. To undo |
|
2341 | 2344 | a remove before that, see hg revert. |
|
2342 | 2345 | """ |
|
2343 | 2346 | |
|
2344 | 2347 | after, force = opts.get('after'), opts.get('force') |
|
2345 | 2348 | if not pats and not after: |
|
2346 | 2349 | raise util.Abort(_('no files specified')) |
|
2347 | 2350 | |
|
2348 | 2351 | m = cmdutil.match(repo, pats, opts) |
|
2349 | 2352 | s = repo.status(match=m, clean=True) |
|
2350 | 2353 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
2351 | 2354 | |
|
2352 | 2355 | for f in m.files(): |
|
2353 | 2356 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
2354 | 2357 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) |
|
2355 | 2358 | |
|
2356 | 2359 | def warn(files, reason): |
|
2357 | 2360 | for f in files: |
|
2358 | 2361 | ui.warn(_('not removing %s: file %s (use -f to force removal)\n') |
|
2359 | 2362 | % (m.rel(f), reason)) |
|
2360 | 2363 | |
|
2361 | 2364 | if force: |
|
2362 | 2365 | remove, forget = modified + deleted + clean, added |
|
2363 | 2366 | elif after: |
|
2364 | 2367 | remove, forget = deleted, [] |
|
2365 | 2368 | warn(modified + added + clean, _('still exists')) |
|
2366 | 2369 | else: |
|
2367 | 2370 | remove, forget = deleted + clean, [] |
|
2368 | 2371 | warn(modified, _('is modified')) |
|
2369 | 2372 | warn(added, _('has been marked for add')) |
|
2370 | 2373 | |
|
2371 | 2374 | for f in sorted(remove + forget): |
|
2372 | 2375 | if ui.verbose or not m.exact(f): |
|
2373 | 2376 | ui.status(_('removing %s\n') % m.rel(f)) |
|
2374 | 2377 | |
|
2375 | 2378 | repo.forget(forget) |
|
2376 | 2379 | repo.remove(remove, unlink=not after) |
|
2377 | 2380 | |
|
2378 | 2381 | def rename(ui, repo, *pats, **opts): |
|
2379 | 2382 | """rename files; equivalent of copy + remove |
|
2380 | 2383 | |
|
2381 | 2384 | Mark dest as copies of sources; mark sources for deletion. If dest is a |
|
2382 | 2385 | directory, copies are put in that directory. If dest is a file, there can |
|
2383 | 2386 | only be one source. |
|
2384 | 2387 | |
|
2385 | 2388 | By default, this command copies the contents of files as they exist in the |
|
2386 | 2389 | working directory. If invoked with -A/--after, the operation is recorded, |
|
2387 | 2390 | but no copying is performed. |
|
2388 | 2391 | |
|
2389 | 2392 | This command takes effect at the next commit. To undo a rename before |
|
2390 | 2393 | that, see hg revert. |
|
2391 | 2394 | """ |
|
2392 | 2395 | wlock = repo.wlock(False) |
|
2393 | 2396 | try: |
|
2394 | 2397 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
2395 | 2398 | finally: |
|
2396 | 2399 | wlock.release() |
|
2397 | 2400 | |
|
2398 | 2401 | def resolve(ui, repo, *pats, **opts): |
|
2399 | 2402 | """retry file merges from a merge or update |
|
2400 | 2403 | |
|
2401 | 2404 | This command will cleanly retry unresolved file merges using file |
|
2402 | 2405 | revisions preserved from the last update or merge. To attempt to resolve |
|
2403 | 2406 | all unresolved files, use the -a/--all switch. |
|
2404 | 2407 | |
|
2405 | 2408 | If a conflict is resolved manually, please note that the changes will be |
|
2406 | 2409 | overwritten if the merge is retried with resolve. The -m/--mark switch |
|
2407 | 2410 | should be used to mark the file as resolved. |
|
2408 | 2411 | |
|
2409 | 2412 | This command also allows listing resolved files and manually indicating |
|
2410 | 2413 | whether or not files are resolved. All files must be marked as resolved |
|
2411 | 2414 | before a commit is permitted. |
|
2412 | 2415 | |
|
2413 | The codes used to show the status of files are: | |
|
2414 | U = unresolved | |
|
2415 |
|
|
|
2416 | The codes used to show the status of files are:: | |
|
2417 | ||
|
2418 | U = unresolved | |
|
2419 | R = resolved | |
|
2416 | 2420 | """ |
|
2417 | 2421 | |
|
2418 | 2422 | all, mark, unmark, show = [opts.get(o) for o in 'all mark unmark list'.split()] |
|
2419 | 2423 | |
|
2420 | 2424 | if (show and (mark or unmark)) or (mark and unmark): |
|
2421 | 2425 | raise util.Abort(_("too many options specified")) |
|
2422 | 2426 | if pats and all: |
|
2423 | 2427 | raise util.Abort(_("can't specify --all and patterns")) |
|
2424 | 2428 | if not (all or pats or show or mark or unmark): |
|
2425 | 2429 | raise util.Abort(_('no files or directories specified; ' |
|
2426 | 2430 | 'use --all to remerge all files')) |
|
2427 | 2431 | |
|
2428 | 2432 | ms = merge_.mergestate(repo) |
|
2429 | 2433 | m = cmdutil.match(repo, pats, opts) |
|
2430 | 2434 | |
|
2431 | 2435 | for f in ms: |
|
2432 | 2436 | if m(f): |
|
2433 | 2437 | if show: |
|
2434 | 2438 | ui.write("%s %s\n" % (ms[f].upper(), f)) |
|
2435 | 2439 | elif mark: |
|
2436 | 2440 | ms.mark(f, "r") |
|
2437 | 2441 | elif unmark: |
|
2438 | 2442 | ms.mark(f, "u") |
|
2439 | 2443 | else: |
|
2440 | 2444 | wctx = repo[None] |
|
2441 | 2445 | mctx = wctx.parents()[-1] |
|
2442 | 2446 | |
|
2443 | 2447 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
2444 | 2448 | a = repo.wjoin(f) |
|
2445 | 2449 | util.copyfile(a, a + ".resolve") |
|
2446 | 2450 | |
|
2447 | 2451 | # resolve file |
|
2448 | 2452 | ms.resolve(f, wctx, mctx) |
|
2449 | 2453 | |
|
2450 | 2454 | # replace filemerge's .orig file with our resolve file |
|
2451 | 2455 | util.rename(a + ".resolve", a + ".orig") |
|
2452 | 2456 | |
|
2453 | 2457 | def revert(ui, repo, *pats, **opts): |
|
2454 | 2458 | """restore individual files or directories to an earlier state |
|
2455 | 2459 | |
|
2456 | 2460 | (Use update -r to check out earlier revisions, revert does not change the |
|
2457 | 2461 | working directory parents.) |
|
2458 | 2462 | |
|
2459 | 2463 | With no revision specified, revert the named files or directories to the |
|
2460 | 2464 | contents they had in the parent of the working directory. This restores |
|
2461 | 2465 | the contents of the affected files to an unmodified state and unschedules |
|
2462 | 2466 | adds, removes, copies, and renames. If the working directory has two |
|
2463 | 2467 | parents, you must explicitly specify the revision to revert to. |
|
2464 | 2468 | |
|
2465 | 2469 | Using the -r/--rev option, revert the given files or directories to their |
|
2466 | 2470 | contents as of a specific revision. This can be helpful to "roll back" |
|
2467 | 2471 | some or all of an earlier change. See 'hg help dates' for a list of |
|
2468 | 2472 | formats valid for -d/--date. |
|
2469 | 2473 | |
|
2470 | 2474 | Revert modifies the working directory. It does not commit any changes, or |
|
2471 | 2475 | change the parent of the working directory. If you revert to a revision |
|
2472 | 2476 | other than the parent of the working directory, the reverted files will |
|
2473 | 2477 | thus appear modified afterwards. |
|
2474 | 2478 | |
|
2475 | 2479 | If a file has been deleted, it is restored. If the executable mode of a |
|
2476 | 2480 | file was changed, it is reset. |
|
2477 | 2481 | |
|
2478 | 2482 | If names are given, all files matching the names are reverted. If no |
|
2479 | 2483 | arguments are given, no files are reverted. |
|
2480 | 2484 | |
|
2481 | 2485 | Modified files are saved with a .orig suffix before reverting. To disable |
|
2482 | 2486 | these backups, use --no-backup. |
|
2483 | 2487 | """ |
|
2484 | 2488 | |
|
2485 | 2489 | if opts["date"]: |
|
2486 | 2490 | if opts["rev"]: |
|
2487 | 2491 | raise util.Abort(_("you can't specify a revision and a date")) |
|
2488 | 2492 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
2489 | 2493 | |
|
2490 | 2494 | if not pats and not opts.get('all'): |
|
2491 | 2495 | raise util.Abort(_('no files or directories specified; ' |
|
2492 | 2496 | 'use --all to revert the whole repo')) |
|
2493 | 2497 | |
|
2494 | 2498 | parent, p2 = repo.dirstate.parents() |
|
2495 | 2499 | if not opts.get('rev') and p2 != nullid: |
|
2496 | 2500 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2497 | 2501 | 'specific revision')) |
|
2498 | 2502 | ctx = repo[opts.get('rev')] |
|
2499 | 2503 | node = ctx.node() |
|
2500 | 2504 | mf = ctx.manifest() |
|
2501 | 2505 | if node == parent: |
|
2502 | 2506 | pmf = mf |
|
2503 | 2507 | else: |
|
2504 | 2508 | pmf = None |
|
2505 | 2509 | |
|
2506 | 2510 | # need all matching names in dirstate and manifest of target rev, |
|
2507 | 2511 | # so have to walk both. do not print errors if files exist in one |
|
2508 | 2512 | # but not other. |
|
2509 | 2513 | |
|
2510 | 2514 | names = {} |
|
2511 | 2515 | |
|
2512 | 2516 | wlock = repo.wlock() |
|
2513 | 2517 | try: |
|
2514 | 2518 | # walk dirstate. |
|
2515 | 2519 | |
|
2516 | 2520 | m = cmdutil.match(repo, pats, opts) |
|
2517 | 2521 | m.bad = lambda x,y: False |
|
2518 | 2522 | for abs in repo.walk(m): |
|
2519 | 2523 | names[abs] = m.rel(abs), m.exact(abs) |
|
2520 | 2524 | |
|
2521 | 2525 | # walk target manifest. |
|
2522 | 2526 | |
|
2523 | 2527 | def badfn(path, msg): |
|
2524 | 2528 | if path in names: |
|
2525 | 2529 | return |
|
2526 | 2530 | path_ = path + '/' |
|
2527 | 2531 | for f in names: |
|
2528 | 2532 | if f.startswith(path_): |
|
2529 | 2533 | return |
|
2530 | 2534 | ui.warn("%s: %s\n" % (m.rel(path), msg)) |
|
2531 | 2535 | |
|
2532 | 2536 | m = cmdutil.match(repo, pats, opts) |
|
2533 | 2537 | m.bad = badfn |
|
2534 | 2538 | for abs in repo[node].walk(m): |
|
2535 | 2539 | if abs not in names: |
|
2536 | 2540 | names[abs] = m.rel(abs), m.exact(abs) |
|
2537 | 2541 | |
|
2538 | 2542 | m = cmdutil.matchfiles(repo, names) |
|
2539 | 2543 | changes = repo.status(match=m)[:4] |
|
2540 | 2544 | modified, added, removed, deleted = map(set, changes) |
|
2541 | 2545 | |
|
2542 | 2546 | # if f is a rename, also revert the source |
|
2543 | 2547 | cwd = repo.getcwd() |
|
2544 | 2548 | for f in added: |
|
2545 | 2549 | src = repo.dirstate.copied(f) |
|
2546 | 2550 | if src and src not in names and repo.dirstate[src] == 'r': |
|
2547 | 2551 | removed.add(src) |
|
2548 | 2552 | names[src] = (repo.pathto(src, cwd), True) |
|
2549 | 2553 | |
|
2550 | 2554 | def removeforget(abs): |
|
2551 | 2555 | if repo.dirstate[abs] == 'a': |
|
2552 | 2556 | return _('forgetting %s\n') |
|
2553 | 2557 | return _('removing %s\n') |
|
2554 | 2558 | |
|
2555 | 2559 | revert = ([], _('reverting %s\n')) |
|
2556 | 2560 | add = ([], _('adding %s\n')) |
|
2557 | 2561 | remove = ([], removeforget) |
|
2558 | 2562 | undelete = ([], _('undeleting %s\n')) |
|
2559 | 2563 | |
|
2560 | 2564 | disptable = ( |
|
2561 | 2565 | # dispatch table: |
|
2562 | 2566 | # file state |
|
2563 | 2567 | # action if in target manifest |
|
2564 | 2568 | # action if not in target manifest |
|
2565 | 2569 | # make backup if in target manifest |
|
2566 | 2570 | # make backup if not in target manifest |
|
2567 | 2571 | (modified, revert, remove, True, True), |
|
2568 | 2572 | (added, revert, remove, True, False), |
|
2569 | 2573 | (removed, undelete, None, False, False), |
|
2570 | 2574 | (deleted, revert, remove, False, False), |
|
2571 | 2575 | ) |
|
2572 | 2576 | |
|
2573 | 2577 | for abs, (rel, exact) in sorted(names.items()): |
|
2574 | 2578 | mfentry = mf.get(abs) |
|
2575 | 2579 | target = repo.wjoin(abs) |
|
2576 | 2580 | def handle(xlist, dobackup): |
|
2577 | 2581 | xlist[0].append(abs) |
|
2578 | 2582 | if dobackup and not opts.get('no_backup') and util.lexists(target): |
|
2579 | 2583 | bakname = "%s.orig" % rel |
|
2580 | 2584 | ui.note(_('saving current version of %s as %s\n') % |
|
2581 | 2585 | (rel, bakname)) |
|
2582 | 2586 | if not opts.get('dry_run'): |
|
2583 | 2587 | util.copyfile(target, bakname) |
|
2584 | 2588 | if ui.verbose or not exact: |
|
2585 | 2589 | msg = xlist[1] |
|
2586 | 2590 | if not isinstance(msg, basestring): |
|
2587 | 2591 | msg = msg(abs) |
|
2588 | 2592 | ui.status(msg % rel) |
|
2589 | 2593 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2590 | 2594 | if abs not in table: continue |
|
2591 | 2595 | # file has changed in dirstate |
|
2592 | 2596 | if mfentry: |
|
2593 | 2597 | handle(hitlist, backuphit) |
|
2594 | 2598 | elif misslist is not None: |
|
2595 | 2599 | handle(misslist, backupmiss) |
|
2596 | 2600 | break |
|
2597 | 2601 | else: |
|
2598 | 2602 | if abs not in repo.dirstate: |
|
2599 | 2603 | if mfentry: |
|
2600 | 2604 | handle(add, True) |
|
2601 | 2605 | elif exact: |
|
2602 | 2606 | ui.warn(_('file not managed: %s\n') % rel) |
|
2603 | 2607 | continue |
|
2604 | 2608 | # file has not changed in dirstate |
|
2605 | 2609 | if node == parent: |
|
2606 | 2610 | if exact: ui.warn(_('no changes needed to %s\n') % rel) |
|
2607 | 2611 | continue |
|
2608 | 2612 | if pmf is None: |
|
2609 | 2613 | # only need parent manifest in this unlikely case, |
|
2610 | 2614 | # so do not read by default |
|
2611 | 2615 | pmf = repo[parent].manifest() |
|
2612 | 2616 | if abs in pmf: |
|
2613 | 2617 | if mfentry: |
|
2614 | 2618 | # if version of file is same in parent and target |
|
2615 | 2619 | # manifests, do nothing |
|
2616 | 2620 | if (pmf[abs] != mfentry or |
|
2617 | 2621 | pmf.flags(abs) != mf.flags(abs)): |
|
2618 | 2622 | handle(revert, False) |
|
2619 | 2623 | else: |
|
2620 | 2624 | handle(remove, False) |
|
2621 | 2625 | |
|
2622 | 2626 | if not opts.get('dry_run'): |
|
2623 | 2627 | def checkout(f): |
|
2624 | 2628 | fc = ctx[f] |
|
2625 | 2629 | repo.wwrite(f, fc.data(), fc.flags()) |
|
2626 | 2630 | |
|
2627 | 2631 | audit_path = util.path_auditor(repo.root) |
|
2628 | 2632 | for f in remove[0]: |
|
2629 | 2633 | if repo.dirstate[f] == 'a': |
|
2630 | 2634 | repo.dirstate.forget(f) |
|
2631 | 2635 | continue |
|
2632 | 2636 | audit_path(f) |
|
2633 | 2637 | try: |
|
2634 | 2638 | util.unlink(repo.wjoin(f)) |
|
2635 | 2639 | except OSError: |
|
2636 | 2640 | pass |
|
2637 | 2641 | repo.dirstate.remove(f) |
|
2638 | 2642 | |
|
2639 | 2643 | normal = None |
|
2640 | 2644 | if node == parent: |
|
2641 | 2645 | # We're reverting to our parent. If possible, we'd like status |
|
2642 | 2646 | # to report the file as clean. We have to use normallookup for |
|
2643 | 2647 | # merges to avoid losing information about merged/dirty files. |
|
2644 | 2648 | if p2 != nullid: |
|
2645 | 2649 | normal = repo.dirstate.normallookup |
|
2646 | 2650 | else: |
|
2647 | 2651 | normal = repo.dirstate.normal |
|
2648 | 2652 | for f in revert[0]: |
|
2649 | 2653 | checkout(f) |
|
2650 | 2654 | if normal: |
|
2651 | 2655 | normal(f) |
|
2652 | 2656 | |
|
2653 | 2657 | for f in add[0]: |
|
2654 | 2658 | checkout(f) |
|
2655 | 2659 | repo.dirstate.add(f) |
|
2656 | 2660 | |
|
2657 | 2661 | normal = repo.dirstate.normallookup |
|
2658 | 2662 | if node == parent and p2 == nullid: |
|
2659 | 2663 | normal = repo.dirstate.normal |
|
2660 | 2664 | for f in undelete[0]: |
|
2661 | 2665 | checkout(f) |
|
2662 | 2666 | normal(f) |
|
2663 | 2667 | |
|
2664 | 2668 | finally: |
|
2665 | 2669 | wlock.release() |
|
2666 | 2670 | |
|
2667 | 2671 | def rollback(ui, repo): |
|
2668 | 2672 | """roll back the last transaction |
|
2669 | 2673 | |
|
2670 | 2674 | This command should be used with care. There is only one level of |
|
2671 | 2675 | rollback, and there is no way to undo a rollback. It will also restore the |
|
2672 | 2676 | dirstate at the time of the last transaction, losing any dirstate changes |
|
2673 | 2677 | since that time. This command does not alter the working directory. |
|
2674 | 2678 | |
|
2675 | 2679 | Transactions are used to encapsulate the effects of all commands that |
|
2676 | 2680 | create new changesets or propagate existing changesets into a repository. |
|
2677 | 2681 | For example, the following commands are transactional, and their effects |
|
2678 | can be rolled back: | |
|
2682 | can be rolled back:: | |
|
2679 | 2683 | |
|
2680 | 2684 | commit |
|
2681 | 2685 | import |
|
2682 | 2686 | pull |
|
2683 | 2687 | push (with this repository as destination) |
|
2684 | 2688 | unbundle |
|
2685 | 2689 | |
|
2686 | 2690 | This command is not intended for use on public repositories. Once changes |
|
2687 | 2691 | are visible for pull by other users, rolling a transaction back locally is |
|
2688 | 2692 | ineffective (someone else may already have pulled the changes). |
|
2689 | 2693 | Furthermore, a race is possible with readers of the repository; for |
|
2690 | 2694 | example an in-progress pull from the repository may fail if a rollback is |
|
2691 | 2695 | performed. |
|
2692 | 2696 | """ |
|
2693 | 2697 | repo.rollback() |
|
2694 | 2698 | |
|
2695 | 2699 | def root(ui, repo): |
|
2696 | 2700 | """print the root (top) of the current working directory |
|
2697 | 2701 | |
|
2698 | 2702 | Print the root directory of the current repository. |
|
2699 | 2703 | """ |
|
2700 | 2704 | ui.write(repo.root + "\n") |
|
2701 | 2705 | |
|
2702 | 2706 | def serve(ui, repo, **opts): |
|
2703 | 2707 | """export the repository via HTTP |
|
2704 | 2708 | |
|
2705 | 2709 | Start a local HTTP repository browser and pull server. |
|
2706 | 2710 | |
|
2707 | 2711 | By default, the server logs accesses to stdout and errors to stderr. Use |
|
2708 | 2712 | the -A/--accesslog and -E/--errorlog options to log to files. |
|
2709 | 2713 | """ |
|
2710 | 2714 | |
|
2711 | 2715 | if opts["stdio"]: |
|
2712 | 2716 | if repo is None: |
|
2713 | 2717 | raise error.RepoError(_("There is no Mercurial repository here" |
|
2714 | 2718 | " (.hg not found)")) |
|
2715 | 2719 | s = sshserver.sshserver(ui, repo) |
|
2716 | 2720 | s.serve_forever() |
|
2717 | 2721 | |
|
2718 | 2722 | baseui = repo and repo.baseui or ui |
|
2719 | 2723 | optlist = ("name templates style address port prefix ipv6" |
|
2720 | 2724 | " accesslog errorlog webdir_conf certificate encoding") |
|
2721 | 2725 | for o in optlist.split(): |
|
2722 | 2726 | if opts.get(o, None): |
|
2723 | 2727 | baseui.setconfig("web", o, str(opts[o])) |
|
2724 | 2728 | if (repo is not None) and (repo.ui != baseui): |
|
2725 | 2729 | repo.ui.setconfig("web", o, str(opts[o])) |
|
2726 | 2730 | |
|
2727 | 2731 | if repo is None and not ui.config("web", "webdir_conf"): |
|
2728 | 2732 | raise error.RepoError(_("There is no Mercurial repository here" |
|
2729 | 2733 | " (.hg not found)")) |
|
2730 | 2734 | |
|
2731 | 2735 | class service(object): |
|
2732 | 2736 | def init(self): |
|
2733 | 2737 | util.set_signal_handler() |
|
2734 | 2738 | self.httpd = server.create_server(baseui, repo) |
|
2735 | 2739 | |
|
2736 | 2740 | if not ui.verbose: return |
|
2737 | 2741 | |
|
2738 | 2742 | if self.httpd.prefix: |
|
2739 | 2743 | prefix = self.httpd.prefix.strip('/') + '/' |
|
2740 | 2744 | else: |
|
2741 | 2745 | prefix = '' |
|
2742 | 2746 | |
|
2743 | 2747 | port = ':%d' % self.httpd.port |
|
2744 | 2748 | if port == ':80': |
|
2745 | 2749 | port = '' |
|
2746 | 2750 | |
|
2747 | 2751 | bindaddr = self.httpd.addr |
|
2748 | 2752 | if bindaddr == '0.0.0.0': |
|
2749 | 2753 | bindaddr = '*' |
|
2750 | 2754 | elif ':' in bindaddr: # IPv6 |
|
2751 | 2755 | bindaddr = '[%s]' % bindaddr |
|
2752 | 2756 | |
|
2753 | 2757 | fqaddr = self.httpd.fqaddr |
|
2754 | 2758 | if ':' in fqaddr: |
|
2755 | 2759 | fqaddr = '[%s]' % fqaddr |
|
2756 | 2760 | ui.status(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
2757 | 2761 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
2758 | 2762 | |
|
2759 | 2763 | def run(self): |
|
2760 | 2764 | self.httpd.serve_forever() |
|
2761 | 2765 | |
|
2762 | 2766 | service = service() |
|
2763 | 2767 | |
|
2764 | 2768 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
2765 | 2769 | |
|
2766 | 2770 | def status(ui, repo, *pats, **opts): |
|
2767 | 2771 | """show changed files in the working directory |
|
2768 | 2772 | |
|
2769 | 2773 | Show status of files in the repository. If names are given, only files |
|
2770 | 2774 | that match are shown. Files that are clean or ignored or the source of a |
|
2771 | 2775 | copy/move operation, are not listed unless -c/--clean, -i/--ignored, |
|
2772 | 2776 | -C/--copies or -A/--all are given. Unless options described with "show |
|
2773 | 2777 | only ..." are given, the options -mardu are used. |
|
2774 | 2778 | |
|
2775 | 2779 | Option -q/--quiet hides untracked (unknown and ignored) files unless |
|
2776 | 2780 | explicitly requested with -u/--unknown or -i/--ignored. |
|
2777 | 2781 | |
|
2778 | 2782 | NOTE: status may appear to disagree with diff if permissions have changed |
|
2779 | 2783 | or a merge has occurred. The standard diff format does not report |
|
2780 | 2784 | permission changes and diff only reports changes relative to one merge |
|
2781 | 2785 | parent. |
|
2782 | 2786 | |
|
2783 | 2787 | If one revision is given, it is used as the base revision. If two |
|
2784 | 2788 | revisions are given, the differences between them are shown. |
|
2785 | 2789 | |
|
2786 | The codes used to show the status of files are: | |
|
2787 | M = modified | |
|
2788 |
|
|
|
2789 |
|
|
|
2790 | C = clean | |
|
2791 | ! = missing (deleted by non-hg command, but still tracked) | |
|
2792 | ? = not tracked | |
|
2793 |
|
|
|
2794 | = origin of the previous file listed as A (added) | |
|
2790 | The codes used to show the status of files are:: | |
|
2791 | ||
|
2792 | M = modified | |
|
2793 | A = added | |
|
2794 | R = removed | |
|
2795 | C = clean | |
|
2796 | ! = missing (deleted by non-hg command, but still tracked) | |
|
2797 | ? = not tracked | |
|
2798 | I = ignored | |
|
2799 | = origin of the previous file listed as A (added) | |
|
2795 | 2800 | """ |
|
2796 | 2801 | |
|
2797 | 2802 | node1, node2 = cmdutil.revpair(repo, opts.get('rev')) |
|
2798 | 2803 | cwd = (pats and repo.getcwd()) or '' |
|
2799 | 2804 | end = opts.get('print0') and '\0' or '\n' |
|
2800 | 2805 | copy = {} |
|
2801 | 2806 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
2802 | 2807 | show = [k for k in states if opts.get(k)] |
|
2803 | 2808 | if opts.get('all'): |
|
2804 | 2809 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
2805 | 2810 | if not show: |
|
2806 | 2811 | show = ui.quiet and states[:4] or states[:5] |
|
2807 | 2812 | |
|
2808 | 2813 | stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts), |
|
2809 | 2814 | 'ignored' in show, 'clean' in show, 'unknown' in show) |
|
2810 | 2815 | changestates = zip(states, 'MAR!?IC', stat) |
|
2811 | 2816 | |
|
2812 | 2817 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): |
|
2813 | 2818 | ctxn = repo[nullid] |
|
2814 | 2819 | ctx1 = repo[node1] |
|
2815 | 2820 | ctx2 = repo[node2] |
|
2816 | 2821 | added = stat[1] |
|
2817 | 2822 | if node2 is None: |
|
2818 | 2823 | added = stat[0] + stat[1] # merged? |
|
2819 | 2824 | |
|
2820 | 2825 | for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems(): |
|
2821 | 2826 | if k in added: |
|
2822 | 2827 | copy[k] = v |
|
2823 | 2828 | elif v in added: |
|
2824 | 2829 | copy[v] = k |
|
2825 | 2830 | |
|
2826 | 2831 | for state, char, files in changestates: |
|
2827 | 2832 | if state in show: |
|
2828 | 2833 | format = "%s %%s%s" % (char, end) |
|
2829 | 2834 | if opts.get('no_status'): |
|
2830 | 2835 | format = "%%s%s" % end |
|
2831 | 2836 | |
|
2832 | 2837 | for f in files: |
|
2833 | 2838 | ui.write(format % repo.pathto(f, cwd)) |
|
2834 | 2839 | if f in copy: |
|
2835 | 2840 | ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end)) |
|
2836 | 2841 | |
|
2837 | 2842 | def tag(ui, repo, name1, *names, **opts): |
|
2838 | 2843 | """add one or more tags for the current or given revision |
|
2839 | 2844 | |
|
2840 | 2845 | Name a particular revision using <name>. |
|
2841 | 2846 | |
|
2842 | 2847 | Tags are used to name particular revisions of the repository and are very |
|
2843 | 2848 | useful to compare different revisions, to go back to significant earlier |
|
2844 | 2849 | versions or to mark branch points as releases, etc. |
|
2845 | 2850 | |
|
2846 | 2851 | If no revision is given, the parent of the working directory is used, or |
|
2847 | 2852 | tip if no revision is checked out. |
|
2848 | 2853 | |
|
2849 | 2854 | To facilitate version control, distribution, and merging of tags, they are |
|
2850 | 2855 | stored as a file named ".hgtags" which is managed similarly to other |
|
2851 | 2856 | project files and can be hand-edited if necessary. The file |
|
2852 | 2857 | '.hg/localtags' is used for local tags (not shared among repositories). |
|
2853 | 2858 | |
|
2854 | 2859 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
2855 | 2860 | """ |
|
2856 | 2861 | |
|
2857 | 2862 | rev_ = "." |
|
2858 | 2863 | names = (name1,) + names |
|
2859 | 2864 | if len(names) != len(set(names)): |
|
2860 | 2865 | raise util.Abort(_('tag names must be unique')) |
|
2861 | 2866 | for n in names: |
|
2862 | 2867 | if n in ['tip', '.', 'null']: |
|
2863 | 2868 | raise util.Abort(_('the name \'%s\' is reserved') % n) |
|
2864 | 2869 | if opts.get('rev') and opts.get('remove'): |
|
2865 | 2870 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
2866 | 2871 | if opts.get('rev'): |
|
2867 | 2872 | rev_ = opts['rev'] |
|
2868 | 2873 | message = opts.get('message') |
|
2869 | 2874 | if opts.get('remove'): |
|
2870 | 2875 | expectedtype = opts.get('local') and 'local' or 'global' |
|
2871 | 2876 | for n in names: |
|
2872 | 2877 | if not repo.tagtype(n): |
|
2873 | 2878 | raise util.Abort(_('tag \'%s\' does not exist') % n) |
|
2874 | 2879 | if repo.tagtype(n) != expectedtype: |
|
2875 | 2880 | if expectedtype == 'global': |
|
2876 | 2881 | raise util.Abort(_('tag \'%s\' is not a global tag') % n) |
|
2877 | 2882 | else: |
|
2878 | 2883 | raise util.Abort(_('tag \'%s\' is not a local tag') % n) |
|
2879 | 2884 | rev_ = nullid |
|
2880 | 2885 | if not message: |
|
2881 | 2886 | message = _('Removed tag %s') % ', '.join(names) |
|
2882 | 2887 | elif not opts.get('force'): |
|
2883 | 2888 | for n in names: |
|
2884 | 2889 | if n in repo.tags(): |
|
2885 | 2890 | raise util.Abort(_('tag \'%s\' already exists ' |
|
2886 | 2891 | '(use -f to force)') % n) |
|
2887 | 2892 | if not rev_ and repo.dirstate.parents()[1] != nullid: |
|
2888 | 2893 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
2889 | 2894 | 'specific revision')) |
|
2890 | 2895 | r = repo[rev_].node() |
|
2891 | 2896 | |
|
2892 | 2897 | if not message: |
|
2893 | 2898 | message = (_('Added tag %s for changeset %s') % |
|
2894 | 2899 | (', '.join(names), short(r))) |
|
2895 | 2900 | |
|
2896 | 2901 | date = opts.get('date') |
|
2897 | 2902 | if date: |
|
2898 | 2903 | date = util.parsedate(date) |
|
2899 | 2904 | |
|
2900 | 2905 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) |
|
2901 | 2906 | |
|
2902 | 2907 | def tags(ui, repo): |
|
2903 | 2908 | """list repository tags |
|
2904 | 2909 | |
|
2905 | 2910 | This lists both regular and local tags. When the -v/--verbose switch is |
|
2906 | 2911 | used, a third column "local" is printed for local tags. |
|
2907 | 2912 | """ |
|
2908 | 2913 | |
|
2909 | 2914 | hexfunc = ui.debugflag and hex or short |
|
2910 | 2915 | tagtype = "" |
|
2911 | 2916 | |
|
2912 | 2917 | for t, n in reversed(repo.tagslist()): |
|
2913 | 2918 | if ui.quiet: |
|
2914 | 2919 | ui.write("%s\n" % t) |
|
2915 | 2920 | continue |
|
2916 | 2921 | |
|
2917 | 2922 | try: |
|
2918 | 2923 | hn = hexfunc(n) |
|
2919 | 2924 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
2920 | 2925 | except error.LookupError: |
|
2921 | 2926 | r = " ?:%s" % hn |
|
2922 | 2927 | else: |
|
2923 | 2928 | spaces = " " * (30 - encoding.colwidth(t)) |
|
2924 | 2929 | if ui.verbose: |
|
2925 | 2930 | if repo.tagtype(t) == 'local': |
|
2926 | 2931 | tagtype = " local" |
|
2927 | 2932 | else: |
|
2928 | 2933 | tagtype = "" |
|
2929 | 2934 | ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype)) |
|
2930 | 2935 | |
|
2931 | 2936 | def tip(ui, repo, **opts): |
|
2932 | 2937 | """show the tip revision |
|
2933 | 2938 | |
|
2934 | 2939 | The tip revision (usually just called the tip) is the changeset most |
|
2935 | 2940 | recently added to the repository (and therefore the most recently changed |
|
2936 | 2941 | head). |
|
2937 | 2942 | |
|
2938 | 2943 | If you have just made a commit, that commit will be the tip. If you have |
|
2939 | 2944 | just pulled changes from another repository, the tip of that repository |
|
2940 | 2945 | becomes the current tip. The "tip" tag is special and cannot be renamed or |
|
2941 | 2946 | assigned to a different changeset. |
|
2942 | 2947 | """ |
|
2943 | 2948 | cmdutil.show_changeset(ui, repo, opts).show(repo[len(repo) - 1]) |
|
2944 | 2949 | |
|
2945 | 2950 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
2946 | 2951 | """apply one or more changegroup files |
|
2947 | 2952 | |
|
2948 | 2953 | Apply one or more compressed changegroup files generated by the bundle |
|
2949 | 2954 | command. |
|
2950 | 2955 | """ |
|
2951 | 2956 | fnames = (fname1,) + fnames |
|
2952 | 2957 | |
|
2953 | 2958 | lock = repo.lock() |
|
2954 | 2959 | try: |
|
2955 | 2960 | for fname in fnames: |
|
2956 | 2961 | f = url.open(ui, fname) |
|
2957 | 2962 | gen = changegroup.readbundle(f, fname) |
|
2958 | 2963 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) |
|
2959 | 2964 | finally: |
|
2960 | 2965 | lock.release() |
|
2961 | 2966 | |
|
2962 | 2967 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
2963 | 2968 | |
|
2964 | 2969 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): |
|
2965 | 2970 | """update working directory |
|
2966 | 2971 | |
|
2967 | 2972 | Update the repository's working directory to the specified revision, or |
|
2968 | 2973 | the tip of the current branch if none is specified. Use null as the |
|
2969 | 2974 | revision to remove the working copy (like 'hg clone -U'). |
|
2970 | 2975 | |
|
2971 | 2976 | When the working directory contains no uncommitted changes, it will be |
|
2972 | 2977 | replaced by the state of the requested revision from the repository. When |
|
2973 | 2978 | the requested revision is on a different branch, the working directory |
|
2974 | 2979 | will additionally be switched to that branch. |
|
2975 | 2980 | |
|
2976 | 2981 | When there are uncommitted changes, use option -C/--clean to discard them, |
|
2977 | 2982 | forcibly replacing the state of the working directory with the requested |
|
2978 | 2983 | revision. Alternately, use -c/--check to abort. |
|
2979 | 2984 | |
|
2980 | 2985 | When there are uncommitted changes and option -C/--clean is not used, and |
|
2981 | 2986 | the parent revision and requested revision are on the same branch, and one |
|
2982 | 2987 | of them is an ancestor of the other, then the new working directory will |
|
2983 | 2988 | contain the requested revision merged with the uncommitted changes. |
|
2984 | 2989 | Otherwise, the update will fail with a suggestion to use 'merge' or |
|
2985 | 2990 | 'update -C' instead. |
|
2986 | 2991 | |
|
2987 | 2992 | If you want to update just one file to an older revision, use revert. |
|
2988 | 2993 | |
|
2989 | 2994 | See 'hg help dates' for a list of formats valid for -d/--date. |
|
2990 | 2995 | """ |
|
2991 | 2996 | if rev and node: |
|
2992 | 2997 | raise util.Abort(_("please specify just one revision")) |
|
2993 | 2998 | |
|
2994 | 2999 | if not rev: |
|
2995 | 3000 | rev = node |
|
2996 | 3001 | |
|
2997 | 3002 | if not clean and check: |
|
2998 | 3003 | # we could use dirty() but we can ignore merge and branch trivia |
|
2999 | 3004 | c = repo[None] |
|
3000 | 3005 | if c.modified() or c.added() or c.removed(): |
|
3001 | 3006 | raise util.Abort(_("uncommitted local changes")) |
|
3002 | 3007 | |
|
3003 | 3008 | if date: |
|
3004 | 3009 | if rev: |
|
3005 | 3010 | raise util.Abort(_("you can't specify a revision and a date")) |
|
3006 | 3011 | rev = cmdutil.finddate(ui, repo, date) |
|
3007 | 3012 | |
|
3008 | 3013 | if clean: |
|
3009 | 3014 | return hg.clean(repo, rev) |
|
3010 | 3015 | else: |
|
3011 | 3016 | return hg.update(repo, rev) |
|
3012 | 3017 | |
|
3013 | 3018 | def verify(ui, repo): |
|
3014 | 3019 | """verify the integrity of the repository |
|
3015 | 3020 | |
|
3016 | 3021 | Verify the integrity of the current repository. |
|
3017 | 3022 | |
|
3018 | 3023 | This will perform an extensive check of the repository's integrity, |
|
3019 | 3024 | validating the hashes and checksums of each entry in the changelog, |
|
3020 | 3025 | manifest, and tracked files, as well as the integrity of their crosslinks |
|
3021 | 3026 | and indices. |
|
3022 | 3027 | """ |
|
3023 | 3028 | return hg.verify(repo) |
|
3024 | 3029 | |
|
3025 | 3030 | def version_(ui): |
|
3026 | 3031 | """output version and copyright information""" |
|
3027 | 3032 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
3028 | 3033 | % util.version()) |
|
3029 | 3034 | ui.status(_( |
|
3030 | 3035 | "\nCopyright (C) 2005-2009 Matt Mackall <mpm@selenic.com> and others\n" |
|
3031 | 3036 | "This is free software; see the source for copying conditions. " |
|
3032 | 3037 | "There is NO\nwarranty; " |
|
3033 | 3038 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
3034 | 3039 | )) |
|
3035 | 3040 | |
|
3036 | 3041 | # Command options and aliases are listed here, alphabetically |
|
3037 | 3042 | |
|
3038 | 3043 | globalopts = [ |
|
3039 | 3044 | ('R', 'repository', '', |
|
3040 | 3045 | _('repository root directory or symbolic path name')), |
|
3041 | 3046 | ('', 'cwd', '', _('change working directory')), |
|
3042 | 3047 | ('y', 'noninteractive', None, |
|
3043 | 3048 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3044 | 3049 | ('q', 'quiet', None, _('suppress output')), |
|
3045 | 3050 | ('v', 'verbose', None, _('enable additional output')), |
|
3046 | 3051 | ('', 'config', [], _('set/override config option')), |
|
3047 | 3052 | ('', 'debug', None, _('enable debugging output')), |
|
3048 | 3053 | ('', 'debugger', None, _('start debugger')), |
|
3049 | 3054 | ('', 'encoding', encoding.encoding, _('set the charset encoding')), |
|
3050 | 3055 | ('', 'encodingmode', encoding.encodingmode, |
|
3051 | 3056 | _('set the charset encoding mode')), |
|
3052 | 3057 | ('', 'traceback', None, _('print traceback on exception')), |
|
3053 | 3058 | ('', 'time', None, _('time how long the command takes')), |
|
3054 | 3059 | ('', 'profile', None, _('print command execution profile')), |
|
3055 | 3060 | ('', 'version', None, _('output version information and exit')), |
|
3056 | 3061 | ('h', 'help', None, _('display help and exit')), |
|
3057 | 3062 | ] |
|
3058 | 3063 | |
|
3059 | 3064 | dryrunopts = [('n', 'dry-run', None, |
|
3060 | 3065 | _('do not perform actions, just print output'))] |
|
3061 | 3066 | |
|
3062 | 3067 | remoteopts = [ |
|
3063 | 3068 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3064 | 3069 | ('', 'remotecmd', '', _('specify hg command to run on the remote side')), |
|
3065 | 3070 | ] |
|
3066 | 3071 | |
|
3067 | 3072 | walkopts = [ |
|
3068 | 3073 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3069 | 3074 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
3070 | 3075 | ] |
|
3071 | 3076 | |
|
3072 | 3077 | commitopts = [ |
|
3073 | 3078 | ('m', 'message', '', _('use <text> as commit message')), |
|
3074 | 3079 | ('l', 'logfile', '', _('read commit message from <file>')), |
|
3075 | 3080 | ] |
|
3076 | 3081 | |
|
3077 | 3082 | commitopts2 = [ |
|
3078 | 3083 | ('d', 'date', '', _('record datecode as commit date')), |
|
3079 | 3084 | ('u', 'user', '', _('record the specified user as committer')), |
|
3080 | 3085 | ] |
|
3081 | 3086 | |
|
3082 | 3087 | templateopts = [ |
|
3083 | 3088 | ('', 'style', '', _('display using template map file')), |
|
3084 | 3089 | ('', 'template', '', _('display with template')), |
|
3085 | 3090 | ] |
|
3086 | 3091 | |
|
3087 | 3092 | logopts = [ |
|
3088 | 3093 | ('p', 'patch', None, _('show patch')), |
|
3089 | 3094 | ('g', 'git', None, _('use git extended diff format')), |
|
3090 | 3095 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
3091 | 3096 | ('M', 'no-merges', None, _('do not show merges')), |
|
3092 | 3097 | ] + templateopts |
|
3093 | 3098 | |
|
3094 | 3099 | diffopts = [ |
|
3095 | 3100 | ('a', 'text', None, _('treat all files as text')), |
|
3096 | 3101 | ('g', 'git', None, _('use git extended diff format')), |
|
3097 | 3102 | ('', 'nodates', None, _("don't include dates in diff headers")) |
|
3098 | 3103 | ] |
|
3099 | 3104 | |
|
3100 | 3105 | diffopts2 = [ |
|
3101 | 3106 | ('p', 'show-function', None, _('show which function each change is in')), |
|
3102 | 3107 | ('w', 'ignore-all-space', None, |
|
3103 | 3108 | _('ignore white space when comparing lines')), |
|
3104 | 3109 | ('b', 'ignore-space-change', None, |
|
3105 | 3110 | _('ignore changes in the amount of white space')), |
|
3106 | 3111 | ('B', 'ignore-blank-lines', None, |
|
3107 | 3112 | _('ignore changes whose lines are all blank')), |
|
3108 | 3113 | ('U', 'unified', '', _('number of lines of context to show')) |
|
3109 | 3114 | ] |
|
3110 | 3115 | |
|
3111 | 3116 | similarityopts = [ |
|
3112 | 3117 | ('s', 'similarity', '', |
|
3113 | 3118 | _('guess renamed files by similarity (0<=s<=100)')) |
|
3114 | 3119 | ] |
|
3115 | 3120 | |
|
3116 | 3121 | table = { |
|
3117 | 3122 | "^add": (add, walkopts + dryrunopts, _('[OPTION]... [FILE]...')), |
|
3118 | 3123 | "addremove": |
|
3119 | 3124 | (addremove, similarityopts + walkopts + dryrunopts, |
|
3120 | 3125 | _('[OPTION]... [FILE]...')), |
|
3121 | 3126 | "^annotate|blame": |
|
3122 | 3127 | (annotate, |
|
3123 | 3128 | [('r', 'rev', '', _('annotate the specified revision')), |
|
3124 | 3129 | ('f', 'follow', None, _('follow file copies and renames')), |
|
3125 | 3130 | ('a', 'text', None, _('treat all files as text')), |
|
3126 | 3131 | ('u', 'user', None, _('list the author (long with -v)')), |
|
3127 | 3132 | ('d', 'date', None, _('list the date (short with -q)')), |
|
3128 | 3133 | ('n', 'number', None, _('list the revision number (default)')), |
|
3129 | 3134 | ('c', 'changeset', None, _('list the changeset')), |
|
3130 | 3135 | ('l', 'line-number', None, |
|
3131 | 3136 | _('show line number at the first appearance')) |
|
3132 | 3137 | ] + walkopts, |
|
3133 | 3138 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')), |
|
3134 | 3139 | "archive": |
|
3135 | 3140 | (archive, |
|
3136 | 3141 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
3137 | 3142 | ('p', 'prefix', '', _('directory prefix for files in archive')), |
|
3138 | 3143 | ('r', 'rev', '', _('revision to distribute')), |
|
3139 | 3144 | ('t', 'type', '', _('type of distribution to create')), |
|
3140 | 3145 | ] + walkopts, |
|
3141 | 3146 | _('[OPTION]... DEST')), |
|
3142 | 3147 | "backout": |
|
3143 | 3148 | (backout, |
|
3144 | 3149 | [('', 'merge', None, |
|
3145 | 3150 | _('merge with old dirstate parent after backout')), |
|
3146 | 3151 | ('', 'parent', '', _('parent to choose when backing out merge')), |
|
3147 | 3152 | ('r', 'rev', '', _('revision to backout')), |
|
3148 | 3153 | ] + walkopts + commitopts + commitopts2, |
|
3149 | 3154 | _('[OPTION]... [-r] REV')), |
|
3150 | 3155 | "bisect": |
|
3151 | 3156 | (bisect, |
|
3152 | 3157 | [('r', 'reset', False, _('reset bisect state')), |
|
3153 | 3158 | ('g', 'good', False, _('mark changeset good')), |
|
3154 | 3159 | ('b', 'bad', False, _('mark changeset bad')), |
|
3155 | 3160 | ('s', 'skip', False, _('skip testing changeset')), |
|
3156 | 3161 | ('c', 'command', '', _('use command to check changeset state')), |
|
3157 | 3162 | ('U', 'noupdate', False, _('do not update to target'))], |
|
3158 | 3163 | _("[-gbsr] [-c CMD] [REV]")), |
|
3159 | 3164 | "branch": |
|
3160 | 3165 | (branch, |
|
3161 | 3166 | [('f', 'force', None, |
|
3162 | 3167 | _('set branch name even if it shadows an existing branch')), |
|
3163 | 3168 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
3164 | 3169 | _('[-fC] [NAME]')), |
|
3165 | 3170 | "branches": |
|
3166 | 3171 | (branches, |
|
3167 | 3172 | [('a', 'active', False, |
|
3168 | 3173 | _('show only branches that have unmerged heads')), |
|
3169 | 3174 | ('c', 'closed', False, |
|
3170 | 3175 | _('show normal and closed heads'))], |
|
3171 | 3176 | _('[-a]')), |
|
3172 | 3177 | "bundle": |
|
3173 | 3178 | (bundle, |
|
3174 | 3179 | [('f', 'force', None, |
|
3175 | 3180 | _('run even when remote repository is unrelated')), |
|
3176 | 3181 | ('r', 'rev', [], |
|
3177 | 3182 | _('a changeset up to which you would like to bundle')), |
|
3178 | 3183 | ('', 'base', [], |
|
3179 | 3184 | _('a base changeset to specify instead of a destination')), |
|
3180 | 3185 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
3181 | 3186 | ('t', 'type', 'bzip2', _('bundle compression type to use')), |
|
3182 | 3187 | ] + remoteopts, |
|
3183 | 3188 | _('[-f] [-a] [-r REV]... [--base REV]... FILE [DEST]')), |
|
3184 | 3189 | "cat": |
|
3185 | 3190 | (cat, |
|
3186 | 3191 | [('o', 'output', '', _('print output to file with formatted name')), |
|
3187 | 3192 | ('r', 'rev', '', _('print the given revision')), |
|
3188 | 3193 | ('', 'decode', None, _('apply any matching decode filter')), |
|
3189 | 3194 | ] + walkopts, |
|
3190 | 3195 | _('[OPTION]... FILE...')), |
|
3191 | 3196 | "^clone": |
|
3192 | 3197 | (clone, |
|
3193 | 3198 | [('U', 'noupdate', None, |
|
3194 | 3199 | _('the clone will only contain a repository (no working copy)')), |
|
3195 | 3200 | ('r', 'rev', [], |
|
3196 | 3201 | _('a changeset you would like to have after cloning')), |
|
3197 | 3202 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
3198 | 3203 | ('', 'uncompressed', None, |
|
3199 | 3204 | _('use uncompressed transfer (fast over LAN)')), |
|
3200 | 3205 | ] + remoteopts, |
|
3201 | 3206 | _('[OPTION]... SOURCE [DEST]')), |
|
3202 | 3207 | "^commit|ci": |
|
3203 | 3208 | (commit, |
|
3204 | 3209 | [('A', 'addremove', None, |
|
3205 | 3210 | _('mark new/missing files as added/removed before committing')), |
|
3206 | 3211 | ('', 'close-branch', None, |
|
3207 | 3212 | _('mark a branch as closed, hiding it from the branch list')), |
|
3208 | 3213 | ] + walkopts + commitopts + commitopts2, |
|
3209 | 3214 | _('[OPTION]... [FILE]...')), |
|
3210 | 3215 | "copy|cp": |
|
3211 | 3216 | (copy, |
|
3212 | 3217 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
3213 | 3218 | ('f', 'force', None, |
|
3214 | 3219 | _('forcibly copy over an existing managed file')), |
|
3215 | 3220 | ] + walkopts + dryrunopts, |
|
3216 | 3221 | _('[OPTION]... [SOURCE]... DEST')), |
|
3217 | 3222 | "debugancestor": (debugancestor, [], _('[INDEX] REV1 REV2')), |
|
3218 | 3223 | "debugcheckstate": (debugcheckstate, []), |
|
3219 | 3224 | "debugcommands": (debugcommands, [], _('[COMMAND]')), |
|
3220 | 3225 | "debugcomplete": |
|
3221 | 3226 | (debugcomplete, |
|
3222 | 3227 | [('o', 'options', None, _('show the command options'))], |
|
3223 | 3228 | _('[-o] CMD')), |
|
3224 | 3229 | "debugdate": |
|
3225 | 3230 | (debugdate, |
|
3226 | 3231 | [('e', 'extended', None, _('try extended date formats'))], |
|
3227 | 3232 | _('[-e] DATE [RANGE]')), |
|
3228 | 3233 | "debugdata": (debugdata, [], _('FILE REV')), |
|
3229 | 3234 | "debugfsinfo": (debugfsinfo, [], _('[PATH]')), |
|
3230 | 3235 | "debugindex": (debugindex, [], _('FILE')), |
|
3231 | 3236 | "debugindexdot": (debugindexdot, [], _('FILE')), |
|
3232 | 3237 | "debuginstall": (debuginstall, []), |
|
3233 | 3238 | "debugrebuildstate": |
|
3234 | 3239 | (debugrebuildstate, |
|
3235 | 3240 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
3236 | 3241 | _('[-r REV] [REV]')), |
|
3237 | 3242 | "debugrename": |
|
3238 | 3243 | (debugrename, |
|
3239 | 3244 | [('r', 'rev', '', _('revision to debug'))], |
|
3240 | 3245 | _('[-r REV] FILE')), |
|
3241 | 3246 | "debugsetparents": |
|
3242 | 3247 | (debugsetparents, [], _('REV1 [REV2]')), |
|
3243 | 3248 | "debugstate": |
|
3244 | 3249 | (debugstate, |
|
3245 | 3250 | [('', 'nodates', None, _('do not display the saved mtime'))], |
|
3246 | 3251 | _('[OPTION]...')), |
|
3247 | 3252 | "debugsub": |
|
3248 | 3253 | (debugsub, |
|
3249 | 3254 | [('r', 'rev', '', _('revision to check'))], |
|
3250 | 3255 | _('[-r REV] [REV]')), |
|
3251 | 3256 | "debugwalk": (debugwalk, walkopts, _('[OPTION]... [FILE]...')), |
|
3252 | 3257 | "^diff": |
|
3253 | 3258 | (diff, |
|
3254 | 3259 | [('r', 'rev', [], _('revision')), |
|
3255 | 3260 | ('c', 'change', '', _('change made by revision')) |
|
3256 | 3261 | ] + diffopts + diffopts2 + walkopts, |
|
3257 | 3262 | _('[OPTION]... [-r REV1 [-r REV2]] [FILE]...')), |
|
3258 | 3263 | "^export": |
|
3259 | 3264 | (export, |
|
3260 | 3265 | [('o', 'output', '', _('print output to file with formatted name')), |
|
3261 | 3266 | ('', 'switch-parent', None, _('diff against the second parent')) |
|
3262 | 3267 | ] + diffopts, |
|
3263 | 3268 | _('[OPTION]... [-o OUTFILESPEC] REV...')), |
|
3264 | 3269 | "^forget": |
|
3265 | 3270 | (forget, |
|
3266 | 3271 | [] + walkopts, |
|
3267 | 3272 | _('[OPTION]... FILE...')), |
|
3268 | 3273 | "grep": |
|
3269 | 3274 | (grep, |
|
3270 | 3275 | [('0', 'print0', None, _('end fields with NUL')), |
|
3271 | 3276 | ('', 'all', None, _('print all revisions that match')), |
|
3272 | 3277 | ('f', 'follow', None, |
|
3273 | 3278 | _('follow changeset history, or file history across copies and renames')), |
|
3274 | 3279 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
3275 | 3280 | ('l', 'files-with-matches', None, |
|
3276 | 3281 | _('print only filenames and revisions that match')), |
|
3277 | 3282 | ('n', 'line-number', None, _('print matching line numbers')), |
|
3278 | 3283 | ('r', 'rev', [], _('search in given revision range')), |
|
3279 | 3284 | ('u', 'user', None, _('list the author (long with -v)')), |
|
3280 | 3285 | ('d', 'date', None, _('list the date (short with -q)')), |
|
3281 | 3286 | ] + walkopts, |
|
3282 | 3287 | _('[OPTION]... PATTERN [FILE]...')), |
|
3283 | 3288 | "heads": |
|
3284 | 3289 | (heads, |
|
3285 | 3290 | [('r', 'rev', '', _('show only heads which are descendants of REV')), |
|
3286 | 3291 | ('a', 'active', False, |
|
3287 | 3292 | _('show only the active heads from open branches')), |
|
3288 | 3293 | ('c', 'closed', False, |
|
3289 | 3294 | _('show normal and closed heads')), |
|
3290 | 3295 | ] + templateopts, |
|
3291 | 3296 | _('[-r STARTREV] [REV]...')), |
|
3292 | 3297 | "help": (help_, [], _('[TOPIC]')), |
|
3293 | 3298 | "identify|id": |
|
3294 | 3299 | (identify, |
|
3295 | 3300 | [('r', 'rev', '', _('identify the specified revision')), |
|
3296 | 3301 | ('n', 'num', None, _('show local revision number')), |
|
3297 | 3302 | ('i', 'id', None, _('show global revision id')), |
|
3298 | 3303 | ('b', 'branch', None, _('show branch')), |
|
3299 | 3304 | ('t', 'tags', None, _('show tags'))], |
|
3300 | 3305 | _('[-nibt] [-r REV] [SOURCE]')), |
|
3301 | 3306 | "import|patch": |
|
3302 | 3307 | (import_, |
|
3303 | 3308 | [('p', 'strip', 1, |
|
3304 | 3309 | _('directory strip option for patch. This has the same ' |
|
3305 | 3310 | 'meaning as the corresponding patch option')), |
|
3306 | 3311 | ('b', 'base', '', _('base path')), |
|
3307 | 3312 | ('f', 'force', None, |
|
3308 | 3313 | _('skip check for outstanding uncommitted changes')), |
|
3309 | 3314 | ('', 'no-commit', None, _("don't commit, just update the working directory")), |
|
3310 | 3315 | ('', 'exact', None, |
|
3311 | 3316 | _('apply patch to the nodes from which it was generated')), |
|
3312 | 3317 | ('', 'import-branch', None, |
|
3313 | 3318 | _('use any branch information in patch (implied by --exact)'))] + |
|
3314 | 3319 | commitopts + commitopts2 + similarityopts, |
|
3315 | 3320 | _('[OPTION]... PATCH...')), |
|
3316 | 3321 | "incoming|in": |
|
3317 | 3322 | (incoming, |
|
3318 | 3323 | [('f', 'force', None, |
|
3319 | 3324 | _('run even when remote repository is unrelated')), |
|
3320 | 3325 | ('n', 'newest-first', None, _('show newest record first')), |
|
3321 | 3326 | ('', 'bundle', '', _('file to store the bundles into')), |
|
3322 | 3327 | ('r', 'rev', [], |
|
3323 | 3328 | _('a specific revision up to which you would like to pull')), |
|
3324 | 3329 | ] + logopts + remoteopts, |
|
3325 | 3330 | _('[-p] [-n] [-M] [-f] [-r REV]...' |
|
3326 | 3331 | ' [--bundle FILENAME] [SOURCE]')), |
|
3327 | 3332 | "^init": |
|
3328 | 3333 | (init, |
|
3329 | 3334 | remoteopts, |
|
3330 | 3335 | _('[-e CMD] [--remotecmd CMD] [DEST]')), |
|
3331 | 3336 | "locate": |
|
3332 | 3337 | (locate, |
|
3333 | 3338 | [('r', 'rev', '', _('search the repository as it stood at REV')), |
|
3334 | 3339 | ('0', 'print0', None, |
|
3335 | 3340 | _('end filenames with NUL, for use with xargs')), |
|
3336 | 3341 | ('f', 'fullpath', None, |
|
3337 | 3342 | _('print complete paths from the filesystem root')), |
|
3338 | 3343 | ] + walkopts, |
|
3339 | 3344 | _('[OPTION]... [PATTERN]...')), |
|
3340 | 3345 | "^log|history": |
|
3341 | 3346 | (log, |
|
3342 | 3347 | [('f', 'follow', None, |
|
3343 | 3348 | _('follow changeset history, or file history across copies and renames')), |
|
3344 | 3349 | ('', 'follow-first', None, |
|
3345 | 3350 | _('only follow the first parent of merge changesets')), |
|
3346 | 3351 | ('d', 'date', '', _('show revisions matching date spec')), |
|
3347 | 3352 | ('C', 'copies', None, _('show copied files')), |
|
3348 | 3353 | ('k', 'keyword', [], _('do case-insensitive search for a keyword')), |
|
3349 | 3354 | ('r', 'rev', [], _('show the specified revision or range')), |
|
3350 | 3355 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3351 | 3356 | ('m', 'only-merges', None, _('show only merges')), |
|
3352 | 3357 | ('u', 'user', [], _('revisions committed by user')), |
|
3353 | 3358 | ('b', 'only-branch', [], |
|
3354 | 3359 | _('show only changesets within the given named branch')), |
|
3355 | 3360 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), |
|
3356 | 3361 | ] + logopts + walkopts, |
|
3357 | 3362 | _('[OPTION]... [FILE]')), |
|
3358 | 3363 | "manifest": |
|
3359 | 3364 | (manifest, |
|
3360 | 3365 | [('r', 'rev', '', _('revision to display'))], |
|
3361 | 3366 | _('[-r REV]')), |
|
3362 | 3367 | "^merge": |
|
3363 | 3368 | (merge, |
|
3364 | 3369 | [('f', 'force', None, _('force a merge with outstanding changes')), |
|
3365 | 3370 | ('r', 'rev', '', _('revision to merge')), |
|
3366 | 3371 | ('P', 'preview', None, |
|
3367 | 3372 | _('review revisions to merge (no merge is performed)'))], |
|
3368 | 3373 | _('[-f] [[-r] REV]')), |
|
3369 | 3374 | "outgoing|out": |
|
3370 | 3375 | (outgoing, |
|
3371 | 3376 | [('f', 'force', None, |
|
3372 | 3377 | _('run even when remote repository is unrelated')), |
|
3373 | 3378 | ('r', 'rev', [], |
|
3374 | 3379 | _('a specific revision up to which you would like to push')), |
|
3375 | 3380 | ('n', 'newest-first', None, _('show newest record first')), |
|
3376 | 3381 | ] + logopts + remoteopts, |
|
3377 | 3382 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')), |
|
3378 | 3383 | "^parents": |
|
3379 | 3384 | (parents, |
|
3380 | 3385 | [('r', 'rev', '', _('show parents from the specified revision')), |
|
3381 | 3386 | ] + templateopts, |
|
3382 | 3387 | _('[-r REV] [FILE]')), |
|
3383 | 3388 | "paths": (paths, [], _('[NAME]')), |
|
3384 | 3389 | "^pull": |
|
3385 | 3390 | (pull, |
|
3386 | 3391 | [('u', 'update', None, |
|
3387 | 3392 | _('update to new tip if changesets were pulled')), |
|
3388 | 3393 | ('f', 'force', None, |
|
3389 | 3394 | _('run even when remote repository is unrelated')), |
|
3390 | 3395 | ('r', 'rev', [], |
|
3391 | 3396 | _('a specific revision up to which you would like to pull')), |
|
3392 | 3397 | ] + remoteopts, |
|
3393 | 3398 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')), |
|
3394 | 3399 | "^push": |
|
3395 | 3400 | (push, |
|
3396 | 3401 | [('f', 'force', None, _('force push')), |
|
3397 | 3402 | ('r', 'rev', [], |
|
3398 | 3403 | _('a specific revision up to which you would like to push')), |
|
3399 | 3404 | ] + remoteopts, |
|
3400 | 3405 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')), |
|
3401 | 3406 | "recover": (recover, []), |
|
3402 | 3407 | "^remove|rm": |
|
3403 | 3408 | (remove, |
|
3404 | 3409 | [('A', 'after', None, _('record delete for missing files')), |
|
3405 | 3410 | ('f', 'force', None, |
|
3406 | 3411 | _('remove (and delete) file even if added or modified')), |
|
3407 | 3412 | ] + walkopts, |
|
3408 | 3413 | _('[OPTION]... FILE...')), |
|
3409 | 3414 | "rename|mv": |
|
3410 | 3415 | (rename, |
|
3411 | 3416 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3412 | 3417 | ('f', 'force', None, |
|
3413 | 3418 | _('forcibly copy over an existing managed file')), |
|
3414 | 3419 | ] + walkopts + dryrunopts, |
|
3415 | 3420 | _('[OPTION]... SOURCE... DEST')), |
|
3416 | 3421 | "resolve": |
|
3417 | 3422 | (resolve, |
|
3418 | 3423 | [('a', 'all', None, _('remerge all unresolved files')), |
|
3419 | 3424 | ('l', 'list', None, _('list state of files needing merge')), |
|
3420 | 3425 | ('m', 'mark', None, _('mark files as resolved')), |
|
3421 | 3426 | ('u', 'unmark', None, _('unmark files as resolved'))] |
|
3422 | 3427 | + walkopts, |
|
3423 | 3428 | _('[OPTION]... [FILE]...')), |
|
3424 | 3429 | "revert": |
|
3425 | 3430 | (revert, |
|
3426 | 3431 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
3427 | 3432 | ('d', 'date', '', _('tipmost revision matching date')), |
|
3428 | 3433 | ('r', 'rev', '', _('revision to revert to')), |
|
3429 | 3434 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3430 | 3435 | ] + walkopts + dryrunopts, |
|
3431 | 3436 | _('[OPTION]... [-r REV] [NAME]...')), |
|
3432 | 3437 | "rollback": (rollback, []), |
|
3433 | 3438 | "root": (root, []), |
|
3434 | 3439 | "^serve": |
|
3435 | 3440 | (serve, |
|
3436 | 3441 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3437 | 3442 | ('d', 'daemon', None, _('run server in background')), |
|
3438 | 3443 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3439 | 3444 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3440 | 3445 | ('p', 'port', 0, _('port to listen on (default: 8000)')), |
|
3441 | 3446 | ('a', 'address', '', _('address to listen on (default: all interfaces)')), |
|
3442 | 3447 | ('', 'prefix', '', _('prefix path to serve from (default: server root)')), |
|
3443 | 3448 | ('n', 'name', '', |
|
3444 | 3449 | _('name to show in web pages (default: working directory)')), |
|
3445 | 3450 | ('', 'webdir-conf', '', _('name of the webdir config file' |
|
3446 | 3451 | ' (serve more than one repository)')), |
|
3447 | 3452 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3448 | 3453 | ('', 'stdio', None, _('for remote clients')), |
|
3449 | 3454 | ('t', 'templates', '', _('web templates to use')), |
|
3450 | 3455 | ('', 'style', '', _('template style to use')), |
|
3451 | 3456 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
3452 | 3457 | ('', 'certificate', '', _('SSL certificate file'))], |
|
3453 | 3458 | _('[OPTION]...')), |
|
3454 | 3459 | "showconfig|debugconfig": |
|
3455 | 3460 | (showconfig, |
|
3456 | 3461 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
3457 | 3462 | _('[-u] [NAME]...')), |
|
3458 | 3463 | "^status|st": |
|
3459 | 3464 | (status, |
|
3460 | 3465 | [('A', 'all', None, _('show status of all files')), |
|
3461 | 3466 | ('m', 'modified', None, _('show only modified files')), |
|
3462 | 3467 | ('a', 'added', None, _('show only added files')), |
|
3463 | 3468 | ('r', 'removed', None, _('show only removed files')), |
|
3464 | 3469 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3465 | 3470 | ('c', 'clean', None, _('show only files without changes')), |
|
3466 | 3471 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3467 | 3472 | ('i', 'ignored', None, _('show only ignored files')), |
|
3468 | 3473 | ('n', 'no-status', None, _('hide status prefix')), |
|
3469 | 3474 | ('C', 'copies', None, _('show source of copied files')), |
|
3470 | 3475 | ('0', 'print0', None, |
|
3471 | 3476 | _('end filenames with NUL, for use with xargs')), |
|
3472 | 3477 | ('', 'rev', [], _('show difference from revision')), |
|
3473 | 3478 | ] + walkopts, |
|
3474 | 3479 | _('[OPTION]... [FILE]...')), |
|
3475 | 3480 | "tag": |
|
3476 | 3481 | (tag, |
|
3477 | 3482 | [('f', 'force', None, _('replace existing tag')), |
|
3478 | 3483 | ('l', 'local', None, _('make the tag local')), |
|
3479 | 3484 | ('r', 'rev', '', _('revision to tag')), |
|
3480 | 3485 | ('', 'remove', None, _('remove a tag')), |
|
3481 | 3486 | # -l/--local is already there, commitopts cannot be used |
|
3482 | 3487 | ('m', 'message', '', _('use <text> as commit message')), |
|
3483 | 3488 | ] + commitopts2, |
|
3484 | 3489 | _('[-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')), |
|
3485 | 3490 | "tags": (tags, []), |
|
3486 | 3491 | "tip": |
|
3487 | 3492 | (tip, |
|
3488 | 3493 | [('p', 'patch', None, _('show patch')), |
|
3489 | 3494 | ('g', 'git', None, _('use git extended diff format')), |
|
3490 | 3495 | ] + templateopts, |
|
3491 | 3496 | _('[-p]')), |
|
3492 | 3497 | "unbundle": |
|
3493 | 3498 | (unbundle, |
|
3494 | 3499 | [('u', 'update', None, |
|
3495 | 3500 | _('update to new tip if changesets were unbundled'))], |
|
3496 | 3501 | _('[-u] FILE...')), |
|
3497 | 3502 | "^update|up|checkout|co": |
|
3498 | 3503 | (update, |
|
3499 | 3504 | [('C', 'clean', None, _('overwrite locally modified files (no backup)')), |
|
3500 | 3505 | ('c', 'check', None, _('check for uncommitted changes')), |
|
3501 | 3506 | ('d', 'date', '', _('tipmost revision matching date')), |
|
3502 | 3507 | ('r', 'rev', '', _('revision'))], |
|
3503 | 3508 | _('[-C] [-d DATE] [[-r] REV]')), |
|
3504 | 3509 | "verify": (verify, []), |
|
3505 | 3510 | "version": (version_, []), |
|
3506 | 3511 | } |
|
3507 | 3512 | |
|
3508 | 3513 | norepo = ("clone init version help debugcommands debugcomplete debugdata" |
|
3509 | 3514 | " debugindex debugindexdot debugdate debuginstall debugfsinfo") |
|
3510 | 3515 | optionalrepo = ("identify paths serve showconfig debugancestor") |
@@ -1,491 +1,500 b'' | |||
|
1 | 1 | # help.py - help data for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from i18n import _ |
|
9 | 9 | import extensions, util |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | def moduledoc(file): |
|
13 | 13 | '''return the top-level python documentation for the given file |
|
14 | 14 | |
|
15 | 15 | Loosely inspired by pydoc.source_synopsis(), but rewritten to handle \''' |
|
16 | 16 | as well as """ and to return the whole text instead of just the synopsis''' |
|
17 | 17 | result = [] |
|
18 | 18 | |
|
19 | 19 | line = file.readline() |
|
20 | 20 | while line[:1] == '#' or not line.strip(): |
|
21 | 21 | line = file.readline() |
|
22 | 22 | if not line: break |
|
23 | 23 | |
|
24 | 24 | start = line[:3] |
|
25 | 25 | if start == '"""' or start == "'''": |
|
26 | 26 | line = line[3:] |
|
27 | 27 | while line: |
|
28 | 28 | if line.rstrip().endswith(start): |
|
29 | 29 | line = line.split(start)[0] |
|
30 | 30 | if line: |
|
31 | 31 | result.append(line) |
|
32 | 32 | break |
|
33 | 33 | elif not line: |
|
34 | 34 | return None # unmatched delimiter |
|
35 | 35 | result.append(line) |
|
36 | 36 | line = file.readline() |
|
37 | 37 | else: |
|
38 | 38 | return None |
|
39 | 39 | |
|
40 | 40 | return ''.join(result) |
|
41 | 41 | |
|
42 | 42 | def listexts(header, exts, maxlength): |
|
43 | 43 | '''return a text listing of the given extensions''' |
|
44 | 44 | if not exts: |
|
45 | 45 | return '' |
|
46 | result = '\n%s\n\n' % header | |
|
46 | # TODO: literal block is wrong, should be a field list or a simple table. | |
|
47 | result = '\n%s\n\n ::\n\n' % header | |
|
47 | 48 | for name, desc in sorted(exts.iteritems()): |
|
48 |
desc = util.wrap(desc, maxlength + |
|
|
49 | result += ' %s %s\n' % (name.ljust(maxlength), desc) | |
|
49 | desc = util.wrap(desc, maxlength + 5) | |
|
50 | result += ' %s %s\n' % (name.ljust(maxlength), desc) | |
|
50 | 51 | return result |
|
51 | 52 | |
|
52 | 53 | def extshelp(): |
|
53 | 54 | doc = _(r''' |
|
54 | 55 | Mercurial has the ability to add new features through the use of |
|
55 | 56 | extensions. Extensions may add new commands, add options to existing |
|
56 | 57 | commands, change the default behavior of commands, or implement hooks. |
|
57 | 58 | |
|
58 | 59 | Extensions are not loaded by default for a variety of reasons: they can |
|
59 | 60 | increase startup overhead; they may be meant for advanced usage only; they |
|
60 | 61 | may provide potentially dangerous abilities (such as letting you destroy |
|
61 | 62 | or modify history); they might not be ready for prime time; or they may |
|
62 | 63 | alter some usual behaviors of stock Mercurial. It is thus up to the user |
|
63 | 64 | to activate extensions as needed. |
|
64 | 65 | |
|
65 | 66 | To enable the "foo" extension, either shipped with Mercurial or in the |
|
66 | Python search path, create an entry for it in your hgrc, like this: | |
|
67 | Python search path, create an entry for it in your hgrc, like this:: | |
|
67 | 68 | |
|
68 | 69 | [extensions] |
|
69 | 70 | foo = |
|
70 | 71 | |
|
71 | You may also specify the full path to an extension: | |
|
72 | You may also specify the full path to an extension:: | |
|
72 | 73 | |
|
73 | 74 | [extensions] |
|
74 | 75 | myfeature = ~/.hgext/myfeature.py |
|
75 | 76 | |
|
76 | 77 | To explicitly disable an extension enabled in an hgrc of broader scope, |
|
77 | prepend its path with !: | |
|
78 | prepend its path with !:: | |
|
78 | 79 | |
|
79 | 80 | [extensions] |
|
80 | 81 | # disabling extension bar residing in /path/to/extension/bar.py |
|
81 | 82 | hgext.bar = !/path/to/extension/bar.py |
|
82 | 83 | # ditto, but no path was supplied for extension baz |
|
83 | 84 | hgext.baz = ! |
|
84 | 85 | ''') |
|
85 | 86 | |
|
86 | 87 | exts, maxlength = extensions.enabled() |
|
87 | 88 | doc += listexts(_('enabled extensions:'), exts, maxlength) |
|
88 | 89 | |
|
89 | 90 | exts, maxlength = extensions.disabled() |
|
90 | 91 | doc += listexts(_('disabled extensions:'), exts, maxlength) |
|
91 | 92 | |
|
92 | 93 | return doc |
|
93 | 94 | |
|
94 | 95 | helptable = ( |
|
95 | 96 | (["dates"], _("Date Formats"), |
|
96 | 97 | _(r''' |
|
97 | 98 | Some commands allow the user to specify a date, e.g.: |
|
98 | * backout, commit, import, tag: Specify the commit date. | |
|
99 | * log, revert, update: Select revision(s) by date. | |
|
100 | 99 | |
|
101 | Many date formats are valid. Here are some examples: | |
|
100 | - backout, commit, import, tag: Specify the commit date. | |
|
101 | - log, revert, update: Select revision(s) by date. | |
|
102 | ||
|
103 | Many date formats are valid. Here are some examples:: | |
|
102 | 104 | |
|
103 | "Wed Dec 6 13:18:29 2006" (local timezone assumed) | |
|
104 | "Dec 6 13:18 -0600" (year assumed, time offset provided) | |
|
105 | "Dec 6 13:18 UTC" (UTC and GMT are aliases for +0000) | |
|
106 | "Dec 6" (midnight) | |
|
107 | "13:18" (today assumed) | |
|
108 | "3:39" (3:39AM assumed) | |
|
109 | "3:39pm" (15:39) | |
|
110 | "2006-12-06 13:18:29" (ISO 8601 format) | |
|
111 | "2006-12-6 13:18" | |
|
112 | "2006-12-6" | |
|
113 | "12-6" | |
|
114 | "12/6" | |
|
115 | "12/6/6" (Dec 6 2006) | |
|
105 | "Wed Dec 6 13:18:29 2006" (local timezone assumed) | |
|
106 | "Dec 6 13:18 -0600" (year assumed, time offset provided) | |
|
107 | "Dec 6 13:18 UTC" (UTC and GMT are aliases for +0000) | |
|
108 | "Dec 6" (midnight) | |
|
109 | "13:18" (today assumed) | |
|
110 | "3:39" (3:39AM assumed) | |
|
111 | "3:39pm" (15:39) | |
|
112 | "2006-12-06 13:18:29" (ISO 8601 format) | |
|
113 | "2006-12-6 13:18" | |
|
114 | "2006-12-6" | |
|
115 | "12-6" | |
|
116 | "12/6" | |
|
117 | "12/6/6" (Dec 6 2006) | |
|
116 | 118 | |
|
117 | 119 | Lastly, there is Mercurial's internal format: |
|
118 | 120 | |
|
119 | 121 | "1165432709 0" (Wed Dec 6 13:18:29 2006 UTC) |
|
120 | 122 | |
|
121 | 123 | This is the internal representation format for dates. unixtime is the |
|
122 | 124 | number of seconds since the epoch (1970-01-01 00:00 UTC). offset is the |
|
123 | 125 | offset of the local timezone, in seconds west of UTC (negative if the |
|
124 | 126 | timezone is east of UTC). |
|
125 | 127 | |
|
126 | The log command also accepts date ranges: | |
|
128 | The log command also accepts date ranges:: | |
|
127 | 129 | |
|
128 | "<{datetime}" - at or before a given date/time | |
|
129 | ">{datetime}" - on or after a given date/time | |
|
130 | "{datetime} to {datetime}" - a date range, inclusive | |
|
131 | "-{days}" - within a given number of days of today | |
|
130 | "<{datetime}" - at or before a given date/time | |
|
131 | ">{datetime}" - on or after a given date/time | |
|
132 | "{datetime} to {datetime}" - a date range, inclusive | |
|
133 | "-{days}" - within a given number of days of today | |
|
132 | 134 | ''')), |
|
133 | 135 | |
|
134 | 136 | (["patterns"], _("File Name Patterns"), |
|
135 | 137 | _(r''' |
|
136 | 138 | Mercurial accepts several notations for identifying one or more files at a |
|
137 | 139 | time. |
|
138 | 140 | |
|
139 | 141 | By default, Mercurial treats filenames as shell-style extended glob |
|
140 | 142 | patterns. |
|
141 | 143 | |
|
142 | 144 | Alternate pattern notations must be specified explicitly. |
|
143 | 145 | |
|
144 | 146 | To use a plain path name without any pattern matching, start it with |
|
145 | 147 | "path:". These path names must completely match starting at the current |
|
146 | 148 | repository root. |
|
147 | 149 | |
|
148 | 150 | To use an extended glob, start a name with "glob:". Globs are rooted at |
|
149 | 151 | the current directory; a glob such as "*.c" will only match files in the |
|
150 | 152 | current directory ending with ".c". |
|
151 | 153 | |
|
152 | 154 | The supported glob syntax extensions are "**" to match any string across |
|
153 | 155 | path separators and "{a,b}" to mean "a or b". |
|
154 | 156 | |
|
155 | 157 | To use a Perl/Python regular expression, start a name with "re:". Regexp |
|
156 | 158 | pattern matching is anchored at the root of the repository. |
|
157 | 159 | |
|
158 | Plain examples: | |
|
160 | Plain examples:: | |
|
159 | 161 | |
|
160 | path:foo/bar a name bar in a directory named foo in the root of | |
|
161 | the repository | |
|
162 | path:path:name a file or directory named "path:name" | |
|
162 | path:foo/bar a name bar in a directory named foo in the root of | |
|
163 | the repository | |
|
164 | path:path:name a file or directory named "path:name" | |
|
163 | 165 | |
|
164 | Glob examples: | |
|
166 | Glob examples:: | |
|
165 | 167 | |
|
166 | glob:*.c any name ending in ".c" in the current directory | |
|
167 | *.c any name ending in ".c" in the current directory | |
|
168 |
**.c any name ending in ".c" in any subdirectory of the |
|
|
169 | directory including itself. | |
|
170 | foo/*.c any name ending in ".c" in the directory foo | |
|
171 | foo/**.c any name ending in ".c" in any subdirectory of foo | |
|
172 | including itself. | |
|
168 | glob:*.c any name ending in ".c" in the current directory | |
|
169 | *.c any name ending in ".c" in the current directory | |
|
170 | **.c any name ending in ".c" in any subdirectory of the | |
|
171 | current directory including itself. | |
|
172 | foo/*.c any name ending in ".c" in the directory foo | |
|
173 | foo/**.c any name ending in ".c" in any subdirectory of foo | |
|
174 | including itself. | |
|
173 | 175 | |
|
174 | Regexp examples: | |
|
176 | Regexp examples:: | |
|
175 | 177 | |
|
176 | re:.*\.c$ any name ending in ".c", anywhere in the repository | |
|
178 | re:.*\.c$ any name ending in ".c", anywhere in the repository | |
|
177 | 179 | |
|
178 | 180 | ''')), |
|
179 | 181 | |
|
180 | 182 | (['environment', 'env'], _('Environment Variables'), |
|
181 | 183 | _(r''' |
|
182 |
HG |
|
|
184 | HG | |
|
183 | 185 | Path to the 'hg' executable, automatically passed when running hooks, |
|
184 | 186 | extensions or external tools. If unset or empty, this is the hg |
|
185 | 187 | executable's name if it's frozen, or an executable named 'hg' (with |
|
186 | 188 | %PATHEXT% [defaulting to COM/EXE/BAT/CMD] extensions on Windows) is |
|
187 | 189 | searched. |
|
188 | 190 | |
|
189 |
HGEDITOR |
|
|
191 | HGEDITOR | |
|
190 | 192 | This is the name of the editor to run when committing. See EDITOR. |
|
191 | 193 | |
|
192 | 194 | (deprecated, use .hgrc) |
|
193 | 195 | |
|
194 |
HGENCODING |
|
|
196 | HGENCODING | |
|
195 | 197 | This overrides the default locale setting detected by Mercurial. This |
|
196 | 198 | setting is used to convert data including usernames, changeset |
|
197 | 199 | descriptions, tag names, and branches. This setting can be overridden with |
|
198 | 200 | the --encoding command-line option. |
|
199 | 201 | |
|
200 |
HGENCODINGMODE |
|
|
202 | HGENCODINGMODE | |
|
201 | 203 | This sets Mercurial's behavior for handling unknown characters while |
|
202 | 204 | transcoding user input. The default is "strict", which causes Mercurial to |
|
203 | 205 | abort if it can't map a character. Other settings include "replace", which |
|
204 | 206 | replaces unknown characters, and "ignore", which drops them. This setting |
|
205 | 207 | can be overridden with the --encodingmode command-line option. |
|
206 | 208 | |
|
207 |
HGMERGE |
|
|
209 | HGMERGE | |
|
208 | 210 | An executable to use for resolving merge conflicts. The program will be |
|
209 | 211 | executed with three arguments: local file, remote file, ancestor file. |
|
210 | 212 | |
|
211 | 213 | (deprecated, use .hgrc) |
|
212 | 214 | |
|
213 |
HGRCPATH |
|
|
215 | HGRCPATH | |
|
214 | 216 | A list of files or directories to search for hgrc files. Item separator is |
|
215 | 217 | ":" on Unix, ";" on Windows. If HGRCPATH is not set, platform default |
|
216 | 218 | search path is used. If empty, only the .hg/hgrc from the current |
|
217 | 219 | repository is read. |
|
218 | 220 | |
|
219 | 221 | For each element in HGRCPATH: |
|
220 | * if it's a directory, all files ending with .rc are added | |
|
221 | * otherwise, the file itself will be added | |
|
222 | 222 | |
|
223 | HGUSER:: | |
|
223 | - if it's a directory, all files ending with .rc are added | |
|
224 | - otherwise, the file itself will be added | |
|
225 | ||
|
226 | HGUSER | |
|
224 | 227 | This is the string used as the author of a commit. If not set, available |
|
225 | 228 | values will be considered in this order: |
|
226 | 229 | |
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
230 | - HGUSER (deprecated) | |
|
231 | - hgrc files from the HGRCPATH | |
|
232 | ||
|
233 | - interactive prompt | |
|
234 | - LOGNAME (with '@hostname' appended) | |
|
232 | 235 | |
|
233 | 236 | (deprecated, use .hgrc) |
|
234 | 237 | |
|
235 |
EMAIL |
|
|
238 | ||
|
236 | 239 | May be used as the author of a commit; see HGUSER. |
|
237 | 240 | |
|
238 |
LOGNAME |
|
|
241 | LOGNAME | |
|
239 | 242 | May be used as the author of a commit; see HGUSER. |
|
240 | 243 | |
|
241 |
VISUAL |
|
|
244 | VISUAL | |
|
242 | 245 | This is the name of the editor to use when committing. See EDITOR. |
|
243 | 246 | |
|
244 |
EDITOR |
|
|
247 | EDITOR | |
|
245 | 248 | Sometimes Mercurial needs to open a text file in an editor for a user to |
|
246 | 249 | modify, for example when writing commit messages. The editor it uses is |
|
247 | 250 | determined by looking at the environment variables HGEDITOR, VISUAL and |
|
248 | 251 | EDITOR, in that order. The first non-empty one is chosen. If all of them |
|
249 | 252 | are empty, the editor defaults to 'vi'. |
|
250 | 253 | |
|
251 |
PYTHONPATH |
|
|
254 | PYTHONPATH | |
|
252 | 255 | This is used by Python to find imported modules and may need to be set |
|
253 | 256 | appropriately if this Mercurial is not installed system-wide. |
|
254 | 257 | ''')), |
|
255 | 258 | |
|
256 | 259 | (['revs', 'revisions'], _('Specifying Single Revisions'), |
|
257 | 260 | _(r''' |
|
258 | 261 | Mercurial supports several ways to specify individual revisions. |
|
259 | 262 | |
|
260 | 263 | A plain integer is treated as a revision number. Negative integers are |
|
261 | 264 | treated as topological offsets from the tip, with -1 denoting the tip. As |
|
262 | 265 | such, negative numbers are only useful if you've memorized your local tree |
|
263 | 266 | numbers and want to save typing a single digit. This editor suggests copy |
|
264 | 267 | and paste. |
|
265 | 268 | |
|
266 | 269 | A 40-digit hexadecimal string is treated as a unique revision identifier. |
|
267 | 270 | |
|
268 | 271 | A hexadecimal string less than 40 characters long is treated as a unique |
|
269 | 272 | revision identifier, and referred to as a short-form identifier. A |
|
270 | 273 | short-form identifier is only valid if it is the prefix of exactly one |
|
271 | 274 | full-length identifier. |
|
272 | 275 | |
|
273 | 276 | Any other string is treated as a tag name, which is a symbolic name |
|
274 | 277 | associated with a revision identifier. Tag names may not contain the ":" |
|
275 | 278 | character. |
|
276 | 279 | |
|
277 | 280 | The reserved name "tip" is a special tag that always identifies the most |
|
278 | 281 | recent revision. |
|
279 | 282 | |
|
280 | 283 | The reserved name "null" indicates the null revision. This is the revision |
|
281 | 284 | of an empty repository, and the parent of revision 0. |
|
282 | 285 | |
|
283 | 286 | The reserved name "." indicates the working directory parent. If no |
|
284 | 287 | working directory is checked out, it is equivalent to null. If an |
|
285 | 288 | uncommitted merge is in progress, "." is the revision of the first parent. |
|
286 | 289 | ''')), |
|
287 | 290 | |
|
288 | 291 | (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), |
|
289 | 292 | _(r''' |
|
290 | 293 | When Mercurial accepts more than one revision, they may be specified |
|
291 | 294 | individually, or provided as a topologically continuous range, separated |
|
292 | 295 | by the ":" character. |
|
293 | 296 | |
|
294 | 297 | The syntax of range notation is [BEGIN]:[END], where BEGIN and END are |
|
295 | 298 | revision identifiers. Both BEGIN and END are optional. If BEGIN is not |
|
296 | 299 | specified, it defaults to revision number 0. If END is not specified, it |
|
297 | 300 | defaults to the tip. The range ":" thus means "all revisions". |
|
298 | 301 | |
|
299 | 302 | If BEGIN is greater than END, revisions are treated in reverse order. |
|
300 | 303 | |
|
301 | 304 | A range acts as a closed interval. This means that a range of 3:5 gives 3, |
|
302 | 305 | 4 and 5. Similarly, a range of 9:6 gives 9, 8, 7, and 6. |
|
303 | 306 | ''')), |
|
304 | 307 | |
|
305 | 308 | (['diffs'], _('Diff Formats'), |
|
306 | 309 | _(r''' |
|
307 | 310 | Mercurial's default format for showing changes between two versions of a |
|
308 | 311 | file is compatible with the unified format of GNU diff, which can be used |
|
309 | 312 | by GNU patch and many other standard tools. |
|
310 | 313 | |
|
311 | 314 | While this standard format is often enough, it does not encode the |
|
312 | 315 | following information: |
|
313 | 316 | |
|
314 | 317 | - executable status and other permission bits |
|
315 | 318 | - copy or rename information |
|
316 | 319 | - changes in binary files |
|
317 | 320 | - creation or deletion of empty files |
|
318 | 321 | |
|
319 | 322 | Mercurial also supports the extended diff format from the git VCS which |
|
320 | 323 | addresses these limitations. The git diff format is not produced by |
|
321 | 324 | default because a few widespread tools still do not understand this |
|
322 | 325 | format. |
|
323 | 326 | |
|
324 | 327 | This means that when generating diffs from a Mercurial repository (e.g. |
|
325 | 328 | with "hg export"), you should be careful about things like file copies and |
|
326 | 329 | renames or other things mentioned above, because when applying a standard |
|
327 | 330 | diff to a different repository, this extra information is lost. |
|
328 | 331 | Mercurial's internal operations (like push and pull) are not affected by |
|
329 | 332 | this, because they use an internal binary format for communicating |
|
330 | 333 | changes. |
|
331 | 334 | |
|
332 | 335 | To make Mercurial produce the git extended diff format, use the --git |
|
333 | 336 | option available for many commands, or set 'git = True' in the [diff] |
|
334 | 337 | section of your hgrc. You do not need to set this option when importing |
|
335 | 338 | diffs in this format or using them in the mq extension. |
|
336 | 339 | ''')), |
|
337 | 340 | (['templating'], _('Template Usage'), |
|
338 | 341 | _(r''' |
|
339 | 342 | Mercurial allows you to customize output of commands through templates. |
|
340 | 343 | You can either pass in a template from the command line, via the |
|
341 | 344 | --template option, or select an existing template-style (--style). |
|
342 | 345 | |
|
343 | 346 | You can customize output for any "log-like" command: log, outgoing, |
|
344 | 347 | incoming, tip, parents, heads and glog. |
|
345 | 348 | |
|
346 | 349 | Three styles are packaged with Mercurial: default (the style used when no |
|
347 | 350 | explicit preference is passed), compact and changelog. Usage: |
|
348 | 351 | |
|
349 | 352 | $ hg log -r1 --style changelog |
|
350 | 353 | |
|
351 | 354 | A template is a piece of text, with markup to invoke variable expansion: |
|
352 | 355 | |
|
353 | 356 | $ hg log -r1 --template "{node}\n" |
|
354 | 357 | b56ce7b07c52de7d5fd79fb89701ea538af65746 |
|
355 | 358 | |
|
356 | 359 | Strings in curly braces are called keywords. The availability of keywords |
|
357 | 360 | depends on the exact context of the templater. These keywords are usually |
|
358 | 361 | available for templating a log-like command: |
|
359 | 362 | |
|
360 | 363 | - author: String. The unmodified author of the changeset. |
|
361 | 364 | - branches: String. The name of the branch on which the changeset was |
|
362 | 365 | committed. Will be empty if the branch name was default. |
|
363 | 366 | - date: Date information. The date when the changeset was committed. |
|
364 | 367 | - desc: String. The text of the changeset description. |
|
365 | 368 | - diffstat: String. Statistics of changes with the following format: |
|
366 | 369 | "modified files: +added/-removed lines" |
|
367 | 370 | - files: List of strings. All files modified, added, or removed by this |
|
368 | 371 | changeset. |
|
369 | 372 | - file_adds: List of strings. Files added by this changeset. |
|
370 | 373 | - file_mods: List of strings. Files modified by this changeset. |
|
371 | 374 | - file_dels: List of strings. Files removed by this changeset. |
|
372 | 375 | - node: String. The changeset identification hash, as a 40-character |
|
373 | 376 | hexadecimal string. |
|
374 | 377 | - parents: List of strings. The parents of the changeset. |
|
375 | 378 | - rev: Integer. The repository-local changeset revision number. |
|
376 | 379 | - tags: List of strings. Any tags associated with the changeset. |
|
377 | 380 | |
|
378 | 381 | The "date" keyword does not produce human-readable output. If you want to |
|
379 | 382 | use a date in your output, you can use a filter to process it. Filters are |
|
380 | 383 | functions which return a string based on the input variable. You can also |
|
381 | 384 | use a chain of filters to get the desired output: |
|
382 | 385 | |
|
383 | 386 | $ hg tip --template "{date|isodate}\n" |
|
384 | 387 | 2008-08-21 18:22 +0000 |
|
385 | 388 | |
|
386 | 389 | List of filters: |
|
387 | 390 | |
|
388 | 391 | - addbreaks: Any text. Add an XHTML "<br />" tag before the end of every |
|
389 | 392 | line except the last. |
|
390 | 393 | - age: Date. Returns a human-readable date/time difference between the |
|
391 | 394 | given date/time and the current date/time. |
|
392 | 395 | - basename: Any text. Treats the text as a path, and returns the last |
|
393 | 396 | component of the path after splitting by the path separator |
|
394 | 397 | (ignoring trailing separators). For example, "foo/bar/baz" becomes |
|
395 | 398 | "baz" and "foo/bar//" becomes "bar". |
|
396 | 399 | - stripdir: Treat the text as path and strip a directory level, if |
|
397 | 400 | possible. For example, "foo" and "foo/bar" becomes "foo". |
|
398 | 401 | - date: Date. Returns a date in a Unix date format, including the |
|
399 | 402 | timezone: "Mon Sep 04 15:13:13 2006 0700". |
|
400 | 403 | - domain: Any text. Finds the first string that looks like an email |
|
401 | 404 | address, and extracts just the domain component. Example: 'User |
|
402 | 405 | <user@example.com>' becomes 'example.com'. |
|
403 | 406 | - email: Any text. Extracts the first string that looks like an email |
|
404 | 407 | address. Example: 'User <user@example.com>' becomes |
|
405 | 408 | 'user@example.com'. |
|
406 | 409 | - escape: Any text. Replaces the special XML/XHTML characters "&", "<" and |
|
407 | 410 | ">" with XML entities. |
|
408 | 411 | - fill68: Any text. Wraps the text to fit in 68 columns. |
|
409 | 412 | - fill76: Any text. Wraps the text to fit in 76 columns. |
|
410 | 413 | - firstline: Any text. Returns the first line of text. |
|
411 | 414 | - nonempty: Any text. Returns '(none)' if the string is empty. |
|
412 | 415 | - hgdate: Date. Returns the date as a pair of numbers: "1157407993 25200" |
|
413 | 416 | (Unix timestamp, timezone offset). |
|
414 | 417 | - isodate: Date. Returns the date in ISO 8601 format. |
|
415 | 418 | - localdate: Date. Converts a date to local date. |
|
416 | 419 | - obfuscate: Any text. Returns the input text rendered as a sequence of |
|
417 | 420 | XML entities. |
|
418 | 421 | - person: Any text. Returns the text before an email address. |
|
419 | 422 | - rfc822date: Date. Returns a date using the same format used in email |
|
420 | 423 | headers. |
|
421 | 424 | - short: Changeset hash. Returns the short form of a changeset hash, i.e. |
|
422 | 425 | a 12-byte hexadecimal string. |
|
423 | 426 | - shortdate: Date. Returns a date like "2006-09-18". |
|
424 | 427 | - strip: Any text. Strips all leading and trailing whitespace. |
|
425 | 428 | - tabindent: Any text. Returns the text, with every line except the first |
|
426 | 429 | starting with a tab character. |
|
427 | 430 | - urlescape: Any text. Escapes all "special" characters. For example, "foo |
|
428 | 431 | bar" becomes "foo%20bar". |
|
429 | 432 | - user: Any text. Returns the user portion of an email address. |
|
430 | 433 | ''')), |
|
431 | 434 | |
|
432 | 435 | (['urls'], _('URL Paths'), |
|
433 | 436 | _(r''' |
|
434 | Valid URLs are of the form: | |
|
437 | Valid URLs are of the form:: | |
|
435 | 438 | |
|
436 | 439 | local/filesystem/path[#revision] |
|
437 | 440 | file://local/filesystem/path[#revision] |
|
438 | 441 | http://[user[:pass]@]host[:port]/[path][#revision] |
|
439 | 442 | https://[user[:pass]@]host[:port]/[path][#revision] |
|
440 | 443 | ssh://[user[:pass]@]host[:port]/[path][#revision] |
|
441 | 444 | |
|
442 | 445 | Paths in the local filesystem can either point to Mercurial repositories |
|
443 | 446 | or to bundle files (as created by 'hg bundle' or 'hg incoming --bundle'). |
|
444 | 447 | |
|
445 | 448 | An optional identifier after # indicates a particular branch, tag, or |
|
446 | 449 | changeset to use from the remote repository. See also 'hg help revisions'. |
|
447 | 450 | |
|
448 | 451 | Some features, such as pushing to http:// and https:// URLs are only |
|
449 | 452 | possible if the feature is explicitly enabled on the remote Mercurial |
|
450 | 453 | server. |
|
451 | 454 | |
|
452 | 455 | Some notes about using SSH with Mercurial: |
|
456 | ||
|
453 | 457 | - SSH requires an accessible shell account on the destination machine and |
|
454 | 458 | a copy of hg in the remote path or specified with as remotecmd. |
|
455 | 459 | - path is relative to the remote user's home directory by default. Use an |
|
456 | extra slash at the start of a path to specify an absolute path: | |
|
460 | extra slash at the start of a path to specify an absolute path:: | |
|
461 | ||
|
457 | 462 | ssh://example.com//tmp/repository |
|
463 | ||
|
458 | 464 | - Mercurial doesn't use its own compression via SSH; the right thing to do |
|
459 | is to configure it in your ~/.ssh/config, e.g.: | |
|
465 | is to configure it in your ~/.ssh/config, e.g.:: | |
|
466 | ||
|
460 | 467 | Host *.mylocalnetwork.example.com |
|
461 | 468 | Compression no |
|
462 | 469 | Host * |
|
463 | 470 | Compression yes |
|
471 | ||
|
464 | 472 | Alternatively specify "ssh -C" as your ssh command in your hgrc or with |
|
465 | 473 | the --ssh command line option. |
|
466 | 474 | |
|
467 | 475 | These URLs can all be stored in your hgrc with path aliases under the |
|
468 | [paths] section like so: | |
|
469 | [paths] | |
|
470 | alias1 = URL1 | |
|
471 |
|
|
|
472 | ... | |
|
476 | [paths] section like so:: | |
|
477 | ||
|
478 | [paths] | |
|
479 | alias1 = URL1 | |
|
480 | alias2 = URL2 | |
|
481 | ... | |
|
473 | 482 | |
|
474 | 483 | You can then use the alias for any command that uses a URL (for example |
|
475 | 484 | 'hg pull alias1' would pull from the 'alias1' path). |
|
476 | 485 | |
|
477 | 486 | Two path aliases are special because they are used as defaults when you do |
|
478 | 487 | not provide the URL to a command: |
|
479 | 488 | |
|
480 | 489 | default: |
|
481 | 490 | When you create a repository with hg clone, the clone command saves the |
|
482 | 491 | location of the source repository as the new repository's 'default' |
|
483 | 492 | path. This is then used when you omit path from push- and pull-like |
|
484 | 493 | commands (including incoming and outgoing). |
|
485 | 494 | |
|
486 | 495 | default-push: |
|
487 | 496 | The push command will look for a path named 'default-push', and prefer |
|
488 | 497 | it over 'default' if both are defined. |
|
489 | 498 | ''')), |
|
490 | 499 | (["extensions"], _("Using additional features"), extshelp), |
|
491 | 500 | ) |
@@ -1,270 +1,272 b'' | |||
|
1 | 1 | hg convert [OPTION]... SOURCE [DEST [REVMAP]] |
|
2 | 2 | |
|
3 | 3 | convert a foreign SCM repository to a Mercurial one. |
|
4 | 4 | |
|
5 | 5 | Accepted source formats [identifiers]: |
|
6 | ||
|
6 | 7 | - Mercurial [hg] |
|
7 | 8 | - CVS [cvs] |
|
8 | 9 | - Darcs [darcs] |
|
9 | 10 | - git [git] |
|
10 | 11 | - Subversion [svn] |
|
11 | 12 | - Monotone [mtn] |
|
12 | 13 | - GNU Arch [gnuarch] |
|
13 | 14 | - Bazaar [bzr] |
|
14 | 15 | - Perforce [p4] |
|
15 | 16 | |
|
16 | 17 | Accepted destination formats [identifiers]: |
|
18 | ||
|
17 | 19 | - Mercurial [hg] |
|
18 | 20 | - Subversion [svn] (history on branches is not preserved) |
|
19 | 21 | |
|
20 | 22 | If no revision is given, all revisions will be converted. Otherwise, |
|
21 | 23 | convert will only import up to the named revision (given in a format |
|
22 | 24 | understood by the source). |
|
23 | 25 | |
|
24 | 26 | If no destination directory name is specified, it defaults to the basename |
|
25 | 27 | of the source with '-hg' appended. If the destination repository doesn't |
|
26 | 28 | exist, it will be created. |
|
27 | 29 | |
|
28 | 30 | By default, all sources except Mercurial will use --branchsort. Mercurial |
|
29 | 31 | uses --sourcesort to preserve original revision numbers order. Sort modes |
|
30 | 32 | have the following effects: |
|
31 | 33 | |
|
32 |
--branchsort |
|
|
33 |
means branches are usually converted one after the other. It |
|
|
34 | more compact repositories. | |
|
35 |
--datesort |
|
|
36 |
|
|
|
37 | the same ones generated by --branchsort. | |
|
38 |
--sourcesort |
|
|
39 | Mercurial sources. | |
|
34 | --branchsort convert from parent to child revision when possible, which | |
|
35 | means branches are usually converted one after the other. It | |
|
36 | generates more compact repositories. | |
|
37 | --datesort sort revisions by date. Converted repositories have good- | |
|
38 | looking changelogs but are often an order of magnitude | |
|
39 | larger than the same ones generated by --branchsort. | |
|
40 | --sourcesort try to preserve source revisions order, only supported by | |
|
41 | Mercurial sources. | |
|
40 | 42 | |
|
41 | 43 | If <REVMAP> isn't given, it will be put in a default location |
|
42 | 44 | (<dest>/.hg/shamap by default). The <REVMAP> is a simple text file that |
|
43 | 45 | maps each source commit ID to the destination ID for that revision, like |
|
44 | 46 | so: |
|
45 | 47 | |
|
46 | 48 | <source ID> <destination ID> |
|
47 | 49 | |
|
48 | 50 | If the file doesn't exist, it's automatically created. It's updated on |
|
49 | 51 | each commit copied, so convert-repo can be interrupted and can be run |
|
50 | 52 | repeatedly to copy new commits. |
|
51 | 53 | |
|
52 | 54 | The [username mapping] file is a simple text file that maps each source |
|
53 | 55 | commit author to a destination commit author. It is handy for source SCMs |
|
54 | 56 | that use unix logins to identify authors (eg: CVS). One line per author |
|
55 | 57 | mapping and the line format is: srcauthor=whatever string you want |
|
56 | 58 | |
|
57 | 59 | The filemap is a file that allows filtering and remapping of files and |
|
58 | 60 | directories. Comment lines start with '#'. Each line can contain one of |
|
59 | 61 | the following directives: |
|
60 | 62 | |
|
61 |
|
|
|
63 | include path/to/file | |
|
62 | 64 | |
|
63 |
|
|
|
65 | exclude path/to/file | |
|
64 | 66 | |
|
65 |
|
|
|
67 | rename from/file to/file | |
|
66 | 68 | |
|
67 | 69 | The 'include' directive causes a file, or all files under a directory, to |
|
68 | 70 | be included in the destination repository, and the exclusion of all other |
|
69 | 71 | files and directories not explicitly included. The 'exclude' directive |
|
70 | 72 | causes files or directories to be omitted. The 'rename' directive renames |
|
71 | 73 | a file or directory. To rename from a subdirectory into the root of the |
|
72 | 74 | repository, use '.' as the path to rename to. |
|
73 | 75 | |
|
74 | 76 | The splicemap is a file that allows insertion of synthetic history, |
|
75 | 77 | letting you specify the parents of a revision. This is useful if you want |
|
76 | 78 | to e.g. give a Subversion merge two parents, or graft two disconnected |
|
77 | 79 | series of history together. Each entry contains a key, followed by a |
|
78 | 80 | space, followed by one or two comma-separated values. The key is the |
|
79 | 81 | revision ID in the source revision control system whose parents should be |
|
80 | 82 | modified (same format as a key in .hg/shamap). The values are the revision |
|
81 | 83 | IDs (in either the source or destination revision control system) that |
|
82 | 84 | should be used as the new parents for that node. |
|
83 | 85 | |
|
84 | 86 | The branchmap is a file that allows you to rename a branch when it is |
|
85 | 87 | being brought in from whatever external repository. When used in |
|
86 | 88 | conjunction with a splicemap, it allows for a powerful combination to help |
|
87 | 89 | fix even the most badly mismanaged repositories and turn them into nicely |
|
88 | 90 | structured Mercurial repositories. The branchmap contains lines of the |
|
89 | 91 | form "original_branch_name new_branch_name". "original_branch_name" is the |
|
90 | 92 | name of the branch in the source repository, and "new_branch_name" is the |
|
91 | 93 | name of the branch is the destination repository. This can be used to (for |
|
92 | 94 | instance) move code in one repository from "default" to a named branch. |
|
93 | 95 | |
|
94 | 96 | Mercurial Source |
|
95 | 97 | ---------------- |
|
96 | 98 | |
|
97 | 99 | --config convert.hg.ignoreerrors=False (boolean) |
|
98 | 100 | ignore integrity errors when reading. Use it to fix Mercurial |
|
99 | 101 | repositories with missing revlogs, by converting from and to |
|
100 | 102 | Mercurial. |
|
101 | 103 | --config convert.hg.saverev=False (boolean) |
|
102 | 104 | store original revision ID in changeset (forces target IDs to change) |
|
103 | 105 | --config convert.hg.startrev=0 (hg revision identifier) |
|
104 | 106 | convert start revision and its descendants |
|
105 | 107 | |
|
106 | 108 | CVS Source |
|
107 | 109 | ---------- |
|
108 | 110 | |
|
109 | 111 | CVS source will use a sandbox (i.e. a checked-out copy) from CVS to |
|
110 | 112 | indicate the starting point of what will be converted. Direct access to |
|
111 | 113 | the repository files is not needed, unless of course the repository is |
|
112 | 114 | :local:. The conversion uses the top level directory in the sandbox to |
|
113 | 115 | find the CVS repository, and then uses CVS rlog commands to find files to |
|
114 | 116 | convert. This means that unless a filemap is given, all files under the |
|
115 | 117 | starting directory will be converted, and that any directory |
|
116 | 118 | reorganization in the CVS sandbox is ignored. |
|
117 | 119 | |
|
118 | 120 | Because CVS does not have changesets, it is necessary to collect |
|
119 | 121 | individual commits to CVS and merge them into changesets. CVS source uses |
|
120 | 122 | its internal changeset merging code by default but can be configured to |
|
121 | 123 | call the external 'cvsps' program by setting: |
|
122 | 124 | |
|
123 | 125 | --config convert.cvsps='cvsps -A -u --cvs-direct -q' |
|
124 | 126 | |
|
125 | 127 | This option is deprecated and will be removed in Mercurial 1.4. |
|
126 | 128 | |
|
127 | 129 | The options shown are the defaults. |
|
128 | 130 | |
|
129 | 131 | Internal cvsps is selected by setting |
|
130 | 132 | |
|
131 | 133 | --config convert.cvsps=builtin |
|
132 | 134 | |
|
133 | 135 | and has a few more configurable options: |
|
134 | 136 | |
|
135 | 137 | --config convert.cvsps.cache=True (boolean) |
|
136 | 138 | Set to False to disable remote log caching, for testing and debugging |
|
137 | 139 | purposes. |
|
138 | 140 | --config convert.cvsps.fuzz=60 (integer) |
|
139 | 141 | Specify the maximum time (in seconds) that is allowed between commits |
|
140 | 142 | with identical user and log message in a single changeset. When very |
|
141 | 143 | large files were checked in as part of a changeset then the default |
|
142 | 144 | may not be long enough. |
|
143 | 145 | --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}' |
|
144 | 146 | Specify a regular expression to which commit log messages are matched. |
|
145 | 147 | If a match occurs, then the conversion process will insert a dummy |
|
146 | 148 | revision merging the branch on which this log message occurs to the |
|
147 | 149 | branch indicated in the regex. |
|
148 | 150 | --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}' |
|
149 | 151 | Specify a regular expression to which commit log messages are matched. |
|
150 | 152 | If a match occurs, then the conversion process will add the most |
|
151 | 153 | recent revision on the branch indicated in the regex as the second |
|
152 | 154 | parent of the changeset. |
|
153 | 155 | |
|
154 | 156 | The hgext/convert/cvsps wrapper script allows the builtin changeset |
|
155 | 157 | merging code to be run without doing a conversion. Its parameters and |
|
156 | 158 | output are similar to that of cvsps 2.1. |
|
157 | 159 | |
|
158 | 160 | Subversion Source |
|
159 | 161 | ----------------- |
|
160 | 162 | |
|
161 | 163 | Subversion source detects classical trunk/branches/tags layouts. By |
|
162 | 164 | default, the supplied "svn://repo/path/" source URL is converted as a |
|
163 | 165 | single branch. If "svn://repo/path/trunk" exists it replaces the default |
|
164 | 166 | branch. If "svn://repo/path/branches" exists, its subdirectories are |
|
165 | 167 | listed as possible branches. If "svn://repo/path/tags" exists, it is |
|
166 | 168 | looked for tags referencing converted branches. Default "trunk", |
|
167 | 169 | "branches" and "tags" values can be overridden with following options. Set |
|
168 | 170 | them to paths relative to the source URL, or leave them blank to disable |
|
169 | 171 | auto detection. |
|
170 | 172 | |
|
171 | 173 | --config convert.svn.branches=branches (directory name) |
|
172 | 174 | specify the directory containing branches |
|
173 | 175 | --config convert.svn.tags=tags (directory name) |
|
174 | 176 | specify the directory containing tags |
|
175 | 177 | --config convert.svn.trunk=trunk (directory name) |
|
176 | 178 | specify the name of the trunk branch |
|
177 | 179 | |
|
178 | 180 | Source history can be retrieved starting at a specific revision, instead |
|
179 | 181 | of being integrally converted. Only single branch conversions are |
|
180 | 182 | supported. |
|
181 | 183 | |
|
182 | 184 | --config convert.svn.startrev=0 (svn revision number) |
|
183 | 185 | specify start Subversion revision. |
|
184 | 186 | |
|
185 | 187 | Perforce Source |
|
186 | 188 | --------------- |
|
187 | 189 | |
|
188 | 190 | The Perforce (P4) importer can be given a p4 depot path or a client |
|
189 | 191 | specification as source. It will convert all files in the source to a flat |
|
190 | 192 | Mercurial repository, ignoring labels, branches and integrations. Note |
|
191 | 193 | that when a depot path is given you then usually should specify a target |
|
192 | 194 | directory, because otherwise the target may be named ...-hg. |
|
193 | 195 | |
|
194 | 196 | It is possible to limit the amount of source history to be converted by |
|
195 | 197 | specifying an initial Perforce revision. |
|
196 | 198 | |
|
197 | 199 | --config convert.p4.startrev=0 (perforce changelist number) |
|
198 | 200 | specify initial Perforce revision. |
|
199 | 201 | |
|
200 | 202 | Mercurial Destination |
|
201 | 203 | --------------------- |
|
202 | 204 | |
|
203 | 205 | --config convert.hg.clonebranches=False (boolean) |
|
204 | 206 | dispatch source branches in separate clones. |
|
205 | 207 | --config convert.hg.tagsbranch=default (branch name) |
|
206 | 208 | tag revisions branch name |
|
207 | 209 | --config convert.hg.usebranchnames=True (boolean) |
|
208 | 210 | preserve branch names |
|
209 | 211 | |
|
210 | 212 | options: |
|
211 | 213 | |
|
212 | 214 | -A --authors username mapping filename |
|
213 | 215 | -d --dest-type destination repository type |
|
214 | 216 | --filemap remap file names using contents of file |
|
215 | 217 | -r --rev import up to target revision REV |
|
216 | 218 | -s --source-type source repository type |
|
217 | 219 | --splicemap splice synthesized history into place |
|
218 | 220 | --branchmap change branch names while converting |
|
219 | 221 | --branchsort try to sort changesets by branches |
|
220 | 222 | --datesort try to sort changesets by date |
|
221 | 223 | --sourcesort preserve source changesets order |
|
222 | 224 | |
|
223 | 225 | use "hg -v help convert" to show global options |
|
224 | 226 | adding a |
|
225 | 227 | assuming destination a-hg |
|
226 | 228 | initializing destination a-hg repository |
|
227 | 229 | scanning source... |
|
228 | 230 | sorting... |
|
229 | 231 | converting... |
|
230 | 232 | 4 a |
|
231 | 233 | 3 b |
|
232 | 234 | 2 c |
|
233 | 235 | 1 d |
|
234 | 236 | 0 e |
|
235 | 237 | pulling from ../a |
|
236 | 238 | searching for changes |
|
237 | 239 | no changes found |
|
238 | 240 | % should fail |
|
239 | 241 | initializing destination bogusfile repository |
|
240 | 242 | abort: cannot create new bundle repository |
|
241 | 243 | % should fail |
|
242 | 244 | abort: Permission denied: bogusdir |
|
243 | 245 | % should succeed |
|
244 | 246 | initializing destination bogusdir repository |
|
245 | 247 | scanning source... |
|
246 | 248 | sorting... |
|
247 | 249 | converting... |
|
248 | 250 | 4 a |
|
249 | 251 | 3 b |
|
250 | 252 | 2 c |
|
251 | 253 | 1 d |
|
252 | 254 | 0 e |
|
253 | 255 | % test pre and post conversion actions |
|
254 | 256 | run hg source pre-conversion action |
|
255 | 257 | run hg sink pre-conversion action |
|
256 | 258 | run hg sink post-conversion action |
|
257 | 259 | run hg source post-conversion action |
|
258 | 260 | % converting empty dir should fail nicely |
|
259 | 261 | assuming destination emptydir-hg |
|
260 | 262 | initializing destination emptydir-hg repository |
|
261 | 263 | emptydir does not look like a CVS checkout |
|
262 | 264 | emptydir does not look like a Git repo |
|
263 | 265 | emptydir does not look like a Subversion repo |
|
264 | 266 | emptydir is not a local Mercurial repo |
|
265 | 267 | emptydir does not look like a darcs repo |
|
266 | 268 | emptydir does not look like a monotone repo |
|
267 | 269 | emptydir does not look like a GNU Arch repo |
|
268 | 270 | emptydir does not look like a Bazaar repo |
|
269 | 271 | cannot find required "p4" tool |
|
270 | 272 | abort: emptydir: missing or unsupported repository |
@@ -1,347 +1,348 b'' | |||
|
1 | 1 | Mercurial Distributed SCM |
|
2 | 2 | |
|
3 | 3 | basic commands: |
|
4 | 4 | |
|
5 | 5 | add add the specified files on the next commit |
|
6 | 6 | annotate show changeset information by line for each file |
|
7 | 7 | clone make a copy of an existing repository |
|
8 | 8 | commit commit the specified files or all outstanding changes |
|
9 | 9 | diff diff repository (or selected files) |
|
10 | 10 | export dump the header and diffs for one or more changesets |
|
11 | 11 | forget forget the specified files on the next commit |
|
12 | 12 | init create a new repository in the given directory |
|
13 | 13 | log show revision history of entire repository or files |
|
14 | 14 | merge merge working directory with another revision |
|
15 | 15 | parents show the parents of the working directory or revision |
|
16 | 16 | pull pull changes from the specified source |
|
17 | 17 | push push changes to the specified destination |
|
18 | 18 | remove remove the specified files on the next commit |
|
19 | 19 | serve export the repository via HTTP |
|
20 | 20 | status show changed files in the working directory |
|
21 | 21 | update update working directory |
|
22 | 22 | |
|
23 | 23 | use "hg help" for the full list of commands or "hg -v" for details |
|
24 | 24 | add add the specified files on the next commit |
|
25 | 25 | annotate show changeset information by line for each file |
|
26 | 26 | clone make a copy of an existing repository |
|
27 | 27 | commit commit the specified files or all outstanding changes |
|
28 | 28 | diff diff repository (or selected files) |
|
29 | 29 | export dump the header and diffs for one or more changesets |
|
30 | 30 | forget forget the specified files on the next commit |
|
31 | 31 | init create a new repository in the given directory |
|
32 | 32 | log show revision history of entire repository or files |
|
33 | 33 | merge merge working directory with another revision |
|
34 | 34 | parents show the parents of the working directory or revision |
|
35 | 35 | pull pull changes from the specified source |
|
36 | 36 | push push changes to the specified destination |
|
37 | 37 | remove remove the specified files on the next commit |
|
38 | 38 | serve export the repository via HTTP |
|
39 | 39 | status show changed files in the working directory |
|
40 | 40 | update update working directory |
|
41 | 41 | Mercurial Distributed SCM |
|
42 | 42 | |
|
43 | 43 | list of commands: |
|
44 | 44 | |
|
45 | 45 | add add the specified files on the next commit |
|
46 | 46 | addremove add all new files, delete all missing files |
|
47 | 47 | annotate show changeset information by line for each file |
|
48 | 48 | archive create an unversioned archive of a repository revision |
|
49 | 49 | backout reverse effect of earlier changeset |
|
50 | 50 | bisect subdivision search of changesets |
|
51 | 51 | branch set or show the current branch name |
|
52 | 52 | branches list repository named branches |
|
53 | 53 | bundle create a changegroup file |
|
54 | 54 | cat output the current or given revision of files |
|
55 | 55 | clone make a copy of an existing repository |
|
56 | 56 | commit commit the specified files or all outstanding changes |
|
57 | 57 | copy mark files as copied for the next commit |
|
58 | 58 | diff diff repository (or selected files) |
|
59 | 59 | export dump the header and diffs for one or more changesets |
|
60 | 60 | forget forget the specified files on the next commit |
|
61 | 61 | grep search for a pattern in specified files and revisions |
|
62 | 62 | heads show current repository heads or show branch heads |
|
63 | 63 | help show help for a given topic or a help overview |
|
64 | 64 | identify identify the working copy or specified revision |
|
65 | 65 | import import an ordered set of patches |
|
66 | 66 | incoming show new changesets found in source |
|
67 | 67 | init create a new repository in the given directory |
|
68 | 68 | locate locate files matching specific patterns |
|
69 | 69 | log show revision history of entire repository or files |
|
70 | 70 | manifest output the current or given revision of the project manifest |
|
71 | 71 | merge merge working directory with another revision |
|
72 | 72 | outgoing show changesets not found in destination |
|
73 | 73 | parents show the parents of the working directory or revision |
|
74 | 74 | paths show aliases for remote repositories |
|
75 | 75 | pull pull changes from the specified source |
|
76 | 76 | push push changes to the specified destination |
|
77 | 77 | recover roll back an interrupted transaction |
|
78 | 78 | remove remove the specified files on the next commit |
|
79 | 79 | rename rename files; equivalent of copy + remove |
|
80 | 80 | resolve retry file merges from a merge or update |
|
81 | 81 | revert restore individual files or directories to an earlier state |
|
82 | 82 | rollback roll back the last transaction |
|
83 | 83 | root print the root (top) of the current working directory |
|
84 | 84 | serve export the repository via HTTP |
|
85 | 85 | showconfig show combined config settings from all hgrc files |
|
86 | 86 | status show changed files in the working directory |
|
87 | 87 | tag add one or more tags for the current or given revision |
|
88 | 88 | tags list repository tags |
|
89 | 89 | tip show the tip revision |
|
90 | 90 | unbundle apply one or more changegroup files |
|
91 | 91 | update update working directory |
|
92 | 92 | verify verify the integrity of the repository |
|
93 | 93 | version output version and copyright information |
|
94 | 94 | |
|
95 | 95 | additional help topics: |
|
96 | 96 | |
|
97 | 97 | dates Date Formats |
|
98 | 98 | patterns File Name Patterns |
|
99 | 99 | environment Environment Variables |
|
100 | 100 | revisions Specifying Single Revisions |
|
101 | 101 | multirevs Specifying Multiple Revisions |
|
102 | 102 | diffs Diff Formats |
|
103 | 103 | templating Template Usage |
|
104 | 104 | urls URL Paths |
|
105 | 105 | extensions Using additional features |
|
106 | 106 | |
|
107 | 107 | use "hg -v help" to show aliases and global options |
|
108 | 108 | add add the specified files on the next commit |
|
109 | 109 | addremove add all new files, delete all missing files |
|
110 | 110 | annotate show changeset information by line for each file |
|
111 | 111 | archive create an unversioned archive of a repository revision |
|
112 | 112 | backout reverse effect of earlier changeset |
|
113 | 113 | bisect subdivision search of changesets |
|
114 | 114 | branch set or show the current branch name |
|
115 | 115 | branches list repository named branches |
|
116 | 116 | bundle create a changegroup file |
|
117 | 117 | cat output the current or given revision of files |
|
118 | 118 | clone make a copy of an existing repository |
|
119 | 119 | commit commit the specified files or all outstanding changes |
|
120 | 120 | copy mark files as copied for the next commit |
|
121 | 121 | diff diff repository (or selected files) |
|
122 | 122 | export dump the header and diffs for one or more changesets |
|
123 | 123 | forget forget the specified files on the next commit |
|
124 | 124 | grep search for a pattern in specified files and revisions |
|
125 | 125 | heads show current repository heads or show branch heads |
|
126 | 126 | help show help for a given topic or a help overview |
|
127 | 127 | identify identify the working copy or specified revision |
|
128 | 128 | import import an ordered set of patches |
|
129 | 129 | incoming show new changesets found in source |
|
130 | 130 | init create a new repository in the given directory |
|
131 | 131 | locate locate files matching specific patterns |
|
132 | 132 | log show revision history of entire repository or files |
|
133 | 133 | manifest output the current or given revision of the project manifest |
|
134 | 134 | merge merge working directory with another revision |
|
135 | 135 | outgoing show changesets not found in destination |
|
136 | 136 | parents show the parents of the working directory or revision |
|
137 | 137 | paths show aliases for remote repositories |
|
138 | 138 | pull pull changes from the specified source |
|
139 | 139 | push push changes to the specified destination |
|
140 | 140 | recover roll back an interrupted transaction |
|
141 | 141 | remove remove the specified files on the next commit |
|
142 | 142 | rename rename files; equivalent of copy + remove |
|
143 | 143 | resolve retry file merges from a merge or update |
|
144 | 144 | revert restore individual files or directories to an earlier state |
|
145 | 145 | rollback roll back the last transaction |
|
146 | 146 | root print the root (top) of the current working directory |
|
147 | 147 | serve export the repository via HTTP |
|
148 | 148 | showconfig show combined config settings from all hgrc files |
|
149 | 149 | status show changed files in the working directory |
|
150 | 150 | tag add one or more tags for the current or given revision |
|
151 | 151 | tags list repository tags |
|
152 | 152 | tip show the tip revision |
|
153 | 153 | unbundle apply one or more changegroup files |
|
154 | 154 | update update working directory |
|
155 | 155 | verify verify the integrity of the repository |
|
156 | 156 | version output version and copyright information |
|
157 | 157 | |
|
158 | 158 | additional help topics: |
|
159 | 159 | |
|
160 | 160 | dates Date Formats |
|
161 | 161 | patterns File Name Patterns |
|
162 | 162 | environment Environment Variables |
|
163 | 163 | revisions Specifying Single Revisions |
|
164 | 164 | multirevs Specifying Multiple Revisions |
|
165 | 165 | diffs Diff Formats |
|
166 | 166 | templating Template Usage |
|
167 | 167 | urls URL Paths |
|
168 | 168 | extensions Using additional features |
|
169 | 169 | hg add [OPTION]... [FILE]... |
|
170 | 170 | |
|
171 | 171 | add the specified files on the next commit |
|
172 | 172 | |
|
173 | 173 | Schedule files to be version controlled and added to the repository. |
|
174 | 174 | |
|
175 | 175 | The files will be added to the repository at the next commit. To undo an |
|
176 | 176 | add before that, see hg forget. |
|
177 | 177 | |
|
178 | 178 | If no names are given, add all files to the repository. |
|
179 | 179 | |
|
180 | 180 | options: |
|
181 | 181 | |
|
182 | 182 | -I --include include names matching the given patterns |
|
183 | 183 | -X --exclude exclude names matching the given patterns |
|
184 | 184 | -n --dry-run do not perform actions, just print output |
|
185 | 185 | |
|
186 | 186 | use "hg -v help add" to show global options |
|
187 | 187 | hg add: option --skjdfks not recognized |
|
188 | 188 | hg add [OPTION]... [FILE]... |
|
189 | 189 | |
|
190 | 190 | add the specified files on the next commit |
|
191 | 191 | |
|
192 | 192 | Schedule files to be version controlled and added to the repository. |
|
193 | 193 | |
|
194 | 194 | The files will be added to the repository at the next commit. To undo an |
|
195 | 195 | add before that, see hg forget. |
|
196 | 196 | |
|
197 | 197 | If no names are given, add all files to the repository. |
|
198 | 198 | |
|
199 | 199 | options: |
|
200 | 200 | |
|
201 | 201 | -I --include include names matching the given patterns |
|
202 | 202 | -X --exclude exclude names matching the given patterns |
|
203 | 203 | -n --dry-run do not perform actions, just print output |
|
204 | 204 | |
|
205 | 205 | use "hg -v help add" to show global options |
|
206 | 206 | hg diff [OPTION]... [-r REV1 [-r REV2]] [FILE]... |
|
207 | 207 | |
|
208 | 208 | diff repository (or selected files) |
|
209 | 209 | |
|
210 | 210 | Show differences between revisions for the specified files. |
|
211 | 211 | |
|
212 | 212 | Differences between files are shown using the unified diff format. |
|
213 | 213 | |
|
214 | 214 | NOTE: diff may generate unexpected results for merges, as it will default |
|
215 | 215 | to comparing against the working directory's first parent changeset if no |
|
216 | 216 | revisions are specified. |
|
217 | 217 | |
|
218 | 218 | When two revision arguments are given, then changes are shown between |
|
219 | 219 | those revisions. If only one revision is specified then that revision is |
|
220 | 220 | compared to the working directory, and, when no revisions are specified, |
|
221 | 221 | the working directory files are compared to its parent. |
|
222 | 222 | |
|
223 | 223 | Without the -a/--text option, diff will avoid generating diffs of files it |
|
224 | 224 | detects as binary. With -a, diff will generate a diff anyway, probably |
|
225 | 225 | with undesirable results. |
|
226 | 226 | |
|
227 | 227 | Use the -g/--git option to generate diffs in the git extended diff format. |
|
228 | 228 | For more information, read 'hg help diffs'. |
|
229 | 229 | |
|
230 | 230 | options: |
|
231 | 231 | |
|
232 | 232 | -r --rev revision |
|
233 | 233 | -c --change change made by revision |
|
234 | 234 | -a --text treat all files as text |
|
235 | 235 | -g --git use git extended diff format |
|
236 | 236 | --nodates don't include dates in diff headers |
|
237 | 237 | -p --show-function show which function each change is in |
|
238 | 238 | -w --ignore-all-space ignore white space when comparing lines |
|
239 | 239 | -b --ignore-space-change ignore changes in the amount of white space |
|
240 | 240 | -B --ignore-blank-lines ignore changes whose lines are all blank |
|
241 | 241 | -U --unified number of lines of context to show |
|
242 | 242 | -I --include include names matching the given patterns |
|
243 | 243 | -X --exclude exclude names matching the given patterns |
|
244 | 244 | |
|
245 | 245 | use "hg -v help diff" to show global options |
|
246 | 246 | hg status [OPTION]... [FILE]... |
|
247 | 247 | |
|
248 | 248 | aliases: st |
|
249 | 249 | |
|
250 | 250 | show changed files in the working directory |
|
251 | 251 | |
|
252 | 252 | Show status of files in the repository. If names are given, only files |
|
253 | 253 | that match are shown. Files that are clean or ignored or the source of a |
|
254 | 254 | copy/move operation, are not listed unless -c/--clean, -i/--ignored, |
|
255 | 255 | -C/--copies or -A/--all are given. Unless options described with "show |
|
256 | 256 | only ..." are given, the options -mardu are used. |
|
257 | 257 | |
|
258 | 258 | Option -q/--quiet hides untracked (unknown and ignored) files unless |
|
259 | 259 | explicitly requested with -u/--unknown or -i/--ignored. |
|
260 | 260 | |
|
261 | 261 | NOTE: status may appear to disagree with diff if permissions have changed |
|
262 | 262 | or a merge has occurred. The standard diff format does not report |
|
263 | 263 | permission changes and diff only reports changes relative to one merge |
|
264 | 264 | parent. |
|
265 | 265 | |
|
266 | 266 | If one revision is given, it is used as the base revision. If two |
|
267 | 267 | revisions are given, the differences between them are shown. |
|
268 | 268 | |
|
269 | 269 | The codes used to show the status of files are: |
|
270 | ||
|
270 | 271 | M = modified |
|
271 | 272 | A = added |
|
272 | 273 | R = removed |
|
273 | 274 | C = clean |
|
274 | 275 | ! = missing (deleted by non-hg command, but still tracked) |
|
275 | 276 | ? = not tracked |
|
276 | 277 | I = ignored |
|
277 | 278 | = origin of the previous file listed as A (added) |
|
278 | 279 | |
|
279 | 280 | options: |
|
280 | 281 | |
|
281 | 282 | -A --all show status of all files |
|
282 | 283 | -m --modified show only modified files |
|
283 | 284 | -a --added show only added files |
|
284 | 285 | -r --removed show only removed files |
|
285 | 286 | -d --deleted show only deleted (but tracked) files |
|
286 | 287 | -c --clean show only files without changes |
|
287 | 288 | -u --unknown show only unknown (not tracked) files |
|
288 | 289 | -i --ignored show only ignored files |
|
289 | 290 | -n --no-status hide status prefix |
|
290 | 291 | -C --copies show source of copied files |
|
291 | 292 | -0 --print0 end filenames with NUL, for use with xargs |
|
292 | 293 | --rev show difference from revision |
|
293 | 294 | -I --include include names matching the given patterns |
|
294 | 295 | -X --exclude exclude names matching the given patterns |
|
295 | 296 | |
|
296 | 297 | use "hg -v help status" to show global options |
|
297 | 298 | hg status [OPTION]... [FILE]... |
|
298 | 299 | |
|
299 | 300 | show changed files in the working directory |
|
300 | 301 | hg: unknown command 'foo' |
|
301 | 302 | Mercurial Distributed SCM |
|
302 | 303 | |
|
303 | 304 | basic commands: |
|
304 | 305 | |
|
305 | 306 | add add the specified files on the next commit |
|
306 | 307 | annotate show changeset information by line for each file |
|
307 | 308 | clone make a copy of an existing repository |
|
308 | 309 | commit commit the specified files or all outstanding changes |
|
309 | 310 | diff diff repository (or selected files) |
|
310 | 311 | export dump the header and diffs for one or more changesets |
|
311 | 312 | forget forget the specified files on the next commit |
|
312 | 313 | init create a new repository in the given directory |
|
313 | 314 | log show revision history of entire repository or files |
|
314 | 315 | merge merge working directory with another revision |
|
315 | 316 | parents show the parents of the working directory or revision |
|
316 | 317 | pull pull changes from the specified source |
|
317 | 318 | push push changes to the specified destination |
|
318 | 319 | remove remove the specified files on the next commit |
|
319 | 320 | serve export the repository via HTTP |
|
320 | 321 | status show changed files in the working directory |
|
321 | 322 | update update working directory |
|
322 | 323 | |
|
323 | 324 | use "hg help" for the full list of commands or "hg -v" for details |
|
324 | 325 | hg: unknown command 'skjdfks' |
|
325 | 326 | Mercurial Distributed SCM |
|
326 | 327 | |
|
327 | 328 | basic commands: |
|
328 | 329 | |
|
329 | 330 | add add the specified files on the next commit |
|
330 | 331 | annotate show changeset information by line for each file |
|
331 | 332 | clone make a copy of an existing repository |
|
332 | 333 | commit commit the specified files or all outstanding changes |
|
333 | 334 | diff diff repository (or selected files) |
|
334 | 335 | export dump the header and diffs for one or more changesets |
|
335 | 336 | forget forget the specified files on the next commit |
|
336 | 337 | init create a new repository in the given directory |
|
337 | 338 | log show revision history of entire repository or files |
|
338 | 339 | merge merge working directory with another revision |
|
339 | 340 | parents show the parents of the working directory or revision |
|
340 | 341 | pull pull changes from the specified source |
|
341 | 342 | push push changes to the specified destination |
|
342 | 343 | remove remove the specified files on the next commit |
|
343 | 344 | serve export the repository via HTTP |
|
344 | 345 | status show changed files in the working directory |
|
345 | 346 | update update working directory |
|
346 | 347 | |
|
347 | 348 | use "hg help" for the full list of commands or "hg -v" for details |
@@ -1,503 +1,503 b'' | |||
|
1 | 1 | % help |
|
2 | 2 | keyword extension - expand keywords in tracked files |
|
3 | 3 | |
|
4 | 4 | This extension expands RCS/CVS-like or self-customized $Keywords$ in tracked |
|
5 | 5 | text files selected by your configuration. |
|
6 | 6 | |
|
7 | 7 | Keywords are only expanded in local repositories and not stored in the change |
|
8 | 8 | history. The mechanism can be regarded as a convenience for the current user |
|
9 | 9 | or for archive distribution. |
|
10 | 10 | |
|
11 | 11 | Configuration is done in the [keyword] and [keywordmaps] sections of hgrc |
|
12 | 12 | files. |
|
13 | 13 | |
|
14 | 14 | Example: |
|
15 | 15 | |
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
16 | [keyword] | |
|
17 | # expand keywords in every python file except those matching "x*" | |
|
18 | **.py = | |
|
19 | x* = ignore | |
|
20 | 20 | |
|
21 | 21 | NOTE: the more specific you are in your filename patterns the less you lose |
|
22 | 22 | speed in huge repositories. |
|
23 | 23 | |
|
24 | 24 | For [keywordmaps] template mapping and expansion demonstration and control run |
|
25 | 25 | "hg kwdemo". |
|
26 | 26 | |
|
27 | 27 | An additional date template filter {date|utcdate} is provided. |
|
28 | 28 | |
|
29 | 29 | The default template mappings (view with "hg kwdemo -d") can be replaced with |
|
30 | 30 | customized keywords and templates. Again, run "hg kwdemo" to control the |
|
31 | 31 | results of your config changes. |
|
32 | 32 | |
|
33 | 33 | Before changing/disabling active keywords, run "hg kwshrink" to avoid the risk |
|
34 | 34 | of inadvertently storing expanded keywords in the change history. |
|
35 | 35 | |
|
36 | 36 | To force expansion after enabling it, or a configuration change, run "hg |
|
37 | 37 | kwexpand". |
|
38 | 38 | |
|
39 | 39 | Also, when committing with the record extension or using mq's qrecord, be |
|
40 | 40 | aware that keywords cannot be updated. Again, run "hg kwexpand" on the files |
|
41 | 41 | in question to update keyword expansions after all changes have been checked |
|
42 | 42 | in. |
|
43 | 43 | |
|
44 | 44 | Expansions spanning more than one line and incremental expansions, like CVS' |
|
45 | 45 | $Log$, are not supported. A keyword template map "Log = {desc}" expands to the |
|
46 | 46 | first line of the changeset description. |
|
47 | 47 | |
|
48 | 48 | list of commands: |
|
49 | 49 | |
|
50 | 50 | kwdemo print [keywordmaps] configuration and an expansion example |
|
51 | 51 | kwexpand expand keywords in the working directory |
|
52 | 52 | kwfiles show files configured for keyword expansion |
|
53 | 53 | kwshrink revert expanded keywords in the working directory |
|
54 | 54 | |
|
55 | 55 | enabled extensions: |
|
56 | 56 | |
|
57 | 57 | keyword expand keywords in tracked files |
|
58 | 58 | mq manage a stack of patches |
|
59 | 59 | notify hooks for sending email notifications at commit/push time |
|
60 | 60 | |
|
61 | 61 | use "hg -v help keyword" to show aliases and global options |
|
62 | 62 | % hg kwdemo |
|
63 | 63 | [extensions] |
|
64 | 64 | hgext.keyword = |
|
65 | 65 | [keyword] |
|
66 | 66 | * = |
|
67 | 67 | b = ignore |
|
68 | 68 | demo.txt = |
|
69 | 69 | [keywordmaps] |
|
70 | 70 | RCSFile = {file|basename},v |
|
71 | 71 | Author = {author|user} |
|
72 | 72 | Header = {root}/{file},v {node|short} {date|utcdate} {author|user} |
|
73 | 73 | Source = {root}/{file},v |
|
74 | 74 | Date = {date|utcdate} |
|
75 | 75 | Id = {file|basename},v {node|short} {date|utcdate} {author|user} |
|
76 | 76 | Revision = {node|short} |
|
77 | 77 | $RCSFile: demo.txt,v $ |
|
78 | 78 | $Author: test $ |
|
79 | 79 | $Header: /TMP/demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $ |
|
80 | 80 | $Source: /TMP/demo.txt,v $ |
|
81 | 81 | $Date: 2000/00/00 00:00:00 $ |
|
82 | 82 | $Id: demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $ |
|
83 | 83 | $Revision: xxxxxxxxxxxx $ |
|
84 | 84 | [extensions] |
|
85 | 85 | hgext.keyword = |
|
86 | 86 | [keyword] |
|
87 | 87 | * = |
|
88 | 88 | b = ignore |
|
89 | 89 | demo.txt = |
|
90 | 90 | [keywordmaps] |
|
91 | 91 | Branch = {branches} |
|
92 | 92 | $Branch: demobranch $ |
|
93 | 93 | % kwshrink should exit silently in empty/invalid repo |
|
94 | 94 | pulling from test-keyword.hg |
|
95 | 95 | requesting all changes |
|
96 | 96 | adding changesets |
|
97 | 97 | adding manifests |
|
98 | 98 | adding file changes |
|
99 | 99 | added 1 changesets with 1 changes to 1 files |
|
100 | 100 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
101 | 101 | % cat |
|
102 | 102 | expand $Id$ |
|
103 | 103 | do not process $Id: |
|
104 | 104 | xxx $ |
|
105 | 105 | ignore $Id$ |
|
106 | 106 | % addremove |
|
107 | 107 | adding a |
|
108 | 108 | adding b |
|
109 | 109 | % status |
|
110 | 110 | A a |
|
111 | 111 | A b |
|
112 | 112 | % default keyword expansion including commit hook |
|
113 | 113 | % interrupted commit should not change state or run commit hook |
|
114 | 114 | abort: empty commit message |
|
115 | 115 | % status |
|
116 | 116 | A a |
|
117 | 117 | A b |
|
118 | 118 | % commit |
|
119 | 119 | a |
|
120 | 120 | b |
|
121 | 121 | overwriting a expanding keywords |
|
122 | 122 | running hook commit.test: cp a hooktest |
|
123 | 123 | committed changeset 1:ef63ca68695bc9495032c6fda1350c71e6d256e9 |
|
124 | 124 | % status |
|
125 | 125 | ? hooktest |
|
126 | 126 | % identify |
|
127 | 127 | ef63ca68695b |
|
128 | 128 | % cat |
|
129 | 129 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
130 | 130 | do not process $Id: |
|
131 | 131 | xxx $ |
|
132 | 132 | ignore $Id$ |
|
133 | 133 | % hg cat |
|
134 | 134 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
135 | 135 | do not process $Id: |
|
136 | 136 | xxx $ |
|
137 | 137 | ignore $Id$ |
|
138 | 138 | a |
|
139 | 139 | % diff a hooktest |
|
140 | 140 | % removing commit hook from config |
|
141 | 141 | % bundle |
|
142 | 142 | 2 changesets found |
|
143 | 143 | % notify on pull to check whether keywords stay as is in email |
|
144 | 144 | % ie. if patch.diff wrapper acts as it should |
|
145 | 145 | % pull from bundle |
|
146 | 146 | pulling from ../kw.hg |
|
147 | 147 | requesting all changes |
|
148 | 148 | adding changesets |
|
149 | 149 | adding manifests |
|
150 | 150 | adding file changes |
|
151 | 151 | added 2 changesets with 3 changes to 3 files |
|
152 | 152 | |
|
153 | 153 | diff -r 000000000000 -r a2392c293916 sym |
|
154 | 154 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
155 | 155 | +++ b/sym Sat Feb 09 20:25:47 2008 +0100 |
|
156 | 156 | @@ -0,0 +1,1 @@ |
|
157 | 157 | +a |
|
158 | 158 | \ No newline at end of file |
|
159 | 159 | |
|
160 | 160 | diff -r a2392c293916 -r ef63ca68695b a |
|
161 | 161 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
162 | 162 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
|
163 | 163 | @@ -0,0 +1,3 @@ |
|
164 | 164 | +expand $Id$ |
|
165 | 165 | +do not process $Id: |
|
166 | 166 | +xxx $ |
|
167 | 167 | diff -r a2392c293916 -r ef63ca68695b b |
|
168 | 168 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
169 | 169 | +++ b/b Thu Jan 01 00:00:00 1970 +0000 |
|
170 | 170 | @@ -0,0 +1,1 @@ |
|
171 | 171 | +ignore $Id$ |
|
172 | 172 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
173 | 173 | % remove notify config |
|
174 | 174 | % touch |
|
175 | 175 | % status |
|
176 | 176 | % update |
|
177 | 177 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
178 | 178 | % cat |
|
179 | 179 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
180 | 180 | do not process $Id: |
|
181 | 181 | xxx $ |
|
182 | 182 | ignore $Id$ |
|
183 | 183 | % check whether expansion is filewise |
|
184 | 184 | % commit c |
|
185 | 185 | adding c |
|
186 | 186 | % force expansion |
|
187 | 187 | overwriting a expanding keywords |
|
188 | 188 | overwriting c expanding keywords |
|
189 | 189 | % compare changenodes in a c |
|
190 | 190 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
191 | 191 | do not process $Id: |
|
192 | 192 | xxx $ |
|
193 | 193 | $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $ |
|
194 | 194 | tests for different changenodes |
|
195 | 195 | % qinit -c |
|
196 | 196 | % qimport |
|
197 | 197 | % qcommit |
|
198 | 198 | % keywords should not be expanded in patch |
|
199 | 199 | # HG changeset patch |
|
200 | 200 | # User User Name <user@example.com> |
|
201 | 201 | # Date 1 0 |
|
202 | 202 | # Node ID 40a904bbbe4cd4ab0a1f28411e35db26341a40ad |
|
203 | 203 | # Parent ef63ca68695bc9495032c6fda1350c71e6d256e9 |
|
204 | 204 | cndiff |
|
205 | 205 | |
|
206 | 206 | diff -r ef63ca68695b -r 40a904bbbe4c c |
|
207 | 207 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
208 | 208 | +++ b/c Thu Jan 01 00:00:01 1970 +0000 |
|
209 | 209 | @@ -0,0 +1,2 @@ |
|
210 | 210 | +$Id$ |
|
211 | 211 | +tests for different changenodes |
|
212 | 212 | % qpop |
|
213 | 213 | popping mqtest.diff |
|
214 | 214 | patch queue now empty |
|
215 | 215 | % qgoto - should imply qpush |
|
216 | 216 | applying mqtest.diff |
|
217 | 217 | now at: mqtest.diff |
|
218 | 218 | % cat |
|
219 | 219 | $Id: c,v 40a904bbbe4c 1970/01/01 00:00:01 user $ |
|
220 | 220 | tests for different changenodes |
|
221 | 221 | % qpop and move on |
|
222 | 222 | popping mqtest.diff |
|
223 | 223 | patch queue now empty |
|
224 | 224 | % copy |
|
225 | 225 | % kwfiles added |
|
226 | 226 | a |
|
227 | 227 | c |
|
228 | 228 | % commit |
|
229 | 229 | c |
|
230 | 230 | c: copy a:0045e12f6c5791aac80ca6cbfd97709a88307292 |
|
231 | 231 | overwriting c expanding keywords |
|
232 | 232 | committed changeset 2:e22d299ac0c2bd8897b3df5114374b9e4d4ca62f |
|
233 | 233 | % cat a c |
|
234 | 234 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
235 | 235 | do not process $Id: |
|
236 | 236 | xxx $ |
|
237 | 237 | expand $Id: c,v e22d299ac0c2 1970/01/01 00:00:01 user $ |
|
238 | 238 | do not process $Id: |
|
239 | 239 | xxx $ |
|
240 | 240 | % touch copied c |
|
241 | 241 | % status |
|
242 | 242 | % kwfiles |
|
243 | 243 | a |
|
244 | 244 | c |
|
245 | 245 | % diff --rev |
|
246 | 246 | diff -r ef63ca68695b c |
|
247 | 247 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
248 | 248 | @@ -0,0 +1,3 @@ |
|
249 | 249 | +expand $Id$ |
|
250 | 250 | +do not process $Id: |
|
251 | 251 | +xxx $ |
|
252 | 252 | % rollback |
|
253 | 253 | rolling back last transaction |
|
254 | 254 | % status |
|
255 | 255 | A c |
|
256 | 256 | % update -C |
|
257 | 257 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
258 | 258 | % custom keyword expansion |
|
259 | 259 | % try with kwdemo |
|
260 | 260 | [extensions] |
|
261 | 261 | hgext.keyword = |
|
262 | 262 | [keyword] |
|
263 | 263 | * = |
|
264 | 264 | b = ignore |
|
265 | 265 | demo.txt = |
|
266 | 266 | [keywordmaps] |
|
267 | 267 | Xinfo = {author}: {desc} |
|
268 | 268 | $Xinfo: test: hg keyword config and expansion example $ |
|
269 | 269 | % cat |
|
270 | 270 | expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $ |
|
271 | 271 | do not process $Id: |
|
272 | 272 | xxx $ |
|
273 | 273 | ignore $Id$ |
|
274 | 274 | % hg cat |
|
275 | 275 | expand $Id: a ef63ca68695b Thu, 01 Jan 1970 00:00:00 +0000 user $ |
|
276 | 276 | do not process $Id: |
|
277 | 277 | xxx $ |
|
278 | 278 | ignore $Id$ |
|
279 | 279 | a |
|
280 | 280 | % interrupted commit should not change state |
|
281 | 281 | abort: empty commit message |
|
282 | 282 | % status |
|
283 | 283 | M a |
|
284 | 284 | ? c |
|
285 | 285 | ? log |
|
286 | 286 | % commit |
|
287 | 287 | a |
|
288 | 288 | overwriting a expanding keywords |
|
289 | 289 | committed changeset 2:bb948857c743469b22bbf51f7ec8112279ca5d83 |
|
290 | 290 | % status |
|
291 | 291 | ? c |
|
292 | 292 | % verify |
|
293 | 293 | checking changesets |
|
294 | 294 | checking manifests |
|
295 | 295 | crosschecking files in changesets and manifests |
|
296 | 296 | checking files |
|
297 | 297 | 3 files, 3 changesets, 4 total revisions |
|
298 | 298 | % cat |
|
299 | 299 | expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ |
|
300 | 300 | do not process $Id: |
|
301 | 301 | xxx $ |
|
302 | 302 | $Xinfo: User Name <user@example.com>: firstline $ |
|
303 | 303 | ignore $Id$ |
|
304 | 304 | % hg cat |
|
305 | 305 | expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ |
|
306 | 306 | do not process $Id: |
|
307 | 307 | xxx $ |
|
308 | 308 | $Xinfo: User Name <user@example.com>: firstline $ |
|
309 | 309 | ignore $Id$ |
|
310 | 310 | a |
|
311 | 311 | % annotate |
|
312 | 312 | 1: expand $Id$ |
|
313 | 313 | 1: do not process $Id: |
|
314 | 314 | 1: xxx $ |
|
315 | 315 | 2: $Xinfo$ |
|
316 | 316 | % remove |
|
317 | 317 | committed changeset 3:d14c712653769de926994cf7fbb06c8fbd68f012 |
|
318 | 318 | % status |
|
319 | 319 | ? c |
|
320 | 320 | % rollback |
|
321 | 321 | rolling back last transaction |
|
322 | 322 | % status |
|
323 | 323 | R a |
|
324 | 324 | ? c |
|
325 | 325 | % revert a |
|
326 | 326 | % cat a |
|
327 | 327 | expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ |
|
328 | 328 | do not process $Id: |
|
329 | 329 | xxx $ |
|
330 | 330 | $Xinfo: User Name <user@example.com>: firstline $ |
|
331 | 331 | % clone to test incoming |
|
332 | 332 | requesting all changes |
|
333 | 333 | adding changesets |
|
334 | 334 | adding manifests |
|
335 | 335 | adding file changes |
|
336 | 336 | added 2 changesets with 3 changes to 3 files |
|
337 | 337 | updating working directory |
|
338 | 338 | 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
339 | 339 | % incoming |
|
340 | 340 | comparing with test-keyword/Test |
|
341 | 341 | searching for changes |
|
342 | 342 | changeset: 2:bb948857c743 |
|
343 | 343 | tag: tip |
|
344 | 344 | user: User Name <user@example.com> |
|
345 | 345 | date: Thu Jan 01 00:00:02 1970 +0000 |
|
346 | 346 | summary: firstline |
|
347 | 347 | |
|
348 | 348 | % commit rejecttest |
|
349 | 349 | a |
|
350 | 350 | overwriting a expanding keywords |
|
351 | 351 | committed changeset 2:85e279d709ffc28c9fdd1b868570985fc3d87082 |
|
352 | 352 | % export |
|
353 | 353 | % import |
|
354 | 354 | applying ../rejecttest.diff |
|
355 | 355 | % cat |
|
356 | 356 | expand $Id: a 4e0994474d25 Thu, 01 Jan 1970 00:00:03 +0000 user $ rejecttest |
|
357 | 357 | do not process $Id: rejecttest |
|
358 | 358 | xxx $ |
|
359 | 359 | $Xinfo: User Name <user@example.com>: rejects? $ |
|
360 | 360 | ignore $Id$ |
|
361 | 361 | |
|
362 | 362 | % rollback |
|
363 | 363 | rolling back last transaction |
|
364 | 364 | % clean update |
|
365 | 365 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
366 | 366 | % kwexpand/kwshrink on selected files |
|
367 | 367 | % copy a x/a |
|
368 | 368 | % kwexpand a |
|
369 | 369 | overwriting a expanding keywords |
|
370 | 370 | % kwexpand x/a should abort |
|
371 | 371 | abort: outstanding uncommitted changes |
|
372 | 372 | x/a |
|
373 | 373 | x/a: copy a:779c764182ce5d43e2b1eb66ce06d7b47bfe342e |
|
374 | 374 | overwriting x/a expanding keywords |
|
375 | 375 | committed changeset 3:cfa68229c1167443337266ebac453c73b1d5d16e |
|
376 | 376 | % cat a |
|
377 | 377 | expand $Id: x/a cfa68229c116 Thu, 01 Jan 1970 00:00:03 +0000 user $ |
|
378 | 378 | do not process $Id: |
|
379 | 379 | xxx $ |
|
380 | 380 | $Xinfo: User Name <user@example.com>: xa $ |
|
381 | 381 | % kwshrink a inside directory x |
|
382 | 382 | overwriting x/a shrinking keywords |
|
383 | 383 | % cat a |
|
384 | 384 | expand $Id$ |
|
385 | 385 | do not process $Id: |
|
386 | 386 | xxx $ |
|
387 | 387 | $Xinfo$ |
|
388 | 388 | % kwexpand nonexistent |
|
389 | 389 | nonexistent: |
|
390 | 390 | % hg serve |
|
391 | 391 | % expansion |
|
392 | 392 | % hgweb file |
|
393 | 393 | 200 Script output follows |
|
394 | 394 | |
|
395 | 395 | expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ |
|
396 | 396 | do not process $Id: |
|
397 | 397 | xxx $ |
|
398 | 398 | $Xinfo: User Name <user@example.com>: firstline $ |
|
399 | 399 | % no expansion |
|
400 | 400 | % hgweb annotate |
|
401 | 401 | 200 Script output follows |
|
402 | 402 | |
|
403 | 403 | |
|
404 | 404 | user@1: expand $Id$ |
|
405 | 405 | user@1: do not process $Id: |
|
406 | 406 | user@1: xxx $ |
|
407 | 407 | user@2: $Xinfo$ |
|
408 | 408 | |
|
409 | 409 | |
|
410 | 410 | |
|
411 | 411 | |
|
412 | 412 | % hgweb changeset |
|
413 | 413 | 200 Script output follows |
|
414 | 414 | |
|
415 | 415 | |
|
416 | 416 | # HG changeset patch |
|
417 | 417 | # User User Name <user@example.com> |
|
418 | 418 | # Date 3 0 |
|
419 | 419 | # Node ID cfa68229c1167443337266ebac453c73b1d5d16e |
|
420 | 420 | # Parent bb948857c743469b22bbf51f7ec8112279ca5d83 |
|
421 | 421 | xa |
|
422 | 422 | |
|
423 | 423 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
424 | 424 | +++ b/x/a Thu Jan 01 00:00:03 1970 +0000 |
|
425 | 425 | @@ -0,0 +1,4 @@ |
|
426 | 426 | +expand $Id$ |
|
427 | 427 | +do not process $Id: |
|
428 | 428 | +xxx $ |
|
429 | 429 | +$Xinfo$ |
|
430 | 430 | |
|
431 | 431 | % hgweb filediff |
|
432 | 432 | 200 Script output follows |
|
433 | 433 | |
|
434 | 434 | |
|
435 | 435 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
436 | 436 | +++ b/a Thu Jan 01 00:00:02 1970 +0000 |
|
437 | 437 | @@ -1,3 +1,4 @@ |
|
438 | 438 | expand $Id$ |
|
439 | 439 | do not process $Id: |
|
440 | 440 | xxx $ |
|
441 | 441 | +$Xinfo$ |
|
442 | 442 | |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | |
|
446 | 446 | % errors encountered |
|
447 | 447 | % merge/resolve |
|
448 | 448 | % simplemerge |
|
449 | 449 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
450 | 450 | created new head |
|
451 | 451 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
452 | 452 | (branch merge, don't forget to commit) |
|
453 | 453 | $Id: m 8731e1dadc99 Thu, 01 Jan 1970 00:00:00 +0000 test $ |
|
454 | 454 | foo |
|
455 | 455 | % conflict |
|
456 | 456 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
457 | 457 | created new head |
|
458 | 458 | merging m |
|
459 | 459 | warning: conflicts during merge. |
|
460 | 460 | merging m failed! |
|
461 | 461 | 0 files updated, 0 files merged, 0 files removed, 1 files unresolved |
|
462 | 462 | use 'hg resolve' to retry unresolved file merges or 'hg up --clean' to abandon |
|
463 | 463 | % keyword stays outside conflict zone |
|
464 | 464 | $Id$ |
|
465 | 465 | <<<<<<< local |
|
466 | 466 | bar |
|
467 | 467 | ======= |
|
468 | 468 | foo |
|
469 | 469 | >>>>>>> other |
|
470 | 470 | % resolve to local |
|
471 | 471 | $Id: m 43dfd2854b5b Thu, 01 Jan 1970 00:00:00 +0000 test $ |
|
472 | 472 | bar |
|
473 | 473 | % switch off expansion |
|
474 | 474 | % kwshrink with unknown file u |
|
475 | 475 | overwriting a shrinking keywords |
|
476 | 476 | overwriting m shrinking keywords |
|
477 | 477 | overwriting x/a shrinking keywords |
|
478 | 478 | % cat |
|
479 | 479 | expand $Id$ |
|
480 | 480 | do not process $Id: |
|
481 | 481 | xxx $ |
|
482 | 482 | $Xinfo$ |
|
483 | 483 | ignore $Id$ |
|
484 | 484 | % hg cat |
|
485 | 485 | expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $ |
|
486 | 486 | do not process $Id: |
|
487 | 487 | xxx $ |
|
488 | 488 | $Xinfo: User Name <user@example.com>: firstline $ |
|
489 | 489 | ignore $Id$ |
|
490 | 490 | a |
|
491 | 491 | % cat |
|
492 | 492 | expand $Id$ |
|
493 | 493 | do not process $Id: |
|
494 | 494 | xxx $ |
|
495 | 495 | $Xinfo$ |
|
496 | 496 | ignore $Id$ |
|
497 | 497 | % hg cat |
|
498 | 498 | expand $Id$ |
|
499 | 499 | do not process $Id: |
|
500 | 500 | xxx $ |
|
501 | 501 | $Xinfo$ |
|
502 | 502 | ignore $Id$ |
|
503 | 503 | a |
@@ -1,218 +1,218 b'' | |||
|
1 | 1 | notify extension - hooks for sending email notifications at commit/push time |
|
2 | 2 | |
|
3 | 3 | Subscriptions can be managed through a hgrc file. Default mode is to print |
|
4 | 4 | messages to stdout, for testing and configuring. |
|
5 | 5 | |
|
6 | 6 | To use, configure the notify extension and enable it in hgrc like this: |
|
7 | 7 | |
|
8 |
|
|
|
9 |
|
|
|
8 | [extensions] | |
|
9 | hgext.notify = | |
|
10 | 10 | |
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
11 | [hooks] | |
|
12 | # one email for each incoming changeset | |
|
13 | incoming.notify = python:hgext.notify.hook | |
|
14 | # batch emails when many changesets incoming at one time | |
|
15 | changegroup.notify = python:hgext.notify.hook | |
|
16 | 16 | |
|
17 |
|
|
|
18 |
|
|
|
17 | [notify] | |
|
18 | # config items go here | |
|
19 | 19 | |
|
20 | 20 | Required configuration items: |
|
21 | 21 | |
|
22 |
|
|
|
22 | config = /path/to/file # file containing subscriptions | |
|
23 | 23 | |
|
24 | 24 | Optional configuration items: |
|
25 | 25 | |
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
26 | test = True # print messages to stdout for testing | |
|
27 | strip = 3 # number of slashes to strip for url paths | |
|
28 | domain = example.com # domain to use if committer missing domain | |
|
29 | style = ... # style file to use when formatting email | |
|
30 | template = ... # template to use when formatting email | |
|
31 | incoming = ... # template to use when run as incoming hook | |
|
32 | changegroup = ... # template when run as changegroup hook | |
|
33 | maxdiff = 300 # max lines of diffs to include (0=none, -1=all) | |
|
34 | maxsubject = 67 # truncate subject line longer than this | |
|
35 | diffstat = True # add a diffstat before the diff content | |
|
36 | sources = serve # notify if source of incoming changes in this list | |
|
37 | # (serve == ssh or http, push, pull, bundle) | |
|
38 | [email] | |
|
39 | from = user@host.com # email address to send as if none given | |
|
40 | [web] | |
|
41 | baseurl = http://hgserver/... # root of hg web site for browsing commits | |
|
42 | 42 | |
|
43 | 43 | The notify config file has same format as a regular hgrc file. It has two |
|
44 | 44 | sections so you can express subscriptions in whatever way is handier for you. |
|
45 | 45 | |
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
46 | [usersubs] | |
|
47 | # key is subscriber email, value is ","-separated list of glob patterns | |
|
48 | user@host = pattern | |
|
49 | 49 | |
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
50 | [reposubs] | |
|
51 | # key is glob pattern, value is ","-separated list of subscriber emails | |
|
52 | pattern = user@host | |
|
53 | 53 | |
|
54 | 54 | Glob patterns are matched against path to repository root. |
|
55 | 55 | |
|
56 | 56 | If you like, you can put notify config file in repository that users can push |
|
57 | 57 | changes to, they can manage their own subscriptions. |
|
58 | 58 | |
|
59 | 59 | no commands defined |
|
60 | 60 | % commit |
|
61 | 61 | adding a |
|
62 | 62 | % clone |
|
63 | 63 | updating working directory |
|
64 | 64 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
65 | 65 | % commit |
|
66 | 66 | % pull (minimal config) |
|
67 | 67 | pulling from ../a |
|
68 | 68 | searching for changes |
|
69 | 69 | adding changesets |
|
70 | 70 | adding manifests |
|
71 | 71 | adding file changes |
|
72 | 72 | added 1 changesets with 1 changes to 1 files |
|
73 | 73 | Content-Type: text/plain; charset="us-ascii" |
|
74 | 74 | MIME-Version: 1.0 |
|
75 | 75 | Content-Transfer-Encoding: 7bit |
|
76 | 76 | Date: |
|
77 | 77 | Subject: changeset in test-notify/b: b |
|
78 | 78 | From: test |
|
79 | 79 | X-Hg-Notification: changeset 0647d048b600 |
|
80 | 80 | Message-Id: |
|
81 | 81 | To: baz, foo@bar |
|
82 | 82 | |
|
83 | 83 | changeset 0647d048b600 in test-notify/b |
|
84 | 84 | details: test-notify/b?cmd=changeset;node=0647d048b600 |
|
85 | 85 | description: b |
|
86 | 86 | |
|
87 | 87 | diffs (6 lines): |
|
88 | 88 | |
|
89 | 89 | diff -r cb9a9f314b8b -r 0647d048b600 a |
|
90 | 90 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
91 | 91 | +++ b/a Thu Jan 01 00:00:01 1970 +0000 |
|
92 | 92 | @@ -1,1 +1,2 @@ |
|
93 | 93 | a |
|
94 | 94 | +a |
|
95 | 95 | (run 'hg update' to get a working copy) |
|
96 | 96 | % fail for config file is missing |
|
97 | 97 | rolling back last transaction |
|
98 | 98 | pull failed |
|
99 | 99 | % pull |
|
100 | 100 | rolling back last transaction |
|
101 | 101 | pulling from ../a |
|
102 | 102 | searching for changes |
|
103 | 103 | adding changesets |
|
104 | 104 | adding manifests |
|
105 | 105 | adding file changes |
|
106 | 106 | added 1 changesets with 1 changes to 1 files |
|
107 | 107 | Content-Type: text/plain; charset="us-ascii" |
|
108 | 108 | MIME-Version: 1.0 |
|
109 | 109 | Content-Transfer-Encoding: 7bit |
|
110 | 110 | X-Test: foo |
|
111 | 111 | Date: |
|
112 | 112 | Subject: b |
|
113 | 113 | From: test@test.com |
|
114 | 114 | X-Hg-Notification: changeset 0647d048b600 |
|
115 | 115 | Message-Id: |
|
116 | 116 | To: baz@test.com, foo@bar |
|
117 | 117 | |
|
118 | 118 | changeset 0647d048b600 |
|
119 | 119 | description: |
|
120 | 120 | b |
|
121 | 121 | diffs (6 lines): |
|
122 | 122 | |
|
123 | 123 | diff -r cb9a9f314b8b -r 0647d048b600 a |
|
124 | 124 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
125 | 125 | +++ b/a Thu Jan 01 00:00:01 1970 +0000 |
|
126 | 126 | @@ -1,1 +1,2 @@ |
|
127 | 127 | a |
|
128 | 128 | +a |
|
129 | 129 | (run 'hg update' to get a working copy) |
|
130 | 130 | % pull |
|
131 | 131 | rolling back last transaction |
|
132 | 132 | pulling from ../a |
|
133 | 133 | searching for changes |
|
134 | 134 | adding changesets |
|
135 | 135 | adding manifests |
|
136 | 136 | adding file changes |
|
137 | 137 | added 1 changesets with 1 changes to 1 files |
|
138 | 138 | Content-Type: text/plain; charset="us-ascii" |
|
139 | 139 | MIME-Version: 1.0 |
|
140 | 140 | Content-Transfer-Encoding: 7bit |
|
141 | 141 | X-Test: foo |
|
142 | 142 | Date: |
|
143 | 143 | Subject: b |
|
144 | 144 | From: test@test.com |
|
145 | 145 | X-Hg-Notification: changeset 0647d048b600 |
|
146 | 146 | Message-Id: |
|
147 | 147 | To: baz@test.com, foo@bar |
|
148 | 148 | |
|
149 | 149 | changeset 0647d048b600 |
|
150 | 150 | description: |
|
151 | 151 | b |
|
152 | 152 | diffstat: |
|
153 | 153 | |
|
154 | 154 | a | 1 + |
|
155 | 155 | 1 files changed, 1 insertions(+), 0 deletions(-) |
|
156 | 156 | |
|
157 | 157 | diffs (6 lines): |
|
158 | 158 | |
|
159 | 159 | diff -r cb9a9f314b8b -r 0647d048b600 a |
|
160 | 160 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
161 | 161 | +++ b/a Thu Jan 01 00:00:01 1970 +0000 |
|
162 | 162 | @@ -1,1 +1,2 @@ |
|
163 | 163 | a |
|
164 | 164 | +a |
|
165 | 165 | (run 'hg update' to get a working copy) |
|
166 | 166 | % test merge |
|
167 | 167 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
168 | 168 | created new head |
|
169 | 169 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
170 | 170 | (branch merge, don't forget to commit) |
|
171 | 171 | pulling from ../a |
|
172 | 172 | searching for changes |
|
173 | 173 | adding changesets |
|
174 | 174 | adding manifests |
|
175 | 175 | adding file changes |
|
176 | 176 | added 2 changesets with 0 changes to 1 files |
|
177 | 177 | Content-Type: text/plain; charset="us-ascii" |
|
178 | 178 | MIME-Version: 1.0 |
|
179 | 179 | Content-Transfer-Encoding: 7bit |
|
180 | 180 | X-Test: foo |
|
181 | 181 | Date: |
|
182 | 182 | Subject: adda2 |
|
183 | 183 | From: test@test.com |
|
184 | 184 | X-Hg-Notification: changeset 0a184ce6067f |
|
185 | 185 | Message-Id: |
|
186 | 186 | To: baz@test.com, foo@bar |
|
187 | 187 | |
|
188 | 188 | changeset 0a184ce6067f |
|
189 | 189 | description: |
|
190 | 190 | adda2 |
|
191 | 191 | diffstat: |
|
192 | 192 | |
|
193 | 193 | a | 1 + |
|
194 | 194 | 1 files changed, 1 insertions(+), 0 deletions(-) |
|
195 | 195 | |
|
196 | 196 | diffs (6 lines): |
|
197 | 197 | |
|
198 | 198 | diff -r cb9a9f314b8b -r 0a184ce6067f a |
|
199 | 199 | --- a/a Thu Jan 01 00:00:00 1970 +0000 |
|
200 | 200 | +++ b/a Thu Jan 01 00:00:02 1970 +0000 |
|
201 | 201 | @@ -1,1 +1,2 @@ |
|
202 | 202 | a |
|
203 | 203 | +a |
|
204 | 204 | Content-Type: text/plain; charset="us-ascii" |
|
205 | 205 | MIME-Version: 1.0 |
|
206 | 206 | Content-Transfer-Encoding: 7bit |
|
207 | 207 | X-Test: foo |
|
208 | 208 | Date: |
|
209 | 209 | Subject: merge |
|
210 | 210 | From: test@test.com |
|
211 | 211 | X-Hg-Notification: changeset 22c88b85aa27 |
|
212 | 212 | Message-Id: |
|
213 | 213 | To: baz@test.com, foo@bar |
|
214 | 214 | |
|
215 | 215 | changeset 22c88b85aa27 |
|
216 | 216 | description: |
|
217 | 217 | merge |
|
218 | 218 | (run 'hg update' to get a working copy) |
General Comments 0
You need to be logged in to leave comments.
Login now