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