21 |
21 |
22 def help(): |
22 def help(): |
23 print """\ |
23 print """\ |
24 commands: |
24 commands: |
25 |
25 |
26 init create a new repository in this directory |
26 add [files...] add the given files in the next commit |
|
27 addremove add all new files, delete all missing files |
|
28 annotate [files...] show changeset number per file line |
27 branch <path> create a branch of <path> in this directory |
29 branch <path> create a branch of <path> in this directory |
28 merge <path> merge changes from <path> into local repository |
|
29 checkout [changeset] checkout the latest or given changeset |
30 checkout [changeset] checkout the latest or given changeset |
30 status show new, missing, and changed files in working dir |
|
31 add [files...] add the given files in the next commit |
|
32 remove [files...] remove the given files in the next commit |
|
33 addremove add all new files, delete all missing files |
|
34 commit commit all changes to the repository |
31 commit commit all changes to the repository |
35 history show changeset history |
32 diff [files...] diff working directory (or selected files) |
36 log <file> show revision history of a single file |
|
37 dump <file> [rev] dump the latest or given revision of a file |
33 dump <file> [rev] dump the latest or given revision of a file |
38 dumpmanifest [rev] dump the latest or given revision of the manifest |
34 dumpmanifest [rev] dump the latest or given revision of the manifest |
39 diff [files...] diff working directory (or selected files) |
35 history show changeset history |
|
36 init create a new repository in this directory |
|
37 log <file> show revision history of a single file |
|
38 merge <path> merge changes from <path> into local repository |
|
39 remove [files...] remove the given files in the next commit |
|
40 status show new, missing, and changed files in working dir |
40 tags show current changeset tags |
41 tags show current changeset tags |
41 annotate [files...] show changeset number per file line |
|
42 blame [files...] show commit user per file line |
|
43 """ |
42 """ |
44 |
43 |
45 def filterfiles(list, files): |
44 def filterfiles(list, files): |
46 l = [ x for x in list if x in files ] |
45 l = [ x for x in list if x in files ] |
47 |
46 |
213 else: args = [ os.path.join(relpath, x) for x in args ] |
212 else: args = [ os.path.join(relpath, x) for x in args ] |
214 |
213 |
215 diff(args, *revs) |
214 diff(args, *revs) |
216 |
215 |
217 elif cmd == "annotate": |
216 elif cmd == "annotate": |
|
217 bcache = {} |
|
218 |
|
219 def getnode(rev): |
|
220 return hg.short(repo.changelog.node(rev)) |
|
221 |
|
222 def getname(rev): |
|
223 try: |
|
224 return bcache[rev] |
|
225 except KeyError: |
|
226 cl = repo.changelog.read(repo.changelog.node(rev)) |
|
227 name = cl[1] |
|
228 f = name.find('@') |
|
229 if f >= 0: |
|
230 name = name[:f] |
|
231 bcache[rev] = name |
|
232 return name |
|
233 |
218 aoptions = {} |
234 aoptions = {} |
219 opts = [('r', 'revision', '', 'revision')] |
235 opts = [('r', 'revision', '', 'revision'), |
|
236 ('u', 'user', None, 'show user'), |
|
237 ('n', 'number', None, 'show revision number'), |
|
238 ('c', 'changeset', None, 'show changeset')] |
|
239 |
220 args = fancyopts.fancyopts(args, opts, aoptions, |
240 args = fancyopts.fancyopts(args, opts, aoptions, |
221 'hg annotate [-r id] [files]') |
241 'hg annotate [-u] [-c] [-n] [-r id] [files]') |
|
242 |
|
243 opmap = [['user', getname], ['number', str], ['changeset', getnode]] |
|
244 if not aoptions['user'] and not aoptions['changeset']: |
|
245 aoptions['number'] = 1 |
222 |
246 |
223 if args: |
247 if args: |
224 if relpath: args = [ os.path.join(relpath, x) for x in args ] |
248 if relpath: args = [ os.path.join(relpath, x) for x in args ] |
225 |
|
226 node = repo.current |
249 node = repo.current |
227 if aoptions['revision']: |
250 if aoptions['revision']: |
228 node = repo.changelog.lookup(aoptions['revision']) |
251 node = repo.changelog.lookup(aoptions['revision']) |
229 change = repo.changelog.read(node) |
252 change = repo.changelog.read(node) |
230 mmap = repo.manifest.read(change[0]) |
253 mmap = repo.manifest.read(change[0]) |
|
254 maxuserlen = 0 |
|
255 maxchangelen = 0 |
231 for f in args: |
256 for f in args: |
232 for n, l in repo.file(f).annotate(mmap[f]): |
257 lines = repo.file(f).annotate(mmap[f]) |
233 sys.stdout.write("% 6s:%s"%(n, l)) |
258 pieces = [] |
234 |
259 |
235 elif cmd == "blame": |
260 for o, f in opmap: |
236 aoptions = {} |
261 if aoptions[o]: |
237 opts = [('r', 'revision', '', 'revision')] |
262 l = [ f(n) for n,t in lines ] |
238 args = fancyopts.fancyopts(args, opts, aoptions, |
263 m = max(map(len, l)) |
239 'hg blame [-r id] [files]') |
264 pieces.append([ "%*s" % (m, x) for x in l]) |
240 if args: |
265 |
241 bcache = {} |
266 for p,l in zip(zip(*pieces), lines): |
242 node = repo.current |
267 sys.stdout.write(" ".join(p) + ": " + l[1]) |
243 if aoptions['revision']: |
|
244 node = repo.changelog.lookup(aoptions['revision']) |
|
245 change = repo.changelog.read(node) |
|
246 mmap = repo.manifest.read(change[0]) |
|
247 for f in args: |
|
248 for n, l in repo.file(f).annotate(mmap[f]): |
|
249 try: |
|
250 name = bcache[n] |
|
251 except KeyError: |
|
252 cl = repo.changelog.read(repo.changelog.node(n)) |
|
253 name = cl[1] |
|
254 f = name.find('@') |
|
255 if f >= 0: |
|
256 name = name[:f] |
|
257 bcache[n] = name |
|
258 sys.stdout.write("% 10s:%s"%(name, l)) |
|
259 |
268 |
260 elif cmd == "export": |
269 elif cmd == "export": |
261 node = repo.lookup(args[0]) |
270 node = repo.lookup(args[0]) |
262 prev, other = repo.changelog.parents(node) |
271 prev, other = repo.changelog.parents(node) |
263 change = repo.changelog.read(node) |
272 change = repo.changelog.read(node) |