mirror of
https://github.com/facebook/sapling.git
synced 2025-01-06 04:43:19 +03:00
Add options to annotate for user/rev/changeset
This eliminates the blame command and makes annotate more flexible.
This commit is contained in:
parent
a9d4acea6a
commit
33b3059287
89
hg
89
hg
@ -23,23 +23,22 @@ def help():
|
||||
print """\
|
||||
commands:
|
||||
|
||||
init create a new repository in this directory
|
||||
branch <path> create a branch of <path> in this directory
|
||||
merge <path> merge changes from <path> into local repository
|
||||
checkout [changeset] checkout the latest or given changeset
|
||||
status show new, missing, and changed files in working dir
|
||||
add [files...] add the given files in the next commit
|
||||
remove [files...] remove the given files in the next commit
|
||||
addremove add all new files, delete all missing files
|
||||
annotate [files...] show changeset number per file line
|
||||
branch <path> create a branch of <path> in this directory
|
||||
checkout [changeset] checkout the latest or given changeset
|
||||
commit commit all changes to the repository
|
||||
history show changeset history
|
||||
log <file> show revision history of a single file
|
||||
diff [files...] diff working directory (or selected files)
|
||||
dump <file> [rev] dump the latest or given revision of a file
|
||||
dumpmanifest [rev] dump the latest or given revision of the manifest
|
||||
diff [files...] diff working directory (or selected files)
|
||||
history show changeset history
|
||||
init create a new repository in this directory
|
||||
log <file> show revision history of a single file
|
||||
merge <path> merge changes from <path> into local repository
|
||||
remove [files...] remove the given files in the next commit
|
||||
status show new, missing, and changed files in working dir
|
||||
tags show current changeset tags
|
||||
annotate [files...] show changeset number per file line
|
||||
blame [files...] show commit user per file line
|
||||
"""
|
||||
|
||||
def filterfiles(list, files):
|
||||
@ -215,47 +214,57 @@ elif cmd == "diff":
|
||||
diff(args, *revs)
|
||||
|
||||
elif cmd == "annotate":
|
||||
bcache = {}
|
||||
|
||||
def getnode(rev):
|
||||
return hg.short(repo.changelog.node(rev))
|
||||
|
||||
def getname(rev):
|
||||
try:
|
||||
return bcache[rev]
|
||||
except KeyError:
|
||||
cl = repo.changelog.read(repo.changelog.node(rev))
|
||||
name = cl[1]
|
||||
f = name.find('@')
|
||||
if f >= 0:
|
||||
name = name[:f]
|
||||
bcache[rev] = name
|
||||
return name
|
||||
|
||||
aoptions = {}
|
||||
opts = [('r', 'revision', '', 'revision')]
|
||||
opts = [('r', 'revision', '', 'revision'),
|
||||
('u', 'user', None, 'show user'),
|
||||
('n', 'number', None, 'show revision number'),
|
||||
('c', 'changeset', None, 'show changeset')]
|
||||
|
||||
args = fancyopts.fancyopts(args, opts, aoptions,
|
||||
'hg annotate [-r id] [files]')
|
||||
'hg annotate [-u] [-c] [-n] [-r id] [files]')
|
||||
|
||||
opmap = [['user', getname], ['number', str], ['changeset', getnode]]
|
||||
if not aoptions['user'] and not aoptions['changeset']:
|
||||
aoptions['number'] = 1
|
||||
|
||||
if args:
|
||||
if relpath: args = [ os.path.join(relpath, x) for x in args ]
|
||||
|
||||
node = repo.current
|
||||
if aoptions['revision']:
|
||||
node = repo.changelog.lookup(aoptions['revision'])
|
||||
change = repo.changelog.read(node)
|
||||
mmap = repo.manifest.read(change[0])
|
||||
maxuserlen = 0
|
||||
maxchangelen = 0
|
||||
for f in args:
|
||||
for n, l in repo.file(f).annotate(mmap[f]):
|
||||
sys.stdout.write("% 6s:%s"%(n, l))
|
||||
lines = repo.file(f).annotate(mmap[f])
|
||||
pieces = []
|
||||
|
||||
elif cmd == "blame":
|
||||
aoptions = {}
|
||||
opts = [('r', 'revision', '', 'revision')]
|
||||
args = fancyopts.fancyopts(args, opts, aoptions,
|
||||
'hg blame [-r id] [files]')
|
||||
if args:
|
||||
bcache = {}
|
||||
node = repo.current
|
||||
if aoptions['revision']:
|
||||
node = repo.changelog.lookup(aoptions['revision'])
|
||||
change = repo.changelog.read(node)
|
||||
mmap = repo.manifest.read(change[0])
|
||||
for f in args:
|
||||
for n, l in repo.file(f).annotate(mmap[f]):
|
||||
try:
|
||||
name = bcache[n]
|
||||
except KeyError:
|
||||
cl = repo.changelog.read(repo.changelog.node(n))
|
||||
name = cl[1]
|
||||
f = name.find('@')
|
||||
if f >= 0:
|
||||
name = name[:f]
|
||||
bcache[n] = name
|
||||
sys.stdout.write("% 10s:%s"%(name, l))
|
||||
for o, f in opmap:
|
||||
if aoptions[o]:
|
||||
l = [ f(n) for n,t in lines ]
|
||||
m = max(map(len, l))
|
||||
pieces.append([ "%*s" % (m, x) for x in l])
|
||||
|
||||
for p,l in zip(zip(*pieces), lines):
|
||||
sys.stdout.write(" ".join(p) + ": " + l[1])
|
||||
|
||||
elif cmd == "export":
|
||||
node = repo.lookup(args[0])
|
||||
|
Loading…
Reference in New Issue
Block a user