##// END OF EJS Templates
formatter: add pickle format...
Matt Mackall -
r22430:968247e8 default
parent child Browse files
Show More
@@ -1,119 +1,132
1 # formatter.py - generic output formatting for mercurial
1 # formatter.py - generic output formatting for mercurial
2 #
2 #
3 # Copyright 2012 Matt Mackall <mpm@selenic.com>
3 # Copyright 2012 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import cPickle
8 from i18n import _
9 from i18n import _
9 import encoding, util
10 import encoding, util
10
11
11 class baseformatter(object):
12 class baseformatter(object):
12 def __init__(self, ui, topic, opts):
13 def __init__(self, ui, topic, opts):
13 self._ui = ui
14 self._ui = ui
14 self._topic = topic
15 self._topic = topic
15 self._style = opts.get("style")
16 self._style = opts.get("style")
16 self._template = opts.get("template")
17 self._template = opts.get("template")
17 self._item = None
18 self._item = None
18 def __bool__(self):
19 def __bool__(self):
19 '''return False if we're not doing real templating so we can
20 '''return False if we're not doing real templating so we can
20 skip extra work'''
21 skip extra work'''
21 return True
22 return True
22 def _showitem(self):
23 def _showitem(self):
23 '''show a formatted item once all data is collected'''
24 '''show a formatted item once all data is collected'''
24 pass
25 pass
25 def startitem(self):
26 def startitem(self):
26 '''begin an item in the format list'''
27 '''begin an item in the format list'''
27 if self._item is not None:
28 if self._item is not None:
28 self._showitem()
29 self._showitem()
29 self._item = {}
30 self._item = {}
30 def data(self, **data):
31 def data(self, **data):
31 '''insert data into item that's not shown in default output'''
32 '''insert data into item that's not shown in default output'''
32 self._item.update(data)
33 self._item.update(data)
33 def write(self, fields, deftext, *fielddata, **opts):
34 def write(self, fields, deftext, *fielddata, **opts):
34 '''do default text output while assigning data to item'''
35 '''do default text output while assigning data to item'''
35 for k, v in zip(fields.split(), fielddata):
36 for k, v in zip(fields.split(), fielddata):
36 self._item[k] = v
37 self._item[k] = v
37 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
38 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
38 '''do conditional write (primarily for plain formatter)'''
39 '''do conditional write (primarily for plain formatter)'''
39 for k, v in zip(fields.split(), fielddata):
40 for k, v in zip(fields.split(), fielddata):
40 self._item[k] = v
41 self._item[k] = v
41 def plain(self, text, **opts):
42 def plain(self, text, **opts):
42 '''show raw text for non-templated mode'''
43 '''show raw text for non-templated mode'''
43 pass
44 pass
44 def end(self):
45 def end(self):
45 '''end output for the formatter'''
46 '''end output for the formatter'''
46 if self._item is not None:
47 if self._item is not None:
47 self._showitem()
48 self._showitem()
48
49
49 class plainformatter(baseformatter):
50 class plainformatter(baseformatter):
50 '''the default text output scheme'''
51 '''the default text output scheme'''
51 def __init__(self, ui, topic, opts):
52 def __init__(self, ui, topic, opts):
52 baseformatter.__init__(self, ui, topic, opts)
53 baseformatter.__init__(self, ui, topic, opts)
53 def __bool__(self):
54 def __bool__(self):
54 return False
55 return False
55 def startitem(self):
56 def startitem(self):
56 pass
57 pass
57 def data(self, **data):
58 def data(self, **data):
58 pass
59 pass
59 def write(self, fields, deftext, *fielddata, **opts):
60 def write(self, fields, deftext, *fielddata, **opts):
60 self._ui.write(deftext % fielddata, **opts)
61 self._ui.write(deftext % fielddata, **opts)
61 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
62 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
62 '''do conditional write'''
63 '''do conditional write'''
63 if cond:
64 if cond:
64 self._ui.write(deftext % fielddata, **opts)
65 self._ui.write(deftext % fielddata, **opts)
65 def plain(self, text, **opts):
66 def plain(self, text, **opts):
66 self._ui.write(text, **opts)
67 self._ui.write(text, **opts)
67 def end(self):
68 def end(self):
68 pass
69 pass
69
70
70 class debugformatter(baseformatter):
71 class debugformatter(baseformatter):
71 def __init__(self, ui, topic, opts):
72 def __init__(self, ui, topic, opts):
72 baseformatter.__init__(self, ui, topic, opts)
73 baseformatter.__init__(self, ui, topic, opts)
73 self._ui.write("%s = [\n" % self._topic)
74 self._ui.write("%s = [\n" % self._topic)
74 def _showitem(self):
75 def _showitem(self):
75 self._ui.write(" " + repr(self._item) + ",\n")
76 self._ui.write(" " + repr(self._item) + ",\n")
76 def end(self):
77 def end(self):
77 baseformatter.end(self)
78 baseformatter.end(self)
78 self._ui.write("]\n")
79 self._ui.write("]\n")
79
80
81 class pickleformatter(baseformatter):
82 def __init__(self, ui, topic, opts):
83 baseformatter.__init__(self, ui, topic, opts)
84 self._data = []
85 def _showitem(self):
86 self._data.append(self._item)
87 def end(self):
88 baseformatter.end(self)
89 self._ui.write(cPickle.dumps(self._data))
90
80 class jsonformatter(baseformatter):
91 class jsonformatter(baseformatter):
81 def __init__(self, ui, topic, opts):
92 def __init__(self, ui, topic, opts):
82 baseformatter.__init__(self, ui, topic, opts)
93 baseformatter.__init__(self, ui, topic, opts)
83 self._ui.write("[")
94 self._ui.write("[")
84 self._ui._first = True
95 self._ui._first = True
85 def _showitem(self):
96 def _showitem(self):
86 if self._ui._first:
97 if self._ui._first:
87 self._ui._first = False
98 self._ui._first = False
88 else:
99 else:
89 self._ui.write(",")
100 self._ui.write(",")
90
101
91 self._ui.write("\n {\n")
102 self._ui.write("\n {\n")
92 first = True
103 first = True
93 for k, v in sorted(self._item.items()):
104 for k, v in sorted(self._item.items()):
94 if first:
105 if first:
95 first = False
106 first = False
96 else:
107 else:
97 self._ui.write(",\n")
108 self._ui.write(",\n")
98 if isinstance(v, int):
109 if isinstance(v, int):
99 self._ui.write(' "%s": %d' % (k, v))
110 self._ui.write(' "%s": %d' % (k, v))
100 else:
111 else:
101 self._ui.write(' "%s": "%s"' % (k, encoding.jsonescape(v)))
112 self._ui.write(' "%s": "%s"' % (k, encoding.jsonescape(v)))
102 self._ui.write("\n }")
113 self._ui.write("\n }")
103 def end(self):
114 def end(self):
104 baseformatter.end(self)
115 baseformatter.end(self)
105 self._ui.write("\n]\n")
116 self._ui.write("\n]\n")
106
117
107 def formatter(ui, topic, opts):
118 def formatter(ui, topic, opts):
108 template = opts.get("template", "")
119 template = opts.get("template", "")
109 if template == "json":
120 if template == "json":
110 return jsonformatter(ui, topic, opts)
121 return jsonformatter(ui, topic, opts)
122 elif template == "pickle":
123 return pickleformatter(ui, topic, opts)
111 elif template == "debug":
124 elif template == "debug":
112 return debugformatter(ui, topic, opts)
125 return debugformatter(ui, topic, opts)
113 elif template != "":
126 elif template != "":
114 raise util.Abort(_("custom templates not yet supported"))
127 raise util.Abort(_("custom templates not yet supported"))
115 elif ui.configbool('ui', 'formatdebug'):
128 elif ui.configbool('ui', 'formatdebug'):
116 return debugformatter(ui, topic, opts)
129 return debugformatter(ui, topic, opts)
117 elif ui.configbool('ui', 'formatjson'):
130 elif ui.configbool('ui', 'formatjson'):
118 return jsonformatter(ui, topic, opts)
131 return jsonformatter(ui, topic, opts)
119 return plainformatter(ui, topic, opts)
132 return plainformatter(ui, topic, opts)
@@ -1,131 +1,141
1 $ hg init repo
1 $ hg init repo
2 $ cd repo
2 $ cd repo
3 $ echo 0 > a
3 $ echo 0 > a
4 $ echo 0 > b
4 $ echo 0 > b
5 $ echo 0 > t.h
5 $ echo 0 > t.h
6 $ mkdir t
6 $ mkdir t
7 $ echo 0 > t/x
7 $ echo 0 > t/x
8 $ echo 0 > t/b
8 $ echo 0 > t/b
9 $ echo 0 > t/e.h
9 $ echo 0 > t/e.h
10 $ mkdir dir.h
10 $ mkdir dir.h
11 $ echo 0 > dir.h/foo
11 $ echo 0 > dir.h/foo
12
12
13 $ hg ci -A -m m
13 $ hg ci -A -m m
14 adding a
14 adding a
15 adding b
15 adding b
16 adding dir.h/foo
16 adding dir.h/foo
17 adding t.h
17 adding t.h
18 adding t/b
18 adding t/b
19 adding t/e.h
19 adding t/e.h
20 adding t/x
20 adding t/x
21
21
22 $ touch nottracked
22 $ touch nottracked
23
23
24 $ hg locate a
24 $ hg locate a
25 a
25 a
26
26
27 $ hg locate NONEXISTENT
27 $ hg locate NONEXISTENT
28 [1]
28 [1]
29
29
30 $ hg locate
30 $ hg locate
31 a
31 a
32 b
32 b
33 dir.h/foo
33 dir.h/foo
34 t.h
34 t.h
35 t/b
35 t/b
36 t/e.h
36 t/e.h
37 t/x
37 t/x
38
38
39 $ hg rm a
39 $ hg rm a
40 $ hg ci -m m
40 $ hg ci -m m
41
41
42 $ hg locate a
42 $ hg locate a
43 [1]
43 [1]
44 $ hg locate NONEXISTENT
44 $ hg locate NONEXISTENT
45 [1]
45 [1]
46 $ hg locate relpath:NONEXISTENT
46 $ hg locate relpath:NONEXISTENT
47 [1]
47 [1]
48 $ hg locate
48 $ hg locate
49 b
49 b
50 dir.h/foo
50 dir.h/foo
51 t.h
51 t.h
52 t/b
52 t/b
53 t/e.h
53 t/e.h
54 t/x
54 t/x
55 $ hg locate -r 0 a
55 $ hg locate -r 0 a
56 a
56 a
57 $ hg locate -r 0 NONEXISTENT
57 $ hg locate -r 0 NONEXISTENT
58 [1]
58 [1]
59 $ hg locate -r 0 relpath:NONEXISTENT
59 $ hg locate -r 0 relpath:NONEXISTENT
60 [1]
60 [1]
61 $ hg locate -r 0
61 $ hg locate -r 0
62 a
62 a
63 b
63 b
64 dir.h/foo
64 dir.h/foo
65 t.h
65 t.h
66 t/b
66 t/b
67 t/e.h
67 t/e.h
68 t/x
68 t/x
69
69
70 -I/-X with relative path should work:
70 -I/-X with relative path should work:
71
71
72 $ cd t
72 $ cd t
73 $ hg locate
73 $ hg locate
74 b
74 b
75 dir.h/foo
75 dir.h/foo
76 t.h
76 t.h
77 t/b
77 t/b
78 t/e.h
78 t/e.h
79 t/x
79 t/x
80 $ hg locate -I ../t
80 $ hg locate -I ../t
81 t/b
81 t/b
82 t/e.h
82 t/e.h
83 t/x
83 t/x
84
84
85 Issue294: hg remove --after dir fails when dir.* also exists
85 Issue294: hg remove --after dir fails when dir.* also exists
86
86
87 $ cd ..
87 $ cd ..
88 $ rm -r t
88 $ rm -r t
89
89
90 $ hg locate 't/**'
90 $ hg locate 't/**'
91 t/b (glob)
91 t/b (glob)
92 t/e.h (glob)
92 t/e.h (glob)
93 t/x (glob)
93 t/x (glob)
94
94
95 $ hg files
95 $ hg files
96 b
96 b
97 dir.h/foo
97 dir.h/foo
98 t.h
98 t.h
99 t/b
99 t/b
100 t/e.h
100 t/e.h
101 t/x
101 t/x
102 $ hg files b
102 $ hg files b
103 b
103 b
104
104
105 $ mkdir otherdir
105 $ mkdir otherdir
106 $ cd otherdir
106 $ cd otherdir
107
107
108 $ hg locate b
108 $ hg locate b
109 ../b (glob)
109 ../b (glob)
110 ../t/b (glob)
110 ../t/b (glob)
111 $ hg locate '*.h'
111 $ hg locate '*.h'
112 ../t.h (glob)
112 ../t.h (glob)
113 ../t/e.h (glob)
113 ../t/e.h (glob)
114 $ hg locate path:t/x
114 $ hg locate path:t/x
115 ../t/x (glob)
115 ../t/x (glob)
116 $ hg locate 're:.*\.h$'
116 $ hg locate 're:.*\.h$'
117 ../t.h (glob)
117 ../t.h (glob)
118 ../t/e.h (glob)
118 ../t/e.h (glob)
119 $ hg locate -r 0 b
119 $ hg locate -r 0 b
120 ../b (glob)
120 ../b (glob)
121 ../t/b (glob)
121 ../t/b (glob)
122 $ hg locate -r 0 '*.h'
122 $ hg locate -r 0 '*.h'
123 ../t.h (glob)
123 ../t.h (glob)
124 ../t/e.h (glob)
124 ../t/e.h (glob)
125 $ hg locate -r 0 path:t/x
125 $ hg locate -r 0 path:t/x
126 ../t/x (glob)
126 ../t/x (glob)
127 $ hg locate -r 0 're:.*\.h$'
127 $ hg locate -r 0 're:.*\.h$'
128 ../t.h (glob)
128 ../t.h (glob)
129 ../t/e.h (glob)
129 ../t/e.h (glob)
130
130
131 $ hg files
132 ../b
133 ../dir.h/foo
134 ../t.h
135 ../t/b
136 ../t/e.h
137 ../t/x
138 $ hg files .
139 [1]
140
131 $ cd ../..
141 $ cd ../..
@@ -1,399 +1,405
1 $ hg init repo1
1 $ hg init repo1
2 $ cd repo1
2 $ cd repo1
3 $ mkdir a b a/1 b/1 b/2
3 $ mkdir a b a/1 b/1 b/2
4 $ touch in_root a/in_a b/in_b a/1/in_a_1 b/1/in_b_1 b/2/in_b_2
4 $ touch in_root a/in_a b/in_b a/1/in_a_1 b/1/in_b_1 b/2/in_b_2
5
5
6 hg status in repo root:
6 hg status in repo root:
7
7
8 $ hg status
8 $ hg status
9 ? a/1/in_a_1
9 ? a/1/in_a_1
10 ? a/in_a
10 ? a/in_a
11 ? b/1/in_b_1
11 ? b/1/in_b_1
12 ? b/2/in_b_2
12 ? b/2/in_b_2
13 ? b/in_b
13 ? b/in_b
14 ? in_root
14 ? in_root
15
15
16 hg status . in repo root:
16 hg status . in repo root:
17
17
18 $ hg status .
18 $ hg status .
19 ? a/1/in_a_1
19 ? a/1/in_a_1
20 ? a/in_a
20 ? a/in_a
21 ? b/1/in_b_1
21 ? b/1/in_b_1
22 ? b/2/in_b_2
22 ? b/2/in_b_2
23 ? b/in_b
23 ? b/in_b
24 ? in_root
24 ? in_root
25
25
26 $ hg status --cwd a
26 $ hg status --cwd a
27 ? a/1/in_a_1
27 ? a/1/in_a_1
28 ? a/in_a
28 ? a/in_a
29 ? b/1/in_b_1
29 ? b/1/in_b_1
30 ? b/2/in_b_2
30 ? b/2/in_b_2
31 ? b/in_b
31 ? b/in_b
32 ? in_root
32 ? in_root
33 $ hg status --cwd a .
33 $ hg status --cwd a .
34 ? 1/in_a_1
34 ? 1/in_a_1
35 ? in_a
35 ? in_a
36 $ hg status --cwd a ..
36 $ hg status --cwd a ..
37 ? 1/in_a_1
37 ? 1/in_a_1
38 ? in_a
38 ? in_a
39 ? ../b/1/in_b_1
39 ? ../b/1/in_b_1
40 ? ../b/2/in_b_2
40 ? ../b/2/in_b_2
41 ? ../b/in_b
41 ? ../b/in_b
42 ? ../in_root
42 ? ../in_root
43
43
44 $ hg status --cwd b
44 $ hg status --cwd b
45 ? a/1/in_a_1
45 ? a/1/in_a_1
46 ? a/in_a
46 ? a/in_a
47 ? b/1/in_b_1
47 ? b/1/in_b_1
48 ? b/2/in_b_2
48 ? b/2/in_b_2
49 ? b/in_b
49 ? b/in_b
50 ? in_root
50 ? in_root
51 $ hg status --cwd b .
51 $ hg status --cwd b .
52 ? 1/in_b_1
52 ? 1/in_b_1
53 ? 2/in_b_2
53 ? 2/in_b_2
54 ? in_b
54 ? in_b
55 $ hg status --cwd b ..
55 $ hg status --cwd b ..
56 ? ../a/1/in_a_1
56 ? ../a/1/in_a_1
57 ? ../a/in_a
57 ? ../a/in_a
58 ? 1/in_b_1
58 ? 1/in_b_1
59 ? 2/in_b_2
59 ? 2/in_b_2
60 ? in_b
60 ? in_b
61 ? ../in_root
61 ? ../in_root
62
62
63 $ hg status --cwd a/1
63 $ hg status --cwd a/1
64 ? a/1/in_a_1
64 ? a/1/in_a_1
65 ? a/in_a
65 ? a/in_a
66 ? b/1/in_b_1
66 ? b/1/in_b_1
67 ? b/2/in_b_2
67 ? b/2/in_b_2
68 ? b/in_b
68 ? b/in_b
69 ? in_root
69 ? in_root
70 $ hg status --cwd a/1 .
70 $ hg status --cwd a/1 .
71 ? in_a_1
71 ? in_a_1
72 $ hg status --cwd a/1 ..
72 $ hg status --cwd a/1 ..
73 ? in_a_1
73 ? in_a_1
74 ? ../in_a
74 ? ../in_a
75
75
76 $ hg status --cwd b/1
76 $ hg status --cwd b/1
77 ? a/1/in_a_1
77 ? a/1/in_a_1
78 ? a/in_a
78 ? a/in_a
79 ? b/1/in_b_1
79 ? b/1/in_b_1
80 ? b/2/in_b_2
80 ? b/2/in_b_2
81 ? b/in_b
81 ? b/in_b
82 ? in_root
82 ? in_root
83 $ hg status --cwd b/1 .
83 $ hg status --cwd b/1 .
84 ? in_b_1
84 ? in_b_1
85 $ hg status --cwd b/1 ..
85 $ hg status --cwd b/1 ..
86 ? in_b_1
86 ? in_b_1
87 ? ../2/in_b_2
87 ? ../2/in_b_2
88 ? ../in_b
88 ? ../in_b
89
89
90 $ hg status --cwd b/2
90 $ hg status --cwd b/2
91 ? a/1/in_a_1
91 ? a/1/in_a_1
92 ? a/in_a
92 ? a/in_a
93 ? b/1/in_b_1
93 ? b/1/in_b_1
94 ? b/2/in_b_2
94 ? b/2/in_b_2
95 ? b/in_b
95 ? b/in_b
96 ? in_root
96 ? in_root
97 $ hg status --cwd b/2 .
97 $ hg status --cwd b/2 .
98 ? in_b_2
98 ? in_b_2
99 $ hg status --cwd b/2 ..
99 $ hg status --cwd b/2 ..
100 ? ../1/in_b_1
100 ? ../1/in_b_1
101 ? in_b_2
101 ? in_b_2
102 ? ../in_b
102 ? ../in_b
103
103
104 combining patterns with root and patterns without a root works
104 combining patterns with root and patterns without a root works
105
105
106 $ hg st a/in_a re:.*b$
106 $ hg st a/in_a re:.*b$
107 ? a/in_a
107 ? a/in_a
108 ? b/in_b
108 ? b/in_b
109
109
110 $ cd ..
110 $ cd ..
111
111
112 $ hg init repo2
112 $ hg init repo2
113 $ cd repo2
113 $ cd repo2
114 $ touch modified removed deleted ignored
114 $ touch modified removed deleted ignored
115 $ echo "^ignored$" > .hgignore
115 $ echo "^ignored$" > .hgignore
116 $ hg ci -A -m 'initial checkin'
116 $ hg ci -A -m 'initial checkin'
117 adding .hgignore
117 adding .hgignore
118 adding deleted
118 adding deleted
119 adding modified
119 adding modified
120 adding removed
120 adding removed
121 $ touch modified added unknown ignored
121 $ touch modified added unknown ignored
122 $ hg add added
122 $ hg add added
123 $ hg remove removed
123 $ hg remove removed
124 $ rm deleted
124 $ rm deleted
125
125
126 hg status:
126 hg status:
127
127
128 $ hg status
128 $ hg status
129 A added
129 A added
130 R removed
130 R removed
131 ! deleted
131 ! deleted
132 ? unknown
132 ? unknown
133
133
134 hg status modified added removed deleted unknown never-existed ignored:
134 hg status modified added removed deleted unknown never-existed ignored:
135
135
136 $ hg status modified added removed deleted unknown never-existed ignored
136 $ hg status modified added removed deleted unknown never-existed ignored
137 never-existed: * (glob)
137 never-existed: * (glob)
138 A added
138 A added
139 R removed
139 R removed
140 ! deleted
140 ! deleted
141 ? unknown
141 ? unknown
142
142
143 $ hg copy modified copied
143 $ hg copy modified copied
144
144
145 hg status -C:
145 hg status -C:
146
146
147 $ hg status -C
147 $ hg status -C
148 A added
148 A added
149 A copied
149 A copied
150 modified
150 modified
151 R removed
151 R removed
152 ! deleted
152 ! deleted
153 ? unknown
153 ? unknown
154
154
155 hg status -A:
155 hg status -A:
156
156
157 $ hg status -A
157 $ hg status -A
158 A added
158 A added
159 A copied
159 A copied
160 modified
160 modified
161 R removed
161 R removed
162 ! deleted
162 ! deleted
163 ? unknown
163 ? unknown
164 I ignored
164 I ignored
165 C .hgignore
165 C .hgignore
166 C modified
166 C modified
167
167
168 $ hg status -A -Tjson
168 $ hg status -A -Tjson
169 [
169 [
170 {
170 {
171 "path": "added",
171 "path": "added",
172 "status": "A"
172 "status": "A"
173 },
173 },
174 {
174 {
175 "copy": "modified",
175 "copy": "modified",
176 "path": "copied",
176 "path": "copied",
177 "status": "A"
177 "status": "A"
178 },
178 },
179 {
179 {
180 "path": "removed",
180 "path": "removed",
181 "status": "R"
181 "status": "R"
182 },
182 },
183 {
183 {
184 "path": "deleted",
184 "path": "deleted",
185 "status": "!"
185 "status": "!"
186 },
186 },
187 {
187 {
188 "path": "unknown",
188 "path": "unknown",
189 "status": "?"
189 "status": "?"
190 },
190 },
191 {
191 {
192 "path": "ignored",
192 "path": "ignored",
193 "status": "I"
193 "status": "I"
194 },
194 },
195 {
195 {
196 "path": ".hgignore",
196 "path": ".hgignore",
197 "status": "C"
197 "status": "C"
198 },
198 },
199 {
199 {
200 "path": "modified",
200 "path": "modified",
201 "status": "C"
201 "status": "C"
202 }
202 }
203 ]
203 ]
204
204
205 $ hg status -A -Tpickle > pickle
206 >>> import pickle
207 >>> print sorted((x['status'], x['path']) for x in pickle.load(open("pickle")))
208 [('!', 'deleted'), ('?', 'pickle'), ('?', 'unknown'), ('A', 'added'), ('A', 'copied'), ('C', '.hgignore'), ('C', 'modified'), ('I', 'ignored'), ('R', 'removed')]
209 $ rm pickle
210
205 $ echo "^ignoreddir$" > .hgignore
211 $ echo "^ignoreddir$" > .hgignore
206 $ mkdir ignoreddir
212 $ mkdir ignoreddir
207 $ touch ignoreddir/file
213 $ touch ignoreddir/file
208
214
209 hg status ignoreddir/file:
215 hg status ignoreddir/file:
210
216
211 $ hg status ignoreddir/file
217 $ hg status ignoreddir/file
212
218
213 hg status -i ignoreddir/file:
219 hg status -i ignoreddir/file:
214
220
215 $ hg status -i ignoreddir/file
221 $ hg status -i ignoreddir/file
216 I ignoreddir/file
222 I ignoreddir/file
217 $ cd ..
223 $ cd ..
218
224
219 Check 'status -q' and some combinations
225 Check 'status -q' and some combinations
220
226
221 $ hg init repo3
227 $ hg init repo3
222 $ cd repo3
228 $ cd repo3
223 $ touch modified removed deleted ignored
229 $ touch modified removed deleted ignored
224 $ echo "^ignored$" > .hgignore
230 $ echo "^ignored$" > .hgignore
225 $ hg commit -A -m 'initial checkin'
231 $ hg commit -A -m 'initial checkin'
226 adding .hgignore
232 adding .hgignore
227 adding deleted
233 adding deleted
228 adding modified
234 adding modified
229 adding removed
235 adding removed
230 $ touch added unknown ignored
236 $ touch added unknown ignored
231 $ hg add added
237 $ hg add added
232 $ echo "test" >> modified
238 $ echo "test" >> modified
233 $ hg remove removed
239 $ hg remove removed
234 $ rm deleted
240 $ rm deleted
235 $ hg copy modified copied
241 $ hg copy modified copied
236
242
237 Run status with 2 different flags.
243 Run status with 2 different flags.
238 Check if result is the same or different.
244 Check if result is the same or different.
239 If result is not as expected, raise error
245 If result is not as expected, raise error
240
246
241 $ assert() {
247 $ assert() {
242 > hg status $1 > ../a
248 > hg status $1 > ../a
243 > hg status $2 > ../b
249 > hg status $2 > ../b
244 > if diff ../a ../b > /dev/null; then
250 > if diff ../a ../b > /dev/null; then
245 > out=0
251 > out=0
246 > else
252 > else
247 > out=1
253 > out=1
248 > fi
254 > fi
249 > if [ $3 -eq 0 ]; then
255 > if [ $3 -eq 0 ]; then
250 > df="same"
256 > df="same"
251 > else
257 > else
252 > df="different"
258 > df="different"
253 > fi
259 > fi
254 > if [ $out -ne $3 ]; then
260 > if [ $out -ne $3 ]; then
255 > echo "Error on $1 and $2, should be $df."
261 > echo "Error on $1 and $2, should be $df."
256 > fi
262 > fi
257 > }
263 > }
258
264
259 Assert flag1 flag2 [0-same | 1-different]
265 Assert flag1 flag2 [0-same | 1-different]
260
266
261 $ assert "-q" "-mard" 0
267 $ assert "-q" "-mard" 0
262 $ assert "-A" "-marduicC" 0
268 $ assert "-A" "-marduicC" 0
263 $ assert "-qA" "-mardcC" 0
269 $ assert "-qA" "-mardcC" 0
264 $ assert "-qAui" "-A" 0
270 $ assert "-qAui" "-A" 0
265 $ assert "-qAu" "-marducC" 0
271 $ assert "-qAu" "-marducC" 0
266 $ assert "-qAi" "-mardicC" 0
272 $ assert "-qAi" "-mardicC" 0
267 $ assert "-qu" "-u" 0
273 $ assert "-qu" "-u" 0
268 $ assert "-q" "-u" 1
274 $ assert "-q" "-u" 1
269 $ assert "-m" "-a" 1
275 $ assert "-m" "-a" 1
270 $ assert "-r" "-d" 1
276 $ assert "-r" "-d" 1
271 $ cd ..
277 $ cd ..
272
278
273 $ hg init repo4
279 $ hg init repo4
274 $ cd repo4
280 $ cd repo4
275 $ touch modified removed deleted
281 $ touch modified removed deleted
276 $ hg ci -q -A -m 'initial checkin'
282 $ hg ci -q -A -m 'initial checkin'
277 $ touch added unknown
283 $ touch added unknown
278 $ hg add added
284 $ hg add added
279 $ hg remove removed
285 $ hg remove removed
280 $ rm deleted
286 $ rm deleted
281 $ echo x > modified
287 $ echo x > modified
282 $ hg copy modified copied
288 $ hg copy modified copied
283 $ hg ci -m 'test checkin' -d "1000001 0"
289 $ hg ci -m 'test checkin' -d "1000001 0"
284 $ rm *
290 $ rm *
285 $ touch unrelated
291 $ touch unrelated
286 $ hg ci -q -A -m 'unrelated checkin' -d "1000002 0"
292 $ hg ci -q -A -m 'unrelated checkin' -d "1000002 0"
287
293
288 hg status --change 1:
294 hg status --change 1:
289
295
290 $ hg status --change 1
296 $ hg status --change 1
291 M modified
297 M modified
292 A added
298 A added
293 A copied
299 A copied
294 R removed
300 R removed
295
301
296 hg status --change 1 unrelated:
302 hg status --change 1 unrelated:
297
303
298 $ hg status --change 1 unrelated
304 $ hg status --change 1 unrelated
299
305
300 hg status -C --change 1 added modified copied removed deleted:
306 hg status -C --change 1 added modified copied removed deleted:
301
307
302 $ hg status -C --change 1 added modified copied removed deleted
308 $ hg status -C --change 1 added modified copied removed deleted
303 M modified
309 M modified
304 A added
310 A added
305 A copied
311 A copied
306 modified
312 modified
307 R removed
313 R removed
308
314
309 hg status -A --change 1 and revset:
315 hg status -A --change 1 and revset:
310
316
311 $ hg status -A --change '1|1'
317 $ hg status -A --change '1|1'
312 M modified
318 M modified
313 A added
319 A added
314 A copied
320 A copied
315 modified
321 modified
316 R removed
322 R removed
317 C deleted
323 C deleted
318
324
319 status against non-parent with unknown file (issue4321)
325 status against non-parent with unknown file (issue4321)
320
326
321 $ touch unknown
327 $ touch unknown
322 $ hg status --rev 0 unknown
328 $ hg status --rev 0 unknown
323 ? unknown
329 ? unknown
324
330
325 status of removed but existing in working directory. "? removed" should
331 status of removed but existing in working directory. "? removed" should
326 not be included:
332 not be included:
327
333
328 $ touch removed
334 $ touch removed
329 $ hg status --rev 0 removed
335 $ hg status --rev 0 removed
330 R removed
336 R removed
331
337
332 $ cd ..
338 $ cd ..
333
339
334 hg status of binary file starting with '\1\n', a separator for metadata:
340 hg status of binary file starting with '\1\n', a separator for metadata:
335
341
336 $ hg init repo5
342 $ hg init repo5
337 $ cd repo5
343 $ cd repo5
338 >>> open("010a", "wb").write("\1\nfoo")
344 >>> open("010a", "wb").write("\1\nfoo")
339 $ hg ci -q -A -m 'initial checkin'
345 $ hg ci -q -A -m 'initial checkin'
340 $ hg status -A
346 $ hg status -A
341 C 010a
347 C 010a
342
348
343 >>> open("010a", "wb").write("\1\nbar")
349 >>> open("010a", "wb").write("\1\nbar")
344 $ hg status -A
350 $ hg status -A
345 M 010a
351 M 010a
346 $ hg ci -q -m 'modify 010a'
352 $ hg ci -q -m 'modify 010a'
347 $ hg status -A --rev 0:1
353 $ hg status -A --rev 0:1
348 M 010a
354 M 010a
349
355
350 $ touch empty
356 $ touch empty
351 $ hg ci -q -A -m 'add another file'
357 $ hg ci -q -A -m 'add another file'
352 $ hg status -A --rev 1:2 010a
358 $ hg status -A --rev 1:2 010a
353 C 010a
359 C 010a
354
360
355 $ cd ..
361 $ cd ..
356
362
357 test "hg status" with "directory pattern" which matches against files
363 test "hg status" with "directory pattern" which matches against files
358 only known on target revision.
364 only known on target revision.
359
365
360 $ hg init repo6
366 $ hg init repo6
361 $ cd repo6
367 $ cd repo6
362
368
363 $ echo a > a.txt
369 $ echo a > a.txt
364 $ hg add a.txt
370 $ hg add a.txt
365 $ hg commit -m '#0'
371 $ hg commit -m '#0'
366 $ mkdir -p 1/2/3/4/5
372 $ mkdir -p 1/2/3/4/5
367 $ echo b > 1/2/3/4/5/b.txt
373 $ echo b > 1/2/3/4/5/b.txt
368 $ hg add 1/2/3/4/5/b.txt
374 $ hg add 1/2/3/4/5/b.txt
369 $ hg commit -m '#1'
375 $ hg commit -m '#1'
370
376
371 $ hg update -C 0 > /dev/null
377 $ hg update -C 0 > /dev/null
372 $ hg status -A
378 $ hg status -A
373 C a.txt
379 C a.txt
374
380
375 the directory matching against specified pattern should be removed,
381 the directory matching against specified pattern should be removed,
376 because directory existence prevents 'dirstate.walk()' from showing
382 because directory existence prevents 'dirstate.walk()' from showing
377 warning message about such pattern.
383 warning message about such pattern.
378
384
379 $ test ! -d 1
385 $ test ! -d 1
380 $ hg status -A --rev 1 1/2/3/4/5/b.txt
386 $ hg status -A --rev 1 1/2/3/4/5/b.txt
381 R 1/2/3/4/5/b.txt
387 R 1/2/3/4/5/b.txt
382 $ hg status -A --rev 1 1/2/3/4/5
388 $ hg status -A --rev 1 1/2/3/4/5
383 R 1/2/3/4/5/b.txt
389 R 1/2/3/4/5/b.txt
384 $ hg status -A --rev 1 1/2/3
390 $ hg status -A --rev 1 1/2/3
385 R 1/2/3/4/5/b.txt
391 R 1/2/3/4/5/b.txt
386 $ hg status -A --rev 1 1
392 $ hg status -A --rev 1 1
387 R 1/2/3/4/5/b.txt
393 R 1/2/3/4/5/b.txt
388
394
389 $ hg status --config ui.formatdebug=True --rev 1 1
395 $ hg status --config ui.formatdebug=True --rev 1 1
390 status = [
396 status = [
391 {*'path': '1/2/3/4/5/b.txt'*}, (glob)
397 {*'path': '1/2/3/4/5/b.txt'*}, (glob)
392 ]
398 ]
393
399
394 #if windows
400 #if windows
395 $ hg --config ui.slash=false status -A --rev 1 1
401 $ hg --config ui.slash=false status -A --rev 1 1
396 R 1\2\3\4\5\b.txt
402 R 1\2\3\4\5\b.txt
397 #endif
403 #endif
398
404
399 $ cd ..
405 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now