comparison mercurial/cmdutil.py @ 16776:5088d0b9a9a1

cmdutil: extract increasing_windows() from walkchangerevs() It will be reused in the revset-based version.
author Patrick Mezard <patrick@mezard.eu>
date Tue, 08 May 2012 22:43:44 +0200
parents 34c30506dd4e
children 5487088f0d43
comparison
equal deleted inserted replaced
16775:e6af8676302f 16776:5088d0b9a9a1
956 (rev, util.datestr(results[rev]))) 956 (rev, util.datestr(results[rev])))
957 return str(rev) 957 return str(rev)
958 958
959 raise util.Abort(_("revision matching date not found")) 959 raise util.Abort(_("revision matching date not found"))
960 960
961 def increasingwindows(start, end, windowsize=8, sizelimit=512):
962 if start < end:
963 while start < end:
964 yield start, min(windowsize, end - start)
965 start += windowsize
966 if windowsize < sizelimit:
967 windowsize *= 2
968 else:
969 while start > end:
970 yield start, min(windowsize, start - end - 1)
971 start -= windowsize
972 if windowsize < sizelimit:
973 windowsize *= 2
974
961 def walkchangerevs(repo, match, opts, prepare): 975 def walkchangerevs(repo, match, opts, prepare):
962 '''Iterate over files and the revs in which they changed. 976 '''Iterate over files and the revs in which they changed.
963 977
964 Callers most commonly need to iterate backwards over the history 978 Callers most commonly need to iterate backwards over the history
965 in which they are interested. Doing so has awful (quadratic-looking) 979 in which they are interested. Doing so has awful (quadratic-looking)
970 order (usually backwards) to display it. 984 order (usually backwards) to display it.
971 985
972 This function returns an iterator yielding contexts. Before 986 This function returns an iterator yielding contexts. Before
973 yielding each context, the iterator will first call the prepare 987 yielding each context, the iterator will first call the prepare
974 function on each context in the window in forward order.''' 988 function on each context in the window in forward order.'''
975
976 def increasing_windows(start, end, windowsize=8, sizelimit=512):
977 if start < end:
978 while start < end:
979 yield start, min(windowsize, end - start)
980 start += windowsize
981 if windowsize < sizelimit:
982 windowsize *= 2
983 else:
984 while start > end:
985 yield start, min(windowsize, start - end - 1)
986 start -= windowsize
987 if windowsize < sizelimit:
988 windowsize *= 2
989 989
990 follow = opts.get('follow') or opts.get('follow_first') 990 follow = opts.get('follow') or opts.get('follow_first')
991 991
992 if not len(repo): 992 if not len(repo):
993 return [] 993 return []
1174 return ff.match(rev) and rev in wanted 1174 return ff.match(rev) and rev in wanted
1175 else: 1175 else:
1176 def want(rev): 1176 def want(rev):
1177 return rev in wanted 1177 return rev in wanted
1178 1178
1179 for i, window in increasing_windows(0, len(revs)): 1179 for i, window in increasingwindows(0, len(revs)):
1180 nrevs = [rev for rev in revs[i:i + window] if want(rev)] 1180 nrevs = [rev for rev in revs[i:i + window] if want(rev)]
1181 for rev in sorted(nrevs): 1181 for rev in sorted(nrevs):
1182 fns = fncache.get(rev) 1182 fns = fncache.get(rev)
1183 ctx = change(rev) 1183 ctx = change(rev)
1184 if not fns: 1184 if not fns: