This is an archive of the discontinued Mercurial Phabricator instance.

infinitepush: add summary of not-backed-up files to smartlog
ClosedPublic

Authored by mbthomas on Jul 26 2017, 11:53 AM.

Details

Summary

Allow summarisation of commits that have not been backed up
by infinitepush.

  1. Add a template keyword (backupstatus) which evaluates to one of "Public", "Backed up", "Backup pending", or "Not backed up" depending on the backup state of the commit. Commits are pending for 10 minutes, after which they are declared not backed up.
  1. Add a summary to the end of smartlog that shows the number of commits that are not backed up.

    Configuration options allow the addition of an education message to inform users what to do about their failing backups, and the message can also be suppressed.
Test Plan
New unit test for both the keyword and the summary.

Diff Detail

Repository
rFBHGX Facebook Mercurial Extensions
Branch
default
Lint
Lint OK
Unit
Unit Tests OK

Event Timeline

mbthomas created this revision.Jul 26 2017, 11:53 AM
akushner added inline comments.
tests/test-infinitepush-backup-status.t
86

Might be worthwhile giving slightly more detail. "not backed up" might be worrying. Do people know the expectations for when things are backed up? Should there be advice on how to use 'hg pushbackup' if they are immediately going offline on their laptop?

quark added a subscriber: quark.Jul 26 2017, 6:39 PM

I also think the text might be a bit too verbose. Maybe make it part of the ssl template, or just some color changes in sl output.

infinitepush/backupcommands.py
29

According to a recent discussion, we prefer suppress-summary style config names.

310

Instead of implementing it as a template keyword that hardcodes the text, have you considered implementing a revset that returns all commits that are backed-up?

Supposed the revset was called backedup(), we can use it in templates to customize the text (and color) in our template configs:

hg sl -T '{if(revset("{rev} and backedup()"), "Backed Up")}'

Besides, people gain the flexibility of querying what are (and are not) backed up using revsets:

hg log -r 'backedup()'
hg log -r 'draft() - backedup()'
319

nit: no underscore in variable or method names.

Same for smartlog_summary and other places.

337

nit: prefer changeset to commit as a noun.

mitrandir added inline comments.
tests/test-infinitepush-backup-status.t
86

I have similar concerns about this: how is the message actionable?

mbthomas updated this revision to Diff 424.Jul 27 2017, 8:33 AM

Add configuration option for enabling backup status reporting

More changes incoming to fix up naming of things.

infinitepush/backupcommands.py
310

I hadn't considered that, but it sounds like a good idea. I'll take a look at what it involves.

The purpose of this change is to highlight commits that are more than 10 minutes old but not backed up. That's almost possible with revset syntax, except date() doesn't accept relative date specs. Otherwise I could use (draft() & date("<10 minutes ago")) - backedup(). Is there a way to do that that I am missing?

tests/test-infinitepush-backup-status.t
86

It's expected that the actions the user will need to take will vary depending on the installation, which is the purpose of the "smartlog_education" configuration option. In fact it might just be that the user is offline (and they realise this), which is why backups aren't currently taking place. In which case, this note is just a count of the commits they haven't been able to back up yet.

quark added inline comments.Jul 27 2017, 3:25 PM
infinitepush/backupcommands.py
310

Unfortunately, date does not support that today. I think -1 (within 1 day) could be a good approximate and we could enhance the date revset with another patch.

stash requested changes to this revision.Jul 28 2017, 5:17 AM
stash added inline comments.
infinitepush/backupcommands.py
27–37

I'm worried about the number of options infinitepush has. How about leaving just one option enablestatus? We can hardcode smartlog_education to

Run `hg pushbackup` to run a backup. If it fails please report to Source Control@Fb group.

And we can suppress smartlog summary if enablestatus is false. What do you think?

310

Let's use a revsets instead of templates. Maybe it's not even worth changing the date() revset, -1 day may be enough.

314–315

