comparison mercurial/commands.py @ 3554:7ed86c28f1ae

Fixups for hg grep - kill trimuser function - remove ucache - simplify descending logic - fix files with matches logic - correct tests
author Matt Mackall <mpm@selenic.com>
date Thu, 26 Oct 2006 14:04:58 -0500
parents ba94e80e5540
children 68341c06bc61
comparison
equal deleted inserted replaced
3525:c136c28a425a 3554:7ed86c28f1ae
295 finally: 295 finally:
296 if fh is not None: 296 if fh is not None:
297 fh.close() 297 fh.close()
298 if cleanup is not None: 298 if cleanup is not None:
299 os.unlink(cleanup) 299 os.unlink(cleanup)
300
301 def trimuser(ui, name, rev, revcache):
302 """trim the name of the user who committed a change"""
303 user = revcache.get(rev)
304 if user is None:
305 user = revcache[rev] = ui.shortuser(name)
306 return user
307 300
308 class changeset_printer(object): 301 class changeset_printer(object):
309 '''show changeset information when templating not requested.''' 302 '''show changeset information when templating not requested.'''
310 303
311 def __init__(self, ui, repo): 304 def __init__(self, ui, repo):
1468 yield ('-', a[i]) 1461 yield ('-', a[i])
1469 for i in xrange(blo, bhi): 1462 for i in xrange(blo, bhi):
1470 yield ('+', b[i]) 1463 yield ('+', b[i])
1471 1464
1472 prev = {} 1465 prev = {}
1473 ucache = {}
1474 def display(fn, rev, states, prevstates): 1466 def display(fn, rev, states, prevstates):
1475 counts = {'-': 0, '+': 0} 1467 counts = {'-': 0, '+': 0}
1476 filerevmatches = {} 1468 filerevmatches = {}
1477 if incrementing or not opts['all']: 1469 if incrementing or not opts['all']:
1478 a, b = prevstates, states 1470 a, b, r = prevstates, states, rev
1479 else: 1471 else:
1480 a, b = states, prevstates 1472 a, b, r = states, prevstates, prev.get(fn, -1)
1481 for change, l in difflinestates(a, b): 1473 for change, l in difflinestates(a, b):
1482 if incrementing or not opts['all']:
1483 r = rev
1484 else:
1485 r = prev[fn]
1486 cols = [fn, str(r)] 1474 cols = [fn, str(r)]
1487 if opts['line_number']: 1475 if opts['line_number']:
1488 cols.append(str(l.linenum)) 1476 cols.append(str(l.linenum))
1489 if opts['all']: 1477 if opts['all']:
1490 cols.append(change) 1478 cols.append(change)
1491 if opts['user']: 1479 if opts['user']:
1492 cols.append(trimuser(ui, getchange(r)[1], rev, 1480 cols.append(ui.shortuser(getchange(r)[1]))
1493 ucache))
1494 if opts['files_with_matches']: 1481 if opts['files_with_matches']:
1495 c = (fn, rev) 1482 c = (fn, r)
1496 if c in filerevmatches: 1483 if c in filerevmatches:
1497 continue 1484 continue
1498 filerevmatches[c] = 1 1485 filerevmatches[c] = 1
1499 else: 1486 else:
1500 cols.append(l.line) 1487 cols.append(l.line)