comparison hgext/convert/cvsps.py @ 9032:1fa80c5428b8

compat: use 'key' argument instead of 'cmp' when sorting a list
author Alejandro Santos <alejolp@alejolp.com>
date Sun, 05 Jul 2009 11:02:00 +0200
parents 3b76321aa0de
children 4c041f1ee1b4
comparison
equal deleted inserted replaced
9031:3b76321aa0de 9032:1fa80c5428b8
9 import os 9 import os
10 import re 10 import re
11 import cPickle as pickle 11 import cPickle as pickle
12 from mercurial import util 12 from mercurial import util
13 from mercurial.i18n import _ 13 from mercurial.i18n import _
14
15 def listsort(list, key):
16 "helper to sort by key in Python 2.3"
17 try:
18 list.sort(key=key)
19 except TypeError:
20 list.sort(lambda l, r: cmp(key(l), key(r)))
21 14
22 class logentry(object): 15 class logentry(object):
23 '''Class logentry has the following attributes: 16 '''Class logentry has the following attributes:
24 .author - author name as CVS knows it 17 .author - author name as CVS knows it
25 .branch - name of branch this revision is on 18 .branch - name of branch this revision is on
417 log.append(e) 410 log.append(e)
418 411
419 if len(log) % 100 == 0: 412 if len(log) % 100 == 0:
420 ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n') 413 ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n')
421 414
422 listsort(log, key=lambda x:(x.rcs, x.revision)) 415 log.sort(key=lambda x: (x.rcs, x.revision))
423 416
424 # find parent revisions of individual files 417 # find parent revisions of individual files
425 versions = {} 418 versions = {}
426 for e in log: 419 for e in log:
427 branch = e.revision[:-1] 420 branch = e.revision[:-1]
433 426
434 # update the log cache 427 # update the log cache
435 if cache: 428 if cache:
436 if log: 429 if log:
437 # join up the old and new logs 430 # join up the old and new logs
438 listsort(log, key=lambda x:x.date) 431 log.sort(key=lambda x: x.date)
439 432
440 if oldlog and oldlog[-1].date >= log[0].date: 433 if oldlog and oldlog[-1].date >= log[0].date:
441 raise logerror('Log cache overlaps with new log entries,' 434 raise logerror('Log cache overlaps with new log entries,'
442 ' re-run without cache.') 435 ' re-run without cache.')
443 436
482 475
483 ui.status(_('creating changesets\n')) 476 ui.status(_('creating changesets\n'))
484 477
485 # Merge changesets 478 # Merge changesets
486 479
487 listsort(log, key=lambda x:(x.comment, x.author, x.branch, x.date)) 480 log.sort(key=lambda x: (x.comment, x.author, x.branch, x.date))
488 481
489 changesets = [] 482 changesets = []
490 files = set() 483 files = set()
491 c = None 484 c = None
492 for i, e in enumerate(log): 485 for i, e in enumerate(log):