271 ui.status("summary: %s\n" % description.splitlines()[0]) |
271 ui.status("summary: %s\n" % description.splitlines()[0]) |
272 ui.status("\n") |
272 ui.status("\n") |
273 |
273 |
274 def show_version(ui): |
274 def show_version(ui): |
275 """output version and copyright information""" |
275 """output version and copyright information""" |
276 ui.write("Mercurial version %s\n" % version.get_version()) |
276 ui.write("Mercurial Distributed SCM (version %s)\n" |
|
277 % version.get_version()) |
277 ui.status( |
278 ui.status( |
278 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
279 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
279 "This is free software; see the source for copying conditions. " |
280 "This is free software; see the source for copying conditions. " |
280 "There is NO\nwarranty; " |
281 "There is NO\nwarranty; " |
281 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
282 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
282 ) |
283 ) |
283 |
284 |
284 def help_(ui, cmd=None): |
285 def help_(ui, cmd=None): |
285 """show help for a given command or all commands""" |
286 """show help for a given command or all commands""" |
286 if cmd: |
287 if cmd and cmd != 'shortlist': |
287 try: |
288 key, i = find(cmd) |
288 i = find(cmd) |
289 # synopsis |
289 ui.write("%s\n\n" % i[2]) |
290 ui.write("%s\n\n" % i[2]) |
290 |
291 |
291 if i[1]: |
292 # description |
292 for s, l, d, c in i[1]: |
293 doc = i[0].__doc__ |
293 opt = ' ' |
294 if ui.quiet: |
294 if s: |
295 doc = doc.splitlines(0)[0] |
295 opt = opt + '-' + s + ' ' |
296 ui.write("%s\n" % doc.rstrip()) |
296 if l: |
297 |
297 opt = opt + '--' + l + ' ' |
298 # aliases |
298 if d: |
299 if not ui.quiet: |
299 opt = opt + '(' + str(d) + ')' |
300 aliases = ', '.join(key.split('|')[1:]) |
300 ui.write(opt, "\n") |
301 if aliases: |
301 if c: |
302 ui.write("\naliases: %s\n" % aliases) |
302 ui.write(' %s\n' % c) |
303 |
303 ui.write("\n") |
304 # options |
304 |
305 if not ui.quiet and i[1]: |
305 ui.write(i[0].__doc__, "\n") |
306 ui.write("\noptions:\n\n") |
306 except UnknownCommand: |
307 for s, l, d, c in i[1]: |
307 ui.warn("hg: unknown command %s\n" % cmd) |
308 opt = ' ' |
308 sys.exit(0) |
309 if s: |
|
310 opt = opt + '-' + s + ' ' |
|
311 if l: |
|
312 opt = opt + '--' + l + ' ' |
|
313 if d: |
|
314 opt = opt + '(' + str(d) + ')' |
|
315 ui.write(opt, "\n") |
|
316 if c: |
|
317 ui.write(' %s\n' % c) |
|
318 |
309 else: |
319 else: |
|
320 # program name |
310 if ui.verbose: |
321 if ui.verbose: |
311 show_version(ui) |
322 show_version(ui) |
312 ui.write('\n') |
|
313 if ui.verbose: |
|
314 ui.write('hg commands:\n\n') |
|
315 else: |
323 else: |
316 ui.write('basic hg commands (use "hg help -v" for more):\n\n') |
324 ui.status("Mercurial Distributed SCM\n") |
|
325 ui.status('\n') |
|
326 |
|
327 # list of commands |
|
328 if cmd == "shortlist": |
|
329 ui.status('basic commands (use "hg help" ' |
|
330 'for the full list or option "-v" for details):\n\n') |
|
331 elif ui.verbose: |
|
332 ui.status('list of commands:\n\n') |
|
333 else: |
|
334 ui.status('list of commands (use "hg help -v" ' |
|
335 'to show aliases and global options):\n\n') |
317 |
336 |
318 h = {} |
337 h = {} |
|
338 cmds = {} |
319 for c, e in table.items(): |
339 for c, e in table.items(): |
320 f = c.split("|")[0] |
340 f = c.split("|")[0] |
321 if not ui.verbose and not f.startswith("^"): |
341 if cmd == "shortlist" and not f.startswith("^"): |
322 continue |
342 continue |
|
343 f = f.lstrip("^") |
323 if not ui.debugflag and f.startswith("debug"): |
344 if not ui.debugflag and f.startswith("debug"): |
324 continue |
345 continue |
325 f = f.lstrip("^") |
|
326 d = "" |
346 d = "" |
327 if e[0].__doc__: |
347 if e[0].__doc__: |
328 d = e[0].__doc__.splitlines(0)[0].rstrip() |
348 d = e[0].__doc__.splitlines(0)[0].rstrip() |
329 h[f] = d |
349 h[f] = d |
|
350 cmds[f]=c.lstrip("^") |
330 |
351 |
331 fns = h.keys() |
352 fns = h.keys() |
332 fns.sort() |
353 fns.sort() |
333 m = max(map(len, fns)) |
354 m = max(map(len, fns)) |
334 for f in fns: |
355 for f in fns: |
335 ui.write(' %-*s %s\n' % (m, f, h[f])) |
356 if ui.verbose: |
|
357 commands = cmds[f].replace("|",", ") |
|
358 ui.write(" %s:\n %s\n"%(commands,h[f])) |
|
359 else: |
|
360 ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
361 |
|
362 # global options |
|
363 if ui.verbose: |
|
364 ui.write("\nglobal options:\n\n") |
|
365 for s, l, d, c in globalopts: |
|
366 opt = ' ' |
|
367 if s: |
|
368 opt = opt + '-' + s + ' ' |
|
369 if l: |
|
370 opt = opt + '--' + l + ' ' |
|
371 if d: |
|
372 opt = opt + '(' + str(d) + ')' |
|
373 ui.write(opt, "\n") |
|
374 if c: |
|
375 ui.write(' %s\n' % c) |
336 |
376 |
337 # Commands start here, listed alphabetically |
377 # Commands start here, listed alphabetically |
338 |
378 |
339 def add(ui, repo, *pats, **opts): |
379 def add(ui, repo, *pats, **opts): |
340 '''add the specified files on the next commit''' |
380 '''add the specified files on the next commit''' |
1029 '''show changed files in the working directory |
1070 '''show changed files in the working directory |
1030 |
1071 |
1031 M = modified |
1072 M = modified |
1032 A = added |
1073 A = added |
1033 R = removed |
1074 R = removed |
1034 ? = not tracked''' |
1075 ? = not tracked |
|
1076 ''' |
1035 |
1077 |
1036 cwd = repo.getcwd() |
1078 cwd = repo.getcwd() |
1037 files, matchfn = matchpats(repo, cwd, pats, opts) |
1079 files, matchfn = matchpats(repo, cwd, pats, opts) |
1038 (c, a, d, u) = [[pathto(cwd, x) for x in n] |
1080 (c, a, d, u) = [[pathto(cwd, x) for x in n] |
1039 for n in repo.changes(files=files, match=matchfn)] |
1081 for n in repo.changes(files=files, match=matchfn)] |
1040 |
1082 |
1041 for f in c: |
1083 changetypes = [('modified', 'M', c), |
1042 ui.write("M ", f, "\n") |
1084 ('added', 'A', a), |
1043 for f in a: |
1085 ('removed', 'R', d), |
1044 ui.write("A ", f, "\n") |
1086 ('unknown', '?', u)] |
1045 for f in d: |
1087 |
1046 ui.write("R ", f, "\n") |
1088 for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
1047 for f in u: |
1089 or changetypes): |
1048 ui.write("? ", f, "\n") |
1090 for f in changes: |
|
1091 ui.write("%s %s\n" % (char, f)) |
1049 |
1092 |
1050 def tag(ui, repo, name, rev=None, **opts): |
1093 def tag(ui, repo, name, rev=None, **opts): |
1051 """add a tag for the current tip or a given revision""" |
1094 """add a tag for the current tip or a given revision""" |
1052 if opts['text']: |
1095 if opts['text']: |
1053 ui.warn("Warning: -t and --text is deprecated," |
1096 ui.warn("Warning: -t and --text is deprecated," |
1136 return repo.verify() |
1179 return repo.verify() |
1137 |
1180 |
1138 # Command options and aliases are listed here, alphabetically |
1181 # Command options and aliases are listed here, alphabetically |
1139 |
1182 |
1140 table = { |
1183 table = { |
1141 "^add": (add, |
1184 "^add": |
1142 [('I', 'include', [], 'include path in search'), |
1185 (add, |
1143 ('X', 'exclude', [], 'exclude path from search')], |
1186 [('I', 'include', [], 'include path in search'), |
1144 "hg add [FILE]..."), |
1187 ('X', 'exclude', [], 'exclude path from search')], |
1145 "addremove": (addremove, |
1188 "hg add [FILE]..."), |
1146 [('I', 'include', [], 'include path in search'), |
1189 "addremove": |
1147 ('X', 'exclude', [], 'exclude path from search')], |
1190 (addremove, |
1148 "hg addremove [OPTION]... [FILE]..."), |
1191 [('I', 'include', [], 'include path in search'), |
|
1192 ('X', 'exclude', [], 'exclude path from search')], |
|
1193 "hg addremove [OPTION]... [FILE]..."), |
1149 "^annotate": |
1194 "^annotate": |
1150 (annotate, |
1195 (annotate, |
1151 [('r', 'rev', '', 'revision'), |
1196 [('r', 'rev', '', 'revision'), |
1152 ('u', 'user', None, 'show user'), |
1197 ('u', 'user', None, 'show user'), |
1153 ('n', 'number', None, 'show revision number'), |
1198 ('n', 'number', None, 'show revision number'), |
1177 "copy": (copy, [], 'hg copy SOURCE DEST'), |
1222 "copy": (copy, [], 'hg copy SOURCE DEST'), |
1178 "debugcheckstate": (debugcheckstate, [], 'debugcheckstate'), |
1223 "debugcheckstate": (debugcheckstate, [], 'debugcheckstate'), |
1179 "debugstate": (debugstate, [], 'debugstate'), |
1224 "debugstate": (debugstate, [], 'debugstate'), |
1180 "debugindex": (debugindex, [], 'debugindex FILE'), |
1225 "debugindex": (debugindex, [], 'debugindex FILE'), |
1181 "debugindexdot": (debugindexdot, [], 'debugindexdot FILE'), |
1226 "debugindexdot": (debugindexdot, [], 'debugindexdot FILE'), |
1182 "debugwalk": (debugwalk, |
1227 "debugwalk": |
1183 [('I', 'include', [], 'include path in search'), |
1228 (debugwalk, |
1184 ('X', 'exclude', [], 'exclude path from search')], |
1229 [('I', 'include', [], 'include path in search'), |
1185 'debugwalk [OPTIONS]... [FILE]...'), |
1230 ('X', 'exclude', [], 'exclude path from search')], |
|
1231 'debugwalk [OPTIONS]... [FILE]...'), |
1186 "^diff": |
1232 "^diff": |
1187 (diff, |
1233 (diff, |
1188 [('r', 'rev', [], 'revision'), |
1234 [('r', 'rev', [], 'revision'), |
1189 ('I', 'include', [], 'include path in search'), |
1235 ('I', 'include', [], 'include path in search'), |
1190 ('X', 'exclude', [], 'exclude path from search')], |
1236 ('X', 'exclude', [], 'exclude path from search')], |
1191 'hg diff [-r REV1 [-r REV2]] [FILE]...'), |
1237 'hg diff [-r REV1 [-r REV2]] [FILE]...'), |
1192 "^export": |
1238 "^export": |
1193 (export, |
1239 (export, |
1194 [('o', 'output', "", 'output to file')], |
1240 [('o', 'output', "", 'output to file')], |
1195 "hg export [-o OUTFILE] REV..."), |
1241 "hg export [-o OUTFILE] REV..."), |
1196 "forget": (forget, |
1242 "forget": |
1197 [('I', 'include', [], 'include path in search'), |
1243 (forget, |
1198 ('X', 'exclude', [], 'exclude path from search')], |
1244 [('I', 'include', [], 'include path in search'), |
1199 "hg forget FILE..."), |
1245 ('X', 'exclude', [], 'exclude path from search')], |
|
1246 "hg forget FILE..."), |
1200 "heads": (heads, [], 'hg heads'), |
1247 "heads": (heads, [], 'hg heads'), |
1201 "help": (help_, [], 'hg help [COMMAND]'), |
1248 "help": (help_, [], 'hg help [COMMAND]'), |
1202 "identify|id": (identify, [], 'hg identify'), |
1249 "identify|id": (identify, [], 'hg identify'), |
1203 "import|patch": |
1250 "import|patch": |
1204 (import_, |
1251 (import_, |
1257 ('n', 'name', os.getcwd(), 'repository name'), |
1304 ('n', 'name', os.getcwd(), 'repository name'), |
1258 ('', 'stdio', None, 'for remote clients'), |
1305 ('', 'stdio', None, 'for remote clients'), |
1259 ('t', 'templates', "", 'template map'), |
1306 ('t', 'templates', "", 'template map'), |
1260 ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')], |
1307 ('6', 'ipv6', None, 'use IPv6 in addition to IPv4')], |
1261 "hg serve [OPTION]..."), |
1308 "hg serve [OPTION]..."), |
1262 "^status": (status, |
1309 "^status": |
1263 [('I', 'include', [], 'include path in search'), |
1310 (status, |
1264 ('X', 'exclude', [], 'exclude path from search')], |
1311 [('m', 'modified', None, 'show only modified files'), |
1265 'hg status [FILE]...'), |
1312 ('a', 'added', None, 'show only added files'), |
|
1313 ('r', 'removed', None, 'show only removed files'), |
|
1314 ('u', 'unknown', None, 'show only unknown (not tracked) files'), |
|
1315 ('I', 'include', [], 'include path in search'), |
|
1316 ('X', 'exclude', [], 'exclude path from search')], |
|
1317 "hg status [FILE]..."), |
1266 "tag": |
1318 "tag": |
1267 (tag, |
1319 (tag, |
1268 [('l', 'local', None, 'make the tag local'), |
1320 [('l', 'local', None, 'make the tag local'), |
1269 ('m', 'message', "", 'commit message'), |
1321 ('m', 'message', "", 'commit message'), |
1270 ('t', 'text', "", 'commit message (deprecated: use -m)'), |
1322 ('t', 'text', "", 'commit message (deprecated: use -m)'), |
1281 'hg update [-m] [-C] [REV]'), |
1333 'hg update [-m] [-C] [REV]'), |
1282 "verify": (verify, [], 'hg verify'), |
1334 "verify": (verify, [], 'hg verify'), |
1283 "version": (show_version, [], 'hg version'), |
1335 "version": (show_version, [], 'hg version'), |
1284 } |
1336 } |
1285 |
1337 |
1286 globalopts = [('v', 'verbose', None, 'verbose'), |
1338 globalopts = [('v', 'verbose', None, 'verbose mode'), |
1287 ('', 'debug', None, 'debug'), |
1339 ('', 'debug', None, 'debug mode'), |
1288 ('q', 'quiet', None, 'quiet'), |
1340 ('q', 'quiet', None, 'quiet mode'), |
1289 ('', 'profile', None, 'profile'), |
1341 ('', 'profile', None, 'profile'), |
1290 ('R', 'repository', "", 'repository root directory'), |
1342 ('R', 'repository', "", 'repository root directory'), |
1291 ('', 'traceback', None, 'print traceback on exception'), |
1343 ('', 'traceback', None, 'print traceback on exception'), |
1292 ('y', 'noninteractive', None, 'run non-interactively'), |
1344 ('y', 'noninteractive', None, 'run non-interactively'), |
1293 ('', 'version', None, 'output version information and exit'), |
1345 ('', 'version', None, 'output version information and exit'), |
1325 raise ParseError(None, inst) |
1377 raise ParseError(None, inst) |
1326 |
1378 |
1327 if options["version"]: |
1379 if options["version"]: |
1328 return ("version", show_version, [], options, cmdoptions) |
1380 return ("version", show_version, [], options, cmdoptions) |
1329 elif not args: |
1381 elif not args: |
1330 return ("help", help_, [], options, cmdoptions) |
1382 return ("help", help_, ["shortlist"], options, cmdoptions) |
1331 else: |
1383 else: |
1332 cmd, args = args[0], args[1:] |
1384 cmd, args = args[0], args[1:] |
1333 |
1385 |
1334 i = find(cmd) |
1386 i = find(cmd)[1] |
1335 |
1387 |
1336 # combine global options into local |
1388 # combine global options into local |
1337 c = list(i[1]) |
1389 c = list(i[1]) |
1338 for o in globalopts: |
1390 for o in globalopts: |
1339 c.append((o[0], o[1], options[o[1]], o[3])) |
1391 c.append((o[0], o[1], options[o[1]], o[3])) |