Mercurial > hg
annotate mercurial/progress.py @ 52279:b267c5764cc6 stable 6.9
relnotes: write final 6.9 notes
I've folded bugfixes that only exist to fix 6.9-specific things to the best
of my attention span for this task.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 20 Nov 2024 14:41:23 +0100 |
parents | f4733654f144 |
children |
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 |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49302
diff
changeset
|
8 from __future__ import annotations |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
9 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
10 import threading |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
11 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
|
12 |
25968
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
13 from .i18n import _ |
1139d7cf9405
progress: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25847
diff
changeset
|
14 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
|
15 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
16 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
17 def spacejoin(*args): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
18 return b' '.join(s for s in args if s) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
19 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
20 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
21 def shouldprint(ui): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
22 return not (ui.quiet or ui.plain(b'progress')) and ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
23 ui._isatty(ui.ferr) or ui.configbool(b'progress', b'assume-tty') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
24 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
25 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
26 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
27 def fmtremaining(seconds): |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26407
diff
changeset
|
28 """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
|
29 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
30 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
|
31 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
|
32 # i18n: format XX seconds as "XXs" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
33 return _(b"%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
|
34 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
|
35 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
|
36 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
|
37 # i18n: format X minutes and YY seconds as "XmYYs" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
38 return _(b"%dm%02ds") % (minutes, seconds) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
39 # 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
|
40 minutes += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 # i18n: format X hours and YY minutes as "XhYYm" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
45 return _(b"%dh%02dm") % (hours, minutes) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
46 # 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
|
47 hours += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 # i18n: format X days and YY hours as "XdYYh" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 return _(b"%dd%02dh") % (days, hours) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
53 # 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
|
54 days += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 # i18n: format X weeks and YY days as "XwYYd" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 return _(b"%dw%02dd") % (weeks, days) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
60 # 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
|
61 weeks += 1 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
62 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
|
63 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
|
64 # i18n: format X years and YY weeks as "XyYYw" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 return _(b"%dy%02dw") % (years, weeks) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
66 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
67 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
68 class progbar: |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 self.resetstate() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
73 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
74 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
|
75 self.topics = [] |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
76 self.topicstates = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
77 self.starttimes = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
78 self.startvals = {} |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
79 self.printed = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
80 self.lastprint = time.time() + float( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
81 self.ui.config(b'progress', b'delay') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
82 ) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
83 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
|
84 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
|
85 self.indetcount = 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 self.refresh = float(self.ui.config(b'progress', b'refresh')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
87 self.changedelay = max( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
88 3 * self.refresh, float(self.ui.config(b'progress', b'changedelay')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
89 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
90 self.order = self.ui.configlist(b'progress', b'format') |
34314
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
91 self.estimateinterval = self.ui.configwith( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
92 float, b'progress', b'estimateinterval' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
93 ) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
94 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
95 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
|
96 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
|
97 return |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
98 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
|
99 self.printed = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 head = b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
101 needprogress = False |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 tail = b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
103 for indicator in self.order: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
104 add = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
105 if indicator == b'topic': |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
106 add = topic |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
107 elif indicator == b'number': |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
108 if total: |
36202
707aba4d48b5
progress: use '%*d' to pad progress value
Yuya Nishihara <yuya@tcha.org>
parents:
36152
diff
changeset
|
109 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
|
110 else: |
36423
2831d918e1b4
py3: convert known-int values to bytes using %d
Augie Fackler <augie@google.com>
parents:
36202
diff
changeset
|
111 add = b'%d' % pos |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
112 elif indicator.startswith(b'item') and item: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
113 slice = b'end' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
114 if b'-' in indicator: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 wid = int(indicator.split(b'-')[1]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
116 elif b'+' in indicator: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
117 slice = b'beginning' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
118 wid = int(indicator.split(b'+')[1]) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
119 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
120 wid = 20 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
121 if slice == b'end': |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
122 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
|
123 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
124 add = encoding.trim(item, wid) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
125 add += (wid - encoding.colwidth(add)) * b' ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
126 elif indicator == b'bar': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
127 add = b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
128 needprogress = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 elif indicator == b'unit' and unit: |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
130 add = unit |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
131 elif indicator == b'estimate': |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
132 add = self.estimate(topic, pos, total, now) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 elif indicator == b'speed': |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
138 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
|
139 if needprogress: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
140 used = 0 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
141 if head: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
142 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
|
143 if tail: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 amt = pos * progwidth // total |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 bar = b'=' * (amt - 1) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
149 if amt > 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
150 bar += b'>' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
151 bar += b' ' * (progwidth - amt) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
152 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
153 progwidth -= 3 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
154 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
|
155 # 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
|
156 # 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
|
157 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
|
158 amt -= progwidth |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
159 bar = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
160 b' ' * int(progwidth - abs(amt)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 + b'<=>' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 + b' ' * int(abs(amt)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
163 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 prog = b''.join((b'[', bar, b']')) |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
165 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
|
166 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
167 out = spacejoin(head, tail) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
168 self._writeerr(b'\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
|
169 self.lasttopic = topic |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
170 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
|
171 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
172 def clear(self): |
29089
222b8170d69e
progress: stop excessive clearing (issue4801)
Matt Mackall <mpm@selenic.com>
parents:
28171
diff
changeset
|
173 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
|
174 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
175 self._writeerr(b'\r%s\r' % (b' ' * self.width())) |
44033
4e0a6d157910
progress: flush stderr after clearing
Kyle Lippincott <spectral@google.com>
parents:
43077
diff
changeset
|
176 self._flusherr() |
26407
72bccc1f26b1
progress: force a repaint of a printed progress bar after a clear()
Augie Fackler <augie@google.com>
parents:
25968
diff
changeset
|
177 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
|
178 # 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
|
179 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
|
180 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
181 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
|
182 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
|
183 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
184 if self.ui.configbool(b'progress', b'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
|
185 self.clear() |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
186 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
187 self._writeerr(b'\n') |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
188 self._flusherr() |
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
189 |
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
190 def _flusherr(self): |
49302
ee4537e365c8
py3: remove retry on EINTR errno
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
191 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
|
192 |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
193 def _writeerr(self, msg): |
49302
ee4537e365c8
py3: remove retry on EINTR errno
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
194 self.ui.ferr.write(msg) |
32048
c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
Yuya Nishihara <yuya@tcha.org>
parents:
30324
diff
changeset
|
195 |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
196 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
|
197 tw = self.ui.termwidth() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 return min(int(self.ui.config(b'progress', b'width', default=tw)), tw) |
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 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
|
201 if total is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 return b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 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
|
207 elapsed = now - self.starttimes[topic] |
34313
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
208 seconds = (elapsed * (target - delta)) // delta + 1 |
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
209 return fmtremaining(seconds) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
210 return b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
211 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 elapsed = now - self.starttimes[topic] |
34313
f428c347d32b
progress: remove progress.estimate config
Jun Wu <quark@fb.com>
parents:
33499
diff
changeset
|
216 if elapsed > 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 return _(b'%d %s/sec') % (delta / elapsed, unit) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
218 return b'' |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
219 |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
220 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
|
221 '''Check if conditions are met to print - e.g. changedelay elapsed''' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
222 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
223 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
|
224 # 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
|
225 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
|
226 # it's been long enough we should print anyway |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
227 or now - self.lastprint >= self.changedelay |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
228 ): |
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 True |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
230 else: |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
231 return False |
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
232 |
34314
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
233 def _calibrateestimate(self, topic, now, pos): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44033
diff
changeset
|
234 """Adjust starttimes and startvals for topic so ETA works better |
34314
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
235 |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
236 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:
34313
diff
changeset
|
237 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:
34313
diff
changeset
|
238 calculation. |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
239 |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
240 [======================================> ] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
241 ^^^^^^^ |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
242 estimateinterval, only use this for estimation |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44033
diff
changeset
|
243 """ |
34314
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
244 interval = self.estimateinterval |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
245 if interval <= 0: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
246 return |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
247 elapsed = now - self.starttimes[topic] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
248 if elapsed > interval: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
249 delta = pos - self.startvals[topic] |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
250 newdelta = delta * interval / elapsed |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
251 # 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:
34313
diff
changeset
|
252 # 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:
34313
diff
changeset
|
253 # smoother. |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
254 if newdelta < 0.1: |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
255 return |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
256 self.startvals[topic] = pos - newdelta |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
257 self.starttimes[topic] = now - interval |
a667f0ca1d5f
progress: make ETA only consider progress made in the last minute
Jun Wu <quark@fb.com>
parents:
34313
diff
changeset
|
258 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
259 def progress(self, topic, pos, item=b'', unit=b'', total=None): |
38418
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
260 if pos is None: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
261 self.closetopic(topic) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
262 return |
25497
93b8b0049932
progress: move most extension code into a 'mercurial.progress' module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff
changeset
|
263 now = time.time() |
38417
6bd9f18d31a8
progress: use context manager for lock
Martin von Zweigbergk <martinvonz@google.com>
parents:
36423
diff
changeset
|
264 with self._refreshlock: |
38418
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
265 if topic not in self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
266 self.starttimes[topic] = now |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
267 self.startvals[topic] = pos |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
268 self.topics.append(topic) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
269 self.topicstates[topic] = pos, item, unit, total |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
270 self.curtopic = topic |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
271 self._calibrateestimate(topic, now, pos) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
272 if now - self.lastprint >= self.refresh and self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
273 if self._oktoprint(now): |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
274 self.lastprint = now |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
275 self.show(now, topic, *self.topicstates[topic]) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
276 |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
277 def closetopic(self, topic): |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
278 with self._refreshlock: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
279 self.starttimes.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
280 self.startvals.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
281 self.topicstates.pop(topic, None) |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
282 # reset the progress bar if this is the outermost topic |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
283 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:
38417
diff
changeset
|
284 self.complete() |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
285 self.resetstate() |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
286 # truncate the list of topics assuming all topics within |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
287 # this one are also closed |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
288 if topic in self.topics: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41143
diff
changeset
|
289 self.topics = self.topics[: self.topics.index(topic)] |
38418
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
290 # 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:
38417
diff
changeset
|
291 # so that higher-level topics will be stickier than |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
292 # lower-level topics |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
293 if self.topics: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
294 self.lasttopic = self.topics[-1] |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
295 else: |
b34d0a6ef936
progress: extract function for closing topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
38417
diff
changeset
|
296 self.lasttopic = None |