Mercurial > hg
comparison hgext/relink.py @ 38404:398716063c2d
relink: use progress helper
This doesn't use progress.increment() because progress output is
skipped for some positions (so we may end up calling "update(0),
update(2), update(7)", or similar).
Differential Revision: https://phab.mercurial-scm.org/D3805
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 18 Jun 2018 14:52:41 -0700 |
parents | f0b6fbea00cf |
children | 36edfbac7281 |
comparison
equal
deleted
inserted
replaced
38403:8ce3f91d5f6f | 38404:398716063c2d |
---|---|
92 # the repository. | 92 # the repository. |
93 # | 93 # |
94 # mozilla-central as of 2010-06-10 had a ratio of just over 7:5. | 94 # mozilla-central as of 2010-06-10 had a ratio of just over 7:5. |
95 total = live * 3 // 2 | 95 total = live * 3 // 2 |
96 src = src.store.path | 96 src = src.store.path |
97 progress = ui.makeprogress(_('collecting'), unit=_('files'), total=total) | |
97 pos = 0 | 98 pos = 0 |
98 ui.status(_("tip has %d files, estimated total number of files: %d\n") | 99 ui.status(_("tip has %d files, estimated total number of files: %d\n") |
99 % (live, total)) | 100 % (live, total)) |
100 for dirpath, dirnames, filenames in os.walk(src): | 101 for dirpath, dirnames, filenames in os.walk(src): |
101 dirnames.sort() | 102 dirnames.sort() |
106 st = os.stat(os.path.join(dirpath, filename)) | 107 st = os.stat(os.path.join(dirpath, filename)) |
107 if not stat.S_ISREG(st.st_mode): | 108 if not stat.S_ISREG(st.st_mode): |
108 continue | 109 continue |
109 pos += 1 | 110 pos += 1 |
110 candidates.append((os.path.join(relpath, filename), st)) | 111 candidates.append((os.path.join(relpath, filename), st)) |
111 ui.progress(_('collecting'), pos, filename, _('files'), total) | 112 progress.update(pos, item=filename) |
112 | 113 |
113 ui.progress(_('collecting'), None) | 114 progress.complete() |
114 ui.status(_('collected %d candidate storage files\n') % len(candidates)) | 115 ui.status(_('collected %d candidate storage files\n') % len(candidates)) |
115 return candidates | 116 return candidates |
116 | 117 |
117 def prune(candidates, src, dst, ui): | 118 def prune(candidates, src, dst, ui): |
118 def linkfilter(src, dst, st): | 119 def linkfilter(src, dst, st): |
130 if st.st_size != ts.st_size: | 131 if st.st_size != ts.st_size: |
131 return False | 132 return False |
132 return st | 133 return st |
133 | 134 |
134 targets = [] | 135 targets = [] |
135 total = len(candidates) | 136 progress = ui.makeprogress(_('pruning'), unit=_('files'), |
137 total=len(candidates)) | |
136 pos = 0 | 138 pos = 0 |
137 for fn, st in candidates: | 139 for fn, st in candidates: |
138 pos += 1 | 140 pos += 1 |
139 srcpath = os.path.join(src, fn) | 141 srcpath = os.path.join(src, fn) |
140 tgt = os.path.join(dst, fn) | 142 tgt = os.path.join(dst, fn) |
141 ts = linkfilter(srcpath, tgt, st) | 143 ts = linkfilter(srcpath, tgt, st) |
142 if not ts: | 144 if not ts: |
143 ui.debug('not linkable: %s\n' % fn) | 145 ui.debug('not linkable: %s\n' % fn) |
144 continue | 146 continue |
145 targets.append((fn, ts.st_size)) | 147 targets.append((fn, ts.st_size)) |
146 ui.progress(_('pruning'), pos, fn, _('files'), total) | 148 progress.update(pos, item=fn) |
147 | 149 |
148 ui.progress(_('pruning'), None) | 150 progress.complete() |
149 ui.status(_('pruned down to %d probably relinkable files\n') % len(targets)) | 151 ui.status(_('pruned down to %d probably relinkable files\n') % len(targets)) |
150 return targets | 152 return targets |
151 | 153 |
152 def do_relink(src, dst, files, ui): | 154 def do_relink(src, dst, files, ui): |
153 def relinkfile(src, dst): | 155 def relinkfile(src, dst): |
162 | 164 |
163 CHUNKLEN = 65536 | 165 CHUNKLEN = 65536 |
164 relinked = 0 | 166 relinked = 0 |
165 savedbytes = 0 | 167 savedbytes = 0 |
166 | 168 |
169 progress = ui.makeprogress(_('relinking'), unit=_('files'), | |
170 total=len(files)) | |
167 pos = 0 | 171 pos = 0 |
168 total = len(files) | |
169 for f, sz in files: | 172 for f, sz in files: |
170 pos += 1 | 173 pos += 1 |
171 source = os.path.join(src, f) | 174 source = os.path.join(src, f) |
172 tgt = os.path.join(dst, f) | 175 tgt = os.path.join(dst, f) |
173 # Binary mode, so that read() works correctly, especially on Windows | 176 # Binary mode, so that read() works correctly, especially on Windows |
184 if sin: | 187 if sin: |
185 ui.debug('not linkable: %s\n' % f) | 188 ui.debug('not linkable: %s\n' % f) |
186 continue | 189 continue |
187 try: | 190 try: |
188 relinkfile(source, tgt) | 191 relinkfile(source, tgt) |
189 ui.progress(_('relinking'), pos, f, _('files'), total) | 192 progress.update(pos, item=f) |
190 relinked += 1 | 193 relinked += 1 |
191 savedbytes += sz | 194 savedbytes += sz |
192 except OSError as inst: | 195 except OSError as inst: |
193 ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst))) | 196 ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst))) |
194 | 197 |
195 ui.progress(_('relinking'), None) | 198 progress.complete() |
196 | 199 |
197 ui.status(_('relinked %d files (%s reclaimed)\n') % | 200 ui.status(_('relinked %d files (%s reclaimed)\n') % |
198 (relinked, util.bytecount(savedbytes))) | 201 (relinked, util.bytecount(savedbytes))) |