##// END OF EJS Templates
Show date in history
mpm@selenic.com -
r21:54a57a5e default
parent child Browse files
Show More
@@ -1,288 +1,289 b''
1 1 #!/usr/bin/env python
2 2 #
3 3 # mercurial - a minimal scalable distributed SCM
4 4 # v0.4d "oedipa maas"
5 5 #
6 6 # Copyright 2005 Matt Mackall <mpm@selenic.com>
7 7 #
8 8 # This software may be used and distributed according to the terms
9 9 # of the GNU General Public License, incorporated herein by reference.
10 10
11 11 # the psyco compiler makes commits about twice as fast
12 12 try:
13 13 import psyco
14 14 psyco.full()
15 15 except:
16 16 pass
17 17
18 18 import sys, os
19 19 from mercurial import hg, mdiff, fancyopts
20 20
21 21 def help():
22 22 print """\
23 23 commands:
24 24
25 25 init create a new repository in this directory
26 26 branch <path> create a branch of <path> in this directory
27 27 merge <path> merge changes from <path> into local repository
28 28 checkout [changeset] checkout the latest or given changeset
29 29 status show new, missing, and changed files in working dir
30 30 add [files...] add the given files in the next commit
31 31 remove [files...] remove the given files in the next commit
32 32 addremove add all new files, delete all missing files
33 33 commit commit all changes to the repository
34 34 history show changeset history
35 35 log <file> show revision history of a single file
36 36 dump <file> [rev] dump the latest or given revision of a file
37 37 dumpmanifest [rev] dump the latest or given revision of the manifest
38 38 """
39 39
40
41 40 options = {}
42 41 opts = [('v', 'verbose', None, 'verbose'),
43 42 ('d', 'debug', None, 'debug')]
44 43
45 44 args = fancyopts.fancyopts(sys.argv[1:], opts, options,
46 45 'hg [options] <command> [command options] [files]')
47 46
48 47 try:
49 48 cmd = args[0]
50 49 args = args[1:]
51 50 except:
52 51 cmd = ""
53 52
54 53 ui = hg.ui(options["verbose"], options["debug"])
55 54
56 55 if cmd == "init":
57 56 repo = hg.repository(ui, ".", create=1)
58 57 sys.exit(0)
59 58 elif cmd == "branch" or cmd == "clone":
60 59 os.system("cp -al %s/.hg .hg" % args[0])
61 60 sys.exit(0)
62 61 elif cmd == "help":
63 62 help()
64 63 sys.exit(0)
65 64 else:
66 65 try:
67 66 repo = hg.repository(ui=ui)
68 67 except:
69 68 print "Unable to open repository"
70 69 sys.exit(0)
71 70
72 71 if cmd == "checkout" or cmd == "co":
73 72 node = repo.changelog.tip()
74 73 if len(args):
75 74 if len(args[0]) < 40:
76 75 rev = int(args[0])
77 76 node = repo.changelog.node(rev)
78 77 else:
79 78 node = args[0]
80 79 repo.checkout(node)
81 80
82 81 elif cmd == "add":
83 82 repo.add(args)
84 83
85 84 elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete":
86 85 repo.remove(args)
87 86
88 87 elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
89 88 if 1:
90 89 if len(args) > 0:
91 90 repo.commit(args)
92 91 else:
93 92 repo.commit()
94 93
95 94 elif cmd == "import" or cmd == "patch":
96 95 ioptions = {}
97 96 opts = [('p', 'strip', 1, 'path strip'),
98 97 ('b', 'base', "", 'base path')]
99 98
100 99 args = fancyopts.fancyopts(args, opts, ioptions,
101 100 'hg import [options] <patch names>')
102 101 d = ioptions["base"]
103 102 strip = ioptions["strip"]
104 103
105 104 for patch in args:
106 105 ui.status("applying %s\n" % patch)
107 106 pf = d + patch
108 107 os.system("patch -p%d < %s > /dev/null" % (strip, pf))
109 108 f = os.popen("lsdiff --strip %d %s" % (strip, pf))
110 109 files = f.read().splitlines()
111 110 f.close()
112 111 repo.commit(files)
113 112
114 113 elif cmd == "status":
115 114 (c, a, d) = repo.diffdir(repo.root)
116 115 for f in c: print "C", f
117 116 for f in a: print "?", f
118 117 for f in d: print "R", f
119 118
120 119 elif cmd == "diff":
121 120 mmap = {}
122 121 if repo.current:
123 122 change = repo.changelog.read(repo.current)
124 123 mmap = repo.manifest.read(change[0])
125 124
126 125 (c, a, d) = repo.diffdir(repo.root)
127 126 for f in c:
128 127 to = repo.file(f).read(mmap[f])
129 128 tn = file(f).read()
130 129 sys.stdout.write(mdiff.unidiff(to, tn, f))
131 130 for f in a:
132 131 to = ""
133 132 tn = file(f).read()
134 133 sys.stdout.write(mdiff.unidiff(to, tn, f))
135 134 for f in d:
136 135 to = repo.file(f).read(mmap[f])
137 136 tn = ""
138 137 sys.stdout.write(mdiff.unidiff(to, tn, f))
139 138
140 139 elif cmd == "addremove":
141 140 (c, a, d) = repo.diffdir(repo.root)
142 141 repo.add(a)
143 142 repo.remove(d)
144 143
145 144 elif cmd == "history":
146 145 for i in range(repo.changelog.count()):
147 146 n = repo.changelog.node(i)
148 147 changes = repo.changelog.read(n)
149 148 (p1, p2) = repo.changelog.parents(n)
150 149 (h, h1, h2) = map(hg.hex, (n, p1, p2))
151 150 (i1, i2) = map(repo.changelog.rev, (p1, p2))
152 151 print "rev: %4d:%s" % (i, h)
153 152 print "parents: %4d:%s" % (i1, h1)
154 153 if i2: print " %4d:%s" % (i2, h2)
155 154 print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]),
156 155 hg.hex(changes[0]))
157 156 print "user:", changes[1]
157 print "date:", time.asctime(
158 time.localtime(float(changes[2].split(' ')[0])))
158 159 print "files:", " ".join(changes[3])
159 160 print "description:"
160 161 print changes[4]
161 162
162 163 elif cmd == "log":
163 164 if args:
164 165 r = repo.file(args[0])
165 166 for i in range(r.count()):
166 167 n = r.node(i)
167 168 (p1, p2) = r.parents(n)
168 169 (h, h1, h2) = map(hg.hex, (n, p1, p2))
169 170 (i1, i2) = map(r.rev, (p1, p2))
170 171 cr = r.linkrev(n)
171 172 cn = hg.hex(repo.changelog.node(cr))
172 173 print "rev: %4d:%s" % (i, h)
173 174 print "changeset: %4d:%s" % (cr, cn)
174 175 print "parents: %4d:%s" % (i1, h1)
175 176 if i2: print " %4d:%s" % (i2, h2)
176 177 else:
177 178 print "missing filename"
178 179
179 180 elif cmd == "dump":
180 181 if args:
181 182 r = repo.file(args[0])
182 183 n = r.tip()
183 184 if len(args) > 1: n = hg.bin(args[1])
184 185 sys.stdout.write(r.read(n))
185 186 else:
186 187 print "missing filename"
187 188
188 189 elif cmd == "dumpmanifest":
189 190 n = repo.manifest.tip()
190 191 if len(args) > 0:
191 192 n = hg.bin(args[0])
192 193 m = repo.manifest.read(n)
193 194 files = m.keys()
194 195 files.sort()
195 196
196 197 for f in files:
197 198 print hg.hex(m[f]), f
198 199
199 200 elif cmd == "merge":
200 201 if args:
201 202 other = hg.repository(ui, args[0])
202 203 repo.merge(other)
203 204 else:
204 205 print "missing source repository"
205 206
206 207 elif cmd == "verify":
207 208 filelinkrevs = {}
208 209 filenodes = {}
209 210 manifestchangeset = {}
210 211 changesets = revisions = files = 0
211 212
212 213 print "checking changesets"
213 214 for i in range(repo.changelog.count()):
214 215 changesets += 1
215 216 n = repo.changelog.node(i)
216 217 changes = repo.changelog.read(n)
217 218 manifestchangeset[changes[0]] = n
218 219 for f in changes[3]:
219 220 revisions += 1
220 221 filelinkrevs.setdefault(f, []).append(i)
221 222
222 223 print "checking manifests"
223 224 for i in range(repo.manifest.count()):
224 225 n = repo.manifest.node(i)
225 226 ca = repo.changelog.node(repo.manifest.linkrev(n))
226 227 cc = manifestchangeset[n]
227 228 if ca != cc:
228 229 print "manifest %s points to %s, not %s" % \
229 230 (hg.hex(n), hg.hex(ca), hg.hex(cc))
230 231 m = repo.manifest.read(n)
231 232 for f, fn in m.items():
232 233 filenodes.setdefault(f, {})[fn] = 1
233 234
234 235 print "crosschecking files in changesets and manifests"
235 236 for f in filenodes:
236 237 if f not in filelinkrevs:
237 238 print "file %s in manifest but not in changesets"
238 239
239 240 for f in filelinkrevs:
240 241 if f not in filenodes:
241 242 print "file %s in changeset but not in manifest"
242 243
243 244 print "checking files"
244 245 for f in filenodes:
245 246 files += 1
246 247 fl = repo.file(f)
247 248 nodes = {"\0"*20: 1}
248 249 for i in range(fl.count()):
249 250 n = fl.node(i)
250 251
251 252 if n not in filenodes[f]:
252 253 print "%s:%s not in manifests" % (f, hg.hex(n))
253 254 else:
254 255 del filenodes[f][n]
255 256
256 257 flr = fl.linkrev(n)
257 258 if flr not in filelinkrevs[f]:
258 259 print "%s:%s points to unexpected changeset rev %d" \
259 260 % (f, hg.hex(n), fl.linkrev(n))
260 261 else:
261 262 filelinkrevs[f].remove(flr)
262 263
263 264 # verify contents
264 265 t = fl.read(n)
265 266
266 267 # verify parents
267 268 (p1, p2) = fl.parents(n)
268 269 if p1 not in nodes:
269 270 print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1))
270 271 if p2 not in nodes:
271 272 print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1))
272 273 nodes[n] = 1
273 274
274 275 # cross-check
275 276 for flr in filelinkrevs[f]:
276 277 print "changeset rev %d not in %s" % (flr, f)
277 278
278 279 for node in filenodes[f]:
279 280 print "node %s in manifests not in %s" % (hg.hex(n), f)
280 281
281 282
282 283 print "%d files, %d changesets, %d total revisions" % (files, changesets,
283 284 revisions)
284 285
285 286 else:
286 287 print "unknown command\n"
287 288 help()
288 289 sys.exit(1)
General Comments 0
You need to be logged in to leave comments. Login now