Show More
@@ -1,160 +1,160 | |||||
1 | shopt -s extglob |
|
1 | shopt -s extglob | |
2 |
|
2 | |||
3 | _hg_commands() |
|
3 | _hg_commands() | |
4 | { |
|
4 | { | |
5 | local commands |
|
5 | local commands | |
6 | commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands="" |
|
6 | commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands="" | |
7 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) |
|
7 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur")) | |
8 | } |
|
8 | } | |
9 |
|
9 | |||
10 | _hg_paths() |
|
10 | _hg_paths() | |
11 | { |
|
11 | { | |
12 | local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')" |
|
12 | local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')" | |
13 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) |
|
13 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur")) | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 | _hg_repos() |
|
16 | _hg_repos() | |
17 | { |
|
17 | { | |
18 | local i |
|
18 | local i | |
19 | for i in $(compgen -d -- "$cur"); do |
|
19 | for i in $(compgen -d -- "$cur"); do | |
20 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") |
|
20 | test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") | |
21 | done |
|
21 | done | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | _hg_status() |
|
24 | _hg_status() | |
25 | { |
|
25 | { | |
26 | local files="$("$hg" status -n$1 . 2>/dev/null)" |
|
26 | local files="$("$hg" status -n$1 . 2>/dev/null)" | |
27 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) |
|
27 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur")) | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | _hg_tags() |
|
30 | _hg_tags() | |
31 | { |
|
31 | { | |
32 |
local tags="$("$hg" tags 2>/dev/null |
|
32 | local tags="$("$hg" tags -q 2>/dev/null)" | |
33 | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" |
|
33 | local IFS=$'\n' | |
34 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) |
|
34 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur")) | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | # this is "kind of" ugly... |
|
37 | # this is "kind of" ugly... | |
38 | _hg_count_non_option() |
|
38 | _hg_count_non_option() | |
39 | { |
|
39 | { | |
40 | local i count=0 |
|
40 | local i count=0 | |
41 | local filters="$1" |
|
41 | local filters="$1" | |
42 |
|
42 | |||
43 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
43 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
44 | if [[ "${COMP_WORDS[i]}" != -* ]]; then |
|
44 | if [[ "${COMP_WORDS[i]}" != -* ]]; then | |
45 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then |
|
45 | if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then | |
46 | continue |
|
46 | continue | |
47 | fi |
|
47 | fi | |
48 | count=$(($count + 1)) |
|
48 | count=$(($count + 1)) | |
49 | fi |
|
49 | fi | |
50 | done |
|
50 | done | |
51 |
|
51 | |||
52 | echo $(($count - 1)) |
|
52 | echo $(($count - 1)) | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | _hg() |
|
55 | _hg() | |
56 | { |
|
56 | { | |
57 | local cur prev cmd opts i |
|
57 | local cur prev cmd opts i | |
58 | # global options that receive an argument |
|
58 | # global options that receive an argument | |
59 | local global_args='--cwd|-R|--repository' |
|
59 | local global_args='--cwd|-R|--repository' | |
60 | local hg="$1" |
|
60 | local hg="$1" | |
61 |
|
61 | |||
62 | COMPREPLY=() |
|
62 | COMPREPLY=() | |
63 | cur="$2" |
|
63 | cur="$2" | |
64 | prev="$3" |
|
64 | prev="$3" | |
65 |
|
65 | |||
66 | # searching for the command |
|
66 | # searching for the command | |
67 | # (first non-option argument that doesn't follow a global option that |
|
67 | # (first non-option argument that doesn't follow a global option that | |
68 | # receives an argument) |
|
68 | # receives an argument) | |
69 | for ((i=1; $i<=$COMP_CWORD; i++)); do |
|
69 | for ((i=1; $i<=$COMP_CWORD; i++)); do | |
70 | if [[ ${COMP_WORDS[i]} != -* ]]; then |
|
70 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
71 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then |
|
71 | if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then | |
72 | cmd="${COMP_WORDS[i]}" |
|
72 | cmd="${COMP_WORDS[i]}" | |
73 | break |
|
73 | break | |
74 | fi |
|
74 | fi | |
75 | fi |
|
75 | fi | |
76 | done |
|
76 | done | |
77 |
|
77 | |||
78 | if [[ "$cur" == -* ]]; then |
|
78 | if [[ "$cur" == -* ]]; then | |
79 | opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) |
|
79 | opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null) | |
80 |
|
80 | |||
81 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) |
|
81 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur")) | |
82 | return |
|
82 | return | |
83 | fi |
|
83 | fi | |
84 |
|
84 | |||
85 | # global options |
|
85 | # global options | |
86 | case "$prev" in |
|
86 | case "$prev" in | |
87 | -R|--repository) |
|
87 | -R|--repository) | |
88 | _hg_repos |
|
88 | _hg_repos | |
89 | return |
|
89 | return | |
90 | ;; |
|
90 | ;; | |
91 | --cwd) |
|
91 | --cwd) | |
92 | # Stick with default bash completion |
|
92 | # Stick with default bash completion | |
93 | return |
|
93 | return | |
94 | ;; |
|
94 | ;; | |
95 | esac |
|
95 | esac | |
96 |
|
96 | |||
97 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then |
|
97 | if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
98 | _hg_commands |
|
98 | _hg_commands | |
99 | return |
|
99 | return | |
100 | fi |
|
100 | fi | |
101 |
|
101 | |||
102 | # canonicalize command name |
|
102 | # canonicalize command name | |
103 | cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q') |
|
103 | cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q') | |
104 |
|
104 | |||
105 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then |
|
105 | if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then | |
106 | _hg_tags |
|
106 | _hg_tags | |
107 | return |
|
107 | return | |
108 | fi |
|
108 | fi | |
109 |
|
109 | |||
110 | case "$cmd" in |
|
110 | case "$cmd" in | |
111 | help) |
|
111 | help) | |
112 | _hg_commands |
|
112 | _hg_commands | |
113 | ;; |
|
113 | ;; | |
114 | export|manifest|update) |
|
114 | export|manifest|update) | |
115 | _hg_tags |
|
115 | _hg_tags | |
116 | ;; |
|
116 | ;; | |
117 | pull|push|outgoing|incoming) |
|
117 | pull|push|outgoing|incoming) | |
118 | _hg_paths |
|
118 | _hg_paths | |
119 | _hg_repos |
|
119 | _hg_repos | |
120 | ;; |
|
120 | ;; | |
121 | paths) |
|
121 | paths) | |
122 | _hg_paths |
|
122 | _hg_paths | |
123 | ;; |
|
123 | ;; | |
124 | add) |
|
124 | add) | |
125 | _hg_status "u" |
|
125 | _hg_status "u" | |
126 | ;; |
|
126 | ;; | |
127 | commit) |
|
127 | commit) | |
128 | _hg_status "mar" |
|
128 | _hg_status "mar" | |
129 | ;; |
|
129 | ;; | |
130 | remove) |
|
130 | remove) | |
131 | _hg_status "d" |
|
131 | _hg_status "d" | |
132 | ;; |
|
132 | ;; | |
133 | forget) |
|
133 | forget) | |
134 | _hg_status "a" |
|
134 | _hg_status "a" | |
135 | ;; |
|
135 | ;; | |
136 | diff) |
|
136 | diff) | |
137 | _hg_status "mar" |
|
137 | _hg_status "mar" | |
138 | ;; |
|
138 | ;; | |
139 | revert) |
|
139 | revert) | |
140 | _hg_status "mard" |
|
140 | _hg_status "mard" | |
141 | ;; |
|
141 | ;; | |
142 | clone) |
|
142 | clone) | |
143 | local count=$(_hg_count_non_option) |
|
143 | local count=$(_hg_count_non_option) | |
144 | if [ $count = 1 ]; then |
|
144 | if [ $count = 1 ]; then | |
145 | _hg_paths |
|
145 | _hg_paths | |
146 | fi |
|
146 | fi | |
147 | _hg_repos |
|
147 | _hg_repos | |
148 | ;; |
|
148 | ;; | |
149 | debugindex|debugindexdot) |
|
149 | debugindex|debugindexdot) | |
150 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) |
|
150 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur")) | |
151 | ;; |
|
151 | ;; | |
152 | debugdata) |
|
152 | debugdata) | |
153 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) |
|
153 | COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur")) | |
154 | ;; |
|
154 | ;; | |
155 | esac |
|
155 | esac | |
156 |
|
156 | |||
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ |
|
159 | complete -o bashdefault -o default -F _hg hg 2>/dev/null \ | |
160 | || complete -o default -F _hg hg |
|
160 | || complete -o default -F _hg hg |
@@ -1,3460 +1,3463 | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from demandload import demandload |
|
8 | from demandload import demandload | |
9 | from node import * |
|
9 | from node import * | |
10 | from i18n import gettext as _ |
|
10 | from i18n import gettext as _ | |
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") |
|
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") | |
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
|
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | |
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") |
|
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") | |
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") | |
15 | demandload(globals(), "changegroup") |
|
15 | demandload(globals(), "changegroup") | |
16 |
|
16 | |||
17 | class UnknownCommand(Exception): |
|
17 | class UnknownCommand(Exception): | |
18 | """Exception raised if command is not in the command table.""" |
|
18 | """Exception raised if command is not in the command table.""" | |
19 | class AmbiguousCommand(Exception): |
|
19 | class AmbiguousCommand(Exception): | |
20 | """Exception raised if command shortcut matches more than one command.""" |
|
20 | """Exception raised if command shortcut matches more than one command.""" | |
21 |
|
21 | |||
22 | def filterfiles(filters, files): |
|
22 | def filterfiles(filters, files): | |
23 | l = [x for x in files if x in filters] |
|
23 | l = [x for x in files if x in filters] | |
24 |
|
24 | |||
25 | for t in filters: |
|
25 | for t in filters: | |
26 | if t and t[-1] != "/": |
|
26 | if t and t[-1] != "/": | |
27 | t += "/" |
|
27 | t += "/" | |
28 | l += [x for x in files if x.startswith(t)] |
|
28 | l += [x for x in files if x.startswith(t)] | |
29 | return l |
|
29 | return l | |
30 |
|
30 | |||
31 | def relpath(repo, args): |
|
31 | def relpath(repo, args): | |
32 | cwd = repo.getcwd() |
|
32 | cwd = repo.getcwd() | |
33 | if cwd: |
|
33 | if cwd: | |
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
35 | return args |
|
35 | return args | |
36 |
|
36 | |||
37 | def matchpats(repo, pats=[], opts={}, head=''): |
|
37 | def matchpats(repo, pats=[], opts={}, head=''): | |
38 | cwd = repo.getcwd() |
|
38 | cwd = repo.getcwd() | |
39 | if not pats and cwd: |
|
39 | if not pats and cwd: | |
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
42 | cwd = '' |
|
42 | cwd = '' | |
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
44 | opts.get('exclude'), head) |
|
44 | opts.get('exclude'), head) | |
45 |
|
45 | |||
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
|
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): | |
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
48 | exact = dict(zip(files, files)) |
|
48 | exact = dict(zip(files, files)) | |
49 | def walk(): |
|
49 | def walk(): | |
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
51 | badmatch=None): |
|
51 | badmatch=None): | |
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
53 | return files, matchfn, walk() |
|
53 | return files, matchfn, walk() | |
54 |
|
54 | |||
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): |
|
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): | |
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
|
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) | |
57 | for r in results: |
|
57 | for r in results: | |
58 | yield r |
|
58 | yield r | |
59 |
|
59 | |||
60 | def walkchangerevs(ui, repo, pats, opts): |
|
60 | def walkchangerevs(ui, repo, pats, opts): | |
61 | '''Iterate over files and the revs they changed in. |
|
61 | '''Iterate over files and the revs they changed in. | |
62 |
|
62 | |||
63 | Callers most commonly need to iterate backwards over the history |
|
63 | Callers most commonly need to iterate backwards over the history | |
64 | it is interested in. Doing so has awful (quadratic-looking) |
|
64 | it is interested in. Doing so has awful (quadratic-looking) | |
65 | performance, so we use iterators in a "windowed" way. |
|
65 | performance, so we use iterators in a "windowed" way. | |
66 |
|
66 | |||
67 | We walk a window of revisions in the desired order. Within the |
|
67 | We walk a window of revisions in the desired order. Within the | |
68 | window, we first walk forwards to gather data, then in the desired |
|
68 | window, we first walk forwards to gather data, then in the desired | |
69 | order (usually backwards) to display it. |
|
69 | order (usually backwards) to display it. | |
70 |
|
70 | |||
71 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
71 | This function returns an (iterator, getchange, matchfn) tuple. The | |
72 | getchange function returns the changelog entry for a numeric |
|
72 | getchange function returns the changelog entry for a numeric | |
73 | revision. The iterator yields 3-tuples. They will be of one of |
|
73 | revision. The iterator yields 3-tuples. They will be of one of | |
74 | the following forms: |
|
74 | the following forms: | |
75 |
|
75 | |||
76 | "window", incrementing, lastrev: stepping through a window, |
|
76 | "window", incrementing, lastrev: stepping through a window, | |
77 | positive if walking forwards through revs, last rev in the |
|
77 | positive if walking forwards through revs, last rev in the | |
78 | sequence iterated over - use to reset state for the current window |
|
78 | sequence iterated over - use to reset state for the current window | |
79 |
|
79 | |||
80 | "add", rev, fns: out-of-order traversal of the given file names |
|
80 | "add", rev, fns: out-of-order traversal of the given file names | |
81 | fns, which changed during revision rev - use to gather data for |
|
81 | fns, which changed during revision rev - use to gather data for | |
82 | possible display |
|
82 | possible display | |
83 |
|
83 | |||
84 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
84 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
85 | over with "add" - use to display data''' |
|
85 | over with "add" - use to display data''' | |
86 |
|
86 | |||
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
88 | if start < end: |
|
88 | if start < end: | |
89 | while start < end: |
|
89 | while start < end: | |
90 | yield start, min(windowsize, end-start) |
|
90 | yield start, min(windowsize, end-start) | |
91 | start += windowsize |
|
91 | start += windowsize | |
92 | if windowsize < sizelimit: |
|
92 | if windowsize < sizelimit: | |
93 | windowsize *= 2 |
|
93 | windowsize *= 2 | |
94 | else: |
|
94 | else: | |
95 | while start > end: |
|
95 | while start > end: | |
96 | yield start, min(windowsize, start-end-1) |
|
96 | yield start, min(windowsize, start-end-1) | |
97 | start -= windowsize |
|
97 | start -= windowsize | |
98 | if windowsize < sizelimit: |
|
98 | if windowsize < sizelimit: | |
99 | windowsize *= 2 |
|
99 | windowsize *= 2 | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
102 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
103 |
|
103 | |||
104 | if repo.changelog.count() == 0: |
|
104 | if repo.changelog.count() == 0: | |
105 | return [], False, matchfn |
|
105 | return [], False, matchfn | |
106 |
|
106 | |||
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
108 | wanted = {} |
|
108 | wanted = {} | |
109 | slowpath = anypats |
|
109 | slowpath = anypats | |
110 | fncache = {} |
|
110 | fncache = {} | |
111 |
|
111 | |||
112 | chcache = {} |
|
112 | chcache = {} | |
113 | def getchange(rev): |
|
113 | def getchange(rev): | |
114 | ch = chcache.get(rev) |
|
114 | ch = chcache.get(rev) | |
115 | if ch is None: |
|
115 | if ch is None: | |
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
117 | return ch |
|
117 | return ch | |
118 |
|
118 | |||
119 | if not slowpath and not files: |
|
119 | if not slowpath and not files: | |
120 | # No files, no patterns. Display all revs. |
|
120 | # No files, no patterns. Display all revs. | |
121 | wanted = dict(zip(revs, revs)) |
|
121 | wanted = dict(zip(revs, revs)) | |
122 | if not slowpath: |
|
122 | if not slowpath: | |
123 | # Only files, no patterns. Check the history of each file. |
|
123 | # Only files, no patterns. Check the history of each file. | |
124 | def filerevgen(filelog): |
|
124 | def filerevgen(filelog): | |
125 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
125 | for i, window in increasing_windows(filelog.count()-1, -1): | |
126 | revs = [] |
|
126 | revs = [] | |
127 | for j in xrange(i - window, i + 1): |
|
127 | for j in xrange(i - window, i + 1): | |
128 | revs.append(filelog.linkrev(filelog.node(j))) |
|
128 | revs.append(filelog.linkrev(filelog.node(j))) | |
129 | revs.reverse() |
|
129 | revs.reverse() | |
130 | for rev in revs: |
|
130 | for rev in revs: | |
131 | yield rev |
|
131 | yield rev | |
132 |
|
132 | |||
133 | minrev, maxrev = min(revs), max(revs) |
|
133 | minrev, maxrev = min(revs), max(revs) | |
134 | for file_ in files: |
|
134 | for file_ in files: | |
135 | filelog = repo.file(file_) |
|
135 | filelog = repo.file(file_) | |
136 | # A zero count may be a directory or deleted file, so |
|
136 | # A zero count may be a directory or deleted file, so | |
137 | # try to find matching entries on the slow path. |
|
137 | # try to find matching entries on the slow path. | |
138 | if filelog.count() == 0: |
|
138 | if filelog.count() == 0: | |
139 | slowpath = True |
|
139 | slowpath = True | |
140 | break |
|
140 | break | |
141 | for rev in filerevgen(filelog): |
|
141 | for rev in filerevgen(filelog): | |
142 | if rev <= maxrev: |
|
142 | if rev <= maxrev: | |
143 | if rev < minrev: |
|
143 | if rev < minrev: | |
144 | break |
|
144 | break | |
145 | fncache.setdefault(rev, []) |
|
145 | fncache.setdefault(rev, []) | |
146 | fncache[rev].append(file_) |
|
146 | fncache[rev].append(file_) | |
147 | wanted[rev] = 1 |
|
147 | wanted[rev] = 1 | |
148 | if slowpath: |
|
148 | if slowpath: | |
149 | # The slow path checks files modified in every changeset. |
|
149 | # The slow path checks files modified in every changeset. | |
150 | def changerevgen(): |
|
150 | def changerevgen(): | |
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
152 | for j in xrange(i - window, i + 1): |
|
152 | for j in xrange(i - window, i + 1): | |
153 | yield j, getchange(j)[3] |
|
153 | yield j, getchange(j)[3] | |
154 |
|
154 | |||
155 | for rev, changefiles in changerevgen(): |
|
155 | for rev, changefiles in changerevgen(): | |
156 | matches = filter(matchfn, changefiles) |
|
156 | matches = filter(matchfn, changefiles) | |
157 | if matches: |
|
157 | if matches: | |
158 | fncache[rev] = matches |
|
158 | fncache[rev] = matches | |
159 | wanted[rev] = 1 |
|
159 | wanted[rev] = 1 | |
160 |
|
160 | |||
161 | def iterate(): |
|
161 | def iterate(): | |
162 | for i, window in increasing_windows(0, len(revs)): |
|
162 | for i, window in increasing_windows(0, len(revs)): | |
163 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
163 | yield 'window', revs[0] < revs[-1], revs[-1] | |
164 | nrevs = [rev for rev in revs[i:i+window] |
|
164 | nrevs = [rev for rev in revs[i:i+window] | |
165 | if rev in wanted] |
|
165 | if rev in wanted] | |
166 | srevs = list(nrevs) |
|
166 | srevs = list(nrevs) | |
167 | srevs.sort() |
|
167 | srevs.sort() | |
168 | for rev in srevs: |
|
168 | for rev in srevs: | |
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
170 | yield 'add', rev, fns |
|
170 | yield 'add', rev, fns | |
171 | for rev in nrevs: |
|
171 | for rev in nrevs: | |
172 | yield 'iter', rev, None |
|
172 | yield 'iter', rev, None | |
173 | return iterate(), getchange, matchfn |
|
173 | return iterate(), getchange, matchfn | |
174 |
|
174 | |||
175 | revrangesep = ':' |
|
175 | revrangesep = ':' | |
176 |
|
176 | |||
177 | def revrange(ui, repo, revs, revlog=None): |
|
177 | def revrange(ui, repo, revs, revlog=None): | |
178 | """Yield revision as strings from a list of revision specifications.""" |
|
178 | """Yield revision as strings from a list of revision specifications.""" | |
179 | if revlog is None: |
|
179 | if revlog is None: | |
180 | revlog = repo.changelog |
|
180 | revlog = repo.changelog | |
181 | revcount = revlog.count() |
|
181 | revcount = revlog.count() | |
182 | def fix(val, defval): |
|
182 | def fix(val, defval): | |
183 | if not val: |
|
183 | if not val: | |
184 | return defval |
|
184 | return defval | |
185 | try: |
|
185 | try: | |
186 | num = int(val) |
|
186 | num = int(val) | |
187 | if str(num) != val: |
|
187 | if str(num) != val: | |
188 | raise ValueError |
|
188 | raise ValueError | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num += revcount |
|
190 | num += revcount | |
191 | if num < 0: |
|
191 | if num < 0: | |
192 | num = 0 |
|
192 | num = 0 | |
193 | elif num >= revcount: |
|
193 | elif num >= revcount: | |
194 | raise ValueError |
|
194 | raise ValueError | |
195 | except ValueError: |
|
195 | except ValueError: | |
196 | try: |
|
196 | try: | |
197 | num = repo.changelog.rev(repo.lookup(val)) |
|
197 | num = repo.changelog.rev(repo.lookup(val)) | |
198 | except KeyError: |
|
198 | except KeyError: | |
199 | try: |
|
199 | try: | |
200 | num = revlog.rev(revlog.lookup(val)) |
|
200 | num = revlog.rev(revlog.lookup(val)) | |
201 | except KeyError: |
|
201 | except KeyError: | |
202 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
202 | raise util.Abort(_('invalid revision identifier %s'), val) | |
203 | return num |
|
203 | return num | |
204 | seen = {} |
|
204 | seen = {} | |
205 | for spec in revs: |
|
205 | for spec in revs: | |
206 | if spec.find(revrangesep) >= 0: |
|
206 | if spec.find(revrangesep) >= 0: | |
207 | start, end = spec.split(revrangesep, 1) |
|
207 | start, end = spec.split(revrangesep, 1) | |
208 | start = fix(start, 0) |
|
208 | start = fix(start, 0) | |
209 | end = fix(end, revcount - 1) |
|
209 | end = fix(end, revcount - 1) | |
210 | step = start > end and -1 or 1 |
|
210 | step = start > end and -1 or 1 | |
211 | for rev in xrange(start, end+step, step): |
|
211 | for rev in xrange(start, end+step, step): | |
212 | if rev in seen: |
|
212 | if rev in seen: | |
213 | continue |
|
213 | continue | |
214 | seen[rev] = 1 |
|
214 | seen[rev] = 1 | |
215 | yield str(rev) |
|
215 | yield str(rev) | |
216 | else: |
|
216 | else: | |
217 | rev = fix(spec, None) |
|
217 | rev = fix(spec, None) | |
218 | if rev in seen: |
|
218 | if rev in seen: | |
219 | continue |
|
219 | continue | |
220 | seen[rev] = 1 |
|
220 | seen[rev] = 1 | |
221 | yield str(rev) |
|
221 | yield str(rev) | |
222 |
|
222 | |||
223 | def make_filename(repo, r, pat, node=None, |
|
223 | def make_filename(repo, r, pat, node=None, | |
224 | total=None, seqno=None, revwidth=None, pathname=None): |
|
224 | total=None, seqno=None, revwidth=None, pathname=None): | |
225 | node_expander = { |
|
225 | node_expander = { | |
226 | 'H': lambda: hex(node), |
|
226 | 'H': lambda: hex(node), | |
227 | 'R': lambda: str(r.rev(node)), |
|
227 | 'R': lambda: str(r.rev(node)), | |
228 | 'h': lambda: short(node), |
|
228 | 'h': lambda: short(node), | |
229 | } |
|
229 | } | |
230 | expander = { |
|
230 | expander = { | |
231 | '%': lambda: '%', |
|
231 | '%': lambda: '%', | |
232 | 'b': lambda: os.path.basename(repo.root), |
|
232 | 'b': lambda: os.path.basename(repo.root), | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | try: |
|
235 | try: | |
236 | if node: |
|
236 | if node: | |
237 | expander.update(node_expander) |
|
237 | expander.update(node_expander) | |
238 | if node and revwidth is not None: |
|
238 | if node and revwidth is not None: | |
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
240 | if total is not None: |
|
240 | if total is not None: | |
241 | expander['N'] = lambda: str(total) |
|
241 | expander['N'] = lambda: str(total) | |
242 | if seqno is not None: |
|
242 | if seqno is not None: | |
243 | expander['n'] = lambda: str(seqno) |
|
243 | expander['n'] = lambda: str(seqno) | |
244 | if total is not None and seqno is not None: |
|
244 | if total is not None and seqno is not None: | |
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
246 | if pathname is not None: |
|
246 | if pathname is not None: | |
247 | expander['s'] = lambda: os.path.basename(pathname) |
|
247 | expander['s'] = lambda: os.path.basename(pathname) | |
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
249 | expander['p'] = lambda: pathname |
|
249 | expander['p'] = lambda: pathname | |
250 |
|
250 | |||
251 | newname = [] |
|
251 | newname = [] | |
252 | patlen = len(pat) |
|
252 | patlen = len(pat) | |
253 | i = 0 |
|
253 | i = 0 | |
254 | while i < patlen: |
|
254 | while i < patlen: | |
255 | c = pat[i] |
|
255 | c = pat[i] | |
256 | if c == '%': |
|
256 | if c == '%': | |
257 | i += 1 |
|
257 | i += 1 | |
258 | c = pat[i] |
|
258 | c = pat[i] | |
259 | c = expander[c]() |
|
259 | c = expander[c]() | |
260 | newname.append(c) |
|
260 | newname.append(c) | |
261 | i += 1 |
|
261 | i += 1 | |
262 | return ''.join(newname) |
|
262 | return ''.join(newname) | |
263 | except KeyError, inst: |
|
263 | except KeyError, inst: | |
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
265 | inst.args[0]) |
|
265 | inst.args[0]) | |
266 |
|
266 | |||
267 | def make_file(repo, r, pat, node=None, |
|
267 | def make_file(repo, r, pat, node=None, | |
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
269 | if not pat or pat == '-': |
|
269 | if not pat or pat == '-': | |
270 | return 'w' in mode and sys.stdout or sys.stdin |
|
270 | return 'w' in mode and sys.stdout or sys.stdin | |
271 | if hasattr(pat, 'write') and 'w' in mode: |
|
271 | if hasattr(pat, 'write') and 'w' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | if hasattr(pat, 'read') and 'r' in mode: |
|
273 | if hasattr(pat, 'read') and 'r' in mode: | |
274 | return pat |
|
274 | return pat | |
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
276 | pathname), |
|
276 | pathname), | |
277 | mode) |
|
277 | mode) | |
278 |
|
278 | |||
279 | def write_bundle(cg, filename=None, compress=True): |
|
279 | def write_bundle(cg, filename=None, compress=True): | |
280 | """Write a bundle file and return its filename. |
|
280 | """Write a bundle file and return its filename. | |
281 |
|
281 | |||
282 | Existing files will not be overwritten. |
|
282 | Existing files will not be overwritten. | |
283 | If no filename is specified, a temporary file is created. |
|
283 | If no filename is specified, a temporary file is created. | |
284 | bz2 compression can be turned off. |
|
284 | bz2 compression can be turned off. | |
285 | The bundle file will be deleted in case of errors. |
|
285 | The bundle file will be deleted in case of errors. | |
286 | """ |
|
286 | """ | |
287 | class nocompress(object): |
|
287 | class nocompress(object): | |
288 | def compress(self, x): |
|
288 | def compress(self, x): | |
289 | return x |
|
289 | return x | |
290 | def flush(self): |
|
290 | def flush(self): | |
291 | return "" |
|
291 | return "" | |
292 |
|
292 | |||
293 | fh = None |
|
293 | fh = None | |
294 | cleanup = None |
|
294 | cleanup = None | |
295 | try: |
|
295 | try: | |
296 | if filename: |
|
296 | if filename: | |
297 | if os.path.exists(filename): |
|
297 | if os.path.exists(filename): | |
298 | raise util.Abort(_("file '%s' already exists"), filename) |
|
298 | raise util.Abort(_("file '%s' already exists"), filename) | |
299 | fh = open(filename, "wb") |
|
299 | fh = open(filename, "wb") | |
300 | else: |
|
300 | else: | |
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") |
|
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") | |
302 | fh = os.fdopen(fd, "wb") |
|
302 | fh = os.fdopen(fd, "wb") | |
303 | cleanup = filename |
|
303 | cleanup = filename | |
304 |
|
304 | |||
305 | if compress: |
|
305 | if compress: | |
306 | fh.write("HG10") |
|
306 | fh.write("HG10") | |
307 | z = bz2.BZ2Compressor(9) |
|
307 | z = bz2.BZ2Compressor(9) | |
308 | else: |
|
308 | else: | |
309 | fh.write("HG10UN") |
|
309 | fh.write("HG10UN") | |
310 | z = nocompress() |
|
310 | z = nocompress() | |
311 | # parse the changegroup data, otherwise we will block |
|
311 | # parse the changegroup data, otherwise we will block | |
312 | # in case of sshrepo because we don't know the end of the stream |
|
312 | # in case of sshrepo because we don't know the end of the stream | |
313 |
|
313 | |||
314 | # an empty chunkiter is the end of the changegroup |
|
314 | # an empty chunkiter is the end of the changegroup | |
315 | empty = False |
|
315 | empty = False | |
316 | while not empty: |
|
316 | while not empty: | |
317 | empty = True |
|
317 | empty = True | |
318 | for chunk in changegroup.chunkiter(cg): |
|
318 | for chunk in changegroup.chunkiter(cg): | |
319 | empty = False |
|
319 | empty = False | |
320 | fh.write(z.compress(changegroup.genchunk(chunk))) |
|
320 | fh.write(z.compress(changegroup.genchunk(chunk))) | |
321 | fh.write(z.compress(changegroup.closechunk())) |
|
321 | fh.write(z.compress(changegroup.closechunk())) | |
322 | fh.write(z.flush()) |
|
322 | fh.write(z.flush()) | |
323 | cleanup = None |
|
323 | cleanup = None | |
324 | return filename |
|
324 | return filename | |
325 | finally: |
|
325 | finally: | |
326 | if fh is not None: |
|
326 | if fh is not None: | |
327 | fh.close() |
|
327 | fh.close() | |
328 | if cleanup is not None: |
|
328 | if cleanup is not None: | |
329 | os.unlink(cleanup) |
|
329 | os.unlink(cleanup) | |
330 |
|
330 | |||
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
332 | changes=None, text=False, opts={}): |
|
332 | changes=None, text=False, opts={}): | |
333 | if not node1: |
|
333 | if not node1: | |
334 | node1 = repo.dirstate.parents()[0] |
|
334 | node1 = repo.dirstate.parents()[0] | |
335 | # reading the data for node1 early allows it to play nicely |
|
335 | # reading the data for node1 early allows it to play nicely | |
336 | # with repo.changes and the revlog cache. |
|
336 | # with repo.changes and the revlog cache. | |
337 | change = repo.changelog.read(node1) |
|
337 | change = repo.changelog.read(node1) | |
338 | mmap = repo.manifest.read(change[0]) |
|
338 | mmap = repo.manifest.read(change[0]) | |
339 | date1 = util.datestr(change[2]) |
|
339 | date1 = util.datestr(change[2]) | |
340 |
|
340 | |||
341 | if not changes: |
|
341 | if not changes: | |
342 | changes = repo.changes(node1, node2, files, match=match) |
|
342 | changes = repo.changes(node1, node2, files, match=match) | |
343 | modified, added, removed, deleted, unknown = changes |
|
343 | modified, added, removed, deleted, unknown = changes | |
344 | if files: |
|
344 | if files: | |
345 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
345 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
346 | (modified, added, removed)) |
|
346 | (modified, added, removed)) | |
347 |
|
347 | |||
348 | if not modified and not added and not removed: |
|
348 | if not modified and not added and not removed: | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 | if node2: |
|
351 | if node2: | |
352 | change = repo.changelog.read(node2) |
|
352 | change = repo.changelog.read(node2) | |
353 | mmap2 = repo.manifest.read(change[0]) |
|
353 | mmap2 = repo.manifest.read(change[0]) | |
354 | date2 = util.datestr(change[2]) |
|
354 | date2 = util.datestr(change[2]) | |
355 | def read(f): |
|
355 | def read(f): | |
356 | return repo.file(f).read(mmap2[f]) |
|
356 | return repo.file(f).read(mmap2[f]) | |
357 | else: |
|
357 | else: | |
358 | date2 = util.datestr() |
|
358 | date2 = util.datestr() | |
359 | def read(f): |
|
359 | def read(f): | |
360 | return repo.wread(f) |
|
360 | return repo.wread(f) | |
361 |
|
361 | |||
362 | if ui.quiet: |
|
362 | if ui.quiet: | |
363 | r = None |
|
363 | r = None | |
364 | else: |
|
364 | else: | |
365 | hexfunc = ui.verbose and hex or short |
|
365 | hexfunc = ui.verbose and hex or short | |
366 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
366 | r = [hexfunc(node) for node in [node1, node2] if node] | |
367 |
|
367 | |||
368 | diffopts = ui.diffopts() |
|
368 | diffopts = ui.diffopts() | |
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
371 | for f in modified: |
|
371 | for f in modified: | |
372 | to = None |
|
372 | to = None | |
373 | if f in mmap: |
|
373 | if f in mmap: | |
374 | to = repo.file(f).read(mmap[f]) |
|
374 | to = repo.file(f).read(mmap[f]) | |
375 | tn = read(f) |
|
375 | tn = read(f) | |
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
377 | showfunc=showfunc, ignorews=ignorews)) |
|
377 | showfunc=showfunc, ignorews=ignorews)) | |
378 | for f in added: |
|
378 | for f in added: | |
379 | to = None |
|
379 | to = None | |
380 | tn = read(f) |
|
380 | tn = read(f) | |
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
382 | showfunc=showfunc, ignorews=ignorews)) |
|
382 | showfunc=showfunc, ignorews=ignorews)) | |
383 | for f in removed: |
|
383 | for f in removed: | |
384 | to = repo.file(f).read(mmap[f]) |
|
384 | to = repo.file(f).read(mmap[f]) | |
385 | tn = None |
|
385 | tn = None | |
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
387 | showfunc=showfunc, ignorews=ignorews)) |
|
387 | showfunc=showfunc, ignorews=ignorews)) | |
388 |
|
388 | |||
389 | def trimuser(ui, name, rev, revcache): |
|
389 | def trimuser(ui, name, rev, revcache): | |
390 | """trim the name of the user who committed a change""" |
|
390 | """trim the name of the user who committed a change""" | |
391 | user = revcache.get(rev) |
|
391 | user = revcache.get(rev) | |
392 | if user is None: |
|
392 | if user is None: | |
393 | user = revcache[rev] = ui.shortuser(name) |
|
393 | user = revcache[rev] = ui.shortuser(name) | |
394 | return user |
|
394 | return user | |
395 |
|
395 | |||
396 | class changeset_templater(object): |
|
396 | class changeset_templater(object): | |
397 | '''use templater module to format changeset information.''' |
|
397 | '''use templater module to format changeset information.''' | |
398 |
|
398 | |||
399 | def __init__(self, ui, repo, mapfile): |
|
399 | def __init__(self, ui, repo, mapfile): | |
400 | self.t = templater.templater(mapfile, templater.common_filters, |
|
400 | self.t = templater.templater(mapfile, templater.common_filters, | |
401 | cache={'parent': '{rev}:{node|short} ', |
|
401 | cache={'parent': '{rev}:{node|short} ', | |
402 | 'manifest': '{rev}:{node|short}'}) |
|
402 | 'manifest': '{rev}:{node|short}'}) | |
403 | self.ui = ui |
|
403 | self.ui = ui | |
404 | self.repo = repo |
|
404 | self.repo = repo | |
405 |
|
405 | |||
406 | def use_template(self, t): |
|
406 | def use_template(self, t): | |
407 | '''set template string to use''' |
|
407 | '''set template string to use''' | |
408 | self.t.cache['changeset'] = t |
|
408 | self.t.cache['changeset'] = t | |
409 |
|
409 | |||
410 | def write(self, thing, header=False): |
|
410 | def write(self, thing, header=False): | |
411 | '''write expanded template. |
|
411 | '''write expanded template. | |
412 | uses in-order recursive traverse of iterators.''' |
|
412 | uses in-order recursive traverse of iterators.''' | |
413 | for t in thing: |
|
413 | for t in thing: | |
414 | if hasattr(t, '__iter__'): |
|
414 | if hasattr(t, '__iter__'): | |
415 | self.write(t, header=header) |
|
415 | self.write(t, header=header) | |
416 | elif header: |
|
416 | elif header: | |
417 | self.ui.write_header(t) |
|
417 | self.ui.write_header(t) | |
418 | else: |
|
418 | else: | |
419 | self.ui.write(t) |
|
419 | self.ui.write(t) | |
420 |
|
420 | |||
421 | def write_header(self, thing): |
|
421 | def write_header(self, thing): | |
422 | self.write(thing, header=True) |
|
422 | self.write(thing, header=True) | |
423 |
|
423 | |||
424 | def show(self, rev=0, changenode=None, brinfo=None): |
|
424 | def show(self, rev=0, changenode=None, brinfo=None): | |
425 | '''show a single changeset or file revision''' |
|
425 | '''show a single changeset or file revision''' | |
426 | log = self.repo.changelog |
|
426 | log = self.repo.changelog | |
427 | if changenode is None: |
|
427 | if changenode is None: | |
428 | changenode = log.node(rev) |
|
428 | changenode = log.node(rev) | |
429 | elif not rev: |
|
429 | elif not rev: | |
430 | rev = log.rev(changenode) |
|
430 | rev = log.rev(changenode) | |
431 |
|
431 | |||
432 | changes = log.read(changenode) |
|
432 | changes = log.read(changenode) | |
433 |
|
433 | |||
434 | def showlist(name, values, plural=None, **args): |
|
434 | def showlist(name, values, plural=None, **args): | |
435 | '''expand set of values. |
|
435 | '''expand set of values. | |
436 | name is name of key in template map. |
|
436 | name is name of key in template map. | |
437 | values is list of strings or dicts. |
|
437 | values is list of strings or dicts. | |
438 | plural is plural of name, if not simply name + 's'. |
|
438 | plural is plural of name, if not simply name + 's'. | |
439 |
|
439 | |||
440 | expansion works like this, given name 'foo'. |
|
440 | expansion works like this, given name 'foo'. | |
441 |
|
441 | |||
442 | if values is empty, expand 'no_foos'. |
|
442 | if values is empty, expand 'no_foos'. | |
443 |
|
443 | |||
444 | if 'foo' not in template map, return values as a string, |
|
444 | if 'foo' not in template map, return values as a string, | |
445 | joined by space. |
|
445 | joined by space. | |
446 |
|
446 | |||
447 | expand 'start_foos'. |
|
447 | expand 'start_foos'. | |
448 |
|
448 | |||
449 | for each value, expand 'foo'. if 'last_foo' in template |
|
449 | for each value, expand 'foo'. if 'last_foo' in template | |
450 | map, expand it instead of 'foo' for last key. |
|
450 | map, expand it instead of 'foo' for last key. | |
451 |
|
451 | |||
452 | expand 'end_foos'. |
|
452 | expand 'end_foos'. | |
453 | ''' |
|
453 | ''' | |
454 | if plural: names = plural |
|
454 | if plural: names = plural | |
455 | else: names = name + 's' |
|
455 | else: names = name + 's' | |
456 | if not values: |
|
456 | if not values: | |
457 | noname = 'no_' + names |
|
457 | noname = 'no_' + names | |
458 | if noname in self.t: |
|
458 | if noname in self.t: | |
459 | yield self.t(noname, **args) |
|
459 | yield self.t(noname, **args) | |
460 | return |
|
460 | return | |
461 | if name not in self.t: |
|
461 | if name not in self.t: | |
462 | if isinstance(values[0], str): |
|
462 | if isinstance(values[0], str): | |
463 | yield ' '.join(values) |
|
463 | yield ' '.join(values) | |
464 | else: |
|
464 | else: | |
465 | for v in values: |
|
465 | for v in values: | |
466 | yield dict(v, **args) |
|
466 | yield dict(v, **args) | |
467 | return |
|
467 | return | |
468 | startname = 'start_' + names |
|
468 | startname = 'start_' + names | |
469 | if startname in self.t: |
|
469 | if startname in self.t: | |
470 | yield self.t(startname, **args) |
|
470 | yield self.t(startname, **args) | |
471 | vargs = args.copy() |
|
471 | vargs = args.copy() | |
472 | def one(v, tag=name): |
|
472 | def one(v, tag=name): | |
473 | try: |
|
473 | try: | |
474 | vargs.update(v) |
|
474 | vargs.update(v) | |
475 | except (AttributeError, ValueError): |
|
475 | except (AttributeError, ValueError): | |
476 | try: |
|
476 | try: | |
477 | for a, b in v: |
|
477 | for a, b in v: | |
478 | vargs[a] = b |
|
478 | vargs[a] = b | |
479 | except ValueError: |
|
479 | except ValueError: | |
480 | vargs[name] = v |
|
480 | vargs[name] = v | |
481 | return self.t(tag, **vargs) |
|
481 | return self.t(tag, **vargs) | |
482 | lastname = 'last_' + name |
|
482 | lastname = 'last_' + name | |
483 | if lastname in self.t: |
|
483 | if lastname in self.t: | |
484 | last = values.pop() |
|
484 | last = values.pop() | |
485 | else: |
|
485 | else: | |
486 | last = None |
|
486 | last = None | |
487 | for v in values: |
|
487 | for v in values: | |
488 | yield one(v) |
|
488 | yield one(v) | |
489 | if last is not None: |
|
489 | if last is not None: | |
490 | yield one(last, tag=lastname) |
|
490 | yield one(last, tag=lastname) | |
491 | endname = 'end_' + names |
|
491 | endname = 'end_' + names | |
492 | if endname in self.t: |
|
492 | if endname in self.t: | |
493 | yield self.t(endname, **args) |
|
493 | yield self.t(endname, **args) | |
494 |
|
494 | |||
495 | if brinfo: |
|
495 | if brinfo: | |
496 | def showbranches(**args): |
|
496 | def showbranches(**args): | |
497 | if changenode in brinfo: |
|
497 | if changenode in brinfo: | |
498 | for x in showlist('branch', brinfo[changenode], |
|
498 | for x in showlist('branch', brinfo[changenode], | |
499 | plural='branches', **args): |
|
499 | plural='branches', **args): | |
500 | yield x |
|
500 | yield x | |
501 | else: |
|
501 | else: | |
502 | showbranches = '' |
|
502 | showbranches = '' | |
503 |
|
503 | |||
504 | if self.ui.debugflag: |
|
504 | if self.ui.debugflag: | |
505 | def showmanifest(**args): |
|
505 | def showmanifest(**args): | |
506 | args = args.copy() |
|
506 | args = args.copy() | |
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
508 | node=hex(changes[0]))) |
|
508 | node=hex(changes[0]))) | |
509 | yield self.t('manifest', **args) |
|
509 | yield self.t('manifest', **args) | |
510 | else: |
|
510 | else: | |
511 | showmanifest = '' |
|
511 | showmanifest = '' | |
512 |
|
512 | |||
513 | def showparents(**args): |
|
513 | def showparents(**args): | |
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] | |
515 | for p in log.parents(changenode) |
|
515 | for p in log.parents(changenode) | |
516 | if self.ui.debugflag or p != nullid] |
|
516 | if self.ui.debugflag or p != nullid] | |
517 | if (not self.ui.debugflag and len(parents) == 1 and |
|
517 | if (not self.ui.debugflag and len(parents) == 1 and | |
518 | parents[0][0][1] == rev - 1): |
|
518 | parents[0][0][1] == rev - 1): | |
519 | return |
|
519 | return | |
520 | for x in showlist('parent', parents, **args): |
|
520 | for x in showlist('parent', parents, **args): | |
521 | yield x |
|
521 | yield x | |
522 |
|
522 | |||
523 | def showtags(**args): |
|
523 | def showtags(**args): | |
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): |
|
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): | |
525 | yield x |
|
525 | yield x | |
526 |
|
526 | |||
527 | if self.ui.debugflag: |
|
527 | if self.ui.debugflag: | |
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
529 | def showfiles(**args): |
|
529 | def showfiles(**args): | |
530 | for x in showlist('file', files[0], **args): yield x |
|
530 | for x in showlist('file', files[0], **args): yield x | |
531 | def showadds(**args): |
|
531 | def showadds(**args): | |
532 | for x in showlist('file_add', files[1], **args): yield x |
|
532 | for x in showlist('file_add', files[1], **args): yield x | |
533 | def showdels(**args): |
|
533 | def showdels(**args): | |
534 | for x in showlist('file_del', files[2], **args): yield x |
|
534 | for x in showlist('file_del', files[2], **args): yield x | |
535 | else: |
|
535 | else: | |
536 | def showfiles(**args): |
|
536 | def showfiles(**args): | |
537 | for x in showlist('file', changes[3], **args): yield x |
|
537 | for x in showlist('file', changes[3], **args): yield x | |
538 | showadds = '' |
|
538 | showadds = '' | |
539 | showdels = '' |
|
539 | showdels = '' | |
540 |
|
540 | |||
541 | props = { |
|
541 | props = { | |
542 | 'author': changes[1], |
|
542 | 'author': changes[1], | |
543 | 'branches': showbranches, |
|
543 | 'branches': showbranches, | |
544 | 'date': changes[2], |
|
544 | 'date': changes[2], | |
545 | 'desc': changes[4], |
|
545 | 'desc': changes[4], | |
546 | 'file_adds': showadds, |
|
546 | 'file_adds': showadds, | |
547 | 'file_dels': showdels, |
|
547 | 'file_dels': showdels, | |
548 | 'files': showfiles, |
|
548 | 'files': showfiles, | |
549 | 'manifest': showmanifest, |
|
549 | 'manifest': showmanifest, | |
550 | 'node': hex(changenode), |
|
550 | 'node': hex(changenode), | |
551 | 'parents': showparents, |
|
551 | 'parents': showparents, | |
552 | 'rev': rev, |
|
552 | 'rev': rev, | |
553 | 'tags': showtags, |
|
553 | 'tags': showtags, | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | try: |
|
556 | try: | |
557 | if self.ui.debugflag and 'header_debug' in self.t: |
|
557 | if self.ui.debugflag and 'header_debug' in self.t: | |
558 | key = 'header_debug' |
|
558 | key = 'header_debug' | |
559 | elif self.ui.quiet and 'header_quiet' in self.t: |
|
559 | elif self.ui.quiet and 'header_quiet' in self.t: | |
560 | key = 'header_quiet' |
|
560 | key = 'header_quiet' | |
561 | elif self.ui.verbose and 'header_verbose' in self.t: |
|
561 | elif self.ui.verbose and 'header_verbose' in self.t: | |
562 | key = 'header_verbose' |
|
562 | key = 'header_verbose' | |
563 | elif 'header' in self.t: |
|
563 | elif 'header' in self.t: | |
564 | key = 'header' |
|
564 | key = 'header' | |
565 | else: |
|
565 | else: | |
566 | key = '' |
|
566 | key = '' | |
567 | if key: |
|
567 | if key: | |
568 | self.write_header(self.t(key, **props)) |
|
568 | self.write_header(self.t(key, **props)) | |
569 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
569 | if self.ui.debugflag and 'changeset_debug' in self.t: | |
570 | key = 'changeset_debug' |
|
570 | key = 'changeset_debug' | |
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: | |
572 | key = 'changeset_quiet' |
|
572 | key = 'changeset_quiet' | |
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: | |
574 | key = 'changeset_verbose' |
|
574 | key = 'changeset_verbose' | |
575 | else: |
|
575 | else: | |
576 | key = 'changeset' |
|
576 | key = 'changeset' | |
577 | self.write(self.t(key, **props)) |
|
577 | self.write(self.t(key, **props)) | |
578 | except KeyError, inst: |
|
578 | except KeyError, inst: | |
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | |
580 | inst.args[0])) |
|
580 | inst.args[0])) | |
581 | except SyntaxError, inst: |
|
581 | except SyntaxError, inst: | |
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | |
583 |
|
583 | |||
584 | class changeset_printer(object): |
|
584 | class changeset_printer(object): | |
585 | '''show changeset information when templating not requested.''' |
|
585 | '''show changeset information when templating not requested.''' | |
586 |
|
586 | |||
587 | def __init__(self, ui, repo): |
|
587 | def __init__(self, ui, repo): | |
588 | self.ui = ui |
|
588 | self.ui = ui | |
589 | self.repo = repo |
|
589 | self.repo = repo | |
590 |
|
590 | |||
591 | def show(self, rev=0, changenode=None, brinfo=None): |
|
591 | def show(self, rev=0, changenode=None, brinfo=None): | |
592 | '''show a single changeset or file revision''' |
|
592 | '''show a single changeset or file revision''' | |
593 | log = self.repo.changelog |
|
593 | log = self.repo.changelog | |
594 | if changenode is None: |
|
594 | if changenode is None: | |
595 | changenode = log.node(rev) |
|
595 | changenode = log.node(rev) | |
596 | elif not rev: |
|
596 | elif not rev: | |
597 | rev = log.rev(changenode) |
|
597 | rev = log.rev(changenode) | |
598 |
|
598 | |||
599 | if self.ui.quiet: |
|
599 | if self.ui.quiet: | |
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
601 | return |
|
601 | return | |
602 |
|
602 | |||
603 | changes = log.read(changenode) |
|
603 | changes = log.read(changenode) | |
604 | date = util.datestr(changes[2]) |
|
604 | date = util.datestr(changes[2]) | |
605 |
|
605 | |||
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
607 | for p in log.parents(changenode) |
|
607 | for p in log.parents(changenode) | |
608 | if self.ui.debugflag or p != nullid] |
|
608 | if self.ui.debugflag or p != nullid] | |
609 | if (not self.ui.debugflag and len(parents) == 1 and |
|
609 | if (not self.ui.debugflag and len(parents) == 1 and | |
610 | parents[0][0] == rev-1): |
|
610 | parents[0][0] == rev-1): | |
611 | parents = [] |
|
611 | parents = [] | |
612 |
|
612 | |||
613 | if self.ui.verbose: |
|
613 | if self.ui.verbose: | |
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
615 | else: |
|
615 | else: | |
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
617 |
|
617 | |||
618 | for tag in self.repo.nodetags(changenode): |
|
618 | for tag in self.repo.nodetags(changenode): | |
619 | self.ui.status(_("tag: %s\n") % tag) |
|
619 | self.ui.status(_("tag: %s\n") % tag) | |
620 | for parent in parents: |
|
620 | for parent in parents: | |
621 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
621 | self.ui.write(_("parent: %d:%s\n") % parent) | |
622 |
|
622 | |||
623 | if brinfo and changenode in brinfo: |
|
623 | if brinfo and changenode in brinfo: | |
624 | br = brinfo[changenode] |
|
624 | br = brinfo[changenode] | |
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
626 |
|
626 | |||
627 | self.ui.debug(_("manifest: %d:%s\n") % |
|
627 | self.ui.debug(_("manifest: %d:%s\n") % | |
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
629 | self.ui.status(_("user: %s\n") % changes[1]) |
|
629 | self.ui.status(_("user: %s\n") % changes[1]) | |
630 | self.ui.status(_("date: %s\n") % date) |
|
630 | self.ui.status(_("date: %s\n") % date) | |
631 |
|
631 | |||
632 | if self.ui.debugflag: |
|
632 | if self.ui.debugflag: | |
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
635 | files): |
|
635 | files): | |
636 | if value: |
|
636 | if value: | |
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
638 | else: |
|
638 | else: | |
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
640 |
|
640 | |||
641 | description = changes[4].strip() |
|
641 | description = changes[4].strip() | |
642 | if description: |
|
642 | if description: | |
643 | if self.ui.verbose: |
|
643 | if self.ui.verbose: | |
644 | self.ui.status(_("description:\n")) |
|
644 | self.ui.status(_("description:\n")) | |
645 | self.ui.status(description) |
|
645 | self.ui.status(description) | |
646 | self.ui.status("\n\n") |
|
646 | self.ui.status("\n\n") | |
647 | else: |
|
647 | else: | |
648 | self.ui.status(_("summary: %s\n") % |
|
648 | self.ui.status(_("summary: %s\n") % | |
649 | description.splitlines()[0]) |
|
649 | description.splitlines()[0]) | |
650 | self.ui.status("\n") |
|
650 | self.ui.status("\n") | |
651 |
|
651 | |||
652 | def show_changeset(ui, repo, opts): |
|
652 | def show_changeset(ui, repo, opts): | |
653 | '''show one changeset. uses template or regular display. caller |
|
653 | '''show one changeset. uses template or regular display. caller | |
654 | can pass in 'style' and 'template' options in opts.''' |
|
654 | can pass in 'style' and 'template' options in opts.''' | |
655 |
|
655 | |||
656 | tmpl = opts.get('template') |
|
656 | tmpl = opts.get('template') | |
657 | if tmpl: |
|
657 | if tmpl: | |
658 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
658 | tmpl = templater.parsestring(tmpl, quoted=False) | |
659 | else: |
|
659 | else: | |
660 | tmpl = ui.config('ui', 'logtemplate') |
|
660 | tmpl = ui.config('ui', 'logtemplate') | |
661 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
661 | if tmpl: tmpl = templater.parsestring(tmpl) | |
662 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
662 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
663 | if tmpl or mapfile: |
|
663 | if tmpl or mapfile: | |
664 | if mapfile: |
|
664 | if mapfile: | |
665 | if not os.path.isfile(mapfile): |
|
665 | if not os.path.isfile(mapfile): | |
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
667 | if not mapname: mapname = templater.templatepath(mapfile) |
|
667 | if not mapname: mapname = templater.templatepath(mapfile) | |
668 | if mapname: mapfile = mapname |
|
668 | if mapname: mapfile = mapname | |
669 | try: |
|
669 | try: | |
670 | t = changeset_templater(ui, repo, mapfile) |
|
670 | t = changeset_templater(ui, repo, mapfile) | |
671 | except SyntaxError, inst: |
|
671 | except SyntaxError, inst: | |
672 | raise util.Abort(inst.args[0]) |
|
672 | raise util.Abort(inst.args[0]) | |
673 | if tmpl: t.use_template(tmpl) |
|
673 | if tmpl: t.use_template(tmpl) | |
674 | return t |
|
674 | return t | |
675 | return changeset_printer(ui, repo) |
|
675 | return changeset_printer(ui, repo) | |
676 |
|
676 | |||
677 | def show_version(ui): |
|
677 | def show_version(ui): | |
678 | """output version and copyright information""" |
|
678 | """output version and copyright information""" | |
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
680 | % version.get_version()) |
|
680 | % version.get_version()) | |
681 | ui.status(_( |
|
681 | ui.status(_( | |
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
683 | "This is free software; see the source for copying conditions. " |
|
683 | "This is free software; see the source for copying conditions. " | |
684 | "There is NO\nwarranty; " |
|
684 | "There is NO\nwarranty; " | |
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
686 | )) |
|
686 | )) | |
687 |
|
687 | |||
688 | def help_(ui, cmd=None, with_version=False): |
|
688 | def help_(ui, cmd=None, with_version=False): | |
689 | """show help for a given command or all commands""" |
|
689 | """show help for a given command or all commands""" | |
690 | option_lists = [] |
|
690 | option_lists = [] | |
691 | if cmd and cmd != 'shortlist': |
|
691 | if cmd and cmd != 'shortlist': | |
692 | if with_version: |
|
692 | if with_version: | |
693 | show_version(ui) |
|
693 | show_version(ui) | |
694 | ui.write('\n') |
|
694 | ui.write('\n') | |
695 | aliases, i = find(cmd) |
|
695 | aliases, i = find(cmd) | |
696 | # synopsis |
|
696 | # synopsis | |
697 | ui.write("%s\n\n" % i[2]) |
|
697 | ui.write("%s\n\n" % i[2]) | |
698 |
|
698 | |||
699 | # description |
|
699 | # description | |
700 | doc = i[0].__doc__ |
|
700 | doc = i[0].__doc__ | |
701 | if not doc: |
|
701 | if not doc: | |
702 | doc = _("(No help text available)") |
|
702 | doc = _("(No help text available)") | |
703 | if ui.quiet: |
|
703 | if ui.quiet: | |
704 | doc = doc.splitlines(0)[0] |
|
704 | doc = doc.splitlines(0)[0] | |
705 | ui.write("%s\n" % doc.rstrip()) |
|
705 | ui.write("%s\n" % doc.rstrip()) | |
706 |
|
706 | |||
707 | if not ui.quiet: |
|
707 | if not ui.quiet: | |
708 | # aliases |
|
708 | # aliases | |
709 | if len(aliases) > 1: |
|
709 | if len(aliases) > 1: | |
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
711 |
|
711 | |||
712 | # options |
|
712 | # options | |
713 | if i[1]: |
|
713 | if i[1]: | |
714 | option_lists.append(("options", i[1])) |
|
714 | option_lists.append(("options", i[1])) | |
715 |
|
715 | |||
716 | else: |
|
716 | else: | |
717 | # program name |
|
717 | # program name | |
718 | if ui.verbose or with_version: |
|
718 | if ui.verbose or with_version: | |
719 | show_version(ui) |
|
719 | show_version(ui) | |
720 | else: |
|
720 | else: | |
721 | ui.status(_("Mercurial Distributed SCM\n")) |
|
721 | ui.status(_("Mercurial Distributed SCM\n")) | |
722 | ui.status('\n') |
|
722 | ui.status('\n') | |
723 |
|
723 | |||
724 | # list of commands |
|
724 | # list of commands | |
725 | if cmd == "shortlist": |
|
725 | if cmd == "shortlist": | |
726 | ui.status(_('basic commands (use "hg help" ' |
|
726 | ui.status(_('basic commands (use "hg help" ' | |
727 | 'for the full list or option "-v" for details):\n\n')) |
|
727 | 'for the full list or option "-v" for details):\n\n')) | |
728 | elif ui.verbose: |
|
728 | elif ui.verbose: | |
729 | ui.status(_('list of commands:\n\n')) |
|
729 | ui.status(_('list of commands:\n\n')) | |
730 | else: |
|
730 | else: | |
731 | ui.status(_('list of commands (use "hg help -v" ' |
|
731 | ui.status(_('list of commands (use "hg help -v" ' | |
732 | 'to show aliases and global options):\n\n')) |
|
732 | 'to show aliases and global options):\n\n')) | |
733 |
|
733 | |||
734 | h = {} |
|
734 | h = {} | |
735 | cmds = {} |
|
735 | cmds = {} | |
736 | for c, e in table.items(): |
|
736 | for c, e in table.items(): | |
737 | f = c.split("|")[0] |
|
737 | f = c.split("|")[0] | |
738 | if cmd == "shortlist" and not f.startswith("^"): |
|
738 | if cmd == "shortlist" and not f.startswith("^"): | |
739 | continue |
|
739 | continue | |
740 | f = f.lstrip("^") |
|
740 | f = f.lstrip("^") | |
741 | if not ui.debugflag and f.startswith("debug"): |
|
741 | if not ui.debugflag and f.startswith("debug"): | |
742 | continue |
|
742 | continue | |
743 | doc = e[0].__doc__ |
|
743 | doc = e[0].__doc__ | |
744 | if not doc: |
|
744 | if not doc: | |
745 | doc = _("(No help text available)") |
|
745 | doc = _("(No help text available)") | |
746 | h[f] = doc.splitlines(0)[0].rstrip() |
|
746 | h[f] = doc.splitlines(0)[0].rstrip() | |
747 | cmds[f] = c.lstrip("^") |
|
747 | cmds[f] = c.lstrip("^") | |
748 |
|
748 | |||
749 | fns = h.keys() |
|
749 | fns = h.keys() | |
750 | fns.sort() |
|
750 | fns.sort() | |
751 | m = max(map(len, fns)) |
|
751 | m = max(map(len, fns)) | |
752 | for f in fns: |
|
752 | for f in fns: | |
753 | if ui.verbose: |
|
753 | if ui.verbose: | |
754 | commands = cmds[f].replace("|",", ") |
|
754 | commands = cmds[f].replace("|",", ") | |
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
756 | else: |
|
756 | else: | |
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
758 |
|
758 | |||
759 | # global options |
|
759 | # global options | |
760 | if ui.verbose: |
|
760 | if ui.verbose: | |
761 | option_lists.append(("global options", globalopts)) |
|
761 | option_lists.append(("global options", globalopts)) | |
762 |
|
762 | |||
763 | # list all option lists |
|
763 | # list all option lists | |
764 | opt_output = [] |
|
764 | opt_output = [] | |
765 | for title, options in option_lists: |
|
765 | for title, options in option_lists: | |
766 | opt_output.append(("\n%s:\n" % title, None)) |
|
766 | opt_output.append(("\n%s:\n" % title, None)) | |
767 | for shortopt, longopt, default, desc in options: |
|
767 | for shortopt, longopt, default, desc in options: | |
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
769 | longopt and " --%s" % longopt), |
|
769 | longopt and " --%s" % longopt), | |
770 | "%s%s" % (desc, |
|
770 | "%s%s" % (desc, | |
771 | default |
|
771 | default | |
772 | and _(" (default: %s)") % default |
|
772 | and _(" (default: %s)") % default | |
773 | or ""))) |
|
773 | or ""))) | |
774 |
|
774 | |||
775 | if opt_output: |
|
775 | if opt_output: | |
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
777 | for first, second in opt_output: |
|
777 | for first, second in opt_output: | |
778 | if second: |
|
778 | if second: | |
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
780 | else: |
|
780 | else: | |
781 | ui.write("%s\n" % first) |
|
781 | ui.write("%s\n" % first) | |
782 |
|
782 | |||
783 | # Commands start here, listed alphabetically |
|
783 | # Commands start here, listed alphabetically | |
784 |
|
784 | |||
785 | def add(ui, repo, *pats, **opts): |
|
785 | def add(ui, repo, *pats, **opts): | |
786 | """add the specified files on the next commit |
|
786 | """add the specified files on the next commit | |
787 |
|
787 | |||
788 | Schedule files to be version controlled and added to the repository. |
|
788 | Schedule files to be version controlled and added to the repository. | |
789 |
|
789 | |||
790 | The files will be added to the repository at the next commit. |
|
790 | The files will be added to the repository at the next commit. | |
791 |
|
791 | |||
792 | If no names are given, add all files in the repository. |
|
792 | If no names are given, add all files in the repository. | |
793 | """ |
|
793 | """ | |
794 |
|
794 | |||
795 | names = [] |
|
795 | names = [] | |
796 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
796 | for src, abs, rel, exact in walk(repo, pats, opts): | |
797 | if exact: |
|
797 | if exact: | |
798 | if ui.verbose: |
|
798 | if ui.verbose: | |
799 | ui.status(_('adding %s\n') % rel) |
|
799 | ui.status(_('adding %s\n') % rel) | |
800 | names.append(abs) |
|
800 | names.append(abs) | |
801 | elif repo.dirstate.state(abs) == '?': |
|
801 | elif repo.dirstate.state(abs) == '?': | |
802 | ui.status(_('adding %s\n') % rel) |
|
802 | ui.status(_('adding %s\n') % rel) | |
803 | names.append(abs) |
|
803 | names.append(abs) | |
804 | repo.add(names) |
|
804 | repo.add(names) | |
805 |
|
805 | |||
806 | def addremove(ui, repo, *pats, **opts): |
|
806 | def addremove(ui, repo, *pats, **opts): | |
807 | """add all new files, delete all missing files |
|
807 | """add all new files, delete all missing files | |
808 |
|
808 | |||
809 | Add all new files and remove all missing files from the repository. |
|
809 | Add all new files and remove all missing files from the repository. | |
810 |
|
810 | |||
811 | New files are ignored if they match any of the patterns in .hgignore. As |
|
811 | New files are ignored if they match any of the patterns in .hgignore. As | |
812 | with add, these changes take effect at the next commit. |
|
812 | with add, these changes take effect at the next commit. | |
813 | """ |
|
813 | """ | |
814 | return addremove_lock(ui, repo, pats, opts) |
|
814 | return addremove_lock(ui, repo, pats, opts) | |
815 |
|
815 | |||
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
817 | add, remove = [], [] |
|
817 | add, remove = [], [] | |
818 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
818 | for src, abs, rel, exact in walk(repo, pats, opts): | |
819 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
819 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
820 | add.append(abs) |
|
820 | add.append(abs) | |
821 | if ui.verbose or not exact: |
|
821 | if ui.verbose or not exact: | |
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
824 | remove.append(abs) |
|
824 | remove.append(abs) | |
825 | if ui.verbose or not exact: |
|
825 | if ui.verbose or not exact: | |
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
827 | repo.add(add, wlock=wlock) |
|
827 | repo.add(add, wlock=wlock) | |
828 | repo.remove(remove, wlock=wlock) |
|
828 | repo.remove(remove, wlock=wlock) | |
829 |
|
829 | |||
830 | def annotate(ui, repo, *pats, **opts): |
|
830 | def annotate(ui, repo, *pats, **opts): | |
831 | """show changeset information per file line |
|
831 | """show changeset information per file line | |
832 |
|
832 | |||
833 | List changes in files, showing the revision id responsible for each line |
|
833 | List changes in files, showing the revision id responsible for each line | |
834 |
|
834 | |||
835 | This command is useful to discover who did a change or when a change took |
|
835 | This command is useful to discover who did a change or when a change took | |
836 | place. |
|
836 | place. | |
837 |
|
837 | |||
838 | Without the -a option, annotate will avoid processing files it |
|
838 | Without the -a option, annotate will avoid processing files it | |
839 | detects as binary. With -a, annotate will generate an annotation |
|
839 | detects as binary. With -a, annotate will generate an annotation | |
840 | anyway, probably with undesirable results. |
|
840 | anyway, probably with undesirable results. | |
841 | """ |
|
841 | """ | |
842 | def getnode(rev): |
|
842 | def getnode(rev): | |
843 | return short(repo.changelog.node(rev)) |
|
843 | return short(repo.changelog.node(rev)) | |
844 |
|
844 | |||
845 | ucache = {} |
|
845 | ucache = {} | |
846 | def getname(rev): |
|
846 | def getname(rev): | |
847 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
847 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
848 | return trimuser(ui, cl[1], rev, ucache) |
|
848 | return trimuser(ui, cl[1], rev, ucache) | |
849 |
|
849 | |||
850 | dcache = {} |
|
850 | dcache = {} | |
851 | def getdate(rev): |
|
851 | def getdate(rev): | |
852 | datestr = dcache.get(rev) |
|
852 | datestr = dcache.get(rev) | |
853 | if datestr is None: |
|
853 | if datestr is None: | |
854 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
854 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
855 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
855 | datestr = dcache[rev] = util.datestr(cl[2]) | |
856 | return datestr |
|
856 | return datestr | |
857 |
|
857 | |||
858 | if not pats: |
|
858 | if not pats: | |
859 | raise util.Abort(_('at least one file name or pattern required')) |
|
859 | raise util.Abort(_('at least one file name or pattern required')) | |
860 |
|
860 | |||
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
862 | ['date', getdate]] |
|
862 | ['date', getdate]] | |
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
864 | opts['number'] = 1 |
|
864 | opts['number'] = 1 | |
865 |
|
865 | |||
866 | if opts['rev']: |
|
866 | if opts['rev']: | |
867 | node = repo.changelog.lookup(opts['rev']) |
|
867 | node = repo.changelog.lookup(opts['rev']) | |
868 | else: |
|
868 | else: | |
869 | node = repo.dirstate.parents()[0] |
|
869 | node = repo.dirstate.parents()[0] | |
870 | change = repo.changelog.read(node) |
|
870 | change = repo.changelog.read(node) | |
871 | mmap = repo.manifest.read(change[0]) |
|
871 | mmap = repo.manifest.read(change[0]) | |
872 |
|
872 | |||
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
874 | f = repo.file(abs) |
|
874 | f = repo.file(abs) | |
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
877 | continue |
|
877 | continue | |
878 |
|
878 | |||
879 | lines = f.annotate(mmap[abs]) |
|
879 | lines = f.annotate(mmap[abs]) | |
880 | pieces = [] |
|
880 | pieces = [] | |
881 |
|
881 | |||
882 | for o, f in opmap: |
|
882 | for o, f in opmap: | |
883 | if opts[o]: |
|
883 | if opts[o]: | |
884 | l = [f(n) for n, dummy in lines] |
|
884 | l = [f(n) for n, dummy in lines] | |
885 | if l: |
|
885 | if l: | |
886 | m = max(map(len, l)) |
|
886 | m = max(map(len, l)) | |
887 | pieces.append(["%*s" % (m, x) for x in l]) |
|
887 | pieces.append(["%*s" % (m, x) for x in l]) | |
888 |
|
888 | |||
889 | if pieces: |
|
889 | if pieces: | |
890 | for p, l in zip(zip(*pieces), lines): |
|
890 | for p, l in zip(zip(*pieces), lines): | |
891 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
891 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
892 |
|
892 | |||
893 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
893 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
894 | """create a changegroup file |
|
894 | """create a changegroup file | |
895 |
|
895 | |||
896 | Generate a compressed changegroup file collecting all changesets |
|
896 | Generate a compressed changegroup file collecting all changesets | |
897 | not found in the other repository. |
|
897 | not found in the other repository. | |
898 |
|
898 | |||
899 | This file can then be transferred using conventional means and |
|
899 | This file can then be transferred using conventional means and | |
900 | applied to another repository with the unbundle command. This is |
|
900 | applied to another repository with the unbundle command. This is | |
901 | useful when native push and pull are not available or when |
|
901 | useful when native push and pull are not available or when | |
902 | exporting an entire repository is undesirable. The standard file |
|
902 | exporting an entire repository is undesirable. The standard file | |
903 | extension is ".hg". |
|
903 | extension is ".hg". | |
904 |
|
904 | |||
905 | Unlike import/export, this exactly preserves all changeset |
|
905 | Unlike import/export, this exactly preserves all changeset | |
906 | contents including permissions, rename data, and revision history. |
|
906 | contents including permissions, rename data, and revision history. | |
907 | """ |
|
907 | """ | |
908 | dest = ui.expandpath(dest) |
|
908 | dest = ui.expandpath(dest) | |
909 | other = hg.repository(ui, dest) |
|
909 | other = hg.repository(ui, dest) | |
910 | o = repo.findoutgoing(other, force=opts['force']) |
|
910 | o = repo.findoutgoing(other, force=opts['force']) | |
911 | cg = repo.changegroup(o, 'bundle') |
|
911 | cg = repo.changegroup(o, 'bundle') | |
912 | write_bundle(cg, fname) |
|
912 | write_bundle(cg, fname) | |
913 |
|
913 | |||
914 | def cat(ui, repo, file1, *pats, **opts): |
|
914 | def cat(ui, repo, file1, *pats, **opts): | |
915 | """output the latest or given revisions of files |
|
915 | """output the latest or given revisions of files | |
916 |
|
916 | |||
917 | Print the specified files as they were at the given revision. |
|
917 | Print the specified files as they were at the given revision. | |
918 | If no revision is given then the tip is used. |
|
918 | If no revision is given then the tip is used. | |
919 |
|
919 | |||
920 | Output may be to a file, in which case the name of the file is |
|
920 | Output may be to a file, in which case the name of the file is | |
921 | given using a format string. The formatting rules are the same as |
|
921 | given using a format string. The formatting rules are the same as | |
922 | for the export command, with the following additions: |
|
922 | for the export command, with the following additions: | |
923 |
|
923 | |||
924 | %s basename of file being printed |
|
924 | %s basename of file being printed | |
925 | %d dirname of file being printed, or '.' if in repo root |
|
925 | %d dirname of file being printed, or '.' if in repo root | |
926 | %p root-relative path name of file being printed |
|
926 | %p root-relative path name of file being printed | |
927 | """ |
|
927 | """ | |
928 | mf = {} |
|
928 | mf = {} | |
929 | rev = opts['rev'] |
|
929 | rev = opts['rev'] | |
930 | if rev: |
|
930 | if rev: | |
931 | node = repo.lookup(rev) |
|
931 | node = repo.lookup(rev) | |
932 | else: |
|
932 | else: | |
933 | node = repo.changelog.tip() |
|
933 | node = repo.changelog.tip() | |
934 | change = repo.changelog.read(node) |
|
934 | change = repo.changelog.read(node) | |
935 | mf = repo.manifest.read(change[0]) |
|
935 | mf = repo.manifest.read(change[0]) | |
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
937 | r = repo.file(abs) |
|
937 | r = repo.file(abs) | |
938 | n = mf[abs] |
|
938 | n = mf[abs] | |
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
940 | fp.write(r.read(n)) |
|
940 | fp.write(r.read(n)) | |
941 |
|
941 | |||
942 | def clone(ui, source, dest=None, **opts): |
|
942 | def clone(ui, source, dest=None, **opts): | |
943 | """make a copy of an existing repository |
|
943 | """make a copy of an existing repository | |
944 |
|
944 | |||
945 | Create a copy of an existing repository in a new directory. |
|
945 | Create a copy of an existing repository in a new directory. | |
946 |
|
946 | |||
947 | If no destination directory name is specified, it defaults to the |
|
947 | If no destination directory name is specified, it defaults to the | |
948 | basename of the source. |
|
948 | basename of the source. | |
949 |
|
949 | |||
950 | The location of the source is added to the new repository's |
|
950 | The location of the source is added to the new repository's | |
951 | .hg/hgrc file, as the default to be used for future pulls. |
|
951 | .hg/hgrc file, as the default to be used for future pulls. | |
952 |
|
952 | |||
953 | For efficiency, hardlinks are used for cloning whenever the source |
|
953 | For efficiency, hardlinks are used for cloning whenever the source | |
954 | and destination are on the same filesystem. Some filesystems, |
|
954 | and destination are on the same filesystem. Some filesystems, | |
955 | such as AFS, implement hardlinking incorrectly, but do not report |
|
955 | such as AFS, implement hardlinking incorrectly, but do not report | |
956 | errors. In these cases, use the --pull option to avoid |
|
956 | errors. In these cases, use the --pull option to avoid | |
957 | hardlinking. |
|
957 | hardlinking. | |
958 |
|
958 | |||
959 | See pull for valid source format details. |
|
959 | See pull for valid source format details. | |
960 | """ |
|
960 | """ | |
961 | if dest is None: |
|
961 | if dest is None: | |
962 | dest = os.path.basename(os.path.normpath(source)) |
|
962 | dest = os.path.basename(os.path.normpath(source)) | |
963 |
|
963 | |||
964 | if os.path.exists(dest): |
|
964 | if os.path.exists(dest): | |
965 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
965 | raise util.Abort(_("destination '%s' already exists"), dest) | |
966 |
|
966 | |||
967 | dest = os.path.realpath(dest) |
|
967 | dest = os.path.realpath(dest) | |
968 |
|
968 | |||
969 | class Dircleanup(object): |
|
969 | class Dircleanup(object): | |
970 | def __init__(self, dir_): |
|
970 | def __init__(self, dir_): | |
971 | self.rmtree = shutil.rmtree |
|
971 | self.rmtree = shutil.rmtree | |
972 | self.dir_ = dir_ |
|
972 | self.dir_ = dir_ | |
973 | os.mkdir(dir_) |
|
973 | os.mkdir(dir_) | |
974 | def close(self): |
|
974 | def close(self): | |
975 | self.dir_ = None |
|
975 | self.dir_ = None | |
976 | def __del__(self): |
|
976 | def __del__(self): | |
977 | if self.dir_: |
|
977 | if self.dir_: | |
978 | self.rmtree(self.dir_, True) |
|
978 | self.rmtree(self.dir_, True) | |
979 |
|
979 | |||
980 | if opts['ssh']: |
|
980 | if opts['ssh']: | |
981 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
981 | ui.setconfig("ui", "ssh", opts['ssh']) | |
982 | if opts['remotecmd']: |
|
982 | if opts['remotecmd']: | |
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
984 |
|
984 | |||
985 | source = ui.expandpath(source) |
|
985 | source = ui.expandpath(source) | |
986 |
|
986 | |||
987 | d = Dircleanup(dest) |
|
987 | d = Dircleanup(dest) | |
988 | abspath = source |
|
988 | abspath = source | |
989 | other = hg.repository(ui, source) |
|
989 | other = hg.repository(ui, source) | |
990 |
|
990 | |||
991 | copy = False |
|
991 | copy = False | |
992 | if other.dev() != -1: |
|
992 | if other.dev() != -1: | |
993 | abspath = os.path.abspath(source) |
|
993 | abspath = os.path.abspath(source) | |
994 | if not opts['pull'] and not opts['rev']: |
|
994 | if not opts['pull'] and not opts['rev']: | |
995 | copy = True |
|
995 | copy = True | |
996 |
|
996 | |||
997 | if copy: |
|
997 | if copy: | |
998 | try: |
|
998 | try: | |
999 | # we use a lock here because if we race with commit, we |
|
999 | # we use a lock here because if we race with commit, we | |
1000 | # can end up with extra data in the cloned revlogs that's |
|
1000 | # can end up with extra data in the cloned revlogs that's | |
1001 | # not pointed to by changesets, thus causing verify to |
|
1001 | # not pointed to by changesets, thus causing verify to | |
1002 | # fail |
|
1002 | # fail | |
1003 | l1 = other.lock() |
|
1003 | l1 = other.lock() | |
1004 | except lock.LockException: |
|
1004 | except lock.LockException: | |
1005 | copy = False |
|
1005 | copy = False | |
1006 |
|
1006 | |||
1007 | if copy: |
|
1007 | if copy: | |
1008 | # we lock here to avoid premature writing to the target |
|
1008 | # we lock here to avoid premature writing to the target | |
1009 | os.mkdir(os.path.join(dest, ".hg")) |
|
1009 | os.mkdir(os.path.join(dest, ".hg")) | |
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
1011 |
|
1011 | |||
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
1013 | for f in files.split(): |
|
1013 | for f in files.split(): | |
1014 | src = os.path.join(source, ".hg", f) |
|
1014 | src = os.path.join(source, ".hg", f) | |
1015 | dst = os.path.join(dest, ".hg", f) |
|
1015 | dst = os.path.join(dest, ".hg", f) | |
1016 | try: |
|
1016 | try: | |
1017 | util.copyfiles(src, dst) |
|
1017 | util.copyfiles(src, dst) | |
1018 | except OSError, inst: |
|
1018 | except OSError, inst: | |
1019 | if inst.errno != errno.ENOENT: |
|
1019 | if inst.errno != errno.ENOENT: | |
1020 | raise |
|
1020 | raise | |
1021 |
|
1021 | |||
1022 | repo = hg.repository(ui, dest) |
|
1022 | repo = hg.repository(ui, dest) | |
1023 |
|
1023 | |||
1024 | else: |
|
1024 | else: | |
1025 | revs = None |
|
1025 | revs = None | |
1026 | if opts['rev']: |
|
1026 | if opts['rev']: | |
1027 | if not other.local(): |
|
1027 | if not other.local(): | |
1028 | error = _("clone -r not supported yet for remote repositories.") |
|
1028 | error = _("clone -r not supported yet for remote repositories.") | |
1029 | raise util.Abort(error) |
|
1029 | raise util.Abort(error) | |
1030 | else: |
|
1030 | else: | |
1031 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1031 | revs = [other.lookup(rev) for rev in opts['rev']] | |
1032 | repo = hg.repository(ui, dest, create=1) |
|
1032 | repo = hg.repository(ui, dest, create=1) | |
1033 | repo.pull(other, heads = revs) |
|
1033 | repo.pull(other, heads = revs) | |
1034 |
|
1034 | |||
1035 | f = repo.opener("hgrc", "w", text=True) |
|
1035 | f = repo.opener("hgrc", "w", text=True) | |
1036 | f.write("[paths]\n") |
|
1036 | f.write("[paths]\n") | |
1037 | f.write("default = %s\n" % abspath) |
|
1037 | f.write("default = %s\n" % abspath) | |
1038 | f.close() |
|
1038 | f.close() | |
1039 |
|
1039 | |||
1040 | if not opts['noupdate']: |
|
1040 | if not opts['noupdate']: | |
1041 | update(repo.ui, repo) |
|
1041 | update(repo.ui, repo) | |
1042 |
|
1042 | |||
1043 | d.close() |
|
1043 | d.close() | |
1044 |
|
1044 | |||
1045 | def commit(ui, repo, *pats, **opts): |
|
1045 | def commit(ui, repo, *pats, **opts): | |
1046 | """commit the specified files or all outstanding changes |
|
1046 | """commit the specified files or all outstanding changes | |
1047 |
|
1047 | |||
1048 | Commit changes to the given files into the repository. |
|
1048 | Commit changes to the given files into the repository. | |
1049 |
|
1049 | |||
1050 | If a list of files is omitted, all changes reported by "hg status" |
|
1050 | If a list of files is omitted, all changes reported by "hg status" | |
1051 | will be committed. |
|
1051 | will be committed. | |
1052 |
|
1052 | |||
1053 | If no commit message is specified, the editor configured in your hgrc |
|
1053 | If no commit message is specified, the editor configured in your hgrc | |
1054 | or in the EDITOR environment variable is started to enter a message. |
|
1054 | or in the EDITOR environment variable is started to enter a message. | |
1055 | """ |
|
1055 | """ | |
1056 | message = opts['message'] |
|
1056 | message = opts['message'] | |
1057 | logfile = opts['logfile'] |
|
1057 | logfile = opts['logfile'] | |
1058 |
|
1058 | |||
1059 | if message and logfile: |
|
1059 | if message and logfile: | |
1060 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1060 | raise util.Abort(_('options --message and --logfile are mutually ' | |
1061 | 'exclusive')) |
|
1061 | 'exclusive')) | |
1062 | if not message and logfile: |
|
1062 | if not message and logfile: | |
1063 | try: |
|
1063 | try: | |
1064 | if logfile == '-': |
|
1064 | if logfile == '-': | |
1065 | message = sys.stdin.read() |
|
1065 | message = sys.stdin.read() | |
1066 | else: |
|
1066 | else: | |
1067 | message = open(logfile).read() |
|
1067 | message = open(logfile).read() | |
1068 | except IOError, inst: |
|
1068 | except IOError, inst: | |
1069 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1069 | raise util.Abort(_("can't read commit message '%s': %s") % | |
1070 | (logfile, inst.strerror)) |
|
1070 | (logfile, inst.strerror)) | |
1071 |
|
1071 | |||
1072 | if opts['addremove']: |
|
1072 | if opts['addremove']: | |
1073 | addremove(ui, repo, *pats, **opts) |
|
1073 | addremove(ui, repo, *pats, **opts) | |
1074 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1074 | fns, match, anypats = matchpats(repo, pats, opts) | |
1075 | if pats: |
|
1075 | if pats: | |
1076 | modified, added, removed, deleted, unknown = ( |
|
1076 | modified, added, removed, deleted, unknown = ( | |
1077 | repo.changes(files=fns, match=match)) |
|
1077 | repo.changes(files=fns, match=match)) | |
1078 | files = modified + added + removed |
|
1078 | files = modified + added + removed | |
1079 | else: |
|
1079 | else: | |
1080 | files = [] |
|
1080 | files = [] | |
1081 | try: |
|
1081 | try: | |
1082 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
1082 | repo.commit(files, message, opts['user'], opts['date'], match) | |
1083 | except ValueError, inst: |
|
1083 | except ValueError, inst: | |
1084 | raise util.Abort(str(inst)) |
|
1084 | raise util.Abort(str(inst)) | |
1085 |
|
1085 | |||
1086 | def docopy(ui, repo, pats, opts, wlock): |
|
1086 | def docopy(ui, repo, pats, opts, wlock): | |
1087 | # called with the repo lock held |
|
1087 | # called with the repo lock held | |
1088 | cwd = repo.getcwd() |
|
1088 | cwd = repo.getcwd() | |
1089 | errors = 0 |
|
1089 | errors = 0 | |
1090 | copied = [] |
|
1090 | copied = [] | |
1091 | targets = {} |
|
1091 | targets = {} | |
1092 |
|
1092 | |||
1093 | def okaytocopy(abs, rel, exact): |
|
1093 | def okaytocopy(abs, rel, exact): | |
1094 | reasons = {'?': _('is not managed'), |
|
1094 | reasons = {'?': _('is not managed'), | |
1095 | 'a': _('has been marked for add'), |
|
1095 | 'a': _('has been marked for add'), | |
1096 | 'r': _('has been marked for remove')} |
|
1096 | 'r': _('has been marked for remove')} | |
1097 | state = repo.dirstate.state(abs) |
|
1097 | state = repo.dirstate.state(abs) | |
1098 | reason = reasons.get(state) |
|
1098 | reason = reasons.get(state) | |
1099 | if reason: |
|
1099 | if reason: | |
1100 | if state == 'a': |
|
1100 | if state == 'a': | |
1101 | origsrc = repo.dirstate.copied(abs) |
|
1101 | origsrc = repo.dirstate.copied(abs) | |
1102 | if origsrc is not None: |
|
1102 | if origsrc is not None: | |
1103 | return origsrc |
|
1103 | return origsrc | |
1104 | if exact: |
|
1104 | if exact: | |
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
1106 | else: |
|
1106 | else: | |
1107 | return abs |
|
1107 | return abs | |
1108 |
|
1108 | |||
1109 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1109 | def copy(origsrc, abssrc, relsrc, target, exact): | |
1110 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1110 | abstarget = util.canonpath(repo.root, cwd, target) | |
1111 | reltarget = util.pathto(cwd, abstarget) |
|
1111 | reltarget = util.pathto(cwd, abstarget) | |
1112 | prevsrc = targets.get(abstarget) |
|
1112 | prevsrc = targets.get(abstarget) | |
1113 | if prevsrc is not None: |
|
1113 | if prevsrc is not None: | |
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
1115 | (reltarget, abssrc, prevsrc)) |
|
1115 | (reltarget, abssrc, prevsrc)) | |
1116 | return |
|
1116 | return | |
1117 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1117 | if (not opts['after'] and os.path.exists(reltarget) or | |
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
1119 | if not opts['force']: |
|
1119 | if not opts['force']: | |
1120 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1120 | ui.warn(_('%s: not overwriting - file exists\n') % | |
1121 | reltarget) |
|
1121 | reltarget) | |
1122 | return |
|
1122 | return | |
1123 | if not opts['after']: |
|
1123 | if not opts['after']: | |
1124 | os.unlink(reltarget) |
|
1124 | os.unlink(reltarget) | |
1125 | if opts['after']: |
|
1125 | if opts['after']: | |
1126 | if not os.path.exists(reltarget): |
|
1126 | if not os.path.exists(reltarget): | |
1127 | return |
|
1127 | return | |
1128 | else: |
|
1128 | else: | |
1129 | targetdir = os.path.dirname(reltarget) or '.' |
|
1129 | targetdir = os.path.dirname(reltarget) or '.' | |
1130 | if not os.path.isdir(targetdir): |
|
1130 | if not os.path.isdir(targetdir): | |
1131 | os.makedirs(targetdir) |
|
1131 | os.makedirs(targetdir) | |
1132 | try: |
|
1132 | try: | |
1133 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1133 | restore = repo.dirstate.state(abstarget) == 'r' | |
1134 | if restore: |
|
1134 | if restore: | |
1135 | repo.undelete([abstarget], wlock) |
|
1135 | repo.undelete([abstarget], wlock) | |
1136 | try: |
|
1136 | try: | |
1137 | shutil.copyfile(relsrc, reltarget) |
|
1137 | shutil.copyfile(relsrc, reltarget) | |
1138 | shutil.copymode(relsrc, reltarget) |
|
1138 | shutil.copymode(relsrc, reltarget) | |
1139 | restore = False |
|
1139 | restore = False | |
1140 | finally: |
|
1140 | finally: | |
1141 | if restore: |
|
1141 | if restore: | |
1142 | repo.remove([abstarget], wlock) |
|
1142 | repo.remove([abstarget], wlock) | |
1143 | except shutil.Error, inst: |
|
1143 | except shutil.Error, inst: | |
1144 | raise util.Abort(str(inst)) |
|
1144 | raise util.Abort(str(inst)) | |
1145 | except IOError, inst: |
|
1145 | except IOError, inst: | |
1146 | if inst.errno == errno.ENOENT: |
|
1146 | if inst.errno == errno.ENOENT: | |
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1148 | else: |
|
1148 | else: | |
1149 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1149 | ui.warn(_('%s: cannot copy - %s\n') % | |
1150 | (relsrc, inst.strerror)) |
|
1150 | (relsrc, inst.strerror)) | |
1151 | errors += 1 |
|
1151 | errors += 1 | |
1152 | return |
|
1152 | return | |
1153 | if ui.verbose or not exact: |
|
1153 | if ui.verbose or not exact: | |
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1155 | targets[abstarget] = abssrc |
|
1155 | targets[abstarget] = abssrc | |
1156 | if abstarget != origsrc: |
|
1156 | if abstarget != origsrc: | |
1157 | repo.copy(origsrc, abstarget, wlock) |
|
1157 | repo.copy(origsrc, abstarget, wlock) | |
1158 | copied.append((abssrc, relsrc, exact)) |
|
1158 | copied.append((abssrc, relsrc, exact)) | |
1159 |
|
1159 | |||
1160 | def targetpathfn(pat, dest, srcs): |
|
1160 | def targetpathfn(pat, dest, srcs): | |
1161 | if os.path.isdir(pat): |
|
1161 | if os.path.isdir(pat): | |
1162 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1162 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1163 | if destdirexists: |
|
1163 | if destdirexists: | |
1164 | striplen = len(os.path.split(abspfx)[0]) |
|
1164 | striplen = len(os.path.split(abspfx)[0]) | |
1165 | else: |
|
1165 | else: | |
1166 | striplen = len(abspfx) |
|
1166 | striplen = len(abspfx) | |
1167 | if striplen: |
|
1167 | if striplen: | |
1168 | striplen += len(os.sep) |
|
1168 | striplen += len(os.sep) | |
1169 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1169 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1170 | elif destdirexists: |
|
1170 | elif destdirexists: | |
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1172 | else: |
|
1172 | else: | |
1173 | res = lambda p: dest |
|
1173 | res = lambda p: dest | |
1174 | return res |
|
1174 | return res | |
1175 |
|
1175 | |||
1176 | def targetpathafterfn(pat, dest, srcs): |
|
1176 | def targetpathafterfn(pat, dest, srcs): | |
1177 | if util.patkind(pat, None)[0]: |
|
1177 | if util.patkind(pat, None)[0]: | |
1178 | # a mercurial pattern |
|
1178 | # a mercurial pattern | |
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1180 | else: |
|
1180 | else: | |
1181 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1181 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1182 | if len(abspfx) < len(srcs[0][0]): |
|
1182 | if len(abspfx) < len(srcs[0][0]): | |
1183 | # A directory. Either the target path contains the last |
|
1183 | # A directory. Either the target path contains the last | |
1184 | # component of the source path or it does not. |
|
1184 | # component of the source path or it does not. | |
1185 | def evalpath(striplen): |
|
1185 | def evalpath(striplen): | |
1186 | score = 0 |
|
1186 | score = 0 | |
1187 | for s in srcs: |
|
1187 | for s in srcs: | |
1188 | t = os.path.join(dest, s[0][striplen:]) |
|
1188 | t = os.path.join(dest, s[0][striplen:]) | |
1189 | if os.path.exists(t): |
|
1189 | if os.path.exists(t): | |
1190 | score += 1 |
|
1190 | score += 1 | |
1191 | return score |
|
1191 | return score | |
1192 |
|
1192 | |||
1193 | striplen = len(abspfx) |
|
1193 | striplen = len(abspfx) | |
1194 | if striplen: |
|
1194 | if striplen: | |
1195 | striplen += len(os.sep) |
|
1195 | striplen += len(os.sep) | |
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1197 | score = evalpath(striplen) |
|
1197 | score = evalpath(striplen) | |
1198 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1198 | striplen1 = len(os.path.split(abspfx)[0]) | |
1199 | if striplen1: |
|
1199 | if striplen1: | |
1200 | striplen1 += len(os.sep) |
|
1200 | striplen1 += len(os.sep) | |
1201 | if evalpath(striplen1) > score: |
|
1201 | if evalpath(striplen1) > score: | |
1202 | striplen = striplen1 |
|
1202 | striplen = striplen1 | |
1203 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1203 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1204 | else: |
|
1204 | else: | |
1205 | # a file |
|
1205 | # a file | |
1206 | if destdirexists: |
|
1206 | if destdirexists: | |
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1208 | else: |
|
1208 | else: | |
1209 | res = lambda p: dest |
|
1209 | res = lambda p: dest | |
1210 | return res |
|
1210 | return res | |
1211 |
|
1211 | |||
1212 |
|
1212 | |||
1213 | pats = list(pats) |
|
1213 | pats = list(pats) | |
1214 | if not pats: |
|
1214 | if not pats: | |
1215 | raise util.Abort(_('no source or destination specified')) |
|
1215 | raise util.Abort(_('no source or destination specified')) | |
1216 | if len(pats) == 1: |
|
1216 | if len(pats) == 1: | |
1217 | raise util.Abort(_('no destination specified')) |
|
1217 | raise util.Abort(_('no destination specified')) | |
1218 | dest = pats.pop() |
|
1218 | dest = pats.pop() | |
1219 | destdirexists = os.path.isdir(dest) |
|
1219 | destdirexists = os.path.isdir(dest) | |
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1221 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1221 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1222 | 'existing directory')) |
|
1222 | 'existing directory')) | |
1223 | if opts['after']: |
|
1223 | if opts['after']: | |
1224 | tfn = targetpathafterfn |
|
1224 | tfn = targetpathafterfn | |
1225 | else: |
|
1225 | else: | |
1226 | tfn = targetpathfn |
|
1226 | tfn = targetpathfn | |
1227 | copylist = [] |
|
1227 | copylist = [] | |
1228 | for pat in pats: |
|
1228 | for pat in pats: | |
1229 | srcs = [] |
|
1229 | srcs = [] | |
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1232 | if origsrc: |
|
1232 | if origsrc: | |
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1234 | if not srcs: |
|
1234 | if not srcs: | |
1235 | continue |
|
1235 | continue | |
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1237 | if not copylist: |
|
1237 | if not copylist: | |
1238 | raise util.Abort(_('no files to copy')) |
|
1238 | raise util.Abort(_('no files to copy')) | |
1239 |
|
1239 | |||
1240 | for targetpath, srcs in copylist: |
|
1240 | for targetpath, srcs in copylist: | |
1241 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1241 | for origsrc, abssrc, relsrc, exact in srcs: | |
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1243 |
|
1243 | |||
1244 | if errors: |
|
1244 | if errors: | |
1245 | ui.warn(_('(consider using --after)\n')) |
|
1245 | ui.warn(_('(consider using --after)\n')) | |
1246 | return errors, copied |
|
1246 | return errors, copied | |
1247 |
|
1247 | |||
1248 | def copy(ui, repo, *pats, **opts): |
|
1248 | def copy(ui, repo, *pats, **opts): | |
1249 | """mark files as copied for the next commit |
|
1249 | """mark files as copied for the next commit | |
1250 |
|
1250 | |||
1251 | Mark dest as having copies of source files. If dest is a |
|
1251 | Mark dest as having copies of source files. If dest is a | |
1252 | directory, copies are put in that directory. If dest is a file, |
|
1252 | directory, copies are put in that directory. If dest is a file, | |
1253 | there can only be one source. |
|
1253 | there can only be one source. | |
1254 |
|
1254 | |||
1255 | By default, this command copies the contents of files as they |
|
1255 | By default, this command copies the contents of files as they | |
1256 | stand in the working directory. If invoked with --after, the |
|
1256 | stand in the working directory. If invoked with --after, the | |
1257 | operation is recorded, but no copying is performed. |
|
1257 | operation is recorded, but no copying is performed. | |
1258 |
|
1258 | |||
1259 | This command takes effect in the next commit. |
|
1259 | This command takes effect in the next commit. | |
1260 |
|
1260 | |||
1261 | NOTE: This command should be treated as experimental. While it |
|
1261 | NOTE: This command should be treated as experimental. While it | |
1262 | should properly record copied files, this information is not yet |
|
1262 | should properly record copied files, this information is not yet | |
1263 | fully used by merge, nor fully reported by log. |
|
1263 | fully used by merge, nor fully reported by log. | |
1264 | """ |
|
1264 | """ | |
1265 | wlock = repo.wlock(0) |
|
1265 | wlock = repo.wlock(0) | |
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1267 | return errs |
|
1267 | return errs | |
1268 |
|
1268 | |||
1269 | def debugancestor(ui, index, rev1, rev2): |
|
1269 | def debugancestor(ui, index, rev1, rev2): | |
1270 | """find the ancestor revision of two revisions in a given index""" |
|
1270 | """find the ancestor revision of two revisions in a given index""" | |
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") |
|
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") | |
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1274 |
|
1274 | |||
1275 | def debugcomplete(ui, cmd='', **opts): |
|
1275 | def debugcomplete(ui, cmd='', **opts): | |
1276 | """returns the completion list associated with the given command""" |
|
1276 | """returns the completion list associated with the given command""" | |
1277 |
|
1277 | |||
1278 | if opts['options']: |
|
1278 | if opts['options']: | |
1279 | options = [] |
|
1279 | options = [] | |
1280 | otables = [globalopts] |
|
1280 | otables = [globalopts] | |
1281 | if cmd: |
|
1281 | if cmd: | |
1282 | aliases, entry = find(cmd) |
|
1282 | aliases, entry = find(cmd) | |
1283 | otables.append(entry[1]) |
|
1283 | otables.append(entry[1]) | |
1284 | for t in otables: |
|
1284 | for t in otables: | |
1285 | for o in t: |
|
1285 | for o in t: | |
1286 | if o[0]: |
|
1286 | if o[0]: | |
1287 | options.append('-%s' % o[0]) |
|
1287 | options.append('-%s' % o[0]) | |
1288 | options.append('--%s' % o[1]) |
|
1288 | options.append('--%s' % o[1]) | |
1289 | ui.write("%s\n" % "\n".join(options)) |
|
1289 | ui.write("%s\n" % "\n".join(options)) | |
1290 | return |
|
1290 | return | |
1291 |
|
1291 | |||
1292 | clist = findpossible(cmd).keys() |
|
1292 | clist = findpossible(cmd).keys() | |
1293 | clist.sort() |
|
1293 | clist.sort() | |
1294 | ui.write("%s\n" % "\n".join(clist)) |
|
1294 | ui.write("%s\n" % "\n".join(clist)) | |
1295 |
|
1295 | |||
1296 | def debugrebuildstate(ui, repo, rev=None): |
|
1296 | def debugrebuildstate(ui, repo, rev=None): | |
1297 | """rebuild the dirstate as it would look like for the given revision""" |
|
1297 | """rebuild the dirstate as it would look like for the given revision""" | |
1298 | if not rev: |
|
1298 | if not rev: | |
1299 | rev = repo.changelog.tip() |
|
1299 | rev = repo.changelog.tip() | |
1300 | else: |
|
1300 | else: | |
1301 | rev = repo.lookup(rev) |
|
1301 | rev = repo.lookup(rev) | |
1302 | change = repo.changelog.read(rev) |
|
1302 | change = repo.changelog.read(rev) | |
1303 | n = change[0] |
|
1303 | n = change[0] | |
1304 | files = repo.manifest.readflags(n) |
|
1304 | files = repo.manifest.readflags(n) | |
1305 | wlock = repo.wlock() |
|
1305 | wlock = repo.wlock() | |
1306 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1306 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1307 |
|
1307 | |||
1308 | def debugcheckstate(ui, repo): |
|
1308 | def debugcheckstate(ui, repo): | |
1309 | """validate the correctness of the current dirstate""" |
|
1309 | """validate the correctness of the current dirstate""" | |
1310 | parent1, parent2 = repo.dirstate.parents() |
|
1310 | parent1, parent2 = repo.dirstate.parents() | |
1311 | repo.dirstate.read() |
|
1311 | repo.dirstate.read() | |
1312 | dc = repo.dirstate.map |
|
1312 | dc = repo.dirstate.map | |
1313 | keys = dc.keys() |
|
1313 | keys = dc.keys() | |
1314 | keys.sort() |
|
1314 | keys.sort() | |
1315 | m1n = repo.changelog.read(parent1)[0] |
|
1315 | m1n = repo.changelog.read(parent1)[0] | |
1316 | m2n = repo.changelog.read(parent2)[0] |
|
1316 | m2n = repo.changelog.read(parent2)[0] | |
1317 | m1 = repo.manifest.read(m1n) |
|
1317 | m1 = repo.manifest.read(m1n) | |
1318 | m2 = repo.manifest.read(m2n) |
|
1318 | m2 = repo.manifest.read(m2n) | |
1319 | errors = 0 |
|
1319 | errors = 0 | |
1320 | for f in dc: |
|
1320 | for f in dc: | |
1321 | state = repo.dirstate.state(f) |
|
1321 | state = repo.dirstate.state(f) | |
1322 | if state in "nr" and f not in m1: |
|
1322 | if state in "nr" and f not in m1: | |
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1324 | errors += 1 |
|
1324 | errors += 1 | |
1325 | if state in "a" and f in m1: |
|
1325 | if state in "a" and f in m1: | |
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1327 | errors += 1 |
|
1327 | errors += 1 | |
1328 | if state in "m" and f not in m1 and f not in m2: |
|
1328 | if state in "m" and f not in m1 and f not in m2: | |
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1330 | (f, state)) |
|
1330 | (f, state)) | |
1331 | errors += 1 |
|
1331 | errors += 1 | |
1332 | for f in m1: |
|
1332 | for f in m1: | |
1333 | state = repo.dirstate.state(f) |
|
1333 | state = repo.dirstate.state(f) | |
1334 | if state not in "nrm": |
|
1334 | if state not in "nrm": | |
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1336 | errors += 1 |
|
1336 | errors += 1 | |
1337 | if errors: |
|
1337 | if errors: | |
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1339 | raise util.Abort(error) |
|
1339 | raise util.Abort(error) | |
1340 |
|
1340 | |||
1341 | def debugconfig(ui, repo): |
|
1341 | def debugconfig(ui, repo): | |
1342 | """show combined config settings from all hgrc files""" |
|
1342 | """show combined config settings from all hgrc files""" | |
1343 | for section, name, value in ui.walkconfig(): |
|
1343 | for section, name, value in ui.walkconfig(): | |
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1345 |
|
1345 | |||
1346 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1346 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1347 | """manually set the parents of the current working directory |
|
1347 | """manually set the parents of the current working directory | |
1348 |
|
1348 | |||
1349 | This is useful for writing repository conversion tools, but should |
|
1349 | This is useful for writing repository conversion tools, but should | |
1350 | be used with care. |
|
1350 | be used with care. | |
1351 | """ |
|
1351 | """ | |
1352 |
|
1352 | |||
1353 | if not rev2: |
|
1353 | if not rev2: | |
1354 | rev2 = hex(nullid) |
|
1354 | rev2 = hex(nullid) | |
1355 |
|
1355 | |||
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1357 |
|
1357 | |||
1358 | def debugstate(ui, repo): |
|
1358 | def debugstate(ui, repo): | |
1359 | """show the contents of the current dirstate""" |
|
1359 | """show the contents of the current dirstate""" | |
1360 | repo.dirstate.read() |
|
1360 | repo.dirstate.read() | |
1361 | dc = repo.dirstate.map |
|
1361 | dc = repo.dirstate.map | |
1362 | keys = dc.keys() |
|
1362 | keys = dc.keys() | |
1363 | keys.sort() |
|
1363 | keys.sort() | |
1364 | for file_ in keys: |
|
1364 | for file_ in keys: | |
1365 | ui.write("%c %3o %10d %s %s\n" |
|
1365 | ui.write("%c %3o %10d %s %s\n" | |
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1367 | time.strftime("%x %X", |
|
1367 | time.strftime("%x %X", | |
1368 | time.localtime(dc[file_][3])), file_)) |
|
1368 | time.localtime(dc[file_][3])), file_)) | |
1369 | for f in repo.dirstate.copies: |
|
1369 | for f in repo.dirstate.copies: | |
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1371 |
|
1371 | |||
1372 | def debugdata(ui, file_, rev): |
|
1372 | def debugdata(ui, file_, rev): | |
1373 | """dump the contents of an data file revision""" |
|
1373 | """dump the contents of an data file revision""" | |
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1375 | file_[:-2] + ".i", file_) |
|
1375 | file_[:-2] + ".i", file_) | |
1376 | try: |
|
1376 | try: | |
1377 | ui.write(r.revision(r.lookup(rev))) |
|
1377 | ui.write(r.revision(r.lookup(rev))) | |
1378 | except KeyError: |
|
1378 | except KeyError: | |
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1380 |
|
1380 | |||
1381 | def debugindex(ui, file_): |
|
1381 | def debugindex(ui, file_): | |
1382 | """dump the contents of an index file""" |
|
1382 | """dump the contents of an index file""" | |
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1384 | ui.write(" rev offset length base linkrev" + |
|
1384 | ui.write(" rev offset length base linkrev" + | |
1385 | " nodeid p1 p2\n") |
|
1385 | " nodeid p1 p2\n") | |
1386 | for i in range(r.count()): |
|
1386 | for i in range(r.count()): | |
1387 | e = r.index[i] |
|
1387 | e = r.index[i] | |
1388 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1388 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1389 | i, e[0], e[1], e[2], e[3], |
|
1389 | i, e[0], e[1], e[2], e[3], | |
1390 | short(e[6]), short(e[4]), short(e[5]))) |
|
1390 | short(e[6]), short(e[4]), short(e[5]))) | |
1391 |
|
1391 | |||
1392 | def debugindexdot(ui, file_): |
|
1392 | def debugindexdot(ui, file_): | |
1393 | """dump an index DAG as a .dot file""" |
|
1393 | """dump an index DAG as a .dot file""" | |
1394 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1394 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1395 | ui.write("digraph G {\n") |
|
1395 | ui.write("digraph G {\n") | |
1396 | for i in range(r.count()): |
|
1396 | for i in range(r.count()): | |
1397 | e = r.index[i] |
|
1397 | e = r.index[i] | |
1398 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1398 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1399 | if e[5] != nullid: |
|
1399 | if e[5] != nullid: | |
1400 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1400 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1401 | ui.write("}\n") |
|
1401 | ui.write("}\n") | |
1402 |
|
1402 | |||
1403 | def debugrename(ui, repo, file, rev=None): |
|
1403 | def debugrename(ui, repo, file, rev=None): | |
1404 | """dump rename information""" |
|
1404 | """dump rename information""" | |
1405 | r = repo.file(relpath(repo, [file])[0]) |
|
1405 | r = repo.file(relpath(repo, [file])[0]) | |
1406 | if rev: |
|
1406 | if rev: | |
1407 | try: |
|
1407 | try: | |
1408 | # assume all revision numbers are for changesets |
|
1408 | # assume all revision numbers are for changesets | |
1409 | n = repo.lookup(rev) |
|
1409 | n = repo.lookup(rev) | |
1410 | change = repo.changelog.read(n) |
|
1410 | change = repo.changelog.read(n) | |
1411 | m = repo.manifest.read(change[0]) |
|
1411 | m = repo.manifest.read(change[0]) | |
1412 | n = m[relpath(repo, [file])[0]] |
|
1412 | n = m[relpath(repo, [file])[0]] | |
1413 | except (hg.RepoError, KeyError): |
|
1413 | except (hg.RepoError, KeyError): | |
1414 | n = r.lookup(rev) |
|
1414 | n = r.lookup(rev) | |
1415 | else: |
|
1415 | else: | |
1416 | n = r.tip() |
|
1416 | n = r.tip() | |
1417 | m = r.renamed(n) |
|
1417 | m = r.renamed(n) | |
1418 | if m: |
|
1418 | if m: | |
1419 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1419 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1420 | else: |
|
1420 | else: | |
1421 | ui.write(_("not renamed\n")) |
|
1421 | ui.write(_("not renamed\n")) | |
1422 |
|
1422 | |||
1423 | def debugwalk(ui, repo, *pats, **opts): |
|
1423 | def debugwalk(ui, repo, *pats, **opts): | |
1424 | """show how files match on given patterns""" |
|
1424 | """show how files match on given patterns""" | |
1425 | items = list(walk(repo, pats, opts)) |
|
1425 | items = list(walk(repo, pats, opts)) | |
1426 | if not items: |
|
1426 | if not items: | |
1427 | return |
|
1427 | return | |
1428 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1428 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1429 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1429 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1430 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1430 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1431 | for src, abs, rel, exact in items: |
|
1431 | for src, abs, rel, exact in items: | |
1432 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1432 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1433 | ui.write("%s\n" % line.rstrip()) |
|
1433 | ui.write("%s\n" % line.rstrip()) | |
1434 |
|
1434 | |||
1435 | def diff(ui, repo, *pats, **opts): |
|
1435 | def diff(ui, repo, *pats, **opts): | |
1436 | """diff repository (or selected files) |
|
1436 | """diff repository (or selected files) | |
1437 |
|
1437 | |||
1438 | Show differences between revisions for the specified files. |
|
1438 | Show differences between revisions for the specified files. | |
1439 |
|
1439 | |||
1440 | Differences between files are shown using the unified diff format. |
|
1440 | Differences between files are shown using the unified diff format. | |
1441 |
|
1441 | |||
1442 | When two revision arguments are given, then changes are shown |
|
1442 | When two revision arguments are given, then changes are shown | |
1443 | between those revisions. If only one revision is specified then |
|
1443 | between those revisions. If only one revision is specified then | |
1444 | that revision is compared to the working directory, and, when no |
|
1444 | that revision is compared to the working directory, and, when no | |
1445 | revisions are specified, the working directory files are compared |
|
1445 | revisions are specified, the working directory files are compared | |
1446 | to its parent. |
|
1446 | to its parent. | |
1447 |
|
1447 | |||
1448 | Without the -a option, diff will avoid generating diffs of files |
|
1448 | Without the -a option, diff will avoid generating diffs of files | |
1449 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1449 | it detects as binary. With -a, diff will generate a diff anyway, | |
1450 | probably with undesirable results. |
|
1450 | probably with undesirable results. | |
1451 | """ |
|
1451 | """ | |
1452 | node1, node2 = None, None |
|
1452 | node1, node2 = None, None | |
1453 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1453 | revs = [repo.lookup(x) for x in opts['rev']] | |
1454 |
|
1454 | |||
1455 | if len(revs) > 0: |
|
1455 | if len(revs) > 0: | |
1456 | node1 = revs[0] |
|
1456 | node1 = revs[0] | |
1457 | if len(revs) > 1: |
|
1457 | if len(revs) > 1: | |
1458 | node2 = revs[1] |
|
1458 | node2 = revs[1] | |
1459 | if len(revs) > 2: |
|
1459 | if len(revs) > 2: | |
1460 | raise util.Abort(_("too many revisions to diff")) |
|
1460 | raise util.Abort(_("too many revisions to diff")) | |
1461 |
|
1461 | |||
1462 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1462 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1463 |
|
1463 | |||
1464 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1464 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1465 | text=opts['text'], opts=opts) |
|
1465 | text=opts['text'], opts=opts) | |
1466 |
|
1466 | |||
1467 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1467 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1468 | node = repo.lookup(changeset) |
|
1468 | node = repo.lookup(changeset) | |
1469 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1469 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1470 | if opts['switch_parent']: |
|
1470 | if opts['switch_parent']: | |
1471 | parents.reverse() |
|
1471 | parents.reverse() | |
1472 | prev = (parents and parents[0]) or nullid |
|
1472 | prev = (parents and parents[0]) or nullid | |
1473 | change = repo.changelog.read(node) |
|
1473 | change = repo.changelog.read(node) | |
1474 |
|
1474 | |||
1475 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1475 | fp = make_file(repo, repo.changelog, opts['output'], | |
1476 | node=node, total=total, seqno=seqno, |
|
1476 | node=node, total=total, seqno=seqno, | |
1477 | revwidth=revwidth) |
|
1477 | revwidth=revwidth) | |
1478 | if fp != sys.stdout: |
|
1478 | if fp != sys.stdout: | |
1479 | ui.note("%s\n" % fp.name) |
|
1479 | ui.note("%s\n" % fp.name) | |
1480 |
|
1480 | |||
1481 | fp.write("# HG changeset patch\n") |
|
1481 | fp.write("# HG changeset patch\n") | |
1482 | fp.write("# User %s\n" % change[1]) |
|
1482 | fp.write("# User %s\n" % change[1]) | |
1483 | fp.write("# Node ID %s\n" % hex(node)) |
|
1483 | fp.write("# Node ID %s\n" % hex(node)) | |
1484 | fp.write("# Parent %s\n" % hex(prev)) |
|
1484 | fp.write("# Parent %s\n" % hex(prev)) | |
1485 | if len(parents) > 1: |
|
1485 | if len(parents) > 1: | |
1486 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1486 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1487 | fp.write(change[4].rstrip()) |
|
1487 | fp.write(change[4].rstrip()) | |
1488 | fp.write("\n\n") |
|
1488 | fp.write("\n\n") | |
1489 |
|
1489 | |||
1490 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1490 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1491 | if fp != sys.stdout: |
|
1491 | if fp != sys.stdout: | |
1492 | fp.close() |
|
1492 | fp.close() | |
1493 |
|
1493 | |||
1494 | def export(ui, repo, *changesets, **opts): |
|
1494 | def export(ui, repo, *changesets, **opts): | |
1495 | """dump the header and diffs for one or more changesets |
|
1495 | """dump the header and diffs for one or more changesets | |
1496 |
|
1496 | |||
1497 | Print the changeset header and diffs for one or more revisions. |
|
1497 | Print the changeset header and diffs for one or more revisions. | |
1498 |
|
1498 | |||
1499 | The information shown in the changeset header is: author, |
|
1499 | The information shown in the changeset header is: author, | |
1500 | changeset hash, parent and commit comment. |
|
1500 | changeset hash, parent and commit comment. | |
1501 |
|
1501 | |||
1502 | Output may be to a file, in which case the name of the file is |
|
1502 | Output may be to a file, in which case the name of the file is | |
1503 | given using a format string. The formatting rules are as follows: |
|
1503 | given using a format string. The formatting rules are as follows: | |
1504 |
|
1504 | |||
1505 | %% literal "%" character |
|
1505 | %% literal "%" character | |
1506 | %H changeset hash (40 bytes of hexadecimal) |
|
1506 | %H changeset hash (40 bytes of hexadecimal) | |
1507 | %N number of patches being generated |
|
1507 | %N number of patches being generated | |
1508 | %R changeset revision number |
|
1508 | %R changeset revision number | |
1509 | %b basename of the exporting repository |
|
1509 | %b basename of the exporting repository | |
1510 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1510 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1511 | %n zero-padded sequence number, starting at 1 |
|
1511 | %n zero-padded sequence number, starting at 1 | |
1512 | %r zero-padded changeset revision number |
|
1512 | %r zero-padded changeset revision number | |
1513 |
|
1513 | |||
1514 | Without the -a option, export will avoid generating diffs of files |
|
1514 | Without the -a option, export will avoid generating diffs of files | |
1515 | it detects as binary. With -a, export will generate a diff anyway, |
|
1515 | it detects as binary. With -a, export will generate a diff anyway, | |
1516 | probably with undesirable results. |
|
1516 | probably with undesirable results. | |
1517 |
|
1517 | |||
1518 | With the --switch-parent option, the diff will be against the second |
|
1518 | With the --switch-parent option, the diff will be against the second | |
1519 | parent. It can be useful to review a merge. |
|
1519 | parent. It can be useful to review a merge. | |
1520 | """ |
|
1520 | """ | |
1521 | if not changesets: |
|
1521 | if not changesets: | |
1522 | raise util.Abort(_("export requires at least one changeset")) |
|
1522 | raise util.Abort(_("export requires at least one changeset")) | |
1523 | seqno = 0 |
|
1523 | seqno = 0 | |
1524 | revs = list(revrange(ui, repo, changesets)) |
|
1524 | revs = list(revrange(ui, repo, changesets)) | |
1525 | total = len(revs) |
|
1525 | total = len(revs) | |
1526 | revwidth = max(map(len, revs)) |
|
1526 | revwidth = max(map(len, revs)) | |
1527 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1527 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1528 | ui.note(msg) |
|
1528 | ui.note(msg) | |
1529 | for cset in revs: |
|
1529 | for cset in revs: | |
1530 | seqno += 1 |
|
1530 | seqno += 1 | |
1531 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1531 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1532 |
|
1532 | |||
1533 | def forget(ui, repo, *pats, **opts): |
|
1533 | def forget(ui, repo, *pats, **opts): | |
1534 | """don't add the specified files on the next commit |
|
1534 | """don't add the specified files on the next commit | |
1535 |
|
1535 | |||
1536 | Undo an 'hg add' scheduled for the next commit. |
|
1536 | Undo an 'hg add' scheduled for the next commit. | |
1537 | """ |
|
1537 | """ | |
1538 | forget = [] |
|
1538 | forget = [] | |
1539 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1539 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1540 | if repo.dirstate.state(abs) == 'a': |
|
1540 | if repo.dirstate.state(abs) == 'a': | |
1541 | forget.append(abs) |
|
1541 | forget.append(abs) | |
1542 | if ui.verbose or not exact: |
|
1542 | if ui.verbose or not exact: | |
1543 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1543 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1544 | repo.forget(forget) |
|
1544 | repo.forget(forget) | |
1545 |
|
1545 | |||
1546 | def grep(ui, repo, pattern, *pats, **opts): |
|
1546 | def grep(ui, repo, pattern, *pats, **opts): | |
1547 | """search for a pattern in specified files and revisions |
|
1547 | """search for a pattern in specified files and revisions | |
1548 |
|
1548 | |||
1549 | Search revisions of files for a regular expression. |
|
1549 | Search revisions of files for a regular expression. | |
1550 |
|
1550 | |||
1551 | This command behaves differently than Unix grep. It only accepts |
|
1551 | This command behaves differently than Unix grep. It only accepts | |
1552 | Python/Perl regexps. It searches repository history, not the |
|
1552 | Python/Perl regexps. It searches repository history, not the | |
1553 | working directory. It always prints the revision number in which |
|
1553 | working directory. It always prints the revision number in which | |
1554 | a match appears. |
|
1554 | a match appears. | |
1555 |
|
1555 | |||
1556 | By default, grep only prints output for the first revision of a |
|
1556 | By default, grep only prints output for the first revision of a | |
1557 | file in which it finds a match. To get it to print every revision |
|
1557 | file in which it finds a match. To get it to print every revision | |
1558 | that contains a change in match status ("-" for a match that |
|
1558 | that contains a change in match status ("-" for a match that | |
1559 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1559 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1560 | use the --all flag. |
|
1560 | use the --all flag. | |
1561 | """ |
|
1561 | """ | |
1562 | reflags = 0 |
|
1562 | reflags = 0 | |
1563 | if opts['ignore_case']: |
|
1563 | if opts['ignore_case']: | |
1564 | reflags |= re.I |
|
1564 | reflags |= re.I | |
1565 | regexp = re.compile(pattern, reflags) |
|
1565 | regexp = re.compile(pattern, reflags) | |
1566 | sep, eol = ':', '\n' |
|
1566 | sep, eol = ':', '\n' | |
1567 | if opts['print0']: |
|
1567 | if opts['print0']: | |
1568 | sep = eol = '\0' |
|
1568 | sep = eol = '\0' | |
1569 |
|
1569 | |||
1570 | fcache = {} |
|
1570 | fcache = {} | |
1571 | def getfile(fn): |
|
1571 | def getfile(fn): | |
1572 | if fn not in fcache: |
|
1572 | if fn not in fcache: | |
1573 | fcache[fn] = repo.file(fn) |
|
1573 | fcache[fn] = repo.file(fn) | |
1574 | return fcache[fn] |
|
1574 | return fcache[fn] | |
1575 |
|
1575 | |||
1576 | def matchlines(body): |
|
1576 | def matchlines(body): | |
1577 | begin = 0 |
|
1577 | begin = 0 | |
1578 | linenum = 0 |
|
1578 | linenum = 0 | |
1579 | while True: |
|
1579 | while True: | |
1580 | match = regexp.search(body, begin) |
|
1580 | match = regexp.search(body, begin) | |
1581 | if not match: |
|
1581 | if not match: | |
1582 | break |
|
1582 | break | |
1583 | mstart, mend = match.span() |
|
1583 | mstart, mend = match.span() | |
1584 | linenum += body.count('\n', begin, mstart) + 1 |
|
1584 | linenum += body.count('\n', begin, mstart) + 1 | |
1585 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1585 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1586 | lend = body.find('\n', mend) |
|
1586 | lend = body.find('\n', mend) | |
1587 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1587 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1588 | begin = lend + 1 |
|
1588 | begin = lend + 1 | |
1589 |
|
1589 | |||
1590 | class linestate(object): |
|
1590 | class linestate(object): | |
1591 | def __init__(self, line, linenum, colstart, colend): |
|
1591 | def __init__(self, line, linenum, colstart, colend): | |
1592 | self.line = line |
|
1592 | self.line = line | |
1593 | self.linenum = linenum |
|
1593 | self.linenum = linenum | |
1594 | self.colstart = colstart |
|
1594 | self.colstart = colstart | |
1595 | self.colend = colend |
|
1595 | self.colend = colend | |
1596 | def __eq__(self, other): |
|
1596 | def __eq__(self, other): | |
1597 | return self.line == other.line |
|
1597 | return self.line == other.line | |
1598 | def __hash__(self): |
|
1598 | def __hash__(self): | |
1599 | return hash(self.line) |
|
1599 | return hash(self.line) | |
1600 |
|
1600 | |||
1601 | matches = {} |
|
1601 | matches = {} | |
1602 | def grepbody(fn, rev, body): |
|
1602 | def grepbody(fn, rev, body): | |
1603 | matches[rev].setdefault(fn, {}) |
|
1603 | matches[rev].setdefault(fn, {}) | |
1604 | m = matches[rev][fn] |
|
1604 | m = matches[rev][fn] | |
1605 | for lnum, cstart, cend, line in matchlines(body): |
|
1605 | for lnum, cstart, cend, line in matchlines(body): | |
1606 | s = linestate(line, lnum, cstart, cend) |
|
1606 | s = linestate(line, lnum, cstart, cend) | |
1607 | m[s] = s |
|
1607 | m[s] = s | |
1608 |
|
1608 | |||
1609 | # FIXME: prev isn't used, why ? |
|
1609 | # FIXME: prev isn't used, why ? | |
1610 | prev = {} |
|
1610 | prev = {} | |
1611 | ucache = {} |
|
1611 | ucache = {} | |
1612 | def display(fn, rev, states, prevstates): |
|
1612 | def display(fn, rev, states, prevstates): | |
1613 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1613 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1614 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1614 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1615 | counts = {'-': 0, '+': 0} |
|
1615 | counts = {'-': 0, '+': 0} | |
1616 | filerevmatches = {} |
|
1616 | filerevmatches = {} | |
1617 | for l in diff: |
|
1617 | for l in diff: | |
1618 | if incrementing or not opts['all']: |
|
1618 | if incrementing or not opts['all']: | |
1619 | change = ((l in prevstates) and '-') or '+' |
|
1619 | change = ((l in prevstates) and '-') or '+' | |
1620 | r = rev |
|
1620 | r = rev | |
1621 | else: |
|
1621 | else: | |
1622 | change = ((l in states) and '-') or '+' |
|
1622 | change = ((l in states) and '-') or '+' | |
1623 | r = prev[fn] |
|
1623 | r = prev[fn] | |
1624 | cols = [fn, str(rev)] |
|
1624 | cols = [fn, str(rev)] | |
1625 | if opts['line_number']: |
|
1625 | if opts['line_number']: | |
1626 | cols.append(str(l.linenum)) |
|
1626 | cols.append(str(l.linenum)) | |
1627 | if opts['all']: |
|
1627 | if opts['all']: | |
1628 | cols.append(change) |
|
1628 | cols.append(change) | |
1629 | if opts['user']: |
|
1629 | if opts['user']: | |
1630 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1630 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1631 | ucache)) |
|
1631 | ucache)) | |
1632 | if opts['files_with_matches']: |
|
1632 | if opts['files_with_matches']: | |
1633 | c = (fn, rev) |
|
1633 | c = (fn, rev) | |
1634 | if c in filerevmatches: |
|
1634 | if c in filerevmatches: | |
1635 | continue |
|
1635 | continue | |
1636 | filerevmatches[c] = 1 |
|
1636 | filerevmatches[c] = 1 | |
1637 | else: |
|
1637 | else: | |
1638 | cols.append(l.line) |
|
1638 | cols.append(l.line) | |
1639 | ui.write(sep.join(cols), eol) |
|
1639 | ui.write(sep.join(cols), eol) | |
1640 | counts[change] += 1 |
|
1640 | counts[change] += 1 | |
1641 | return counts['+'], counts['-'] |
|
1641 | return counts['+'], counts['-'] | |
1642 |
|
1642 | |||
1643 | fstate = {} |
|
1643 | fstate = {} | |
1644 | skip = {} |
|
1644 | skip = {} | |
1645 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1645 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1646 | count = 0 |
|
1646 | count = 0 | |
1647 | incrementing = False |
|
1647 | incrementing = False | |
1648 | for st, rev, fns in changeiter: |
|
1648 | for st, rev, fns in changeiter: | |
1649 | if st == 'window': |
|
1649 | if st == 'window': | |
1650 | incrementing = rev |
|
1650 | incrementing = rev | |
1651 | matches.clear() |
|
1651 | matches.clear() | |
1652 | elif st == 'add': |
|
1652 | elif st == 'add': | |
1653 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1653 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1654 | mf = repo.manifest.read(change[0]) |
|
1654 | mf = repo.manifest.read(change[0]) | |
1655 | matches[rev] = {} |
|
1655 | matches[rev] = {} | |
1656 | for fn in fns: |
|
1656 | for fn in fns: | |
1657 | if fn in skip: |
|
1657 | if fn in skip: | |
1658 | continue |
|
1658 | continue | |
1659 | fstate.setdefault(fn, {}) |
|
1659 | fstate.setdefault(fn, {}) | |
1660 | try: |
|
1660 | try: | |
1661 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1661 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1662 | except KeyError: |
|
1662 | except KeyError: | |
1663 | pass |
|
1663 | pass | |
1664 | elif st == 'iter': |
|
1664 | elif st == 'iter': | |
1665 | states = matches[rev].items() |
|
1665 | states = matches[rev].items() | |
1666 | states.sort() |
|
1666 | states.sort() | |
1667 | for fn, m in states: |
|
1667 | for fn, m in states: | |
1668 | if fn in skip: |
|
1668 | if fn in skip: | |
1669 | continue |
|
1669 | continue | |
1670 | if incrementing or not opts['all'] or fstate[fn]: |
|
1670 | if incrementing or not opts['all'] or fstate[fn]: | |
1671 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1671 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1672 | count += pos + neg |
|
1672 | count += pos + neg | |
1673 | if pos and not opts['all']: |
|
1673 | if pos and not opts['all']: | |
1674 | skip[fn] = True |
|
1674 | skip[fn] = True | |
1675 | fstate[fn] = m |
|
1675 | fstate[fn] = m | |
1676 | prev[fn] = rev |
|
1676 | prev[fn] = rev | |
1677 |
|
1677 | |||
1678 | if not incrementing: |
|
1678 | if not incrementing: | |
1679 | fstate = fstate.items() |
|
1679 | fstate = fstate.items() | |
1680 | fstate.sort() |
|
1680 | fstate.sort() | |
1681 | for fn, state in fstate: |
|
1681 | for fn, state in fstate: | |
1682 | if fn in skip: |
|
1682 | if fn in skip: | |
1683 | continue |
|
1683 | continue | |
1684 | display(fn, rev, {}, state) |
|
1684 | display(fn, rev, {}, state) | |
1685 | return (count == 0 and 1) or 0 |
|
1685 | return (count == 0 and 1) or 0 | |
1686 |
|
1686 | |||
1687 | def heads(ui, repo, **opts): |
|
1687 | def heads(ui, repo, **opts): | |
1688 | """show current repository heads |
|
1688 | """show current repository heads | |
1689 |
|
1689 | |||
1690 | Show all repository head changesets. |
|
1690 | Show all repository head changesets. | |
1691 |
|
1691 | |||
1692 | Repository "heads" are changesets that don't have children |
|
1692 | Repository "heads" are changesets that don't have children | |
1693 | changesets. They are where development generally takes place and |
|
1693 | changesets. They are where development generally takes place and | |
1694 | are the usual targets for update and merge operations. |
|
1694 | are the usual targets for update and merge operations. | |
1695 | """ |
|
1695 | """ | |
1696 | if opts['rev']: |
|
1696 | if opts['rev']: | |
1697 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1697 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1698 | else: |
|
1698 | else: | |
1699 | heads = repo.heads() |
|
1699 | heads = repo.heads() | |
1700 | br = None |
|
1700 | br = None | |
1701 | if opts['branches']: |
|
1701 | if opts['branches']: | |
1702 | br = repo.branchlookup(heads) |
|
1702 | br = repo.branchlookup(heads) | |
1703 | displayer = show_changeset(ui, repo, opts) |
|
1703 | displayer = show_changeset(ui, repo, opts) | |
1704 | for n in heads: |
|
1704 | for n in heads: | |
1705 | displayer.show(changenode=n, brinfo=br) |
|
1705 | displayer.show(changenode=n, brinfo=br) | |
1706 |
|
1706 | |||
1707 | def identify(ui, repo): |
|
1707 | def identify(ui, repo): | |
1708 | """print information about the working copy |
|
1708 | """print information about the working copy | |
1709 |
|
1709 | |||
1710 | Print a short summary of the current state of the repo. |
|
1710 | Print a short summary of the current state of the repo. | |
1711 |
|
1711 | |||
1712 | This summary identifies the repository state using one or two parent |
|
1712 | This summary identifies the repository state using one or two parent | |
1713 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1713 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1714 | in the working directory, followed by a list of tags for this revision. |
|
1714 | in the working directory, followed by a list of tags for this revision. | |
1715 | """ |
|
1715 | """ | |
1716 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1716 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1717 | if not parents: |
|
1717 | if not parents: | |
1718 | ui.write(_("unknown\n")) |
|
1718 | ui.write(_("unknown\n")) | |
1719 | return |
|
1719 | return | |
1720 |
|
1720 | |||
1721 | hexfunc = ui.verbose and hex or short |
|
1721 | hexfunc = ui.verbose and hex or short | |
1722 | modified, added, removed, deleted, unknown = repo.changes() |
|
1722 | modified, added, removed, deleted, unknown = repo.changes() | |
1723 | output = ["%s%s" % |
|
1723 | output = ["%s%s" % | |
1724 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1724 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1725 | (modified or added or removed or deleted) and "+" or "")] |
|
1725 | (modified or added or removed or deleted) and "+" or "")] | |
1726 |
|
1726 | |||
1727 | if not ui.quiet: |
|
1727 | if not ui.quiet: | |
1728 | # multiple tags for a single parent separated by '/' |
|
1728 | # multiple tags for a single parent separated by '/' | |
1729 | parenttags = ['/'.join(tags) |
|
1729 | parenttags = ['/'.join(tags) | |
1730 | for tags in map(repo.nodetags, parents) if tags] |
|
1730 | for tags in map(repo.nodetags, parents) if tags] | |
1731 | # tags for multiple parents separated by ' + ' |
|
1731 | # tags for multiple parents separated by ' + ' | |
1732 | if parenttags: |
|
1732 | if parenttags: | |
1733 | output.append(' + '.join(parenttags)) |
|
1733 | output.append(' + '.join(parenttags)) | |
1734 |
|
1734 | |||
1735 | ui.write("%s\n" % ' '.join(output)) |
|
1735 | ui.write("%s\n" % ' '.join(output)) | |
1736 |
|
1736 | |||
1737 | def import_(ui, repo, patch1, *patches, **opts): |
|
1737 | def import_(ui, repo, patch1, *patches, **opts): | |
1738 | """import an ordered set of patches |
|
1738 | """import an ordered set of patches | |
1739 |
|
1739 | |||
1740 | Import a list of patches and commit them individually. |
|
1740 | Import a list of patches and commit them individually. | |
1741 |
|
1741 | |||
1742 | If there are outstanding changes in the working directory, import |
|
1742 | If there are outstanding changes in the working directory, import | |
1743 | will abort unless given the -f flag. |
|
1743 | will abort unless given the -f flag. | |
1744 |
|
1744 | |||
1745 | If a patch looks like a mail message (its first line starts with |
|
1745 | If a patch looks like a mail message (its first line starts with | |
1746 | "From " or looks like an RFC822 header), it will not be applied |
|
1746 | "From " or looks like an RFC822 header), it will not be applied | |
1747 | unless the -f option is used. The importer neither parses nor |
|
1747 | unless the -f option is used. The importer neither parses nor | |
1748 | discards mail headers, so use -f only to override the "mailness" |
|
1748 | discards mail headers, so use -f only to override the "mailness" | |
1749 | safety check, not to import a real mail message. |
|
1749 | safety check, not to import a real mail message. | |
1750 | """ |
|
1750 | """ | |
1751 | patches = (patch1,) + patches |
|
1751 | patches = (patch1,) + patches | |
1752 |
|
1752 | |||
1753 | if not opts['force']: |
|
1753 | if not opts['force']: | |
1754 | modified, added, removed, deleted, unknown = repo.changes() |
|
1754 | modified, added, removed, deleted, unknown = repo.changes() | |
1755 | if modified or added or removed or deleted: |
|
1755 | if modified or added or removed or deleted: | |
1756 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1756 | raise util.Abort(_("outstanding uncommitted changes")) | |
1757 |
|
1757 | |||
1758 | d = opts["base"] |
|
1758 | d = opts["base"] | |
1759 | strip = opts["strip"] |
|
1759 | strip = opts["strip"] | |
1760 |
|
1760 | |||
1761 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1761 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1762 |
|
1762 | |||
1763 | # attempt to detect the start of a patch |
|
1763 | # attempt to detect the start of a patch | |
1764 | # (this heuristic is borrowed from quilt) |
|
1764 | # (this heuristic is borrowed from quilt) | |
1765 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1765 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1766 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1766 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1767 | '(---|\*\*\*)[ \t])') |
|
1767 | '(---|\*\*\*)[ \t])') | |
1768 |
|
1768 | |||
1769 | for patch in patches: |
|
1769 | for patch in patches: | |
1770 | ui.status(_("applying %s\n") % patch) |
|
1770 | ui.status(_("applying %s\n") % patch) | |
1771 | pf = os.path.join(d, patch) |
|
1771 | pf = os.path.join(d, patch) | |
1772 |
|
1772 | |||
1773 | message = [] |
|
1773 | message = [] | |
1774 | user = None |
|
1774 | user = None | |
1775 | hgpatch = False |
|
1775 | hgpatch = False | |
1776 | for line in file(pf): |
|
1776 | for line in file(pf): | |
1777 | line = line.rstrip() |
|
1777 | line = line.rstrip() | |
1778 | if (not message and not hgpatch and |
|
1778 | if (not message and not hgpatch and | |
1779 | mailre.match(line) and not opts['force']): |
|
1779 | mailre.match(line) and not opts['force']): | |
1780 | if len(line) > 35: |
|
1780 | if len(line) > 35: | |
1781 | line = line[:32] + '...' |
|
1781 | line = line[:32] + '...' | |
1782 | raise util.Abort(_('first line looks like a ' |
|
1782 | raise util.Abort(_('first line looks like a ' | |
1783 | 'mail header: ') + line) |
|
1783 | 'mail header: ') + line) | |
1784 | if diffre.match(line): |
|
1784 | if diffre.match(line): | |
1785 | break |
|
1785 | break | |
1786 | elif hgpatch: |
|
1786 | elif hgpatch: | |
1787 | # parse values when importing the result of an hg export |
|
1787 | # parse values when importing the result of an hg export | |
1788 | if line.startswith("# User "): |
|
1788 | if line.startswith("# User "): | |
1789 | user = line[7:] |
|
1789 | user = line[7:] | |
1790 | ui.debug(_('User: %s\n') % user) |
|
1790 | ui.debug(_('User: %s\n') % user) | |
1791 | elif not line.startswith("# ") and line: |
|
1791 | elif not line.startswith("# ") and line: | |
1792 | message.append(line) |
|
1792 | message.append(line) | |
1793 | hgpatch = False |
|
1793 | hgpatch = False | |
1794 | elif line == '# HG changeset patch': |
|
1794 | elif line == '# HG changeset patch': | |
1795 | hgpatch = True |
|
1795 | hgpatch = True | |
1796 | message = [] # We may have collected garbage |
|
1796 | message = [] # We may have collected garbage | |
1797 | else: |
|
1797 | else: | |
1798 | message.append(line) |
|
1798 | message.append(line) | |
1799 |
|
1799 | |||
1800 | # make sure message isn't empty |
|
1800 | # make sure message isn't empty | |
1801 | if not message: |
|
1801 | if not message: | |
1802 | message = _("imported patch %s\n") % patch |
|
1802 | message = _("imported patch %s\n") % patch | |
1803 | else: |
|
1803 | else: | |
1804 | message = "%s\n" % '\n'.join(message) |
|
1804 | message = "%s\n" % '\n'.join(message) | |
1805 | ui.debug(_('message:\n%s\n') % message) |
|
1805 | ui.debug(_('message:\n%s\n') % message) | |
1806 |
|
1806 | |||
1807 | files = util.patch(strip, pf, ui) |
|
1807 | files = util.patch(strip, pf, ui) | |
1808 |
|
1808 | |||
1809 | if len(files) > 0: |
|
1809 | if len(files) > 0: | |
1810 | addremove(ui, repo, *files) |
|
1810 | addremove(ui, repo, *files) | |
1811 | repo.commit(files, message, user) |
|
1811 | repo.commit(files, message, user) | |
1812 |
|
1812 | |||
1813 | def incoming(ui, repo, source="default", **opts): |
|
1813 | def incoming(ui, repo, source="default", **opts): | |
1814 | """show new changesets found in source |
|
1814 | """show new changesets found in source | |
1815 |
|
1815 | |||
1816 | Show new changesets found in the specified path/URL or the default |
|
1816 | Show new changesets found in the specified path/URL or the default | |
1817 | pull location. These are the changesets that would be pulled if a pull |
|
1817 | pull location. These are the changesets that would be pulled if a pull | |
1818 | was requested. |
|
1818 | was requested. | |
1819 |
|
1819 | |||
1820 | For remote repository, using --bundle avoids downloading the changesets |
|
1820 | For remote repository, using --bundle avoids downloading the changesets | |
1821 | twice if the incoming is followed by a pull. |
|
1821 | twice if the incoming is followed by a pull. | |
1822 |
|
1822 | |||
1823 | See pull for valid source format details. |
|
1823 | See pull for valid source format details. | |
1824 | """ |
|
1824 | """ | |
1825 | source = ui.expandpath(source) |
|
1825 | source = ui.expandpath(source) | |
1826 | if opts['ssh']: |
|
1826 | if opts['ssh']: | |
1827 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1827 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1828 | if opts['remotecmd']: |
|
1828 | if opts['remotecmd']: | |
1829 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1829 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1830 |
|
1830 | |||
1831 | other = hg.repository(ui, source) |
|
1831 | other = hg.repository(ui, source) | |
1832 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1832 | incoming = repo.findincoming(other, force=opts["force"]) | |
1833 | if not incoming: |
|
1833 | if not incoming: | |
1834 | ui.status(_("no changes found\n")) |
|
1834 | ui.status(_("no changes found\n")) | |
1835 | return |
|
1835 | return | |
1836 |
|
1836 | |||
1837 | cleanup = None |
|
1837 | cleanup = None | |
1838 | try: |
|
1838 | try: | |
1839 | fname = opts["bundle"] |
|
1839 | fname = opts["bundle"] | |
1840 | if fname or not other.local(): |
|
1840 | if fname or not other.local(): | |
1841 | # create a bundle (uncompressed if other repo is not local) |
|
1841 | # create a bundle (uncompressed if other repo is not local) | |
1842 | cg = other.changegroup(incoming, "incoming") |
|
1842 | cg = other.changegroup(incoming, "incoming") | |
1843 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) |
|
1843 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) | |
1844 | # keep written bundle? |
|
1844 | # keep written bundle? | |
1845 | if opts["bundle"]: |
|
1845 | if opts["bundle"]: | |
1846 | cleanup = None |
|
1846 | cleanup = None | |
1847 | if not other.local(): |
|
1847 | if not other.local(): | |
1848 | # use the created uncompressed bundlerepo |
|
1848 | # use the created uncompressed bundlerepo | |
1849 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1849 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1850 |
|
1850 | |||
1851 | o = other.changelog.nodesbetween(incoming)[0] |
|
1851 | o = other.changelog.nodesbetween(incoming)[0] | |
1852 | if opts['newest_first']: |
|
1852 | if opts['newest_first']: | |
1853 | o.reverse() |
|
1853 | o.reverse() | |
1854 | displayer = show_changeset(ui, other, opts) |
|
1854 | displayer = show_changeset(ui, other, opts) | |
1855 | for n in o: |
|
1855 | for n in o: | |
1856 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1856 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1857 | if opts['no_merges'] and len(parents) == 2: |
|
1857 | if opts['no_merges'] and len(parents) == 2: | |
1858 | continue |
|
1858 | continue | |
1859 | displayer.show(changenode=n) |
|
1859 | displayer.show(changenode=n) | |
1860 | if opts['patch']: |
|
1860 | if opts['patch']: | |
1861 | prev = (parents and parents[0]) or nullid |
|
1861 | prev = (parents and parents[0]) or nullid | |
1862 | dodiff(ui, ui, other, prev, n) |
|
1862 | dodiff(ui, ui, other, prev, n) | |
1863 | ui.write("\n") |
|
1863 | ui.write("\n") | |
1864 | finally: |
|
1864 | finally: | |
1865 | if hasattr(other, 'close'): |
|
1865 | if hasattr(other, 'close'): | |
1866 | other.close() |
|
1866 | other.close() | |
1867 | if cleanup: |
|
1867 | if cleanup: | |
1868 | os.unlink(cleanup) |
|
1868 | os.unlink(cleanup) | |
1869 |
|
1869 | |||
1870 | def init(ui, dest="."): |
|
1870 | def init(ui, dest="."): | |
1871 | """create a new repository in the given directory |
|
1871 | """create a new repository in the given directory | |
1872 |
|
1872 | |||
1873 | Initialize a new repository in the given directory. If the given |
|
1873 | Initialize a new repository in the given directory. If the given | |
1874 | directory does not exist, it is created. |
|
1874 | directory does not exist, it is created. | |
1875 |
|
1875 | |||
1876 | If no directory is given, the current directory is used. |
|
1876 | If no directory is given, the current directory is used. | |
1877 | """ |
|
1877 | """ | |
1878 | if not os.path.exists(dest): |
|
1878 | if not os.path.exists(dest): | |
1879 | os.mkdir(dest) |
|
1879 | os.mkdir(dest) | |
1880 | hg.repository(ui, dest, create=1) |
|
1880 | hg.repository(ui, dest, create=1) | |
1881 |
|
1881 | |||
1882 | def locate(ui, repo, *pats, **opts): |
|
1882 | def locate(ui, repo, *pats, **opts): | |
1883 | """locate files matching specific patterns |
|
1883 | """locate files matching specific patterns | |
1884 |
|
1884 | |||
1885 | Print all files under Mercurial control whose names match the |
|
1885 | Print all files under Mercurial control whose names match the | |
1886 | given patterns. |
|
1886 | given patterns. | |
1887 |
|
1887 | |||
1888 | This command searches the current directory and its |
|
1888 | This command searches the current directory and its | |
1889 | subdirectories. To search an entire repository, move to the root |
|
1889 | subdirectories. To search an entire repository, move to the root | |
1890 | of the repository. |
|
1890 | of the repository. | |
1891 |
|
1891 | |||
1892 | If no patterns are given to match, this command prints all file |
|
1892 | If no patterns are given to match, this command prints all file | |
1893 | names. |
|
1893 | names. | |
1894 |
|
1894 | |||
1895 | If you want to feed the output of this command into the "xargs" |
|
1895 | If you want to feed the output of this command into the "xargs" | |
1896 | command, use the "-0" option to both this command and "xargs". |
|
1896 | command, use the "-0" option to both this command and "xargs". | |
1897 | This will avoid the problem of "xargs" treating single filenames |
|
1897 | This will avoid the problem of "xargs" treating single filenames | |
1898 | that contain white space as multiple filenames. |
|
1898 | that contain white space as multiple filenames. | |
1899 | """ |
|
1899 | """ | |
1900 | end = opts['print0'] and '\0' or '\n' |
|
1900 | end = opts['print0'] and '\0' or '\n' | |
1901 | rev = opts['rev'] |
|
1901 | rev = opts['rev'] | |
1902 | if rev: |
|
1902 | if rev: | |
1903 | node = repo.lookup(rev) |
|
1903 | node = repo.lookup(rev) | |
1904 | else: |
|
1904 | else: | |
1905 | node = None |
|
1905 | node = None | |
1906 |
|
1906 | |||
1907 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1907 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1908 | head='(?:.*/|)'): |
|
1908 | head='(?:.*/|)'): | |
1909 | if not node and repo.dirstate.state(abs) == '?': |
|
1909 | if not node and repo.dirstate.state(abs) == '?': | |
1910 | continue |
|
1910 | continue | |
1911 | if opts['fullpath']: |
|
1911 | if opts['fullpath']: | |
1912 | ui.write(os.path.join(repo.root, abs), end) |
|
1912 | ui.write(os.path.join(repo.root, abs), end) | |
1913 | else: |
|
1913 | else: | |
1914 | ui.write(((pats and rel) or abs), end) |
|
1914 | ui.write(((pats and rel) or abs), end) | |
1915 |
|
1915 | |||
1916 | def log(ui, repo, *pats, **opts): |
|
1916 | def log(ui, repo, *pats, **opts): | |
1917 | """show revision history of entire repository or files |
|
1917 | """show revision history of entire repository or files | |
1918 |
|
1918 | |||
1919 | Print the revision history of the specified files or the entire project. |
|
1919 | Print the revision history of the specified files or the entire project. | |
1920 |
|
1920 | |||
1921 | By default this command outputs: changeset id and hash, tags, |
|
1921 | By default this command outputs: changeset id and hash, tags, | |
1922 | non-trivial parents, user, date and time, and a summary for each |
|
1922 | non-trivial parents, user, date and time, and a summary for each | |
1923 | commit. When the -v/--verbose switch is used, the list of changed |
|
1923 | commit. When the -v/--verbose switch is used, the list of changed | |
1924 | files and full commit message is shown. |
|
1924 | files and full commit message is shown. | |
1925 | """ |
|
1925 | """ | |
1926 | class dui(object): |
|
1926 | class dui(object): | |
1927 | # Implement and delegate some ui protocol. Save hunks of |
|
1927 | # Implement and delegate some ui protocol. Save hunks of | |
1928 | # output for later display in the desired order. |
|
1928 | # output for later display in the desired order. | |
1929 | def __init__(self, ui): |
|
1929 | def __init__(self, ui): | |
1930 | self.ui = ui |
|
1930 | self.ui = ui | |
1931 | self.hunk = {} |
|
1931 | self.hunk = {} | |
1932 | self.header = {} |
|
1932 | self.header = {} | |
1933 | def bump(self, rev): |
|
1933 | def bump(self, rev): | |
1934 | self.rev = rev |
|
1934 | self.rev = rev | |
1935 | self.hunk[rev] = [] |
|
1935 | self.hunk[rev] = [] | |
1936 | self.header[rev] = [] |
|
1936 | self.header[rev] = [] | |
1937 | def note(self, *args): |
|
1937 | def note(self, *args): | |
1938 | if self.verbose: |
|
1938 | if self.verbose: | |
1939 | self.write(*args) |
|
1939 | self.write(*args) | |
1940 | def status(self, *args): |
|
1940 | def status(self, *args): | |
1941 | if not self.quiet: |
|
1941 | if not self.quiet: | |
1942 | self.write(*args) |
|
1942 | self.write(*args) | |
1943 | def write(self, *args): |
|
1943 | def write(self, *args): | |
1944 | self.hunk[self.rev].append(args) |
|
1944 | self.hunk[self.rev].append(args) | |
1945 | def write_header(self, *args): |
|
1945 | def write_header(self, *args): | |
1946 | self.header[self.rev].append(args) |
|
1946 | self.header[self.rev].append(args) | |
1947 | def debug(self, *args): |
|
1947 | def debug(self, *args): | |
1948 | if self.debugflag: |
|
1948 | if self.debugflag: | |
1949 | self.write(*args) |
|
1949 | self.write(*args) | |
1950 | def __getattr__(self, key): |
|
1950 | def __getattr__(self, key): | |
1951 | return getattr(self.ui, key) |
|
1951 | return getattr(self.ui, key) | |
1952 |
|
1952 | |||
1953 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1953 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1954 |
|
1954 | |||
1955 | if opts['limit']: |
|
1955 | if opts['limit']: | |
1956 | try: |
|
1956 | try: | |
1957 | limit = int(opts['limit']) |
|
1957 | limit = int(opts['limit']) | |
1958 | except ValueError: |
|
1958 | except ValueError: | |
1959 | raise util.Abort(_('limit must be a positive integer')) |
|
1959 | raise util.Abort(_('limit must be a positive integer')) | |
1960 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1960 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1961 | else: |
|
1961 | else: | |
1962 | limit = sys.maxint |
|
1962 | limit = sys.maxint | |
1963 | count = 0 |
|
1963 | count = 0 | |
1964 |
|
1964 | |||
1965 | displayer = show_changeset(ui, repo, opts) |
|
1965 | displayer = show_changeset(ui, repo, opts) | |
1966 | for st, rev, fns in changeiter: |
|
1966 | for st, rev, fns in changeiter: | |
1967 | if st == 'window': |
|
1967 | if st == 'window': | |
1968 | du = dui(ui) |
|
1968 | du = dui(ui) | |
1969 | displayer.ui = du |
|
1969 | displayer.ui = du | |
1970 | elif st == 'add': |
|
1970 | elif st == 'add': | |
1971 | du.bump(rev) |
|
1971 | du.bump(rev) | |
1972 | changenode = repo.changelog.node(rev) |
|
1972 | changenode = repo.changelog.node(rev) | |
1973 | parents = [p for p in repo.changelog.parents(changenode) |
|
1973 | parents = [p for p in repo.changelog.parents(changenode) | |
1974 | if p != nullid] |
|
1974 | if p != nullid] | |
1975 | if opts['no_merges'] and len(parents) == 2: |
|
1975 | if opts['no_merges'] and len(parents) == 2: | |
1976 | continue |
|
1976 | continue | |
1977 | if opts['only_merges'] and len(parents) != 2: |
|
1977 | if opts['only_merges'] and len(parents) != 2: | |
1978 | continue |
|
1978 | continue | |
1979 |
|
1979 | |||
1980 | if opts['keyword']: |
|
1980 | if opts['keyword']: | |
1981 | changes = getchange(rev) |
|
1981 | changes = getchange(rev) | |
1982 | miss = 0 |
|
1982 | miss = 0 | |
1983 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1983 | for k in [kw.lower() for kw in opts['keyword']]: | |
1984 | if not (k in changes[1].lower() or |
|
1984 | if not (k in changes[1].lower() or | |
1985 | k in changes[4].lower() or |
|
1985 | k in changes[4].lower() or | |
1986 | k in " ".join(changes[3][:20]).lower()): |
|
1986 | k in " ".join(changes[3][:20]).lower()): | |
1987 | miss = 1 |
|
1987 | miss = 1 | |
1988 | break |
|
1988 | break | |
1989 | if miss: |
|
1989 | if miss: | |
1990 | continue |
|
1990 | continue | |
1991 |
|
1991 | |||
1992 | br = None |
|
1992 | br = None | |
1993 | if opts['branches']: |
|
1993 | if opts['branches']: | |
1994 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1994 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1995 |
|
1995 | |||
1996 | displayer.show(rev, brinfo=br) |
|
1996 | displayer.show(rev, brinfo=br) | |
1997 | if opts['patch']: |
|
1997 | if opts['patch']: | |
1998 | prev = (parents and parents[0]) or nullid |
|
1998 | prev = (parents and parents[0]) or nullid | |
1999 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
1999 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
2000 | du.write("\n\n") |
|
2000 | du.write("\n\n") | |
2001 | elif st == 'iter': |
|
2001 | elif st == 'iter': | |
2002 | if count == limit: break |
|
2002 | if count == limit: break | |
2003 | if du.header[rev]: |
|
2003 | if du.header[rev]: | |
2004 | for args in du.header[rev]: |
|
2004 | for args in du.header[rev]: | |
2005 | ui.write_header(*args) |
|
2005 | ui.write_header(*args) | |
2006 | if du.hunk[rev]: |
|
2006 | if du.hunk[rev]: | |
2007 | count += 1 |
|
2007 | count += 1 | |
2008 | for args in du.hunk[rev]: |
|
2008 | for args in du.hunk[rev]: | |
2009 | ui.write(*args) |
|
2009 | ui.write(*args) | |
2010 |
|
2010 | |||
2011 | def manifest(ui, repo, rev=None): |
|
2011 | def manifest(ui, repo, rev=None): | |
2012 | """output the latest or given revision of the project manifest |
|
2012 | """output the latest or given revision of the project manifest | |
2013 |
|
2013 | |||
2014 | Print a list of version controlled files for the given revision. |
|
2014 | Print a list of version controlled files for the given revision. | |
2015 |
|
2015 | |||
2016 | The manifest is the list of files being version controlled. If no revision |
|
2016 | The manifest is the list of files being version controlled. If no revision | |
2017 | is given then the tip is used. |
|
2017 | is given then the tip is used. | |
2018 | """ |
|
2018 | """ | |
2019 | if rev: |
|
2019 | if rev: | |
2020 | try: |
|
2020 | try: | |
2021 | # assume all revision numbers are for changesets |
|
2021 | # assume all revision numbers are for changesets | |
2022 | n = repo.lookup(rev) |
|
2022 | n = repo.lookup(rev) | |
2023 | change = repo.changelog.read(n) |
|
2023 | change = repo.changelog.read(n) | |
2024 | n = change[0] |
|
2024 | n = change[0] | |
2025 | except hg.RepoError: |
|
2025 | except hg.RepoError: | |
2026 | n = repo.manifest.lookup(rev) |
|
2026 | n = repo.manifest.lookup(rev) | |
2027 | else: |
|
2027 | else: | |
2028 | n = repo.manifest.tip() |
|
2028 | n = repo.manifest.tip() | |
2029 | m = repo.manifest.read(n) |
|
2029 | m = repo.manifest.read(n) | |
2030 | mf = repo.manifest.readflags(n) |
|
2030 | mf = repo.manifest.readflags(n) | |
2031 | files = m.keys() |
|
2031 | files = m.keys() | |
2032 | files.sort() |
|
2032 | files.sort() | |
2033 |
|
2033 | |||
2034 | for f in files: |
|
2034 | for f in files: | |
2035 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
2035 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
2036 |
|
2036 | |||
2037 | def merge(ui, repo, node=None, **opts): |
|
2037 | def merge(ui, repo, node=None, **opts): | |
2038 | """Merge working directory with another revision |
|
2038 | """Merge working directory with another revision | |
2039 |
|
2039 | |||
2040 | Merge the contents of the current working directory and the |
|
2040 | Merge the contents of the current working directory and the | |
2041 | requested revision. Files that changed between either parent are |
|
2041 | requested revision. Files that changed between either parent are | |
2042 | marked as changed for the next commit and a commit must be |
|
2042 | marked as changed for the next commit and a commit must be | |
2043 | performed before any further updates are allowed. |
|
2043 | performed before any further updates are allowed. | |
2044 | """ |
|
2044 | """ | |
2045 | return update(ui, repo, node=node, merge=True, **opts) |
|
2045 | return update(ui, repo, node=node, merge=True, **opts) | |
2046 |
|
2046 | |||
2047 | def outgoing(ui, repo, dest="default-push", **opts): |
|
2047 | def outgoing(ui, repo, dest="default-push", **opts): | |
2048 | """show changesets not found in destination |
|
2048 | """show changesets not found in destination | |
2049 |
|
2049 | |||
2050 | Show changesets not found in the specified destination repository or |
|
2050 | Show changesets not found in the specified destination repository or | |
2051 | the default push location. These are the changesets that would be pushed |
|
2051 | the default push location. These are the changesets that would be pushed | |
2052 | if a push was requested. |
|
2052 | if a push was requested. | |
2053 |
|
2053 | |||
2054 | See pull for valid destination format details. |
|
2054 | See pull for valid destination format details. | |
2055 | """ |
|
2055 | """ | |
2056 | dest = ui.expandpath(dest) |
|
2056 | dest = ui.expandpath(dest) | |
2057 | if opts['ssh']: |
|
2057 | if opts['ssh']: | |
2058 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2058 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2059 | if opts['remotecmd']: |
|
2059 | if opts['remotecmd']: | |
2060 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2060 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2061 |
|
2061 | |||
2062 | other = hg.repository(ui, dest) |
|
2062 | other = hg.repository(ui, dest) | |
2063 | o = repo.findoutgoing(other, force=opts['force']) |
|
2063 | o = repo.findoutgoing(other, force=opts['force']) | |
2064 | if not o: |
|
2064 | if not o: | |
2065 | ui.status(_("no changes found\n")) |
|
2065 | ui.status(_("no changes found\n")) | |
2066 | return |
|
2066 | return | |
2067 | o = repo.changelog.nodesbetween(o)[0] |
|
2067 | o = repo.changelog.nodesbetween(o)[0] | |
2068 | if opts['newest_first']: |
|
2068 | if opts['newest_first']: | |
2069 | o.reverse() |
|
2069 | o.reverse() | |
2070 | displayer = show_changeset(ui, repo, opts) |
|
2070 | displayer = show_changeset(ui, repo, opts) | |
2071 | for n in o: |
|
2071 | for n in o: | |
2072 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2072 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
2073 | if opts['no_merges'] and len(parents) == 2: |
|
2073 | if opts['no_merges'] and len(parents) == 2: | |
2074 | continue |
|
2074 | continue | |
2075 | displayer.show(changenode=n) |
|
2075 | displayer.show(changenode=n) | |
2076 | if opts['patch']: |
|
2076 | if opts['patch']: | |
2077 | prev = (parents and parents[0]) or nullid |
|
2077 | prev = (parents and parents[0]) or nullid | |
2078 | dodiff(ui, ui, repo, prev, n) |
|
2078 | dodiff(ui, ui, repo, prev, n) | |
2079 | ui.write("\n") |
|
2079 | ui.write("\n") | |
2080 |
|
2080 | |||
2081 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
2081 | def parents(ui, repo, rev=None, branches=None, **opts): | |
2082 | """show the parents of the working dir or revision |
|
2082 | """show the parents of the working dir or revision | |
2083 |
|
2083 | |||
2084 | Print the working directory's parent revisions. |
|
2084 | Print the working directory's parent revisions. | |
2085 | """ |
|
2085 | """ | |
2086 | if rev: |
|
2086 | if rev: | |
2087 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2087 | p = repo.changelog.parents(repo.lookup(rev)) | |
2088 | else: |
|
2088 | else: | |
2089 | p = repo.dirstate.parents() |
|
2089 | p = repo.dirstate.parents() | |
2090 |
|
2090 | |||
2091 | br = None |
|
2091 | br = None | |
2092 | if branches is not None: |
|
2092 | if branches is not None: | |
2093 | br = repo.branchlookup(p) |
|
2093 | br = repo.branchlookup(p) | |
2094 | displayer = show_changeset(ui, repo, opts) |
|
2094 | displayer = show_changeset(ui, repo, opts) | |
2095 | for n in p: |
|
2095 | for n in p: | |
2096 | if n != nullid: |
|
2096 | if n != nullid: | |
2097 | displayer.show(changenode=n, brinfo=br) |
|
2097 | displayer.show(changenode=n, brinfo=br) | |
2098 |
|
2098 | |||
2099 | def paths(ui, repo, search=None): |
|
2099 | def paths(ui, repo, search=None): | |
2100 | """show definition of symbolic path names |
|
2100 | """show definition of symbolic path names | |
2101 |
|
2101 | |||
2102 | Show definition of symbolic path name NAME. If no name is given, show |
|
2102 | Show definition of symbolic path name NAME. If no name is given, show | |
2103 | definition of available names. |
|
2103 | definition of available names. | |
2104 |
|
2104 | |||
2105 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2105 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2106 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2106 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2107 | """ |
|
2107 | """ | |
2108 | if search: |
|
2108 | if search: | |
2109 | for name, path in ui.configitems("paths"): |
|
2109 | for name, path in ui.configitems("paths"): | |
2110 | if name == search: |
|
2110 | if name == search: | |
2111 | ui.write("%s\n" % path) |
|
2111 | ui.write("%s\n" % path) | |
2112 | return |
|
2112 | return | |
2113 | ui.warn(_("not found!\n")) |
|
2113 | ui.warn(_("not found!\n")) | |
2114 | return 1 |
|
2114 | return 1 | |
2115 | else: |
|
2115 | else: | |
2116 | for name, path in ui.configitems("paths"): |
|
2116 | for name, path in ui.configitems("paths"): | |
2117 | ui.write("%s = %s\n" % (name, path)) |
|
2117 | ui.write("%s = %s\n" % (name, path)) | |
2118 |
|
2118 | |||
2119 | def postincoming(ui, repo, modheads, optupdate): |
|
2119 | def postincoming(ui, repo, modheads, optupdate): | |
2120 | if modheads == 0: |
|
2120 | if modheads == 0: | |
2121 | return |
|
2121 | return | |
2122 | if optupdate: |
|
2122 | if optupdate: | |
2123 | if modheads == 1: |
|
2123 | if modheads == 1: | |
2124 | return update(ui, repo) |
|
2124 | return update(ui, repo) | |
2125 | else: |
|
2125 | else: | |
2126 | ui.status(_("not updating, since new heads added\n")) |
|
2126 | ui.status(_("not updating, since new heads added\n")) | |
2127 | if modheads > 1: |
|
2127 | if modheads > 1: | |
2128 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2128 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
2129 | else: |
|
2129 | else: | |
2130 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2130 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2131 |
|
2131 | |||
2132 | def pull(ui, repo, source="default", **opts): |
|
2132 | def pull(ui, repo, source="default", **opts): | |
2133 | """pull changes from the specified source |
|
2133 | """pull changes from the specified source | |
2134 |
|
2134 | |||
2135 | Pull changes from a remote repository to a local one. |
|
2135 | Pull changes from a remote repository to a local one. | |
2136 |
|
2136 | |||
2137 | This finds all changes from the repository at the specified path |
|
2137 | This finds all changes from the repository at the specified path | |
2138 | or URL and adds them to the local repository. By default, this |
|
2138 | or URL and adds them to the local repository. By default, this | |
2139 | does not update the copy of the project in the working directory. |
|
2139 | does not update the copy of the project in the working directory. | |
2140 |
|
2140 | |||
2141 | Valid URLs are of the form: |
|
2141 | Valid URLs are of the form: | |
2142 |
|
2142 | |||
2143 | local/filesystem/path |
|
2143 | local/filesystem/path | |
2144 | http://[user@]host[:port][/path] |
|
2144 | http://[user@]host[:port][/path] | |
2145 | https://[user@]host[:port][/path] |
|
2145 | https://[user@]host[:port][/path] | |
2146 | ssh://[user@]host[:port][/path] |
|
2146 | ssh://[user@]host[:port][/path] | |
2147 |
|
2147 | |||
2148 | Some notes about using SSH with Mercurial: |
|
2148 | Some notes about using SSH with Mercurial: | |
2149 | - SSH requires an accessible shell account on the destination machine |
|
2149 | - SSH requires an accessible shell account on the destination machine | |
2150 | and a copy of hg in the remote path or specified with as remotecmd. |
|
2150 | and a copy of hg in the remote path or specified with as remotecmd. | |
2151 | - /path is relative to the remote user's home directory by default. |
|
2151 | - /path is relative to the remote user's home directory by default. | |
2152 | Use two slashes at the start of a path to specify an absolute path. |
|
2152 | Use two slashes at the start of a path to specify an absolute path. | |
2153 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
2153 | - Mercurial doesn't use its own compression via SSH; the right thing | |
2154 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: |
|
2154 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: | |
2155 | Host *.mylocalnetwork.example.com |
|
2155 | Host *.mylocalnetwork.example.com | |
2156 | Compression off |
|
2156 | Compression off | |
2157 | Host * |
|
2157 | Host * | |
2158 | Compression on |
|
2158 | Compression on | |
2159 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
2159 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | |
2160 | with the --ssh command line option. |
|
2160 | with the --ssh command line option. | |
2161 | """ |
|
2161 | """ | |
2162 | source = ui.expandpath(source) |
|
2162 | source = ui.expandpath(source) | |
2163 | ui.status(_('pulling from %s\n') % (source)) |
|
2163 | ui.status(_('pulling from %s\n') % (source)) | |
2164 |
|
2164 | |||
2165 | if opts['ssh']: |
|
2165 | if opts['ssh']: | |
2166 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2166 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2167 | if opts['remotecmd']: |
|
2167 | if opts['remotecmd']: | |
2168 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2168 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2169 |
|
2169 | |||
2170 | other = hg.repository(ui, source) |
|
2170 | other = hg.repository(ui, source) | |
2171 | revs = None |
|
2171 | revs = None | |
2172 | if opts['rev'] and not other.local(): |
|
2172 | if opts['rev'] and not other.local(): | |
2173 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2173 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2174 | elif opts['rev']: |
|
2174 | elif opts['rev']: | |
2175 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2175 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2176 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
2176 | modheads = repo.pull(other, heads=revs, force=opts['force']) | |
2177 | return postincoming(ui, repo, modheads, opts['update']) |
|
2177 | return postincoming(ui, repo, modheads, opts['update']) | |
2178 |
|
2178 | |||
2179 | def push(ui, repo, dest="default-push", **opts): |
|
2179 | def push(ui, repo, dest="default-push", **opts): | |
2180 | """push changes to the specified destination |
|
2180 | """push changes to the specified destination | |
2181 |
|
2181 | |||
2182 | Push changes from the local repository to the given destination. |
|
2182 | Push changes from the local repository to the given destination. | |
2183 |
|
2183 | |||
2184 | This is the symmetrical operation for pull. It helps to move |
|
2184 | This is the symmetrical operation for pull. It helps to move | |
2185 | changes from the current repository to a different one. If the |
|
2185 | changes from the current repository to a different one. If the | |
2186 | destination is local this is identical to a pull in that directory |
|
2186 | destination is local this is identical to a pull in that directory | |
2187 | from the current one. |
|
2187 | from the current one. | |
2188 |
|
2188 | |||
2189 | By default, push will refuse to run if it detects the result would |
|
2189 | By default, push will refuse to run if it detects the result would | |
2190 | increase the number of remote heads. This generally indicates the |
|
2190 | increase the number of remote heads. This generally indicates the | |
2191 | the client has forgotten to sync and merge before pushing. |
|
2191 | the client has forgotten to sync and merge before pushing. | |
2192 |
|
2192 | |||
2193 | Valid URLs are of the form: |
|
2193 | Valid URLs are of the form: | |
2194 |
|
2194 | |||
2195 | local/filesystem/path |
|
2195 | local/filesystem/path | |
2196 | ssh://[user@]host[:port][/path] |
|
2196 | ssh://[user@]host[:port][/path] | |
2197 |
|
2197 | |||
2198 | Look at the help text for the pull command for important details |
|
2198 | Look at the help text for the pull command for important details | |
2199 | about ssh:// URLs. |
|
2199 | about ssh:// URLs. | |
2200 | """ |
|
2200 | """ | |
2201 | dest = ui.expandpath(dest) |
|
2201 | dest = ui.expandpath(dest) | |
2202 | ui.status('pushing to %s\n' % (dest)) |
|
2202 | ui.status('pushing to %s\n' % (dest)) | |
2203 |
|
2203 | |||
2204 | if opts['ssh']: |
|
2204 | if opts['ssh']: | |
2205 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2205 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2206 | if opts['remotecmd']: |
|
2206 | if opts['remotecmd']: | |
2207 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2207 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2208 |
|
2208 | |||
2209 | other = hg.repository(ui, dest) |
|
2209 | other = hg.repository(ui, dest) | |
2210 | revs = None |
|
2210 | revs = None | |
2211 | if opts['rev']: |
|
2211 | if opts['rev']: | |
2212 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2212 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2213 | r = repo.push(other, opts['force'], revs=revs) |
|
2213 | r = repo.push(other, opts['force'], revs=revs) | |
2214 | return r == 0 |
|
2214 | return r == 0 | |
2215 |
|
2215 | |||
2216 | def rawcommit(ui, repo, *flist, **rc): |
|
2216 | def rawcommit(ui, repo, *flist, **rc): | |
2217 | """raw commit interface (DEPRECATED) |
|
2217 | """raw commit interface (DEPRECATED) | |
2218 |
|
2218 | |||
2219 | (DEPRECATED) |
|
2219 | (DEPRECATED) | |
2220 | Lowlevel commit, for use in helper scripts. |
|
2220 | Lowlevel commit, for use in helper scripts. | |
2221 |
|
2221 | |||
2222 | This command is not intended to be used by normal users, as it is |
|
2222 | This command is not intended to be used by normal users, as it is | |
2223 | primarily useful for importing from other SCMs. |
|
2223 | primarily useful for importing from other SCMs. | |
2224 |
|
2224 | |||
2225 | This command is now deprecated and will be removed in a future |
|
2225 | This command is now deprecated and will be removed in a future | |
2226 | release, please use debugsetparents and commit instead. |
|
2226 | release, please use debugsetparents and commit instead. | |
2227 | """ |
|
2227 | """ | |
2228 |
|
2228 | |||
2229 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2229 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2230 |
|
2230 | |||
2231 | message = rc['message'] |
|
2231 | message = rc['message'] | |
2232 | if not message and rc['logfile']: |
|
2232 | if not message and rc['logfile']: | |
2233 | try: |
|
2233 | try: | |
2234 | message = open(rc['logfile']).read() |
|
2234 | message = open(rc['logfile']).read() | |
2235 | except IOError: |
|
2235 | except IOError: | |
2236 | pass |
|
2236 | pass | |
2237 | if not message and not rc['logfile']: |
|
2237 | if not message and not rc['logfile']: | |
2238 | raise util.Abort(_("missing commit message")) |
|
2238 | raise util.Abort(_("missing commit message")) | |
2239 |
|
2239 | |||
2240 | files = relpath(repo, list(flist)) |
|
2240 | files = relpath(repo, list(flist)) | |
2241 | if rc['files']: |
|
2241 | if rc['files']: | |
2242 | files += open(rc['files']).read().splitlines() |
|
2242 | files += open(rc['files']).read().splitlines() | |
2243 |
|
2243 | |||
2244 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2244 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2245 |
|
2245 | |||
2246 | try: |
|
2246 | try: | |
2247 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2247 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2248 | except ValueError, inst: |
|
2248 | except ValueError, inst: | |
2249 | raise util.Abort(str(inst)) |
|
2249 | raise util.Abort(str(inst)) | |
2250 |
|
2250 | |||
2251 | def recover(ui, repo): |
|
2251 | def recover(ui, repo): | |
2252 | """roll back an interrupted transaction |
|
2252 | """roll back an interrupted transaction | |
2253 |
|
2253 | |||
2254 | Recover from an interrupted commit or pull. |
|
2254 | Recover from an interrupted commit or pull. | |
2255 |
|
2255 | |||
2256 | This command tries to fix the repository status after an interrupted |
|
2256 | This command tries to fix the repository status after an interrupted | |
2257 | operation. It should only be necessary when Mercurial suggests it. |
|
2257 | operation. It should only be necessary when Mercurial suggests it. | |
2258 | """ |
|
2258 | """ | |
2259 | if repo.recover(): |
|
2259 | if repo.recover(): | |
2260 | return repo.verify() |
|
2260 | return repo.verify() | |
2261 | return False |
|
2261 | return False | |
2262 |
|
2262 | |||
2263 | def remove(ui, repo, pat, *pats, **opts): |
|
2263 | def remove(ui, repo, pat, *pats, **opts): | |
2264 | """remove the specified files on the next commit |
|
2264 | """remove the specified files on the next commit | |
2265 |
|
2265 | |||
2266 | Schedule the indicated files for removal from the repository. |
|
2266 | Schedule the indicated files for removal from the repository. | |
2267 |
|
2267 | |||
2268 | This command schedules the files to be removed at the next commit. |
|
2268 | This command schedules the files to be removed at the next commit. | |
2269 | This only removes files from the current branch, not from the |
|
2269 | This only removes files from the current branch, not from the | |
2270 | entire project history. If the files still exist in the working |
|
2270 | entire project history. If the files still exist in the working | |
2271 | directory, they will be deleted from it. |
|
2271 | directory, they will be deleted from it. | |
2272 | """ |
|
2272 | """ | |
2273 | names = [] |
|
2273 | names = [] | |
2274 | def okaytoremove(abs, rel, exact): |
|
2274 | def okaytoremove(abs, rel, exact): | |
2275 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
2275 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
2276 | reason = None |
|
2276 | reason = None | |
2277 | if modified and not opts['force']: |
|
2277 | if modified and not opts['force']: | |
2278 | reason = _('is modified') |
|
2278 | reason = _('is modified') | |
2279 | elif added: |
|
2279 | elif added: | |
2280 | reason = _('has been marked for add') |
|
2280 | reason = _('has been marked for add') | |
2281 | elif unknown: |
|
2281 | elif unknown: | |
2282 | reason = _('is not managed') |
|
2282 | reason = _('is not managed') | |
2283 | if reason: |
|
2283 | if reason: | |
2284 | if exact: |
|
2284 | if exact: | |
2285 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2285 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2286 | else: |
|
2286 | else: | |
2287 | return True |
|
2287 | return True | |
2288 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
2288 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
2289 | if okaytoremove(abs, rel, exact): |
|
2289 | if okaytoremove(abs, rel, exact): | |
2290 | if ui.verbose or not exact: |
|
2290 | if ui.verbose or not exact: | |
2291 | ui.status(_('removing %s\n') % rel) |
|
2291 | ui.status(_('removing %s\n') % rel) | |
2292 | names.append(abs) |
|
2292 | names.append(abs) | |
2293 | repo.remove(names, unlink=True) |
|
2293 | repo.remove(names, unlink=True) | |
2294 |
|
2294 | |||
2295 | def rename(ui, repo, *pats, **opts): |
|
2295 | def rename(ui, repo, *pats, **opts): | |
2296 | """rename files; equivalent of copy + remove |
|
2296 | """rename files; equivalent of copy + remove | |
2297 |
|
2297 | |||
2298 | Mark dest as copies of sources; mark sources for deletion. If |
|
2298 | Mark dest as copies of sources; mark sources for deletion. If | |
2299 | dest is a directory, copies are put in that directory. If dest is |
|
2299 | dest is a directory, copies are put in that directory. If dest is | |
2300 | a file, there can only be one source. |
|
2300 | a file, there can only be one source. | |
2301 |
|
2301 | |||
2302 | By default, this command copies the contents of files as they |
|
2302 | By default, this command copies the contents of files as they | |
2303 | stand in the working directory. If invoked with --after, the |
|
2303 | stand in the working directory. If invoked with --after, the | |
2304 | operation is recorded, but no copying is performed. |
|
2304 | operation is recorded, but no copying is performed. | |
2305 |
|
2305 | |||
2306 | This command takes effect in the next commit. |
|
2306 | This command takes effect in the next commit. | |
2307 |
|
2307 | |||
2308 | NOTE: This command should be treated as experimental. While it |
|
2308 | NOTE: This command should be treated as experimental. While it | |
2309 | should properly record rename files, this information is not yet |
|
2309 | should properly record rename files, this information is not yet | |
2310 | fully used by merge, nor fully reported by log. |
|
2310 | fully used by merge, nor fully reported by log. | |
2311 | """ |
|
2311 | """ | |
2312 | wlock = repo.wlock(0) |
|
2312 | wlock = repo.wlock(0) | |
2313 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2313 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2314 | names = [] |
|
2314 | names = [] | |
2315 | for abs, rel, exact in copied: |
|
2315 | for abs, rel, exact in copied: | |
2316 | if ui.verbose or not exact: |
|
2316 | if ui.verbose or not exact: | |
2317 | ui.status(_('removing %s\n') % rel) |
|
2317 | ui.status(_('removing %s\n') % rel) | |
2318 | names.append(abs) |
|
2318 | names.append(abs) | |
2319 | repo.remove(names, True, wlock) |
|
2319 | repo.remove(names, True, wlock) | |
2320 | return errs |
|
2320 | return errs | |
2321 |
|
2321 | |||
2322 | def revert(ui, repo, *pats, **opts): |
|
2322 | def revert(ui, repo, *pats, **opts): | |
2323 | """revert modified files or dirs back to their unmodified states |
|
2323 | """revert modified files or dirs back to their unmodified states | |
2324 |
|
2324 | |||
2325 | In its default mode, it reverts any uncommitted modifications made |
|
2325 | In its default mode, it reverts any uncommitted modifications made | |
2326 | to the named files or directories. This restores the contents of |
|
2326 | to the named files or directories. This restores the contents of | |
2327 | the affected files to an unmodified state. |
|
2327 | the affected files to an unmodified state. | |
2328 |
|
2328 | |||
2329 | Modified files have backup copies saved before revert. To disable |
|
2329 | Modified files have backup copies saved before revert. To disable | |
2330 | backups, use --no-backup. To change the name of backup files, use |
|
2330 | backups, use --no-backup. To change the name of backup files, use | |
2331 | --backup to give a format string. |
|
2331 | --backup to give a format string. | |
2332 |
|
2332 | |||
2333 | Using the -r option, it reverts the given files or directories to |
|
2333 | Using the -r option, it reverts the given files or directories to | |
2334 | their state as of an earlier revision. This can be helpful to "roll |
|
2334 | their state as of an earlier revision. This can be helpful to "roll | |
2335 | back" some or all of a change that should not have been committed. |
|
2335 | back" some or all of a change that should not have been committed. | |
2336 |
|
2336 | |||
2337 | Revert modifies the working directory. It does not commit any |
|
2337 | Revert modifies the working directory. It does not commit any | |
2338 | changes, or change the parent of the current working directory. |
|
2338 | changes, or change the parent of the current working directory. | |
2339 |
|
2339 | |||
2340 | If a file has been deleted, it is recreated. If the executable |
|
2340 | If a file has been deleted, it is recreated. If the executable | |
2341 | mode of a file was changed, it is reset. |
|
2341 | mode of a file was changed, it is reset. | |
2342 |
|
2342 | |||
2343 | If names are given, all files matching the names are reverted. |
|
2343 | If names are given, all files matching the names are reverted. | |
2344 |
|
2344 | |||
2345 | If no arguments are given, all files in the repository are reverted. |
|
2345 | If no arguments are given, all files in the repository are reverted. | |
2346 | """ |
|
2346 | """ | |
2347 | parent = repo.dirstate.parents()[0] |
|
2347 | parent = repo.dirstate.parents()[0] | |
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent |
|
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent | |
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) | |
2350 |
|
2350 | |||
2351 | def backup(name, exact): |
|
2351 | def backup(name, exact): | |
2352 | bakname = make_filename(repo, repo.changelog, |
|
2352 | bakname = make_filename(repo, repo.changelog, | |
2353 | opts['backup_name'] or '%p.orig', |
|
2353 | opts['backup_name'] or '%p.orig', | |
2354 | node=parent, pathname=name) |
|
2354 | node=parent, pathname=name) | |
2355 | if os.path.exists(name): |
|
2355 | if os.path.exists(name): | |
2356 | # if backup already exists and is same as backup we want |
|
2356 | # if backup already exists and is same as backup we want | |
2357 | # to make, do nothing |
|
2357 | # to make, do nothing | |
2358 | if os.path.exists(bakname): |
|
2358 | if os.path.exists(bakname): | |
2359 | if repo.wread(name) == repo.wread(bakname): |
|
2359 | if repo.wread(name) == repo.wread(bakname): | |
2360 | return |
|
2360 | return | |
2361 | raise util.Abort(_('cannot save current version of %s - ' |
|
2361 | raise util.Abort(_('cannot save current version of %s - ' | |
2362 | '%s exists and differs') % |
|
2362 | '%s exists and differs') % | |
2363 | (name, bakname)) |
|
2363 | (name, bakname)) | |
2364 | ui.status(('saving current version of %s as %s\n') % |
|
2364 | ui.status(('saving current version of %s as %s\n') % | |
2365 | (name, bakname)) |
|
2365 | (name, bakname)) | |
2366 | shutil.copyfile(name, bakname) |
|
2366 | shutil.copyfile(name, bakname) | |
2367 | shutil.copymode(name, bakname) |
|
2367 | shutil.copymode(name, bakname) | |
2368 |
|
2368 | |||
2369 | wlock = repo.wlock() |
|
2369 | wlock = repo.wlock() | |
2370 |
|
2370 | |||
2371 | entries = [] |
|
2371 | entries = [] | |
2372 | names = {} |
|
2372 | names = {} | |
2373 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
|
2373 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): | |
2374 | names[abs] = True |
|
2374 | names[abs] = True | |
2375 | entries.append((abs, rel, exact)) |
|
2375 | entries.append((abs, rel, exact)) | |
2376 |
|
2376 | |||
2377 | changes = repo.changes(match=names.has_key, wlock=wlock) |
|
2377 | changes = repo.changes(match=names.has_key, wlock=wlock) | |
2378 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2378 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | |
2379 |
|
2379 | |||
2380 | revert = ([], _('reverting %s\n')) |
|
2380 | revert = ([], _('reverting %s\n')) | |
2381 | add = ([], _('adding %s\n')) |
|
2381 | add = ([], _('adding %s\n')) | |
2382 | remove = ([], _('removing %s\n')) |
|
2382 | remove = ([], _('removing %s\n')) | |
2383 | forget = ([], _('forgetting %s\n')) |
|
2383 | forget = ([], _('forgetting %s\n')) | |
2384 | undelete = ([], _('undeleting %s\n')) |
|
2384 | undelete = ([], _('undeleting %s\n')) | |
2385 | update = {} |
|
2385 | update = {} | |
2386 |
|
2386 | |||
2387 | disptable = ( |
|
2387 | disptable = ( | |
2388 | # dispatch table: |
|
2388 | # dispatch table: | |
2389 | # file state |
|
2389 | # file state | |
2390 | # action if in target manifest |
|
2390 | # action if in target manifest | |
2391 | # action if not in target manifest |
|
2391 | # action if not in target manifest | |
2392 | # make backup if in target manifest |
|
2392 | # make backup if in target manifest | |
2393 | # make backup if not in target manifest |
|
2393 | # make backup if not in target manifest | |
2394 | (modified, revert, remove, True, True), |
|
2394 | (modified, revert, remove, True, True), | |
2395 | (added, revert, forget, True, True), |
|
2395 | (added, revert, forget, True, True), | |
2396 | (removed, undelete, None, False, False), |
|
2396 | (removed, undelete, None, False, False), | |
2397 | (deleted, revert, remove, False, False), |
|
2397 | (deleted, revert, remove, False, False), | |
2398 | (unknown, add, None, True, False), |
|
2398 | (unknown, add, None, True, False), | |
2399 | ) |
|
2399 | ) | |
2400 |
|
2400 | |||
2401 | for abs, rel, exact in entries: |
|
2401 | for abs, rel, exact in entries: | |
2402 | def handle(xlist, dobackup): |
|
2402 | def handle(xlist, dobackup): | |
2403 | xlist[0].append(abs) |
|
2403 | xlist[0].append(abs) | |
2404 | if dobackup and not opts['no_backup']: |
|
2404 | if dobackup and not opts['no_backup']: | |
2405 | backup(rel, exact) |
|
2405 | backup(rel, exact) | |
2406 | if ui.verbose or not exact: |
|
2406 | if ui.verbose or not exact: | |
2407 | ui.status(xlist[1] % rel) |
|
2407 | ui.status(xlist[1] % rel) | |
2408 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2408 | for table, hitlist, misslist, backuphit, backupmiss in disptable: | |
2409 | if abs not in table: continue |
|
2409 | if abs not in table: continue | |
2410 | # file has changed in dirstate |
|
2410 | # file has changed in dirstate | |
2411 | if abs in mf: |
|
2411 | if abs in mf: | |
2412 | handle(hitlist, backuphit) |
|
2412 | handle(hitlist, backuphit) | |
2413 | elif misslist is not None: |
|
2413 | elif misslist is not None: | |
2414 | handle(misslist, backupmiss) |
|
2414 | handle(misslist, backupmiss) | |
2415 | else: |
|
2415 | else: | |
2416 | if exact: ui.warn(_('file not managed: %s\n' % rel)) |
|
2416 | if exact: ui.warn(_('file not managed: %s\n' % rel)) | |
2417 | break |
|
2417 | break | |
2418 | else: |
|
2418 | else: | |
2419 | # file has not changed in dirstate |
|
2419 | # file has not changed in dirstate | |
2420 | if node == parent: |
|
2420 | if node == parent: | |
2421 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
|
2421 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) | |
2422 | continue |
|
2422 | continue | |
2423 | if abs not in mf: |
|
2423 | if abs not in mf: | |
2424 | remove[0].append(abs) |
|
2424 | remove[0].append(abs) | |
2425 | update[abs] = True |
|
2425 | update[abs] = True | |
2426 |
|
2426 | |||
2427 | repo.dirstate.forget(forget[0]) |
|
2427 | repo.dirstate.forget(forget[0]) | |
2428 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) |
|
2428 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) | |
2429 | repo.dirstate.update(add[0], 'a') |
|
2429 | repo.dirstate.update(add[0], 'a') | |
2430 | repo.dirstate.update(undelete[0], 'n') |
|
2430 | repo.dirstate.update(undelete[0], 'n') | |
2431 | repo.dirstate.update(remove[0], 'r') |
|
2431 | repo.dirstate.update(remove[0], 'r') | |
2432 | return r |
|
2432 | return r | |
2433 |
|
2433 | |||
2434 | def root(ui, repo): |
|
2434 | def root(ui, repo): | |
2435 | """print the root (top) of the current working dir |
|
2435 | """print the root (top) of the current working dir | |
2436 |
|
2436 | |||
2437 | Print the root directory of the current repository. |
|
2437 | Print the root directory of the current repository. | |
2438 | """ |
|
2438 | """ | |
2439 | ui.write(repo.root + "\n") |
|
2439 | ui.write(repo.root + "\n") | |
2440 |
|
2440 | |||
2441 | def serve(ui, repo, **opts): |
|
2441 | def serve(ui, repo, **opts): | |
2442 | """export the repository via HTTP |
|
2442 | """export the repository via HTTP | |
2443 |
|
2443 | |||
2444 | Start a local HTTP repository browser and pull server. |
|
2444 | Start a local HTTP repository browser and pull server. | |
2445 |
|
2445 | |||
2446 | By default, the server logs accesses to stdout and errors to |
|
2446 | By default, the server logs accesses to stdout and errors to | |
2447 | stderr. Use the "-A" and "-E" options to log to files. |
|
2447 | stderr. Use the "-A" and "-E" options to log to files. | |
2448 | """ |
|
2448 | """ | |
2449 |
|
2449 | |||
2450 | if opts["stdio"]: |
|
2450 | if opts["stdio"]: | |
2451 | fin, fout = sys.stdin, sys.stdout |
|
2451 | fin, fout = sys.stdin, sys.stdout | |
2452 | sys.stdout = sys.stderr |
|
2452 | sys.stdout = sys.stderr | |
2453 |
|
2453 | |||
2454 | # Prevent insertion/deletion of CRs |
|
2454 | # Prevent insertion/deletion of CRs | |
2455 | util.set_binary(fin) |
|
2455 | util.set_binary(fin) | |
2456 | util.set_binary(fout) |
|
2456 | util.set_binary(fout) | |
2457 |
|
2457 | |||
2458 | def getarg(): |
|
2458 | def getarg(): | |
2459 | argline = fin.readline()[:-1] |
|
2459 | argline = fin.readline()[:-1] | |
2460 | arg, l = argline.split() |
|
2460 | arg, l = argline.split() | |
2461 | val = fin.read(int(l)) |
|
2461 | val = fin.read(int(l)) | |
2462 | return arg, val |
|
2462 | return arg, val | |
2463 | def respond(v): |
|
2463 | def respond(v): | |
2464 | fout.write("%d\n" % len(v)) |
|
2464 | fout.write("%d\n" % len(v)) | |
2465 | fout.write(v) |
|
2465 | fout.write(v) | |
2466 | fout.flush() |
|
2466 | fout.flush() | |
2467 |
|
2467 | |||
2468 | lock = None |
|
2468 | lock = None | |
2469 |
|
2469 | |||
2470 | while 1: |
|
2470 | while 1: | |
2471 | cmd = fin.readline()[:-1] |
|
2471 | cmd = fin.readline()[:-1] | |
2472 | if cmd == '': |
|
2472 | if cmd == '': | |
2473 | return |
|
2473 | return | |
2474 | if cmd == "heads": |
|
2474 | if cmd == "heads": | |
2475 | h = repo.heads() |
|
2475 | h = repo.heads() | |
2476 | respond(" ".join(map(hex, h)) + "\n") |
|
2476 | respond(" ".join(map(hex, h)) + "\n") | |
2477 | if cmd == "lock": |
|
2477 | if cmd == "lock": | |
2478 | lock = repo.lock() |
|
2478 | lock = repo.lock() | |
2479 | respond("") |
|
2479 | respond("") | |
2480 | if cmd == "unlock": |
|
2480 | if cmd == "unlock": | |
2481 | if lock: |
|
2481 | if lock: | |
2482 | lock.release() |
|
2482 | lock.release() | |
2483 | lock = None |
|
2483 | lock = None | |
2484 | respond("") |
|
2484 | respond("") | |
2485 | elif cmd == "branches": |
|
2485 | elif cmd == "branches": | |
2486 | arg, nodes = getarg() |
|
2486 | arg, nodes = getarg() | |
2487 | nodes = map(bin, nodes.split(" ")) |
|
2487 | nodes = map(bin, nodes.split(" ")) | |
2488 | r = [] |
|
2488 | r = [] | |
2489 | for b in repo.branches(nodes): |
|
2489 | for b in repo.branches(nodes): | |
2490 | r.append(" ".join(map(hex, b)) + "\n") |
|
2490 | r.append(" ".join(map(hex, b)) + "\n") | |
2491 | respond("".join(r)) |
|
2491 | respond("".join(r)) | |
2492 | elif cmd == "between": |
|
2492 | elif cmd == "between": | |
2493 | arg, pairs = getarg() |
|
2493 | arg, pairs = getarg() | |
2494 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2494 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2495 | r = [] |
|
2495 | r = [] | |
2496 | for b in repo.between(pairs): |
|
2496 | for b in repo.between(pairs): | |
2497 | r.append(" ".join(map(hex, b)) + "\n") |
|
2497 | r.append(" ".join(map(hex, b)) + "\n") | |
2498 | respond("".join(r)) |
|
2498 | respond("".join(r)) | |
2499 | elif cmd == "changegroup": |
|
2499 | elif cmd == "changegroup": | |
2500 | nodes = [] |
|
2500 | nodes = [] | |
2501 | arg, roots = getarg() |
|
2501 | arg, roots = getarg() | |
2502 | nodes = map(bin, roots.split(" ")) |
|
2502 | nodes = map(bin, roots.split(" ")) | |
2503 |
|
2503 | |||
2504 | cg = repo.changegroup(nodes, 'serve') |
|
2504 | cg = repo.changegroup(nodes, 'serve') | |
2505 | while 1: |
|
2505 | while 1: | |
2506 | d = cg.read(4096) |
|
2506 | d = cg.read(4096) | |
2507 | if not d: |
|
2507 | if not d: | |
2508 | break |
|
2508 | break | |
2509 | fout.write(d) |
|
2509 | fout.write(d) | |
2510 |
|
2510 | |||
2511 | fout.flush() |
|
2511 | fout.flush() | |
2512 |
|
2512 | |||
2513 | elif cmd == "addchangegroup": |
|
2513 | elif cmd == "addchangegroup": | |
2514 | if not lock: |
|
2514 | if not lock: | |
2515 | respond("not locked") |
|
2515 | respond("not locked") | |
2516 | continue |
|
2516 | continue | |
2517 | respond("") |
|
2517 | respond("") | |
2518 |
|
2518 | |||
2519 | r = repo.addchangegroup(fin) |
|
2519 | r = repo.addchangegroup(fin) | |
2520 | respond(str(r)) |
|
2520 | respond(str(r)) | |
2521 |
|
2521 | |||
2522 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2522 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2523 | for o in optlist.split(): |
|
2523 | for o in optlist.split(): | |
2524 | if opts[o]: |
|
2524 | if opts[o]: | |
2525 | ui.setconfig("web", o, opts[o]) |
|
2525 | ui.setconfig("web", o, opts[o]) | |
2526 |
|
2526 | |||
2527 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2527 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2528 | rfd, wfd = os.pipe() |
|
2528 | rfd, wfd = os.pipe() | |
2529 | args = sys.argv[:] |
|
2529 | args = sys.argv[:] | |
2530 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2530 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2531 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2531 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2532 | args[0], args) |
|
2532 | args[0], args) | |
2533 | os.close(wfd) |
|
2533 | os.close(wfd) | |
2534 | os.read(rfd, 1) |
|
2534 | os.read(rfd, 1) | |
2535 | os._exit(0) |
|
2535 | os._exit(0) | |
2536 |
|
2536 | |||
2537 | try: |
|
2537 | try: | |
2538 | httpd = hgweb.create_server(repo) |
|
2538 | httpd = hgweb.create_server(repo) | |
2539 | except socket.error, inst: |
|
2539 | except socket.error, inst: | |
2540 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2540 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2541 |
|
2541 | |||
2542 | if ui.verbose: |
|
2542 | if ui.verbose: | |
2543 | addr, port = httpd.socket.getsockname() |
|
2543 | addr, port = httpd.socket.getsockname() | |
2544 | if addr == '0.0.0.0': |
|
2544 | if addr == '0.0.0.0': | |
2545 | addr = socket.gethostname() |
|
2545 | addr = socket.gethostname() | |
2546 | else: |
|
2546 | else: | |
2547 | try: |
|
2547 | try: | |
2548 | addr = socket.gethostbyaddr(addr)[0] |
|
2548 | addr = socket.gethostbyaddr(addr)[0] | |
2549 | except socket.error: |
|
2549 | except socket.error: | |
2550 | pass |
|
2550 | pass | |
2551 | if port != 80: |
|
2551 | if port != 80: | |
2552 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2552 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2553 | else: |
|
2553 | else: | |
2554 | ui.status(_('listening at http://%s/\n') % addr) |
|
2554 | ui.status(_('listening at http://%s/\n') % addr) | |
2555 |
|
2555 | |||
2556 | if opts['pid_file']: |
|
2556 | if opts['pid_file']: | |
2557 | fp = open(opts['pid_file'], 'w') |
|
2557 | fp = open(opts['pid_file'], 'w') | |
2558 | fp.write(str(os.getpid())) |
|
2558 | fp.write(str(os.getpid())) | |
2559 | fp.close() |
|
2559 | fp.close() | |
2560 |
|
2560 | |||
2561 | if opts['daemon_pipefds']: |
|
2561 | if opts['daemon_pipefds']: | |
2562 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2562 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2563 | os.close(rfd) |
|
2563 | os.close(rfd) | |
2564 | os.write(wfd, 'y') |
|
2564 | os.write(wfd, 'y') | |
2565 | os.close(wfd) |
|
2565 | os.close(wfd) | |
2566 | sys.stdout.flush() |
|
2566 | sys.stdout.flush() | |
2567 | sys.stderr.flush() |
|
2567 | sys.stderr.flush() | |
2568 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2568 | fd = os.open(util.nulldev, os.O_RDWR) | |
2569 | if fd != 0: os.dup2(fd, 0) |
|
2569 | if fd != 0: os.dup2(fd, 0) | |
2570 | if fd != 1: os.dup2(fd, 1) |
|
2570 | if fd != 1: os.dup2(fd, 1) | |
2571 | if fd != 2: os.dup2(fd, 2) |
|
2571 | if fd != 2: os.dup2(fd, 2) | |
2572 | if fd not in (0, 1, 2): os.close(fd) |
|
2572 | if fd not in (0, 1, 2): os.close(fd) | |
2573 |
|
2573 | |||
2574 | httpd.serve_forever() |
|
2574 | httpd.serve_forever() | |
2575 |
|
2575 | |||
2576 | def status(ui, repo, *pats, **opts): |
|
2576 | def status(ui, repo, *pats, **opts): | |
2577 | """show changed files in the working directory |
|
2577 | """show changed files in the working directory | |
2578 |
|
2578 | |||
2579 | Show changed files in the repository. If names are |
|
2579 | Show changed files in the repository. If names are | |
2580 | given, only files that match are shown. |
|
2580 | given, only files that match are shown. | |
2581 |
|
2581 | |||
2582 | The codes used to show the status of files are: |
|
2582 | The codes used to show the status of files are: | |
2583 | M = modified |
|
2583 | M = modified | |
2584 | A = added |
|
2584 | A = added | |
2585 | R = removed |
|
2585 | R = removed | |
2586 | ! = deleted, but still tracked |
|
2586 | ! = deleted, but still tracked | |
2587 | ? = not tracked |
|
2587 | ? = not tracked | |
2588 | I = ignored (not shown by default) |
|
2588 | I = ignored (not shown by default) | |
2589 | """ |
|
2589 | """ | |
2590 |
|
2590 | |||
2591 | show_ignored = opts['ignored'] and True or False |
|
2591 | show_ignored = opts['ignored'] and True or False | |
2592 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2592 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2593 | cwd = (pats and repo.getcwd()) or '' |
|
2593 | cwd = (pats and repo.getcwd()) or '' | |
2594 | modified, added, removed, deleted, unknown, ignored = [ |
|
2594 | modified, added, removed, deleted, unknown, ignored = [ | |
2595 | [util.pathto(cwd, x) for x in n] |
|
2595 | [util.pathto(cwd, x) for x in n] | |
2596 | for n in repo.changes(files=files, match=matchfn, |
|
2596 | for n in repo.changes(files=files, match=matchfn, | |
2597 | show_ignored=show_ignored)] |
|
2597 | show_ignored=show_ignored)] | |
2598 |
|
2598 | |||
2599 | changetypes = [('modified', 'M', modified), |
|
2599 | changetypes = [('modified', 'M', modified), | |
2600 | ('added', 'A', added), |
|
2600 | ('added', 'A', added), | |
2601 | ('removed', 'R', removed), |
|
2601 | ('removed', 'R', removed), | |
2602 | ('deleted', '!', deleted), |
|
2602 | ('deleted', '!', deleted), | |
2603 | ('unknown', '?', unknown), |
|
2603 | ('unknown', '?', unknown), | |
2604 | ('ignored', 'I', ignored)] |
|
2604 | ('ignored', 'I', ignored)] | |
2605 |
|
2605 | |||
2606 | end = opts['print0'] and '\0' or '\n' |
|
2606 | end = opts['print0'] and '\0' or '\n' | |
2607 |
|
2607 | |||
2608 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2608 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2609 | or changetypes): |
|
2609 | or changetypes): | |
2610 | if opts['no_status']: |
|
2610 | if opts['no_status']: | |
2611 | format = "%%s%s" % end |
|
2611 | format = "%%s%s" % end | |
2612 | else: |
|
2612 | else: | |
2613 | format = "%s %%s%s" % (char, end) |
|
2613 | format = "%s %%s%s" % (char, end) | |
2614 |
|
2614 | |||
2615 | for f in changes: |
|
2615 | for f in changes: | |
2616 | ui.write(format % f) |
|
2616 | ui.write(format % f) | |
2617 |
|
2617 | |||
2618 | def tag(ui, repo, name, rev_=None, **opts): |
|
2618 | def tag(ui, repo, name, rev_=None, **opts): | |
2619 | """add a tag for the current tip or a given revision |
|
2619 | """add a tag for the current tip or a given revision | |
2620 |
|
2620 | |||
2621 | Name a particular revision using <name>. |
|
2621 | Name a particular revision using <name>. | |
2622 |
|
2622 | |||
2623 | Tags are used to name particular revisions of the repository and are |
|
2623 | Tags are used to name particular revisions of the repository and are | |
2624 | very useful to compare different revision, to go back to significant |
|
2624 | very useful to compare different revision, to go back to significant | |
2625 | earlier versions or to mark branch points as releases, etc. |
|
2625 | earlier versions or to mark branch points as releases, etc. | |
2626 |
|
2626 | |||
2627 | If no revision is given, the tip is used. |
|
2627 | If no revision is given, the tip is used. | |
2628 |
|
2628 | |||
2629 | To facilitate version control, distribution, and merging of tags, |
|
2629 | To facilitate version control, distribution, and merging of tags, | |
2630 | they are stored as a file named ".hgtags" which is managed |
|
2630 | they are stored as a file named ".hgtags" which is managed | |
2631 | similarly to other project files and can be hand-edited if |
|
2631 | similarly to other project files and can be hand-edited if | |
2632 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2632 | necessary. The file '.hg/localtags' is used for local tags (not | |
2633 | shared among repositories). |
|
2633 | shared among repositories). | |
2634 | """ |
|
2634 | """ | |
2635 | if name == "tip": |
|
2635 | if name == "tip": | |
2636 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2636 | raise util.Abort(_("the name 'tip' is reserved")) | |
2637 | if rev_ is not None: |
|
2637 | if rev_ is not None: | |
2638 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2638 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2639 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2639 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2640 | if opts['rev']: |
|
2640 | if opts['rev']: | |
2641 | raise util.Abort(_("use only one form to specify the revision")) |
|
2641 | raise util.Abort(_("use only one form to specify the revision")) | |
2642 | if opts['rev']: |
|
2642 | if opts['rev']: | |
2643 | rev_ = opts['rev'] |
|
2643 | rev_ = opts['rev'] | |
2644 | if rev_: |
|
2644 | if rev_: | |
2645 | r = hex(repo.lookup(rev_)) |
|
2645 | r = hex(repo.lookup(rev_)) | |
2646 | else: |
|
2646 | else: | |
2647 | r = hex(repo.changelog.tip()) |
|
2647 | r = hex(repo.changelog.tip()) | |
2648 |
|
2648 | |||
2649 | disallowed = (revrangesep, '\r', '\n') |
|
2649 | disallowed = (revrangesep, '\r', '\n') | |
2650 | for c in disallowed: |
|
2650 | for c in disallowed: | |
2651 | if name.find(c) >= 0: |
|
2651 | if name.find(c) >= 0: | |
2652 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2652 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2653 |
|
2653 | |||
2654 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2654 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2655 | local=int(not not opts['local'])) |
|
2655 | local=int(not not opts['local'])) | |
2656 |
|
2656 | |||
2657 | if opts['local']: |
|
2657 | if opts['local']: | |
2658 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2658 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2659 | repo.hook('tag', node=r, tag=name, local=1) |
|
2659 | repo.hook('tag', node=r, tag=name, local=1) | |
2660 | return |
|
2660 | return | |
2661 |
|
2661 | |||
2662 | for x in repo.changes(): |
|
2662 | for x in repo.changes(): | |
2663 | if ".hgtags" in x: |
|
2663 | if ".hgtags" in x: | |
2664 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2664 | raise util.Abort(_("working copy of .hgtags is changed " | |
2665 | "(please commit .hgtags manually)")) |
|
2665 | "(please commit .hgtags manually)")) | |
2666 |
|
2666 | |||
2667 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2667 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2668 | if repo.dirstate.state(".hgtags") == '?': |
|
2668 | if repo.dirstate.state(".hgtags") == '?': | |
2669 | repo.add([".hgtags"]) |
|
2669 | repo.add([".hgtags"]) | |
2670 |
|
2670 | |||
2671 | message = (opts['message'] or |
|
2671 | message = (opts['message'] or | |
2672 | _("Added tag %s for changeset %s") % (name, r)) |
|
2672 | _("Added tag %s for changeset %s") % (name, r)) | |
2673 | try: |
|
2673 | try: | |
2674 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2674 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2675 | repo.hook('tag', node=r, tag=name, local=0) |
|
2675 | repo.hook('tag', node=r, tag=name, local=0) | |
2676 | except ValueError, inst: |
|
2676 | except ValueError, inst: | |
2677 | raise util.Abort(str(inst)) |
|
2677 | raise util.Abort(str(inst)) | |
2678 |
|
2678 | |||
2679 | def tags(ui, repo): |
|
2679 | def tags(ui, repo): | |
2680 | """list repository tags |
|
2680 | """list repository tags | |
2681 |
|
2681 | |||
2682 | List the repository tags. |
|
2682 | List the repository tags. | |
2683 |
|
2683 | |||
2684 | This lists both regular and local tags. |
|
2684 | This lists both regular and local tags. | |
2685 | """ |
|
2685 | """ | |
2686 |
|
2686 | |||
2687 | l = repo.tagslist() |
|
2687 | l = repo.tagslist() | |
2688 | l.reverse() |
|
2688 | l.reverse() | |
2689 | for t, n in l: |
|
2689 | for t, n in l: | |
2690 | try: |
|
2690 | try: | |
2691 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2691 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2692 | except KeyError: |
|
2692 | except KeyError: | |
2693 | r = " ?:?" |
|
2693 | r = " ?:?" | |
2694 | ui.write("%-30s %s\n" % (t, r)) |
|
2694 | if ui.quiet: | |
|
2695 | ui.write("%s\n" % t) | |||
|
2696 | else: | |||
|
2697 | ui.write("%-30s %s\n" % (t, r)) | |||
2695 |
|
2698 | |||
2696 | def tip(ui, repo, **opts): |
|
2699 | def tip(ui, repo, **opts): | |
2697 | """show the tip revision |
|
2700 | """show the tip revision | |
2698 |
|
2701 | |||
2699 | Show the tip revision. |
|
2702 | Show the tip revision. | |
2700 | """ |
|
2703 | """ | |
2701 | n = repo.changelog.tip() |
|
2704 | n = repo.changelog.tip() | |
2702 | br = None |
|
2705 | br = None | |
2703 | if opts['branches']: |
|
2706 | if opts['branches']: | |
2704 | br = repo.branchlookup([n]) |
|
2707 | br = repo.branchlookup([n]) | |
2705 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2708 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2706 | if opts['patch']: |
|
2709 | if opts['patch']: | |
2707 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2710 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2708 |
|
2711 | |||
2709 | def unbundle(ui, repo, fname, **opts): |
|
2712 | def unbundle(ui, repo, fname, **opts): | |
2710 | """apply a changegroup file |
|
2713 | """apply a changegroup file | |
2711 |
|
2714 | |||
2712 | Apply a compressed changegroup file generated by the bundle |
|
2715 | Apply a compressed changegroup file generated by the bundle | |
2713 | command. |
|
2716 | command. | |
2714 | """ |
|
2717 | """ | |
2715 | f = urllib.urlopen(fname) |
|
2718 | f = urllib.urlopen(fname) | |
2716 |
|
2719 | |||
2717 | header = f.read(6) |
|
2720 | header = f.read(6) | |
2718 | if not header.startswith("HG"): |
|
2721 | if not header.startswith("HG"): | |
2719 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2722 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2720 | elif not header.startswith("HG10"): |
|
2723 | elif not header.startswith("HG10"): | |
2721 | raise util.Abort(_("%s: unknown bundle version") % fname) |
|
2724 | raise util.Abort(_("%s: unknown bundle version") % fname) | |
2722 | elif header == "HG10BZ": |
|
2725 | elif header == "HG10BZ": | |
2723 | def generator(f): |
|
2726 | def generator(f): | |
2724 | zd = bz2.BZ2Decompressor() |
|
2727 | zd = bz2.BZ2Decompressor() | |
2725 | zd.decompress("BZ") |
|
2728 | zd.decompress("BZ") | |
2726 | for chunk in f: |
|
2729 | for chunk in f: | |
2727 | yield zd.decompress(chunk) |
|
2730 | yield zd.decompress(chunk) | |
2728 | elif header == "HG10UN": |
|
2731 | elif header == "HG10UN": | |
2729 | def generator(f): |
|
2732 | def generator(f): | |
2730 | for chunk in f: |
|
2733 | for chunk in f: | |
2731 | yield chunk |
|
2734 | yield chunk | |
2732 | else: |
|
2735 | else: | |
2733 | raise util.Abort(_("%s: unknown bundle compression type") |
|
2736 | raise util.Abort(_("%s: unknown bundle compression type") | |
2734 | % fname) |
|
2737 | % fname) | |
2735 | gen = generator(util.filechunkiter(f, 4096)) |
|
2738 | gen = generator(util.filechunkiter(f, 4096)) | |
2736 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) |
|
2739 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) | |
2737 | return postincoming(ui, repo, modheads, opts['update']) |
|
2740 | return postincoming(ui, repo, modheads, opts['update']) | |
2738 |
|
2741 | |||
2739 | def undo(ui, repo): |
|
2742 | def undo(ui, repo): | |
2740 | """undo the last commit or pull |
|
2743 | """undo the last commit or pull | |
2741 |
|
2744 | |||
2742 | Roll back the last pull or commit transaction on the |
|
2745 | Roll back the last pull or commit transaction on the | |
2743 | repository, restoring the project to its earlier state. |
|
2746 | repository, restoring the project to its earlier state. | |
2744 |
|
2747 | |||
2745 | This command should be used with care. There is only one level of |
|
2748 | This command should be used with care. There is only one level of | |
2746 | undo and there is no redo. |
|
2749 | undo and there is no redo. | |
2747 |
|
2750 | |||
2748 | This command is not intended for use on public repositories. Once |
|
2751 | This command is not intended for use on public repositories. Once | |
2749 | a change is visible for pull by other users, undoing it locally is |
|
2752 | a change is visible for pull by other users, undoing it locally is | |
2750 | ineffective. |
|
2753 | ineffective. | |
2751 | """ |
|
2754 | """ | |
2752 | repo.undo() |
|
2755 | repo.undo() | |
2753 |
|
2756 | |||
2754 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2757 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2755 | branch=None, **opts): |
|
2758 | branch=None, **opts): | |
2756 | """update or merge working directory |
|
2759 | """update or merge working directory | |
2757 |
|
2760 | |||
2758 | Update the working directory to the specified revision. |
|
2761 | Update the working directory to the specified revision. | |
2759 |
|
2762 | |||
2760 | If there are no outstanding changes in the working directory and |
|
2763 | If there are no outstanding changes in the working directory and | |
2761 | there is a linear relationship between the current version and the |
|
2764 | there is a linear relationship between the current version and the | |
2762 | requested version, the result is the requested version. |
|
2765 | requested version, the result is the requested version. | |
2763 |
|
2766 | |||
2764 | Otherwise the result is a merge between the contents of the |
|
2767 | Otherwise the result is a merge between the contents of the | |
2765 | current working directory and the requested version. Files that |
|
2768 | current working directory and the requested version. Files that | |
2766 | changed between either parent are marked as changed for the next |
|
2769 | changed between either parent are marked as changed for the next | |
2767 | commit and a commit must be performed before any further updates |
|
2770 | commit and a commit must be performed before any further updates | |
2768 | are allowed. |
|
2771 | are allowed. | |
2769 |
|
2772 | |||
2770 | By default, update will refuse to run if doing so would require |
|
2773 | By default, update will refuse to run if doing so would require | |
2771 | merging or discarding local changes. |
|
2774 | merging or discarding local changes. | |
2772 | """ |
|
2775 | """ | |
2773 | if branch: |
|
2776 | if branch: | |
2774 | br = repo.branchlookup(branch=branch) |
|
2777 | br = repo.branchlookup(branch=branch) | |
2775 | found = [] |
|
2778 | found = [] | |
2776 | for x in br: |
|
2779 | for x in br: | |
2777 | if branch in br[x]: |
|
2780 | if branch in br[x]: | |
2778 | found.append(x) |
|
2781 | found.append(x) | |
2779 | if len(found) > 1: |
|
2782 | if len(found) > 1: | |
2780 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2783 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2781 | for x in found: |
|
2784 | for x in found: | |
2782 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2785 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | |
2783 | return 1 |
|
2786 | return 1 | |
2784 | if len(found) == 1: |
|
2787 | if len(found) == 1: | |
2785 | node = found[0] |
|
2788 | node = found[0] | |
2786 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2789 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2787 | else: |
|
2790 | else: | |
2788 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2791 | ui.warn(_("branch %s not found\n") % (branch)) | |
2789 | return 1 |
|
2792 | return 1 | |
2790 | else: |
|
2793 | else: | |
2791 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2794 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2792 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2795 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2793 |
|
2796 | |||
2794 | def verify(ui, repo): |
|
2797 | def verify(ui, repo): | |
2795 | """verify the integrity of the repository |
|
2798 | """verify the integrity of the repository | |
2796 |
|
2799 | |||
2797 | Verify the integrity of the current repository. |
|
2800 | Verify the integrity of the current repository. | |
2798 |
|
2801 | |||
2799 | This will perform an extensive check of the repository's |
|
2802 | This will perform an extensive check of the repository's | |
2800 | integrity, validating the hashes and checksums of each entry in |
|
2803 | integrity, validating the hashes and checksums of each entry in | |
2801 | the changelog, manifest, and tracked files, as well as the |
|
2804 | the changelog, manifest, and tracked files, as well as the | |
2802 | integrity of their crosslinks and indices. |
|
2805 | integrity of their crosslinks and indices. | |
2803 | """ |
|
2806 | """ | |
2804 | return repo.verify() |
|
2807 | return repo.verify() | |
2805 |
|
2808 | |||
2806 | # Command options and aliases are listed here, alphabetically |
|
2809 | # Command options and aliases are listed here, alphabetically | |
2807 |
|
2810 | |||
2808 | table = { |
|
2811 | table = { | |
2809 | "^add": |
|
2812 | "^add": | |
2810 | (add, |
|
2813 | (add, | |
2811 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2814 | [('I', 'include', [], _('include names matching the given patterns')), | |
2812 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2815 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2813 | _('hg add [OPTION]... [FILE]...')), |
|
2816 | _('hg add [OPTION]... [FILE]...')), | |
2814 | "addremove": |
|
2817 | "addremove": | |
2815 | (addremove, |
|
2818 | (addremove, | |
2816 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2819 | [('I', 'include', [], _('include names matching the given patterns')), | |
2817 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2820 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2818 | _('hg addremove [OPTION]... [FILE]...')), |
|
2821 | _('hg addremove [OPTION]... [FILE]...')), | |
2819 | "^annotate": |
|
2822 | "^annotate": | |
2820 | (annotate, |
|
2823 | (annotate, | |
2821 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2824 | [('r', 'rev', '', _('annotate the specified revision')), | |
2822 | ('a', 'text', None, _('treat all files as text')), |
|
2825 | ('a', 'text', None, _('treat all files as text')), | |
2823 | ('u', 'user', None, _('list the author')), |
|
2826 | ('u', 'user', None, _('list the author')), | |
2824 | ('d', 'date', None, _('list the date')), |
|
2827 | ('d', 'date', None, _('list the date')), | |
2825 | ('n', 'number', None, _('list the revision number (default)')), |
|
2828 | ('n', 'number', None, _('list the revision number (default)')), | |
2826 | ('c', 'changeset', None, _('list the changeset')), |
|
2829 | ('c', 'changeset', None, _('list the changeset')), | |
2827 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2830 | ('I', 'include', [], _('include names matching the given patterns')), | |
2828 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2831 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2829 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2832 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2830 | "bundle": |
|
2833 | "bundle": | |
2831 | (bundle, |
|
2834 | (bundle, | |
2832 | [('f', 'force', None, |
|
2835 | [('f', 'force', None, | |
2833 | _('run even when remote repository is unrelated'))], |
|
2836 | _('run even when remote repository is unrelated'))], | |
2834 | _('hg bundle FILE DEST')), |
|
2837 | _('hg bundle FILE DEST')), | |
2835 | "cat": |
|
2838 | "cat": | |
2836 | (cat, |
|
2839 | (cat, | |
2837 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2840 | [('o', 'output', '', _('print output to file with formatted name')), | |
2838 | ('r', 'rev', '', _('print the given revision')), |
|
2841 | ('r', 'rev', '', _('print the given revision')), | |
2839 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2842 | ('I', 'include', [], _('include names matching the given patterns')), | |
2840 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2843 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2841 | _('hg cat [OPTION]... FILE...')), |
|
2844 | _('hg cat [OPTION]... FILE...')), | |
2842 | "^clone": |
|
2845 | "^clone": | |
2843 | (clone, |
|
2846 | (clone, | |
2844 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2847 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2845 | ('r', 'rev', [], |
|
2848 | ('r', 'rev', [], | |
2846 | _('a changeset you would like to have after cloning')), |
|
2849 | _('a changeset you would like to have after cloning')), | |
2847 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2850 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2848 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2851 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2849 | ('', 'remotecmd', '', |
|
2852 | ('', 'remotecmd', '', | |
2850 | _('specify hg command to run on the remote side'))], |
|
2853 | _('specify hg command to run on the remote side'))], | |
2851 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2854 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2852 | "^commit|ci": |
|
2855 | "^commit|ci": | |
2853 | (commit, |
|
2856 | (commit, | |
2854 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2857 | [('A', 'addremove', None, _('run addremove during commit')), | |
2855 | ('m', 'message', '', _('use <text> as commit message')), |
|
2858 | ('m', 'message', '', _('use <text> as commit message')), | |
2856 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2859 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2857 | ('d', 'date', '', _('record datecode as commit date')), |
|
2860 | ('d', 'date', '', _('record datecode as commit date')), | |
2858 | ('u', 'user', '', _('record user as commiter')), |
|
2861 | ('u', 'user', '', _('record user as commiter')), | |
2859 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2862 | ('I', 'include', [], _('include names matching the given patterns')), | |
2860 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2863 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2861 | _('hg commit [OPTION]... [FILE]...')), |
|
2864 | _('hg commit [OPTION]... [FILE]...')), | |
2862 | "copy|cp": |
|
2865 | "copy|cp": | |
2863 | (copy, |
|
2866 | (copy, | |
2864 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2867 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2865 | ('f', 'force', None, |
|
2868 | ('f', 'force', None, | |
2866 | _('forcibly copy over an existing managed file')), |
|
2869 | _('forcibly copy over an existing managed file')), | |
2867 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2870 | ('I', 'include', [], _('include names matching the given patterns')), | |
2868 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2871 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2869 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2872 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2870 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2873 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2871 | "debugcomplete": |
|
2874 | "debugcomplete": | |
2872 | (debugcomplete, |
|
2875 | (debugcomplete, | |
2873 | [('o', 'options', None, _('show the command options'))], |
|
2876 | [('o', 'options', None, _('show the command options'))], | |
2874 | _('debugcomplete [-o] CMD')), |
|
2877 | _('debugcomplete [-o] CMD')), | |
2875 | "debugrebuildstate": |
|
2878 | "debugrebuildstate": | |
2876 | (debugrebuildstate, |
|
2879 | (debugrebuildstate, | |
2877 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2880 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2878 | _('debugrebuildstate [-r REV] [REV]')), |
|
2881 | _('debugrebuildstate [-r REV] [REV]')), | |
2879 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2882 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2880 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2883 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2881 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2884 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2882 | "debugstate": (debugstate, [], _('debugstate')), |
|
2885 | "debugstate": (debugstate, [], _('debugstate')), | |
2883 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2886 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2884 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2887 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2885 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2888 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2886 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2889 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2887 | "debugwalk": |
|
2890 | "debugwalk": | |
2888 | (debugwalk, |
|
2891 | (debugwalk, | |
2889 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2892 | [('I', 'include', [], _('include names matching the given patterns')), | |
2890 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2893 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2891 | _('debugwalk [OPTION]... [FILE]...')), |
|
2894 | _('debugwalk [OPTION]... [FILE]...')), | |
2892 | "^diff": |
|
2895 | "^diff": | |
2893 | (diff, |
|
2896 | (diff, | |
2894 | [('r', 'rev', [], _('revision')), |
|
2897 | [('r', 'rev', [], _('revision')), | |
2895 | ('a', 'text', None, _('treat all files as text')), |
|
2898 | ('a', 'text', None, _('treat all files as text')), | |
2896 | ('p', 'show-function', None, |
|
2899 | ('p', 'show-function', None, | |
2897 | _('show which function each change is in')), |
|
2900 | _('show which function each change is in')), | |
2898 | ('w', 'ignore-all-space', None, |
|
2901 | ('w', 'ignore-all-space', None, | |
2899 | _('ignore white space when comparing lines')), |
|
2902 | _('ignore white space when comparing lines')), | |
2900 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2903 | ('I', 'include', [], _('include names matching the given patterns')), | |
2901 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2904 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2902 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2905 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2903 | "^export": |
|
2906 | "^export": | |
2904 | (export, |
|
2907 | (export, | |
2905 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2908 | [('o', 'output', '', _('print output to file with formatted name')), | |
2906 | ('a', 'text', None, _('treat all files as text')), |
|
2909 | ('a', 'text', None, _('treat all files as text')), | |
2907 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2910 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2908 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2911 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2909 | "forget": |
|
2912 | "forget": | |
2910 | (forget, |
|
2913 | (forget, | |
2911 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2914 | [('I', 'include', [], _('include names matching the given patterns')), | |
2912 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2915 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2913 | _('hg forget [OPTION]... FILE...')), |
|
2916 | _('hg forget [OPTION]... FILE...')), | |
2914 | "grep": |
|
2917 | "grep": | |
2915 | (grep, |
|
2918 | (grep, | |
2916 | [('0', 'print0', None, _('end fields with NUL')), |
|
2919 | [('0', 'print0', None, _('end fields with NUL')), | |
2917 | ('', 'all', None, _('print all revisions that match')), |
|
2920 | ('', 'all', None, _('print all revisions that match')), | |
2918 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2921 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2919 | ('l', 'files-with-matches', None, |
|
2922 | ('l', 'files-with-matches', None, | |
2920 | _('print only filenames and revs that match')), |
|
2923 | _('print only filenames and revs that match')), | |
2921 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2924 | ('n', 'line-number', None, _('print matching line numbers')), | |
2922 | ('r', 'rev', [], _('search in given revision range')), |
|
2925 | ('r', 'rev', [], _('search in given revision range')), | |
2923 | ('u', 'user', None, _('print user who committed change')), |
|
2926 | ('u', 'user', None, _('print user who committed change')), | |
2924 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2927 | ('I', 'include', [], _('include names matching the given patterns')), | |
2925 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2928 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2926 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2929 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2927 | "heads": |
|
2930 | "heads": | |
2928 | (heads, |
|
2931 | (heads, | |
2929 | [('b', 'branches', None, _('show branches')), |
|
2932 | [('b', 'branches', None, _('show branches')), | |
2930 | ('', 'style', '', _('display using template map file')), |
|
2933 | ('', 'style', '', _('display using template map file')), | |
2931 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2934 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2932 | ('', 'template', '', _('display with template'))], |
|
2935 | ('', 'template', '', _('display with template'))], | |
2933 | _('hg heads [-b] [-r <rev>]')), |
|
2936 | _('hg heads [-b] [-r <rev>]')), | |
2934 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2937 | "help": (help_, [], _('hg help [COMMAND]')), | |
2935 | "identify|id": (identify, [], _('hg identify')), |
|
2938 | "identify|id": (identify, [], _('hg identify')), | |
2936 | "import|patch": |
|
2939 | "import|patch": | |
2937 | (import_, |
|
2940 | (import_, | |
2938 | [('p', 'strip', 1, |
|
2941 | [('p', 'strip', 1, | |
2939 | _('directory strip option for patch. This has the same\n') + |
|
2942 | _('directory strip option for patch. This has the same\n') + | |
2940 | _('meaning as the corresponding patch option')), |
|
2943 | _('meaning as the corresponding patch option')), | |
2941 | ('b', 'base', '', _('base path')), |
|
2944 | ('b', 'base', '', _('base path')), | |
2942 | ('f', 'force', None, |
|
2945 | ('f', 'force', None, | |
2943 | _('skip check for outstanding uncommitted changes'))], |
|
2946 | _('skip check for outstanding uncommitted changes'))], | |
2944 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2947 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2945 | "incoming|in": (incoming, |
|
2948 | "incoming|in": (incoming, | |
2946 | [('M', 'no-merges', None, _('do not show merges')), |
|
2949 | [('M', 'no-merges', None, _('do not show merges')), | |
2947 | ('f', 'force', None, |
|
2950 | ('f', 'force', None, | |
2948 | _('run even when remote repository is unrelated')), |
|
2951 | _('run even when remote repository is unrelated')), | |
2949 | ('', 'style', '', _('display using template map file')), |
|
2952 | ('', 'style', '', _('display using template map file')), | |
2950 | ('n', 'newest-first', None, _('show newest record first')), |
|
2953 | ('n', 'newest-first', None, _('show newest record first')), | |
2951 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2954 | ('', 'bundle', '', _('file to store the bundles into')), | |
2952 | ('p', 'patch', None, _('show patch')), |
|
2955 | ('p', 'patch', None, _('show patch')), | |
2953 | ('', 'template', '', _('display with template')), |
|
2956 | ('', 'template', '', _('display with template')), | |
2954 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2957 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2955 | ('', 'remotecmd', '', |
|
2958 | ('', 'remotecmd', '', | |
2956 | _('specify hg command to run on the remote side'))], |
|
2959 | _('specify hg command to run on the remote side'))], | |
2957 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
2960 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | |
2958 | "^init": (init, [], _('hg init [DEST]')), |
|
2961 | "^init": (init, [], _('hg init [DEST]')), | |
2959 | "locate": |
|
2962 | "locate": | |
2960 | (locate, |
|
2963 | (locate, | |
2961 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2964 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2962 | ('0', 'print0', None, |
|
2965 | ('0', 'print0', None, | |
2963 | _('end filenames with NUL, for use with xargs')), |
|
2966 | _('end filenames with NUL, for use with xargs')), | |
2964 | ('f', 'fullpath', None, |
|
2967 | ('f', 'fullpath', None, | |
2965 | _('print complete paths from the filesystem root')), |
|
2968 | _('print complete paths from the filesystem root')), | |
2966 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2969 | ('I', 'include', [], _('include names matching the given patterns')), | |
2967 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2970 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2968 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2971 | _('hg locate [OPTION]... [PATTERN]...')), | |
2969 | "^log|history": |
|
2972 | "^log|history": | |
2970 | (log, |
|
2973 | (log, | |
2971 | [('b', 'branches', None, _('show branches')), |
|
2974 | [('b', 'branches', None, _('show branches')), | |
2972 | ('k', 'keyword', [], _('search for a keyword')), |
|
2975 | ('k', 'keyword', [], _('search for a keyword')), | |
2973 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2976 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2974 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2977 | ('r', 'rev', [], _('show the specified revision or range')), | |
2975 | ('M', 'no-merges', None, _('do not show merges')), |
|
2978 | ('M', 'no-merges', None, _('do not show merges')), | |
2976 | ('', 'style', '', _('display using template map file')), |
|
2979 | ('', 'style', '', _('display using template map file')), | |
2977 | ('m', 'only-merges', None, _('show only merges')), |
|
2980 | ('m', 'only-merges', None, _('show only merges')), | |
2978 | ('p', 'patch', None, _('show patch')), |
|
2981 | ('p', 'patch', None, _('show patch')), | |
2979 | ('', 'template', '', _('display with template')), |
|
2982 | ('', 'template', '', _('display with template')), | |
2980 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2983 | ('I', 'include', [], _('include names matching the given patterns')), | |
2981 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2984 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2982 | _('hg log [OPTION]... [FILE]')), |
|
2985 | _('hg log [OPTION]... [FILE]')), | |
2983 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2986 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2984 | "merge": |
|
2987 | "merge": | |
2985 | (merge, |
|
2988 | (merge, | |
2986 | [('b', 'branch', '', _('merge with head of a specific branch')), |
|
2989 | [('b', 'branch', '', _('merge with head of a specific branch')), | |
2987 | ('', 'style', '', _('display using template map file')), |
|
2990 | ('', 'style', '', _('display using template map file')), | |
2988 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
2991 | ('f', 'force', None, _('force a merge with outstanding changes')), | |
2989 | ('', 'template', '', _('display with template'))], |
|
2992 | ('', 'template', '', _('display with template'))], | |
2990 | _('hg merge [-b TAG] [-f] [REV]')), |
|
2993 | _('hg merge [-b TAG] [-f] [REV]')), | |
2991 | "outgoing|out": (outgoing, |
|
2994 | "outgoing|out": (outgoing, | |
2992 | [('M', 'no-merges', None, _('do not show merges')), |
|
2995 | [('M', 'no-merges', None, _('do not show merges')), | |
2993 | ('f', 'force', None, |
|
2996 | ('f', 'force', None, | |
2994 | _('run even when remote repository is unrelated')), |
|
2997 | _('run even when remote repository is unrelated')), | |
2995 | ('p', 'patch', None, _('show patch')), |
|
2998 | ('p', 'patch', None, _('show patch')), | |
2996 | ('', 'style', '', _('display using template map file')), |
|
2999 | ('', 'style', '', _('display using template map file')), | |
2997 | ('n', 'newest-first', None, _('show newest record first')), |
|
3000 | ('n', 'newest-first', None, _('show newest record first')), | |
2998 | ('', 'template', '', _('display with template')), |
|
3001 | ('', 'template', '', _('display with template')), | |
2999 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3002 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3000 | ('', 'remotecmd', '', |
|
3003 | ('', 'remotecmd', '', | |
3001 | _('specify hg command to run on the remote side'))], |
|
3004 | _('specify hg command to run on the remote side'))], | |
3002 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
3005 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
3003 | "^parents": |
|
3006 | "^parents": | |
3004 | (parents, |
|
3007 | (parents, | |
3005 | [('b', 'branches', None, _('show branches')), |
|
3008 | [('b', 'branches', None, _('show branches')), | |
3006 | ('', 'style', '', _('display using template map file')), |
|
3009 | ('', 'style', '', _('display using template map file')), | |
3007 | ('', 'template', '', _('display with template'))], |
|
3010 | ('', 'template', '', _('display with template'))], | |
3008 | _('hg parents [-b] [REV]')), |
|
3011 | _('hg parents [-b] [REV]')), | |
3009 | "paths": (paths, [], _('hg paths [NAME]')), |
|
3012 | "paths": (paths, [], _('hg paths [NAME]')), | |
3010 | "^pull": |
|
3013 | "^pull": | |
3011 | (pull, |
|
3014 | (pull, | |
3012 | [('u', 'update', None, |
|
3015 | [('u', 'update', None, | |
3013 | _('update the working directory to tip after pull')), |
|
3016 | _('update the working directory to tip after pull')), | |
3014 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3017 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3015 | ('f', 'force', None, |
|
3018 | ('f', 'force', None, | |
3016 | _('run even when remote repository is unrelated')), |
|
3019 | _('run even when remote repository is unrelated')), | |
3017 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
3020 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
3018 | ('', 'remotecmd', '', |
|
3021 | ('', 'remotecmd', '', | |
3019 | _('specify hg command to run on the remote side'))], |
|
3022 | _('specify hg command to run on the remote side'))], | |
3020 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
3023 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
3021 | "^push": |
|
3024 | "^push": | |
3022 | (push, |
|
3025 | (push, | |
3023 | [('f', 'force', None, _('force push')), |
|
3026 | [('f', 'force', None, _('force push')), | |
3024 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3027 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3025 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3028 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
3026 | ('', 'remotecmd', '', |
|
3029 | ('', 'remotecmd', '', | |
3027 | _('specify hg command to run on the remote side'))], |
|
3030 | _('specify hg command to run on the remote side'))], | |
3028 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
3031 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
3029 | "debugrawcommit|rawcommit": |
|
3032 | "debugrawcommit|rawcommit": | |
3030 | (rawcommit, |
|
3033 | (rawcommit, | |
3031 | [('p', 'parent', [], _('parent')), |
|
3034 | [('p', 'parent', [], _('parent')), | |
3032 | ('d', 'date', '', _('date code')), |
|
3035 | ('d', 'date', '', _('date code')), | |
3033 | ('u', 'user', '', _('user')), |
|
3036 | ('u', 'user', '', _('user')), | |
3034 | ('F', 'files', '', _('file list')), |
|
3037 | ('F', 'files', '', _('file list')), | |
3035 | ('m', 'message', '', _('commit message')), |
|
3038 | ('m', 'message', '', _('commit message')), | |
3036 | ('l', 'logfile', '', _('commit message file'))], |
|
3039 | ('l', 'logfile', '', _('commit message file'))], | |
3037 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
3040 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
3038 | "recover": (recover, [], _('hg recover')), |
|
3041 | "recover": (recover, [], _('hg recover')), | |
3039 | "^remove|rm": |
|
3042 | "^remove|rm": | |
3040 | (remove, |
|
3043 | (remove, | |
3041 | [('f', 'force', None, _('remove file even if modified')), |
|
3044 | [('f', 'force', None, _('remove file even if modified')), | |
3042 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3045 | ('I', 'include', [], _('include names matching the given patterns')), | |
3043 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3046 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3044 | _('hg remove [OPTION]... FILE...')), |
|
3047 | _('hg remove [OPTION]... FILE...')), | |
3045 | "rename|mv": |
|
3048 | "rename|mv": | |
3046 | (rename, |
|
3049 | (rename, | |
3047 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3050 | [('A', 'after', None, _('record a rename that has already occurred')), | |
3048 | ('f', 'force', None, |
|
3051 | ('f', 'force', None, | |
3049 | _('forcibly copy over an existing managed file')), |
|
3052 | _('forcibly copy over an existing managed file')), | |
3050 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3053 | ('I', 'include', [], _('include names matching the given patterns')), | |
3051 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3054 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3052 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
3055 | _('hg rename [OPTION]... SOURCE... DEST')), | |
3053 | "^revert": |
|
3056 | "^revert": | |
3054 | (revert, |
|
3057 | (revert, | |
3055 | [('r', 'rev', '', _('revision to revert to')), |
|
3058 | [('r', 'rev', '', _('revision to revert to')), | |
3056 | ('', 'backup-name', '', _('save backup with formatted name')), |
|
3059 | ('', 'backup-name', '', _('save backup with formatted name')), | |
3057 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3060 | ('', 'no-backup', None, _('do not save backup copies of files')), | |
3058 | ('I', 'include', [], _('include names matching given patterns')), |
|
3061 | ('I', 'include', [], _('include names matching given patterns')), | |
3059 | ('X', 'exclude', [], _('exclude names matching given patterns'))], |
|
3062 | ('X', 'exclude', [], _('exclude names matching given patterns'))], | |
3060 | _('hg revert [-r REV] [NAME]...')), |
|
3063 | _('hg revert [-r REV] [NAME]...')), | |
3061 | "root": (root, [], _('hg root')), |
|
3064 | "root": (root, [], _('hg root')), | |
3062 | "^serve": |
|
3065 | "^serve": | |
3063 | (serve, |
|
3066 | (serve, | |
3064 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3067 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
3065 | ('d', 'daemon', None, _('run server in background')), |
|
3068 | ('d', 'daemon', None, _('run server in background')), | |
3066 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3069 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
3067 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3070 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
3068 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
3071 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
3069 | ('a', 'address', '', _('address to use')), |
|
3072 | ('a', 'address', '', _('address to use')), | |
3070 | ('n', 'name', '', |
|
3073 | ('n', 'name', '', | |
3071 | _('name to show in web pages (default: working dir)')), |
|
3074 | _('name to show in web pages (default: working dir)')), | |
3072 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3075 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
3073 | ('', 'stdio', None, _('for remote clients')), |
|
3076 | ('', 'stdio', None, _('for remote clients')), | |
3074 | ('t', 'templates', '', _('web templates to use')), |
|
3077 | ('t', 'templates', '', _('web templates to use')), | |
3075 | ('', 'style', '', _('template style to use')), |
|
3078 | ('', 'style', '', _('template style to use')), | |
3076 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
3079 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
3077 | _('hg serve [OPTION]...')), |
|
3080 | _('hg serve [OPTION]...')), | |
3078 | "^status|st": |
|
3081 | "^status|st": | |
3079 | (status, |
|
3082 | (status, | |
3080 | [('m', 'modified', None, _('show only modified files')), |
|
3083 | [('m', 'modified', None, _('show only modified files')), | |
3081 | ('a', 'added', None, _('show only added files')), |
|
3084 | ('a', 'added', None, _('show only added files')), | |
3082 | ('r', 'removed', None, _('show only removed files')), |
|
3085 | ('r', 'removed', None, _('show only removed files')), | |
3083 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3086 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
3084 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3087 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
3085 | ('i', 'ignored', None, _('show ignored files')), |
|
3088 | ('i', 'ignored', None, _('show ignored files')), | |
3086 | ('n', 'no-status', None, _('hide status prefix')), |
|
3089 | ('n', 'no-status', None, _('hide status prefix')), | |
3087 | ('0', 'print0', None, |
|
3090 | ('0', 'print0', None, | |
3088 | _('end filenames with NUL, for use with xargs')), |
|
3091 | _('end filenames with NUL, for use with xargs')), | |
3089 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3092 | ('I', 'include', [], _('include names matching the given patterns')), | |
3090 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3093 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3091 | _('hg status [OPTION]... [FILE]...')), |
|
3094 | _('hg status [OPTION]... [FILE]...')), | |
3092 | "tag": |
|
3095 | "tag": | |
3093 | (tag, |
|
3096 | (tag, | |
3094 | [('l', 'local', None, _('make the tag local')), |
|
3097 | [('l', 'local', None, _('make the tag local')), | |
3095 | ('m', 'message', '', _('message for tag commit log entry')), |
|
3098 | ('m', 'message', '', _('message for tag commit log entry')), | |
3096 | ('d', 'date', '', _('record datecode as commit date')), |
|
3099 | ('d', 'date', '', _('record datecode as commit date')), | |
3097 | ('u', 'user', '', _('record user as commiter')), |
|
3100 | ('u', 'user', '', _('record user as commiter')), | |
3098 | ('r', 'rev', '', _('revision to tag'))], |
|
3101 | ('r', 'rev', '', _('revision to tag'))], | |
3099 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
3102 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
3100 | "tags": (tags, [], _('hg tags')), |
|
3103 | "tags": (tags, [], _('hg tags')), | |
3101 | "tip": |
|
3104 | "tip": | |
3102 | (tip, |
|
3105 | (tip, | |
3103 | [('b', 'branches', None, _('show branches')), |
|
3106 | [('b', 'branches', None, _('show branches')), | |
3104 | ('', 'style', '', _('display using template map file')), |
|
3107 | ('', 'style', '', _('display using template map file')), | |
3105 | ('p', 'patch', None, _('show patch')), |
|
3108 | ('p', 'patch', None, _('show patch')), | |
3106 | ('', 'template', '', _('display with template'))], |
|
3109 | ('', 'template', '', _('display with template'))], | |
3107 | _('hg tip [-b] [-p]')), |
|
3110 | _('hg tip [-b] [-p]')), | |
3108 | "unbundle": |
|
3111 | "unbundle": | |
3109 | (unbundle, |
|
3112 | (unbundle, | |
3110 | [('u', 'update', None, |
|
3113 | [('u', 'update', None, | |
3111 | _('update the working directory to tip after unbundle'))], |
|
3114 | _('update the working directory to tip after unbundle'))], | |
3112 | _('hg unbundle [-u] FILE')), |
|
3115 | _('hg unbundle [-u] FILE')), | |
3113 | "undo": (undo, [], _('hg undo')), |
|
3116 | "undo": (undo, [], _('hg undo')), | |
3114 | "^update|up|checkout|co": |
|
3117 | "^update|up|checkout|co": | |
3115 | (update, |
|
3118 | (update, | |
3116 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
3119 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
3117 | ('', 'style', '', _('display using template map file')), |
|
3120 | ('', 'style', '', _('display using template map file')), | |
3118 | ('m', 'merge', None, _('allow merging of branches')), |
|
3121 | ('m', 'merge', None, _('allow merging of branches')), | |
3119 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
3122 | ('C', 'clean', None, _('overwrite locally modified files')), | |
3120 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
3123 | ('f', 'force', None, _('force a merge with outstanding changes')), | |
3121 | ('', 'template', '', _('display with template'))], |
|
3124 | ('', 'template', '', _('display with template'))], | |
3122 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
3125 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
3123 | "verify": (verify, [], _('hg verify')), |
|
3126 | "verify": (verify, [], _('hg verify')), | |
3124 | "version": (show_version, [], _('hg version')), |
|
3127 | "version": (show_version, [], _('hg version')), | |
3125 | } |
|
3128 | } | |
3126 |
|
3129 | |||
3127 | globalopts = [ |
|
3130 | globalopts = [ | |
3128 | ('R', 'repository', '', |
|
3131 | ('R', 'repository', '', | |
3129 | _('repository root directory or symbolic path name')), |
|
3132 | _('repository root directory or symbolic path name')), | |
3130 | ('', 'cwd', '', _('change working directory')), |
|
3133 | ('', 'cwd', '', _('change working directory')), | |
3131 | ('y', 'noninteractive', None, |
|
3134 | ('y', 'noninteractive', None, | |
3132 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3135 | _('do not prompt, assume \'yes\' for any required answers')), | |
3133 | ('q', 'quiet', None, _('suppress output')), |
|
3136 | ('q', 'quiet', None, _('suppress output')), | |
3134 | ('v', 'verbose', None, _('enable additional output')), |
|
3137 | ('v', 'verbose', None, _('enable additional output')), | |
3135 | ('', 'debug', None, _('enable debugging output')), |
|
3138 | ('', 'debug', None, _('enable debugging output')), | |
3136 | ('', 'debugger', None, _('start debugger')), |
|
3139 | ('', 'debugger', None, _('start debugger')), | |
3137 | ('', 'traceback', None, _('print traceback on exception')), |
|
3140 | ('', 'traceback', None, _('print traceback on exception')), | |
3138 | ('', 'time', None, _('time how long the command takes')), |
|
3141 | ('', 'time', None, _('time how long the command takes')), | |
3139 | ('', 'profile', None, _('print command execution profile')), |
|
3142 | ('', 'profile', None, _('print command execution profile')), | |
3140 | ('', 'version', None, _('output version information and exit')), |
|
3143 | ('', 'version', None, _('output version information and exit')), | |
3141 | ('h', 'help', None, _('display help and exit')), |
|
3144 | ('h', 'help', None, _('display help and exit')), | |
3142 | ] |
|
3145 | ] | |
3143 |
|
3146 | |||
3144 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
3147 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
3145 | " debugindex debugindexdot") |
|
3148 | " debugindex debugindexdot") | |
3146 | optionalrepo = ("paths debugconfig") |
|
3149 | optionalrepo = ("paths debugconfig") | |
3147 |
|
3150 | |||
3148 | def findpossible(cmd): |
|
3151 | def findpossible(cmd): | |
3149 | """ |
|
3152 | """ | |
3150 | Return cmd -> (aliases, command table entry) |
|
3153 | Return cmd -> (aliases, command table entry) | |
3151 | for each matching command |
|
3154 | for each matching command | |
3152 | """ |
|
3155 | """ | |
3153 | choice = {} |
|
3156 | choice = {} | |
3154 | debugchoice = {} |
|
3157 | debugchoice = {} | |
3155 | for e in table.keys(): |
|
3158 | for e in table.keys(): | |
3156 | aliases = e.lstrip("^").split("|") |
|
3159 | aliases = e.lstrip("^").split("|") | |
3157 | if cmd in aliases: |
|
3160 | if cmd in aliases: | |
3158 | choice[cmd] = (aliases, table[e]) |
|
3161 | choice[cmd] = (aliases, table[e]) | |
3159 | continue |
|
3162 | continue | |
3160 | for a in aliases: |
|
3163 | for a in aliases: | |
3161 | if a.startswith(cmd): |
|
3164 | if a.startswith(cmd): | |
3162 | if aliases[0].startswith("debug"): |
|
3165 | if aliases[0].startswith("debug"): | |
3163 | debugchoice[a] = (aliases, table[e]) |
|
3166 | debugchoice[a] = (aliases, table[e]) | |
3164 | else: |
|
3167 | else: | |
3165 | choice[a] = (aliases, table[e]) |
|
3168 | choice[a] = (aliases, table[e]) | |
3166 | break |
|
3169 | break | |
3167 |
|
3170 | |||
3168 | if not choice and debugchoice: |
|
3171 | if not choice and debugchoice: | |
3169 | choice = debugchoice |
|
3172 | choice = debugchoice | |
3170 |
|
3173 | |||
3171 | return choice |
|
3174 | return choice | |
3172 |
|
3175 | |||
3173 | def find(cmd): |
|
3176 | def find(cmd): | |
3174 | """Return (aliases, command table entry) for command string.""" |
|
3177 | """Return (aliases, command table entry) for command string.""" | |
3175 | choice = findpossible(cmd) |
|
3178 | choice = findpossible(cmd) | |
3176 |
|
3179 | |||
3177 | if choice.has_key(cmd): |
|
3180 | if choice.has_key(cmd): | |
3178 | return choice[cmd] |
|
3181 | return choice[cmd] | |
3179 |
|
3182 | |||
3180 | if len(choice) > 1: |
|
3183 | if len(choice) > 1: | |
3181 | clist = choice.keys() |
|
3184 | clist = choice.keys() | |
3182 | clist.sort() |
|
3185 | clist.sort() | |
3183 | raise AmbiguousCommand(cmd, clist) |
|
3186 | raise AmbiguousCommand(cmd, clist) | |
3184 |
|
3187 | |||
3185 | if choice: |
|
3188 | if choice: | |
3186 | return choice.values()[0] |
|
3189 | return choice.values()[0] | |
3187 |
|
3190 | |||
3188 | raise UnknownCommand(cmd) |
|
3191 | raise UnknownCommand(cmd) | |
3189 |
|
3192 | |||
3190 | class SignalInterrupt(Exception): |
|
3193 | class SignalInterrupt(Exception): | |
3191 | """Exception raised on SIGTERM and SIGHUP.""" |
|
3194 | """Exception raised on SIGTERM and SIGHUP.""" | |
3192 |
|
3195 | |||
3193 | def catchterm(*args): |
|
3196 | def catchterm(*args): | |
3194 | raise SignalInterrupt |
|
3197 | raise SignalInterrupt | |
3195 |
|
3198 | |||
3196 | def run(): |
|
3199 | def run(): | |
3197 | sys.exit(dispatch(sys.argv[1:])) |
|
3200 | sys.exit(dispatch(sys.argv[1:])) | |
3198 |
|
3201 | |||
3199 | class ParseError(Exception): |
|
3202 | class ParseError(Exception): | |
3200 | """Exception raised on errors in parsing the command line.""" |
|
3203 | """Exception raised on errors in parsing the command line.""" | |
3201 |
|
3204 | |||
3202 | def parse(ui, args): |
|
3205 | def parse(ui, args): | |
3203 | options = {} |
|
3206 | options = {} | |
3204 | cmdoptions = {} |
|
3207 | cmdoptions = {} | |
3205 |
|
3208 | |||
3206 | try: |
|
3209 | try: | |
3207 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3210 | args = fancyopts.fancyopts(args, globalopts, options) | |
3208 | except fancyopts.getopt.GetoptError, inst: |
|
3211 | except fancyopts.getopt.GetoptError, inst: | |
3209 | raise ParseError(None, inst) |
|
3212 | raise ParseError(None, inst) | |
3210 |
|
3213 | |||
3211 | if args: |
|
3214 | if args: | |
3212 | cmd, args = args[0], args[1:] |
|
3215 | cmd, args = args[0], args[1:] | |
3213 | aliases, i = find(cmd) |
|
3216 | aliases, i = find(cmd) | |
3214 | cmd = aliases[0] |
|
3217 | cmd = aliases[0] | |
3215 | defaults = ui.config("defaults", cmd) |
|
3218 | defaults = ui.config("defaults", cmd) | |
3216 | if defaults: |
|
3219 | if defaults: | |
3217 | args = defaults.split() + args |
|
3220 | args = defaults.split() + args | |
3218 | c = list(i[1]) |
|
3221 | c = list(i[1]) | |
3219 | else: |
|
3222 | else: | |
3220 | cmd = None |
|
3223 | cmd = None | |
3221 | c = [] |
|
3224 | c = [] | |
3222 |
|
3225 | |||
3223 | # combine global options into local |
|
3226 | # combine global options into local | |
3224 | for o in globalopts: |
|
3227 | for o in globalopts: | |
3225 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3228 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3226 |
|
3229 | |||
3227 | try: |
|
3230 | try: | |
3228 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3231 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3229 | except fancyopts.getopt.GetoptError, inst: |
|
3232 | except fancyopts.getopt.GetoptError, inst: | |
3230 | raise ParseError(cmd, inst) |
|
3233 | raise ParseError(cmd, inst) | |
3231 |
|
3234 | |||
3232 | # separate global options back out |
|
3235 | # separate global options back out | |
3233 | for o in globalopts: |
|
3236 | for o in globalopts: | |
3234 | n = o[1] |
|
3237 | n = o[1] | |
3235 | options[n] = cmdoptions[n] |
|
3238 | options[n] = cmdoptions[n] | |
3236 | del cmdoptions[n] |
|
3239 | del cmdoptions[n] | |
3237 |
|
3240 | |||
3238 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3241 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3239 |
|
3242 | |||
3240 | def dispatch(args): |
|
3243 | def dispatch(args): | |
3241 | signal.signal(signal.SIGTERM, catchterm) |
|
3244 | signal.signal(signal.SIGTERM, catchterm) | |
3242 | try: |
|
3245 | try: | |
3243 | signal.signal(signal.SIGHUP, catchterm) |
|
3246 | signal.signal(signal.SIGHUP, catchterm) | |
3244 | except AttributeError: |
|
3247 | except AttributeError: | |
3245 | pass |
|
3248 | pass | |
3246 |
|
3249 | |||
3247 | try: |
|
3250 | try: | |
3248 | u = ui.ui() |
|
3251 | u = ui.ui() | |
3249 | except util.Abort, inst: |
|
3252 | except util.Abort, inst: | |
3250 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3253 | sys.stderr.write(_("abort: %s\n") % inst) | |
3251 | sys.exit(1) |
|
3254 | sys.exit(1) | |
3252 |
|
3255 | |||
3253 | external = [] |
|
3256 | external = [] | |
3254 | for x in u.extensions(): |
|
3257 | for x in u.extensions(): | |
3255 | def on_exception(exc, inst): |
|
3258 | def on_exception(exc, inst): | |
3256 | u.warn(_("*** failed to import extension %s\n") % x[1]) |
|
3259 | u.warn(_("*** failed to import extension %s\n") % x[1]) | |
3257 | u.warn("%s\n" % inst) |
|
3260 | u.warn("%s\n" % inst) | |
3258 | if "--traceback" in sys.argv[1:]: |
|
3261 | if "--traceback" in sys.argv[1:]: | |
3259 | traceback.print_exc() |
|
3262 | traceback.print_exc() | |
3260 | if x[1]: |
|
3263 | if x[1]: | |
3261 | try: |
|
3264 | try: | |
3262 | mod = imp.load_source(x[0], x[1]) |
|
3265 | mod = imp.load_source(x[0], x[1]) | |
3263 | except Exception, inst: |
|
3266 | except Exception, inst: | |
3264 | on_exception(Exception, inst) |
|
3267 | on_exception(Exception, inst) | |
3265 | continue |
|
3268 | continue | |
3266 | else: |
|
3269 | else: | |
3267 | def importh(name): |
|
3270 | def importh(name): | |
3268 | mod = __import__(name) |
|
3271 | mod = __import__(name) | |
3269 | components = name.split('.') |
|
3272 | components = name.split('.') | |
3270 | for comp in components[1:]: |
|
3273 | for comp in components[1:]: | |
3271 | mod = getattr(mod, comp) |
|
3274 | mod = getattr(mod, comp) | |
3272 | return mod |
|
3275 | return mod | |
3273 | try: |
|
3276 | try: | |
3274 | try: |
|
3277 | try: | |
3275 | mod = importh("hgext." + x[0]) |
|
3278 | mod = importh("hgext." + x[0]) | |
3276 | except ImportError: |
|
3279 | except ImportError: | |
3277 | mod = importh(x[0]) |
|
3280 | mod = importh(x[0]) | |
3278 | except Exception, inst: |
|
3281 | except Exception, inst: | |
3279 | on_exception(Exception, inst) |
|
3282 | on_exception(Exception, inst) | |
3280 | continue |
|
3283 | continue | |
3281 |
|
3284 | |||
3282 | external.append(mod) |
|
3285 | external.append(mod) | |
3283 | for x in external: |
|
3286 | for x in external: | |
3284 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3287 | cmdtable = getattr(x, 'cmdtable', {}) | |
3285 | for t in cmdtable: |
|
3288 | for t in cmdtable: | |
3286 | if t in table: |
|
3289 | if t in table: | |
3287 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3290 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
3288 | table.update(cmdtable) |
|
3291 | table.update(cmdtable) | |
3289 |
|
3292 | |||
3290 | try: |
|
3293 | try: | |
3291 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3294 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3292 | if options["time"]: |
|
3295 | if options["time"]: | |
3293 | def get_times(): |
|
3296 | def get_times(): | |
3294 | t = os.times() |
|
3297 | t = os.times() | |
3295 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3298 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3296 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3299 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3297 | return t |
|
3300 | return t | |
3298 | s = get_times() |
|
3301 | s = get_times() | |
3299 | def print_time(): |
|
3302 | def print_time(): | |
3300 | t = get_times() |
|
3303 | t = get_times() | |
3301 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3304 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3302 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3305 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3303 | atexit.register(print_time) |
|
3306 | atexit.register(print_time) | |
3304 |
|
3307 | |||
3305 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3308 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3306 | not options["noninteractive"]) |
|
3309 | not options["noninteractive"]) | |
3307 |
|
3310 | |||
3308 | # enter the debugger before command execution |
|
3311 | # enter the debugger before command execution | |
3309 | if options['debugger']: |
|
3312 | if options['debugger']: | |
3310 | pdb.set_trace() |
|
3313 | pdb.set_trace() | |
3311 |
|
3314 | |||
3312 | try: |
|
3315 | try: | |
3313 | if options['cwd']: |
|
3316 | if options['cwd']: | |
3314 | try: |
|
3317 | try: | |
3315 | os.chdir(options['cwd']) |
|
3318 | os.chdir(options['cwd']) | |
3316 | except OSError, inst: |
|
3319 | except OSError, inst: | |
3317 | raise util.Abort('%s: %s' % |
|
3320 | raise util.Abort('%s: %s' % | |
3318 | (options['cwd'], inst.strerror)) |
|
3321 | (options['cwd'], inst.strerror)) | |
3319 |
|
3322 | |||
3320 | path = u.expandpath(options["repository"]) or "" |
|
3323 | path = u.expandpath(options["repository"]) or "" | |
3321 | repo = path and hg.repository(u, path=path) or None |
|
3324 | repo = path and hg.repository(u, path=path) or None | |
3322 |
|
3325 | |||
3323 | if options['help']: |
|
3326 | if options['help']: | |
3324 | help_(u, cmd, options['version']) |
|
3327 | help_(u, cmd, options['version']) | |
3325 | sys.exit(0) |
|
3328 | sys.exit(0) | |
3326 | elif options['version']: |
|
3329 | elif options['version']: | |
3327 | show_version(u) |
|
3330 | show_version(u) | |
3328 | sys.exit(0) |
|
3331 | sys.exit(0) | |
3329 | elif not cmd: |
|
3332 | elif not cmd: | |
3330 | help_(u, 'shortlist') |
|
3333 | help_(u, 'shortlist') | |
3331 | sys.exit(0) |
|
3334 | sys.exit(0) | |
3332 |
|
3335 | |||
3333 | if cmd not in norepo.split(): |
|
3336 | if cmd not in norepo.split(): | |
3334 | try: |
|
3337 | try: | |
3335 | if not repo: |
|
3338 | if not repo: | |
3336 | repo = hg.repository(u, path=path) |
|
3339 | repo = hg.repository(u, path=path) | |
3337 | u = repo.ui |
|
3340 | u = repo.ui | |
3338 | for x in external: |
|
3341 | for x in external: | |
3339 | if hasattr(x, 'reposetup'): |
|
3342 | if hasattr(x, 'reposetup'): | |
3340 | x.reposetup(u, repo) |
|
3343 | x.reposetup(u, repo) | |
3341 | except hg.RepoError: |
|
3344 | except hg.RepoError: | |
3342 | if cmd not in optionalrepo.split(): |
|
3345 | if cmd not in optionalrepo.split(): | |
3343 | raise |
|
3346 | raise | |
3344 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3347 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3345 | else: |
|
3348 | else: | |
3346 | d = lambda: func(u, *args, **cmdoptions) |
|
3349 | d = lambda: func(u, *args, **cmdoptions) | |
3347 |
|
3350 | |||
3348 | try: |
|
3351 | try: | |
3349 | if options['profile']: |
|
3352 | if options['profile']: | |
3350 | import hotshot, hotshot.stats |
|
3353 | import hotshot, hotshot.stats | |
3351 | prof = hotshot.Profile("hg.prof") |
|
3354 | prof = hotshot.Profile("hg.prof") | |
3352 | try: |
|
3355 | try: | |
3353 | try: |
|
3356 | try: | |
3354 | return prof.runcall(d) |
|
3357 | return prof.runcall(d) | |
3355 | except: |
|
3358 | except: | |
3356 | try: |
|
3359 | try: | |
3357 | u.warn(_('exception raised - generating ' |
|
3360 | u.warn(_('exception raised - generating ' | |
3358 | 'profile anyway\n')) |
|
3361 | 'profile anyway\n')) | |
3359 | except: |
|
3362 | except: | |
3360 | pass |
|
3363 | pass | |
3361 | raise |
|
3364 | raise | |
3362 | finally: |
|
3365 | finally: | |
3363 | prof.close() |
|
3366 | prof.close() | |
3364 | stats = hotshot.stats.load("hg.prof") |
|
3367 | stats = hotshot.stats.load("hg.prof") | |
3365 | stats.strip_dirs() |
|
3368 | stats.strip_dirs() | |
3366 | stats.sort_stats('time', 'calls') |
|
3369 | stats.sort_stats('time', 'calls') | |
3367 | stats.print_stats(40) |
|
3370 | stats.print_stats(40) | |
3368 | else: |
|
3371 | else: | |
3369 | return d() |
|
3372 | return d() | |
3370 | finally: |
|
3373 | finally: | |
3371 | u.flush() |
|
3374 | u.flush() | |
3372 | except: |
|
3375 | except: | |
3373 | # enter the debugger when we hit an exception |
|
3376 | # enter the debugger when we hit an exception | |
3374 | if options['debugger']: |
|
3377 | if options['debugger']: | |
3375 | pdb.post_mortem(sys.exc_info()[2]) |
|
3378 | pdb.post_mortem(sys.exc_info()[2]) | |
3376 | if options['traceback']: |
|
3379 | if options['traceback']: | |
3377 | traceback.print_exc() |
|
3380 | traceback.print_exc() | |
3378 | raise |
|
3381 | raise | |
3379 | except ParseError, inst: |
|
3382 | except ParseError, inst: | |
3380 | if inst.args[0]: |
|
3383 | if inst.args[0]: | |
3381 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3384 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3382 | help_(u, inst.args[0]) |
|
3385 | help_(u, inst.args[0]) | |
3383 | else: |
|
3386 | else: | |
3384 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3387 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3385 | help_(u, 'shortlist') |
|
3388 | help_(u, 'shortlist') | |
3386 | sys.exit(-1) |
|
3389 | sys.exit(-1) | |
3387 | except AmbiguousCommand, inst: |
|
3390 | except AmbiguousCommand, inst: | |
3388 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3391 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3389 | (inst.args[0], " ".join(inst.args[1]))) |
|
3392 | (inst.args[0], " ".join(inst.args[1]))) | |
3390 | sys.exit(1) |
|
3393 | sys.exit(1) | |
3391 | except UnknownCommand, inst: |
|
3394 | except UnknownCommand, inst: | |
3392 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3395 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3393 | help_(u, 'shortlist') |
|
3396 | help_(u, 'shortlist') | |
3394 | sys.exit(1) |
|
3397 | sys.exit(1) | |
3395 | except hg.RepoError, inst: |
|
3398 | except hg.RepoError, inst: | |
3396 | u.warn(_("abort: "), inst, "!\n") |
|
3399 | u.warn(_("abort: "), inst, "!\n") | |
3397 | except lock.LockHeld, inst: |
|
3400 | except lock.LockHeld, inst: | |
3398 | if inst.errno == errno.ETIMEDOUT: |
|
3401 | if inst.errno == errno.ETIMEDOUT: | |
3399 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3402 | reason = _('timed out waiting for lock held by %s') % inst.locker | |
3400 | else: |
|
3403 | else: | |
3401 | reason = _('lock held by %s') % inst.locker |
|
3404 | reason = _('lock held by %s') % inst.locker | |
3402 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3405 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | |
3403 | except lock.LockUnavailable, inst: |
|
3406 | except lock.LockUnavailable, inst: | |
3404 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3407 | u.warn(_("abort: could not lock %s: %s\n") % | |
3405 | (inst.desc or inst.filename, inst.strerror)) |
|
3408 | (inst.desc or inst.filename, inst.strerror)) | |
3406 | except revlog.RevlogError, inst: |
|
3409 | except revlog.RevlogError, inst: | |
3407 | u.warn(_("abort: "), inst, "!\n") |
|
3410 | u.warn(_("abort: "), inst, "!\n") | |
3408 | except SignalInterrupt: |
|
3411 | except SignalInterrupt: | |
3409 | u.warn(_("killed!\n")) |
|
3412 | u.warn(_("killed!\n")) | |
3410 | except KeyboardInterrupt: |
|
3413 | except KeyboardInterrupt: | |
3411 | try: |
|
3414 | try: | |
3412 | u.warn(_("interrupted!\n")) |
|
3415 | u.warn(_("interrupted!\n")) | |
3413 | except IOError, inst: |
|
3416 | except IOError, inst: | |
3414 | if inst.errno == errno.EPIPE: |
|
3417 | if inst.errno == errno.EPIPE: | |
3415 | if u.debugflag: |
|
3418 | if u.debugflag: | |
3416 | u.warn(_("\nbroken pipe\n")) |
|
3419 | u.warn(_("\nbroken pipe\n")) | |
3417 | else: |
|
3420 | else: | |
3418 | raise |
|
3421 | raise | |
3419 | except IOError, inst: |
|
3422 | except IOError, inst: | |
3420 | if hasattr(inst, "code"): |
|
3423 | if hasattr(inst, "code"): | |
3421 | u.warn(_("abort: %s\n") % inst) |
|
3424 | u.warn(_("abort: %s\n") % inst) | |
3422 | elif hasattr(inst, "reason"): |
|
3425 | elif hasattr(inst, "reason"): | |
3423 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3426 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3424 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3427 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3425 | if u.debugflag: |
|
3428 | if u.debugflag: | |
3426 | u.warn(_("broken pipe\n")) |
|
3429 | u.warn(_("broken pipe\n")) | |
3427 | elif getattr(inst, "strerror", None): |
|
3430 | elif getattr(inst, "strerror", None): | |
3428 | if getattr(inst, "filename", None): |
|
3431 | if getattr(inst, "filename", None): | |
3429 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3432 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3430 | else: |
|
3433 | else: | |
3431 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3434 | u.warn(_("abort: %s\n") % inst.strerror) | |
3432 | else: |
|
3435 | else: | |
3433 | raise |
|
3436 | raise | |
3434 | except OSError, inst: |
|
3437 | except OSError, inst: | |
3435 | if hasattr(inst, "filename"): |
|
3438 | if hasattr(inst, "filename"): | |
3436 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3439 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3437 | else: |
|
3440 | else: | |
3438 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3441 | u.warn(_("abort: %s\n") % inst.strerror) | |
3439 | except util.Abort, inst: |
|
3442 | except util.Abort, inst: | |
3440 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3443 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3441 | sys.exit(1) |
|
3444 | sys.exit(1) | |
3442 | except TypeError, inst: |
|
3445 | except TypeError, inst: | |
3443 | # was this an argument error? |
|
3446 | # was this an argument error? | |
3444 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3447 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3445 | if len(tb) > 2: # no |
|
3448 | if len(tb) > 2: # no | |
3446 | raise |
|
3449 | raise | |
3447 | u.debug(inst, "\n") |
|
3450 | u.debug(inst, "\n") | |
3448 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3451 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3449 | help_(u, cmd) |
|
3452 | help_(u, cmd) | |
3450 | except SystemExit: |
|
3453 | except SystemExit: | |
3451 | # don't catch this in the catch-all below |
|
3454 | # don't catch this in the catch-all below | |
3452 | raise |
|
3455 | raise | |
3453 | except: |
|
3456 | except: | |
3454 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3457 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3455 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3458 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
3456 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3459 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3457 | % version.get_version()) |
|
3460 | % version.get_version()) | |
3458 | raise |
|
3461 | raise | |
3459 |
|
3462 | |||
3460 | sys.exit(-1) |
|
3463 | sys.exit(-1) |
General Comments 0
You need to be logged in to leave comments.
Login now