comparison mercurial/commands.py @ 6762:f67d1468ac50

util: add sort helper
author Matt Mackall <mpm@selenic.com>
date Fri, 27 Jun 2008 18:28:45 -0500
parents cb981fc955fb
children 8db64464d136
comparison
equal deleted inserted replaced
6761:cb981fc955fb 6762:f67d1468ac50
378 Use the command 'hg update' to switch to an existing branch. 378 Use the command 'hg update' to switch to an existing branch.
379 """ 379 """
380 hexfunc = ui.debugflag and hex or short 380 hexfunc = ui.debugflag and hex or short
381 activebranches = [util.tolocal(repo[n].branch()) 381 activebranches = [util.tolocal(repo[n].branch())
382 for n in repo.heads()] 382 for n in repo.heads()]
383 branches = [(tag in activebranches, repo.changelog.rev(node), tag) 383 branches = util.sort([(tag in activebranches, repo.changelog.rev(node), tag)
384 for tag, node in repo.branchtags().items()] 384 for tag, node in repo.branchtags().items()])
385 branches.sort()
386 branches.reverse() 385 branches.reverse()
387 386
388 for isactive, node, tag in branches: 387 for isactive, node, tag in branches:
389 if (not active) or isactive: 388 if (not active) or isactive:
390 if ui.quiet: 389 if ui.quiet:
633 options.append('-%s' % o[0]) 632 options.append('-%s' % o[0])
634 options.append('--%s' % o[1]) 633 options.append('--%s' % o[1])
635 ui.write("%s\n" % "\n".join(options)) 634 ui.write("%s\n" % "\n".join(options))
636 return 635 return
637 636
638 clist = cmdutil.findpossible(ui, cmd, table).keys() 637 ui.write("%s\n" % "\n".join(util.sort(cmdutil.findpossible(ui, cmd, table))))
639 clist.sort()
640 ui.write("%s\n" % "\n".join(clist))
641 638
642 def debugfsinfo(ui, path = "."): 639 def debugfsinfo(ui, path = "."):
643 file('.debugfsinfo', 'w').write('') 640 file('.debugfsinfo', 'w').write('')
644 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) 641 ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
645 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) 642 ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
725 finally: 722 finally:
726 del wlock 723 del wlock
727 724
728 def debugstate(ui, repo, nodates=None): 725 def debugstate(ui, repo, nodates=None):
729 """show the contents of the current dirstate""" 726 """show the contents of the current dirstate"""
730 k = repo.dirstate._map.items()
731 k.sort()
732 timestr = "" 727 timestr = ""
733 showdate = not nodates 728 showdate = not nodates
734 for file_, ent in k: 729 for file_, ent in util.sort(repo.dirstate._map.items()):
735 if showdate: 730 if showdate:
736 if ent[3] == -1: 731 if ent[3] == -1:
737 # Pad or slice to locale representation 732 # Pad or slice to locale representation
738 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0))) 733 locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(0)))
739 timestr = 'unset' 734 timestr = 'unset'
1140 if copied: 1135 if copied:
1141 copies.setdefault(rev, {})[fn] = copied[0] 1136 copies.setdefault(rev, {})[fn] = copied[0]
1142 except revlog.LookupError: 1137 except revlog.LookupError:
1143 pass 1138 pass
1144 elif st == 'iter': 1139 elif st == 'iter':
1145 states = matches[rev].items() 1140 for fn, m in util.sort(matches[rev].items()):
1146 states.sort()
1147 for fn, m in states:
1148 copy = copies.get(rev, {}).get(fn) 1141 copy = copies.get(rev, {}).get(fn)
1149 if fn in skip: 1142 if fn in skip:
1150 if copy: 1143 if copy:
1151 skip[copy] = True 1144 skip[copy] = True
1152 continue 1145 continue
1160 fstate[fn] = m 1153 fstate[fn] = m
1161 if copy: 1154 if copy:
1162 fstate[copy] = m 1155 fstate[copy] = m
1163 prev[fn] = rev 1156 prev[fn] = rev
1164 1157
1165 fstate = fstate.items() 1158 for fn, state in util.sort(fstate.items()):
1166 fstate.sort()
1167 for fn, state in fstate:
1168 if fn in skip: 1159 if fn in skip:
1169 continue 1160 continue
1170 if fn not in copies.get(prev[fn], {}): 1161 if fn not in copies.get(prev[fn], {}):
1171 found = display(fn, rev, {}, state) or found 1162 found = display(fn, rev, {}, state) or found
1172 return (not found and 1) or 0 1163 return (not found and 1) or 0
1302 if not h: 1293 if not h:
1303 ui.status(_('no commands defined\n')) 1294 ui.status(_('no commands defined\n'))
1304 return 1295 return
1305 1296
1306 ui.status(header) 1297 ui.status(header)
1307 fns = h.keys() 1298 fns = util.sort(h)
1308 fns.sort()
1309 m = max(map(len, fns)) 1299 m = max(map(len, fns))
1310 for f in fns: 1300 for f in fns:
1311 if ui.verbose: 1301 if ui.verbose:
1312 commands = cmds[f].replace("|",", ") 1302 commands = cmds[f].replace("|",", ")
1313 ui.write(" %s:\n %s\n"%(commands, h[f])) 1303 ui.write(" %s:\n %s\n"%(commands, h[f]))
2213 else: 2203 else:
2214 remove, forget = deleted + clean, [] 2204 remove, forget = deleted + clean, []
2215 warn(modified, _('is modified')) 2205 warn(modified, _('is modified'))
2216 warn(added, _('has been marked for add')) 2206 warn(added, _('has been marked for add'))
2217 2207
2218 files = remove + forget 2208 for f in util.sort(remove + forget):
2219 files.sort()
2220 for f in files:
2221 if ui.verbose or not m.exact(f): 2209 if ui.verbose or not m.exact(f):
2222 ui.status(_('removing %s\n') % m.rel(f)) 2210 ui.status(_('removing %s\n') % m.rel(f))
2223 2211
2224 repo.forget(forget) 2212 repo.forget(forget)
2225 repo.remove(remove, unlink=not after) 2213 repo.remove(remove, unlink=not after)
2399 (added, revert, remove, True, False), 2387 (added, revert, remove, True, False),
2400 (removed, undelete, None, False, False), 2388 (removed, undelete, None, False, False),
2401 (deleted, revert, remove, False, False), 2389 (deleted, revert, remove, False, False),
2402 ) 2390 )
2403 2391
2404 entries = names.items() 2392 for abs, (rel, exact) in util.sort(names.items()):
2405 entries.sort()
2406
2407 for abs, (rel, exact) in entries:
2408 mfentry = mf.get(abs) 2393 mfentry = mf.get(abs)
2409 target = repo.wjoin(abs) 2394 target = repo.wjoin(abs)
2410 def handle(xlist, dobackup): 2395 def handle(xlist, dobackup):
2411 xlist[0].append(abs) 2396 xlist[0].append(abs)
2412 if dobackup and not opts['no_backup'] and util.lexists(target): 2397 if dobackup and not opts['no_backup'] and util.lexists(target):