Show More
@@ -14,6 +14,9 b' demandload(globals(), "errno socket vers' | |||
|
14 | 14 | class UnknownCommand(Exception): |
|
15 | 15 | """Exception raised if command is not in the command table.""" |
|
16 | 16 | |
|
17 | class Abort(Exception): | |
|
18 | """Raised if a command needs to print an error and exit.""" | |
|
19 | ||
|
17 | 20 | def filterfiles(filters, files): |
|
18 | 21 | l = [x for x in files if x in filters] |
|
19 | 22 | |
@@ -93,8 +96,7 b' def revrange(ui, repo, revs, revlog=None' | |||
|
93 | 96 | try: |
|
94 | 97 | num = revlog.rev(revlog.lookup(val)) |
|
95 | 98 | except KeyError: |
|
96 |
|
|
|
97 | sys.exit(1) | |
|
99 | raise Abort('invalid revision identifier %s', val) | |
|
98 | 100 | return num |
|
99 | 101 | for spec in revs: |
|
100 | 102 | if spec.find(revrangesep) >= 0: |
@@ -124,29 +126,33 b' def make_filename(repo, r, pat, node=Non' | |||
|
124 | 126 | 'b': lambda: os.path.basename(repo.root), |
|
125 | 127 | } |
|
126 | 128 | |
|
127 | if node: | |
|
128 | expander.update(node_expander) | |
|
129 | if node and revwidth is not None: | |
|
130 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
|
131 | if total is not None: | |
|
132 | expander['N'] = lambda: str(total) | |
|
133 | if seqno is not None: | |
|
134 | expander['n'] = lambda: str(seqno) | |
|
135 | if total is not None and seqno is not None: | |
|
136 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
|
129 | try: | |
|
130 | if node: | |
|
131 | expander.update(node_expander) | |
|
132 | if node and revwidth is not None: | |
|
133 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
|
134 | if total is not None: | |
|
135 | expander['N'] = lambda: str(total) | |
|
136 | if seqno is not None: | |
|
137 | expander['n'] = lambda: str(seqno) | |
|
138 | if total is not None and seqno is not None: | |
|
139 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
|
137 | 140 | |
|
138 | newname = [] | |
|
139 | patlen = len(pat) | |
|
140 | i = 0 | |
|
141 | while i < patlen: | |
|
142 | c = pat[i] | |
|
143 | if c == '%': | |
|
141 | newname = [] | |
|
142 | patlen = len(pat) | |
|
143 | i = 0 | |
|
144 | while i < patlen: | |
|
145 | c = pat[i] | |
|
146 | if c == '%': | |
|
147 | i += 1 | |
|
148 | c = pat[i] | |
|
149 | c = expander[c]() | |
|
150 | newname.append(c) | |
|
144 | 151 | i += 1 |
|
145 | c = pat[i] | |
|
146 | c = expander[c]() | |
|
147 | newname.append(c) | |
|
148 | i += 1 | |
|
149 | return ''.join(newname) | |
|
152 | return ''.join(newname) | |
|
153 | except KeyError, inst: | |
|
154 | raise Abort("invalid format spec '%%%s' in output file name", | |
|
155 | inst.args[0]) | |
|
150 | 156 | |
|
151 | 157 | def dodiff(fp, ui, repo, files=None, node1=None, node2=None): |
|
152 | 158 | def date(c): |
@@ -404,13 +410,7 b' def cat(ui, repo, file1, rev=None, **opt' | |||
|
404 | 410 | else: |
|
405 | 411 | n = r.tip() |
|
406 | 412 | if opts['output'] and opts['output'] != '-': |
|
407 | try: | |
|
408 | outname = make_filename(repo, r, opts['output'], node=n) | |
|
409 | fp = open(outname, 'wb') | |
|
410 | except KeyError, inst: | |
|
411 | ui.warn("error: invlaid format spec '%%%s' in output file name\n" % | |
|
412 | inst.args[0]) | |
|
413 | sys.exit(1); | |
|
413 | fp = open(make_filename(repo, r, opts['output'], node=n), 'wb') | |
|
414 | 414 | else: |
|
415 | 415 | fp = sys.stdout |
|
416 | 416 | fp.write(r.read(n)) |
@@ -516,8 +516,7 b' def debugcheckstate(ui, repo):' | |||
|
516 | 516 | ui.warn("%s in manifest1, but listed as state %s" % (f, state)) |
|
517 | 517 | errors += 1 |
|
518 | 518 | if errors: |
|
519 |
|
|
|
520 | sys.exit(1) | |
|
519 | raise Abort(".hg/dirstate inconsistent with current parent's manifest") | |
|
521 | 520 | |
|
522 | 521 | def debugstate(ui, repo): |
|
523 | 522 | """show the contents of the current dirstate""" |
@@ -557,8 +556,7 b' def diff(ui, repo, *files, **opts):' | |||
|
557 | 556 | revs = map(lambda x: repo.lookup(x), opts['rev']) |
|
558 | 557 | |
|
559 | 558 | if len(revs) > 2: |
|
560 |
|
|
|
561 | sys.exit(1) | |
|
559 | raise Abort("too many revisions to diff") | |
|
562 | 560 | |
|
563 | 561 | if files: |
|
564 | 562 | files = relpath(repo, files) |
@@ -573,16 +571,11 b' def doexport(ui, repo, changeset, seqno,' | |||
|
573 | 571 | change = repo.changelog.read(node) |
|
574 | 572 | |
|
575 | 573 | if opts['output'] and opts['output'] != '-': |
|
576 | try: | |
|
577 | outname = make_filename(repo, repo.changelog, opts['output'], | |
|
578 | node=node, total=total, seqno=seqno, | |
|
579 | revwidth=revwidth) | |
|
580 | ui.note("Exporting patch to '%s'.\n" % outname) | |
|
581 | fp = open(outname, 'wb') | |
|
582 | except KeyError, inst: | |
|
583 | ui.warn("error: invalid format spec '%%%s' in output file name\n" % | |
|
584 | inst.args[0]) | |
|
585 | sys.exit(1) | |
|
574 | outname = make_filename(repo, repo.changelog, opts['output'], | |
|
575 | node=node, total=total, seqno=seqno, | |
|
576 | revwidth=revwidth) | |
|
577 | ui.note("Exporting patch to '%s'.\n" % outname) | |
|
578 | fp = open(outname, 'wb') | |
|
586 | 579 | else: |
|
587 | 580 | fp = sys.stdout |
|
588 | 581 | |
@@ -600,8 +593,7 b' def doexport(ui, repo, changeset, seqno,' | |||
|
600 | 593 | def export(ui, repo, *changesets, **opts): |
|
601 | 594 | """dump the header and diffs for one or more changesets""" |
|
602 | 595 | if not changesets: |
|
603 |
|
|
|
604 | sys.exit(1) | |
|
596 | raise Abort("export requires at least one changeset") | |
|
605 | 597 | seqno = 0 |
|
606 | 598 | revs = list(revrange(ui, repo, changesets)) |
|
607 | 599 | total = len(revs) |
@@ -695,8 +687,7 b' def import_(ui, repo, patch1, *patches, ' | |||
|
695 | 687 | files.append(pf) |
|
696 | 688 | patcherr = f.close() |
|
697 | 689 | if patcherr: |
|
698 |
|
|
|
699 | sys.exit(1) | |
|
690 | raise Abort("patch failed") | |
|
700 | 691 | |
|
701 | 692 | if len(files) > 0: |
|
702 | 693 | addremove(ui, repo, *files) |
@@ -706,8 +697,7 b' def init(ui, source=None):' | |||
|
706 | 697 | """create a new repository in the current directory""" |
|
707 | 698 | |
|
708 | 699 | if source: |
|
709 |
|
|
|
710 | sys.exit(1) | |
|
700 | raise Abort("no longer supported: use \"hg clone\" instead") | |
|
711 | 701 | hg.repository(ui, ".", create=1) |
|
712 | 702 | |
|
713 | 703 | def locate(ui, repo, *pats, **opts): |
@@ -756,6 +746,11 b' def log(ui, repo, f=None, **opts):' | |||
|
756 | 746 | dodiff(sys.stdout, ui, repo, files, prev, changenode) |
|
757 | 747 | ui.write("\n\n") |
|
758 | 748 | |
|
749 | def ls(ui, repo, *pats, **opts): | |
|
750 | """list files""" | |
|
751 | for src, abs, rel in walk(repo, pats, opts): | |
|
752 | ui.write(rel, '\n') | |
|
753 | ||
|
759 | 754 | def manifest(ui, repo, rev=None): |
|
760 | 755 | """output the latest or given revision of the project manifest""" |
|
761 | 756 | if rev: |
@@ -1162,6 +1157,10 b' table = {' | |||
|
1162 | 1157 | [('r', 'rev', [], 'revision'), |
|
1163 | 1158 | ('p', 'patch', None, 'show patch')], |
|
1164 | 1159 | 'hg log [-r REV1 [-r REV2]] [-p] [FILE]'), |
|
1160 | "list|ls": (ls, | |
|
1161 | [('I', 'include', [], 'include path in search'), | |
|
1162 | ('X', 'exclude', [], 'exclude path from search')], | |
|
1163 | "hg ls [OPTION]... [PATTERN]...."), | |
|
1165 | 1164 | "manifest": (manifest, [], 'hg manifest [REV]'), |
|
1166 | 1165 | "parents": (parents, [], 'hg parents [REV]'), |
|
1167 | 1166 | "^pull": |
@@ -1357,6 +1356,9 b' def dispatch(args):' | |||
|
1357 | 1356 | u.warn("abort: %s: %s\n" % (inst.strerror, inst.filename)) |
|
1358 | 1357 | else: |
|
1359 | 1358 | u.warn("abort: %s\n" % inst.strerror) |
|
1359 | except Abort, inst: | |
|
1360 | u.warn('abort: ', inst.args[0] % inst.args[1:], '\n') | |
|
1361 | sys.exit(1) | |
|
1360 | 1362 | except TypeError, inst: |
|
1361 | 1363 | # was this an argument error? |
|
1362 | 1364 | tb = traceback.extract_tb(sys.exc_info()[2]) |
General Comments 0
You need to be logged in to leave comments.
Login now