This is an archive of the discontinued Mercurial Phabricator instance.

progress: create helper class for incrementing progress
ClosedPublic

Authored by martinvonz on Jun 17 2018, 12:42 PM.

Details

Summary

When using ui.progress(), there's a clear pattern that is followed:

  • Pass the same topic and unit
  • Usually pass the same total
  • Call with pos=None to close the progress bar
  • Often keep track of the current position and increment it

This patch creates a simple helper class for this. I'll probably make
it implement the context manager protocol later (calling update(None)
on exit).

Progress is used in low-level modules like changegroup, so I also
exposed it via a method on the ui object. Perhaps the class itself
should also live in ui.py?

This patch also makes merge.oy use it to show that it works.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

martinvonz created this revision.Jun 17 2018, 12:42 PM
indygreg accepted this revision.Jun 17 2018, 2:01 PM
indygreg added a subscriber: indygreg.

The low-level progress API has always bothered me as well.

Please do follow up and add a context manager to the API!

This revision is now accepted and ready to land.Jun 17 2018, 2:01 PM
This revision was automatically updated to reflect the committed changes.

Also, it's worth keeping in mind Python function call overhead when working on this code. I'm optimistic that things that need progress bars won't be concerned about this. But it might be worth measuring and keeping in the back of your head.

Also, it's worth keeping in mind Python function call overhead when working on this code. I'm optimistic that things that need progress bars won't be concerned about this. But it might be worth measuring and keeping in the back of your head.

Good point. I also think it's unlikely to be noticeable. Also, we can probably inline the ui.progress() logic if it turns out to be an issue.