Mercurial > hg-stable
annotate mercurial/progress.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 7b80406b8271 |
children | 687b865b95ad |
rev | line source |
---|---|
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
1 # progress.py progress bars related code |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
2 # |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
3 # Copyright (C) 2010 Augie Fackler <durin42@gmail.com> |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
4 # |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
7 |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
8 from __future__ import absolute_import |
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
9 |
32049
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
10 import errno |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
11 import threading |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
12 import time |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
13 |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
14 from .i18n import _ |
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
15 from . import encoding |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
16 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
17 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
18 def spacejoin(*args): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
19 return ' '.join(s for s in args if s) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
21 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
22 def shouldprint(ui): |
28171
2d20d1d2ea76
progress: display progress bar when HGPLAINEXCEPT contains "progress"
Matt Anderson <andersonmat@fb.com>
parents:
26781
diff
changeset
|
23 return not (ui.quiet or ui.plain('progress')) and ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
24 ui._isatty(ui.ferr) or ui.configbool('progress', 'assume-tty') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
25 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
26 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
27 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
28 def fmtremaining(seconds): |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26407
diff
changeset
|
29 """format a number of remaining seconds in human readable way |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
30 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
31 This will properly display seconds, minutes, hours, days if needed""" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
32 if seconds < 60: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
33 # i18n: format XX seconds as "XXs" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
34 return _("%02ds") % seconds |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
35 minutes = seconds // 60 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
36 if minutes < 60: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
37 seconds -= minutes * 60 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
38 # i18n: format X minutes and YY seconds as "XmYYs" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
39 return _("%dm%02ds") % (minutes, seconds) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
40 # we're going to ignore seconds in this case |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 minutes += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
42 hours = minutes // 60 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
43 minutes -= hours * 60 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
44 if hours < 30: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
45 # i18n: format X hours and YY minutes as "XhYYm" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
46 return _("%dh%02dm") % (hours, minutes) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
47 # we're going to ignore minutes in this case |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
48 hours += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
49 days = hours // 24 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
50 hours -= days * 24 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
51 if days < 15: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
52 # i18n: format X days and YY hours as "XdYYh" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
53 return _("%dd%02dh") % (days, hours) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
54 # we're going to ignore hours in this case |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
55 days += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
56 weeks = days // 7 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
57 days -= weeks * 7 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
58 if weeks < 55: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
59 # i18n: format X weeks and YY days as "XwYYd" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
60 return _("%dw%02dd") % (weeks, days) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
61 # we're going to ignore days and treat a year as 52 weeks |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
62 weeks += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
63 years = weeks // 52 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
64 weeks -= years * 52 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
65 # i18n: format X years and YY weeks as "XyYYw" |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
66 return _("%dy%02dw") % (years, weeks) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
67 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
68 |
32049
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
69 # file_write() and file_flush() of Python 2 do not restart on EINTR if |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
70 # the file is attached to a "slow" device (e.g. a terminal) and raise |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
71 # IOError. We cannot know how many bytes would be written by file_write(), |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
72 # but a progress text is known to be short enough to be written by a |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
73 # single write() syscall, so we can just retry file_write() with the whole |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
74 # text. (issue5532) |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
75 # |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
76 # This should be a short-term workaround. We'll need to fix every occurrence |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
77 # of write() to a terminal or pipe. |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
78 def _eintrretry(func, *args): |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
79 while True: |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
80 try: |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
81 return func(*args) |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
82 except IOError as err: |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
83 if err.errno == errno.EINTR: |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
84 continue |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
85 raise |
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
86 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
87 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
88 class progbar(object): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
89 def __init__(self, ui): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
90 self.ui = ui |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
91 self._refreshlock = threading.Lock() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
92 self.resetstate() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
93 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
94 def resetstate(self): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
95 self.topics = [] |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
96 self.topicstates = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
97 self.starttimes = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
98 self.startvals = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
99 self.printed = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
100 self.lastprint = time.time() + float( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
101 self.ui.config('progress', 'delay') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
102 ) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
103 self.curtopic = None |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
104 self.lasttopic = None |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
105 self.indetcount = 0 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
106 self.refresh = float(self.ui.config('progress', 'refresh')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
107 self.changedelay = max( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
108 3 * self.refresh, float(self.ui.config('progress', 'changedelay')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
109 ) |
34746
54fa3db5becf
configitems: register the 'progress.format' config
Boris Feld <boris.feld@octobus.net>
parents:
34486
diff
changeset
|
110 self.order = self.ui.configlist('progress', 'format') |
34321
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
111 self.estimateinterval = self.ui.configwith( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
112 float, 'progress', 'estimateinterval' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
113 ) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
114 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
115 def show(self, now, topic, pos, item, unit, total): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
116 if not shouldprint(self.ui): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
117 return |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
118 termwidth = self.width() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
119 self.printed = True |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
120 head = '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
121 needprogress = False |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
122 tail = '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
123 for indicator in self.order: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
124 add = '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
125 if indicator == 'topic': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
126 add = topic |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
127 elif indicator == 'number': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
128 if total: |
36240
707aba4d48b5
progress: use '%*d' to pad progress value
Yuya Nishihara <yuya@tcha.org>
parents:
36190
diff
changeset
|
129 add = b'%*d/%d' % (len(str(total)), pos, total) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
130 else: |
36453
2831d918e1b4
py3: convert known-int values to bytes using %d
Augie Fackler <augie@google.com>
parents:
36240
diff
changeset
|
131 add = b'%d' % pos |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
132 elif indicator.startswith('item') and item: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
133 slice = 'end' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
134 if '-' in indicator: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
135 wid = int(indicator.split('-')[1]) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
136 elif '+' in indicator: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
137 slice = 'beginning' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
138 wid = int(indicator.split('+')[1]) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
139 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
140 wid = 20 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
141 if slice == 'end': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
142 add = encoding.trim(item, wid, leftside=True) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
143 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
144 add = encoding.trim(item, wid) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
145 add += (wid - encoding.colwidth(add)) * ' ' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
146 elif indicator == 'bar': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
147 add = '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
148 needprogress = True |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
149 elif indicator == 'unit' and unit: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
150 add = unit |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
151 elif indicator == 'estimate': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
152 add = self.estimate(topic, pos, total, now) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
153 elif indicator == 'speed': |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
154 add = self.speed(topic, pos, unit, now) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
155 if not needprogress: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
156 head = spacejoin(head, add) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
157 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
158 tail = spacejoin(tail, add) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
159 if needprogress: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
160 used = 0 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
161 if head: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
162 used += encoding.colwidth(head) + 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
163 if tail: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
164 used += encoding.colwidth(tail) + 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
165 progwidth = termwidth - used - 3 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
166 if total and pos <= total: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
167 amt = pos * progwidth // total |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
168 bar = '=' * (amt - 1) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
169 if amt > 0: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
170 bar += '>' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
171 bar += ' ' * (progwidth - amt) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
172 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
173 progwidth -= 3 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
174 self.indetcount += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
175 # mod the count by twice the width so we can make the |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
176 # cursor bounce between the right and left sides |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
177 amt = self.indetcount % (2 * progwidth) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
178 amt -= progwidth |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
179 bar = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
180 ' ' * int(progwidth - abs(amt)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
181 + '<=>' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
182 + ' ' * int(abs(amt)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
183 ) |
34486
a57c938e7ac8
style: never use a space before a colon or comma
Alex Gaynor <agaynor@mozilla.com>
parents:
34321
diff
changeset
|
184 prog = ''.join(('[', bar, ']')) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
185 out = spacejoin(head, prog, tail) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
186 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
187 out = spacejoin(head, tail) |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
188 self._writeerr('\r' + encoding.trim(out, termwidth)) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
189 self.lasttopic = topic |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
190 self._flusherr() |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
191 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
192 def clear(self): |
29089
222b8170d69e
progress: stop excessive clearing (issue4801)
Matt Mackall <mpm@selenic.com>
parents:
28171
diff
changeset
|
193 if not self.printed or not self.lastprint or not shouldprint(self.ui): |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
194 return |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
195 self._writeerr('\r%s\r' % (' ' * self.width())) |
26407
72bccc1f26b1
progress: force a repaint of a printed progress bar after a clear()
Augie Fackler <augie@google.com>
parents:
25968
diff
changeset
|
196 if self.printed: |
72bccc1f26b1
progress: force a repaint of a printed progress bar after a clear()
Augie Fackler <augie@google.com>
parents:
25968
diff
changeset
|
197 # force immediate re-paint of progress bar |
72bccc1f26b1
progress: force a repaint of a printed progress bar after a clear()
Augie Fackler <augie@google.com>
parents:
25968
diff
changeset
|
198 self.lastprint = 0 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
199 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
200 def complete(self): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
201 if not shouldprint(self.ui): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
202 return |
33249
391da1416038
configitems: register the 'progress.clear-complete' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32049
diff
changeset
|
203 if self.ui.configbool('progress', 'clear-complete'): |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
204 self.clear() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
205 else: |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
206 self._writeerr('\n') |
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
207 self._flusherr() |
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
208 |
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
209 def _flusherr(self): |
32049
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
210 _eintrretry(self.ui.ferr.flush) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
211 |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
212 def _writeerr(self, msg): |
32049
ed42e00a5c4e
progress: retry ferr.flush() and .write() on EINTR (issue5532)
Yuya Nishihara <yuya@tcha.org>
parents:
32048
diff
changeset
|
213 _eintrretry(self.ui.ferr.write, msg) |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30334
diff
changeset
|
214 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
215 def width(self): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
216 tw = self.ui.termwidth() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
217 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
218 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
219 def estimate(self, topic, pos, total, now): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
220 if total is None: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
221 return '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
222 initialpos = self.startvals[topic] |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
223 target = total - initialpos |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
224 delta = pos - initialpos |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
225 if delta > 0: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
226 elapsed = now - self.starttimes[topic] |
34320
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
227 seconds = (elapsed * (target - delta)) // delta + 1 |
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
228 return fmtremaining(seconds) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
229 return '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
230 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
231 def speed(self, topic, pos, unit, now): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
232 initialpos = self.startvals[topic] |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
233 delta = pos - initialpos |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
234 elapsed = now - self.starttimes[topic] |
34320
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
235 if elapsed > 0: |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
236 return _('%d %s/sec') % (delta / elapsed, unit) |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
237 return '' |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
238 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
239 def _oktoprint(self, now): |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
240 '''Check if conditions are met to print - e.g. changedelay elapsed''' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
241 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
242 self.lasttopic is None # first time we printed |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
243 # not a topic change |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
244 or self.curtopic == self.lasttopic |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
245 # it's been long enough we should print anyway |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
246 or now - self.lastprint >= self.changedelay |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
247 ): |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
248 return True |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
249 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
250 return False |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
251 |
34321
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
252 def _calibrateestimate(self, topic, now, pos): |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
253 '''Adjust starttimes and startvals for topic so ETA works better |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
254 |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
255 If progress is non-linear (ex. get much slower in the last minute), |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
256 it's more friendly to only use a recent time span for ETA and speed |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
257 calculation. |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
258 |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
259 [======================================> ] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
260 ^^^^^^^ |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
261 estimateinterval, only use this for estimation |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
262 ''' |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
263 interval = self.estimateinterval |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
264 if interval <= 0: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
265 return |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
266 elapsed = now - self.starttimes[topic] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
267 if elapsed > interval: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
268 delta = pos - self.startvals[topic] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
269 newdelta = delta * interval / elapsed |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
270 # If a stall happens temporarily, ETA could change dramatically |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
271 # frequently. This is to avoid such dramatical change and make ETA |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
272 # smoother. |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
273 if newdelta < 0.1: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
274 return |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
275 self.startvals[topic] = pos - newdelta |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
276 self.starttimes[topic] = now - interval |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34320
diff
changeset
|
277 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
278 def progress(self, topic, pos, item='', unit='', total=None): |
38424
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
279 if pos is None: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
280 self.closetopic(topic) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
281 return |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
282 now = time.time() |
38423
6bd9f18d31a8
progress: use context manager for lock
Martin von Zweigbergk <martinvonz@google.com>
parents:
36453
diff
changeset
|
283 with self._refreshlock: |
38424
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
284 if topic not in self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
285 self.starttimes[topic] = now |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
286 self.startvals[topic] = pos |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
287 self.topics.append(topic) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
288 self.topicstates[topic] = pos, item, unit, total |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
289 self.curtopic = topic |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
290 self._calibrateestimate(topic, now, pos) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
291 if now - self.lastprint >= self.refresh and self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
292 if self._oktoprint(now): |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
293 self.lastprint = now |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
294 self.show(now, topic, *self.topicstates[topic]) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
295 |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
296 def closetopic(self, topic): |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
297 with self._refreshlock: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
298 self.starttimes.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
299 self.startvals.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
300 self.topicstates.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
301 # reset the progress bar if this is the outermost topic |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
302 if self.topics and self.topics[0] == topic and self.printed: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
303 self.complete() |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
304 self.resetstate() |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
305 # truncate the list of topics assuming all topics within |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
306 # this one are also closed |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
307 if topic in self.topics: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41144
diff
changeset
|
308 self.topics = self.topics[: self.topics.index(topic)] |
38424
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
309 # reset the last topic to the one we just unwound to, |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
310 # so that higher-level topics will be stickier than |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
311 # lower-level topics |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
312 if self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
313 self.lasttopic = self.topics[-1] |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
314 else: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38423
diff
changeset
|
315 self.lasttopic = None |