I think we discussed offline that we don't want to return 'Public' and 'Backed up'. Have you changed your mind?

321–324

It looks a bit more complicated that I imagined it. Why not:

if time.time() - ctx.date()[0] > 60 * 10:  # 10 minutes
  return 'Backup pending'
343

In that case it would be great to also print commit hash

This revision now requires changes to proceed.Jul 28 2017, 5:17 AM
mbthomas added inline comments.Jul 28 2017, 6:48 AM
infinitepush/backupcommands.py
310

I was wondering whether an age() revset would be a useful addition in general, e.g. age('>10m'), age('<20d'), etc.

quark added inline comments.Jul 28 2017, 11:05 AM
infinitepush/backupcommands.py
310

If you want to make date more flexible, have a look at mercurial.util.matchdate.

mbthomas edited edge metadata.Jul 28 2017, 1:47 PM
mbthomas updated this revision to Diff 445.

Switch to revsetpredicate for backedup()

mbthomas marked 6 inline comments as done.Jul 28 2017, 3:34 PM
mbthomas added inline comments.
infinitepush/backupcommands.py
310

I'm going to add a new age() predicate as a separate diff.

stash added inline comments.Jul 28 2017, 4:02 PM
infinitepush/backupcommands.py
310

How's it different from date(...) revset?

mbthomas marked 3 inline comments as done.Jul 31 2017, 5:39 AM
mbthomas added inline comments.
infinitepush/backupcommands.py
310

Both work on the date of the commit, but age() matches commits based on relative time, whereas date() is absolute time.

I could put this functionality in date(), but I think it's better separate, because:

  • Mercurial's date parsing is custom - I'd need to modify core mercurial to change it, and be careful not to break it.
  • The UX would be fairly poor, date("<2 hours ago") would mean "before 2 hours ago", even though it reads like "less than 2 hours ago".
  • Doing it this way results in a fairly trivial extension.
tests/test-infinitepush-backup-status.t
86

Will update the message as suggested above.

stash requested changes to this revision.Jul 31 2017, 6:28 AM
stash added inline comments.
infinitepush/backupcommands.py
320–322

This is a copy-paste from backedup() function. But that's not a big problem. The bigger problem is if bkpstate.heads have a non-visible commit (it shouldn't happen, but I wouldn't be surprised if it happens from time to time). In that case we'll show to a user that some commits haven't been backed up while nothing is shown in smartlog. I think what we should do is to not use unfiltered repo and filter invisible bkpstate.heads.

visiblebpkstateheads = [head for head in bkpstate.heads if head in repo]
tests/test-infinitepush-backup-status.t
33–39

Instead of pushing you can just do hg phase -p -r . -f

89

Also makes sense to add a test if multiple commits weren't backed up

This revision now requires changes to proceed.Jul 31 2017, 6:28 AM
mbthomas edited edge metadata.Jul 31 2017, 10:13 AM
mbthomas marked 3 inline comments as done.
mbthomas updated this revision to Diff 451.

Rebase and apply review markups

mbthomas marked 11 inline comments as done.Jul 31 2017, 10:32 AM
mbthomas added inline comments.
tests/test-infinitepush-backup-status.t
33–39

I think it's better to leave it as "push" as that better replicates what users would do. The pushbackup 3 lines below would push the commit anyway, so nothing is saved by faking the push.

quark added inline comments.Jul 31 2017, 12:48 PM
infinitepush/backupcommands.py
310

date() accepts relative times too:

- "-DAYS" - within a given number of days of today

So I think it's cleaner to implement there.

stash added a comment.Jul 31 2017, 1:06 PM

@quark , we decided to use age(...) for now, and create a task to move this functionality to date(...) revset.

stash accepted this revision.EditedJul 31 2017, 1:11 PM

Let's also keep an eye on how long smartlog takes after this change

This revision is now accepted and ready to land.Jul 31 2017, 1:11 PM
mbthomas closed this revision.Aug 2 2017, 5:28 AM