This is an archive of the discontinued Mercurial Phabricator instance.

undo: localbranch revset
ClosedPublic

Authored by felixmerk on Jul 20 2017, 6:20 PM.
Tags
None
Subscribers

Details

Reviewers
stash
Group Reviewers
Restricted Project
Commits
rFBHGXac8013486e5a: undo: localbranch revset
Summary

Adds localbranch revset to be used for localbranch undos. A localbranch is a
set of draft commits that are connected via draft commits. Any draft commit
within a branch, or a public commit at the base of the branch, can be passed as
an argument to localbranch(). This will be necessary for selecting the scope
for a localbranch undo. Also fixes oldraft() output when used with other
revsets. Previously olddraft() would ignore operators such as and because of a
missing the necessary handling.

Diff Detail

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

Event Timeline

felixmerk created this revision.Jul 20 2017, 6:20 PM
Herald added a reviewer: Restricted Project. · View Herald TranscriptJul 20 2017, 6:20 PM
stash requested changes to this revision.Jul 21 2017, 5:11 AM
stash added a subscriber: stash.
stash added inline comments.
hgext3rd/undo.py
389

This is recomputed many times, I think it's a good idea to compute it only once

398–408

Doc says that you are accepting changeset, but you are really accepting arbitrary revset. Something needs to be changed, I think doc

417–420

I'm not really sure what you are trying to achieve. Are you trying to remove duplicates? In that case using set is faster and simpler to understand

This revision now requires changes to proceed.Jul 21 2017, 5:11 AM
felixmerk added inline comments.Jul 21 2017, 6:30 PM
hgext3rd/undo.py
398–408

The code does support either, but I wasn't sure how to accept both string arguments (such as 27cb) and a revset (such as draft()) while still using the revsetlang.get commands and so I restricted the input to what I needed and what I tested while allowing for future expansion of allowed inputs. Do we have some more powerful input handling commands?

417–420

Good point! That's definitely cleaner.

felixmerk edited edge metadata.Jul 21 2017, 7:08 PM
felixmerk updated this revision to Diff 384.
stash accepted this revision.Jul 24 2017, 6:20 AM

I don't want to block you so I'm going to accept the change. But before landing please do two things:

  1. Update the docstring of the revset describing the behavior of localbranch(PUBLIC)
  2. Add tests for localbranch(PUBLIC) and maybe localbranch(HASH1 + HASH2)
hgext3rd/undo.py
385–408

Do I understand correctly it's a bug fix?
If yes can you please add it to the commit message?

394

This can also be cached

398–408

No need to change the code, I'd just change the doc string from localbranch(changeset) to localbranch(revset) or something like that.

416

This case is not actually covered with tests, please do.
Also your commit message says
`Any draft commit
within a branch, or a public commit at the base of the branch, can be passed as
an argument to localbranch()`, but your docstring doesn't say it. Can you please update the docstring before landing the commit?

tests/test-undo.t
180–203

Why did you add this change? Is it related to the fix in olddraft() revset?

444

To verify your test I did arc patch and changed the test a bit:

{P57679225}

I think it's a bit clearer.

Also please add tests with public commits.

This revision is now accepted and ready to land.Jul 24 2017, 6:20 AM
felixmerk added inline comments.Jul 24 2017, 6:15 PM
hgext3rd/undo.py
385–408

It allows for logical operations such as "and" to work. I tried covering it in the commit message with "fixes oldraft() output when used with other revsets," but I can be more explicit about the nature of the bug.

tests/test-undo.t
180–203

Yes. olddraft() did not respond to "and" and some other revset operators. I hadn't realized that the revset itself had to cover that logic and I still don't know why "and" didn't work while "-" did work. I now use the same "subset &" logic that other revsets use.

444

Line 504

I guess I should add a newline and comment before

felixmerk added inline comments.Jul 24 2017, 6:33 PM
hgext3rd/undo.py
398–408

Maybe I'm misunderstanding, but "tip()" for example is a revset but not a string and so will raise an error. If you look at a revset that takes both as arguments, such as branch in revset.py, there is a lot of logic that goes with it.

felixmerk updated this revision to Diff 397.Jul 24 2017, 6:56 PM
felixmerk edited the summary of this revision. (Show Details)Jul 24 2017, 6:58 PM
stash added inline comments.Jul 25 2017, 12:58 PM
hgext3rd/undo.py
398–408

Ok, thanks for explanation

felixmerk updated this revision to Diff 414.Jul 26 2017, 2:41 PM
quark added a subscriber: quark.Jul 26 2017, 7:28 PM
quark added inline comments.
hgext3rd/undo.py
416

You can use revs = revset.getset(repo, fullreposet(repo), x) here so it works with arbitrary revset.

417–427

Could you check if the revset is equivalent to the below one?

querystring = revsetlang.formatspec('((::%ld) & draft())::', revs)
return subset & smartset.baseset(repo.revs(querystring))

And that might still have issues with:

$ hg update a-public-commit
$ hg commit
$ hg strip .
$ hg undo # ??

But we can figure out it later.

quark added inline comments.Jul 26 2017, 8:00 PM
hgext3rd/undo.py
417–427

I see the strip case was handled by the public() and %s test. It might be possible to handle it first, like, we can assume len(revs) == 1 and test repo[revs.first()].phase(), if it's phases.public, use an alternative revset:

(children(%d) & draft())::   # executed on an filtered repo
felixmerk updated this revision to Diff 420.Jul 26 2017, 8:27 PM
felixmerk updated this revision to Diff 507.Aug 2 2017, 4:31 PM
This revision was automatically updated to reflect the committed changes.