Mercurial > hg
diff hgext/fix.py @ 44574:5205b46bd887
fix: add a -s option to format a revision and its descendants
`hg fix -r abc123` will format that commit but not its
descendants. That seems expected given the option name (`-r`), but
it's very rarely what the user wants to do. The problem is that any
descendants of that commit will not be formatted, leaving them as
orphans that are hard to evolve. They are hard to evolve because the
new parent will have formatting changes that the orphan doesn't have.
I talked to Danny Hooper (who wrote most of the fix extension) about
the problem and we agreed that deprecating `-r` in favor of a new `-s`
argument (mimicing rebase's `-s`) would be a good way of reducing the
risk that users end up with these hard-to-evolve orphans. So that's
what this patch implements.
Differential Revision: https://phab.mercurial-scm.org/D8287
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 13 Mar 2020 12:16:00 -0700 |
parents | 9f5e94bbc606 |
children | a6ef1e8e2f6d |
line wrap: on
line diff
--- a/hgext/fix.py Thu Dec 12 16:32:01 2019 -0800 +++ b/hgext/fix.py Fri Mar 13 12:16:00 2020 -0700 @@ -214,6 +214,13 @@ _(b'REV'), ) revopt = (b'r', b'rev', [], _(b'revisions to fix'), _(b'REV')) +sourceopt = ( + b's', + b'source', + [], + _(b'fix the specified revisions and their descendants'), + _(b'REV'), +) wdiropt = (b'w', b'working-dir', False, _(b'fix the working directory')) wholeopt = (b'', b'whole', False, _(b'always fix every line of a file')) usage = _(b'[OPTION]... [FILE]...') @@ -221,7 +228,7 @@ @command( b'fix', - [allopt, baseopt, revopt, wdiropt, wholeopt], + [allopt, baseopt, revopt, sourceopt, wdiropt, wholeopt], usage, helpcategory=command.CATEGORY_FILE_CONTENTS, ) @@ -249,8 +256,10 @@ override this default behavior, though it is not usually desirable to do so. """ opts = pycompat.byteskwargs(opts) - cmdutil.check_at_most_one_arg(opts, b'all', b'rev') - cmdutil.check_incompatible_arguments(opts, b'working_dir', [b'all']) + cmdutil.check_at_most_one_arg(opts, b'all', b'source', b'rev') + cmdutil.check_incompatible_arguments( + opts, b'working_dir', [b'all', b'source'] + ) with repo.wlock(), repo.lock(), repo.transaction(b'fix'): revstofix = getrevstofix(ui, repo, opts) @@ -399,6 +408,14 @@ """Returns the set of revision numbers that should be fixed""" if opts[b'all']: revs = repo.revs(b'(not public() and not obsolete()) or wdir()') + elif opts[b'source']: + source_revs = scmutil.revrange(repo, opts[b'source']) + revs = set(repo.revs(b'%ld::', source_revs)) + if wdirrev in source_revs: + # `wdir()::` is currently empty, so manually add wdir + revs.add(wdirrev) + if repo[b'.'].rev() in revs: + revs.add(wdirrev) else: revs = set(scmutil.revrange(repo, opts[b'rev'])) if opts.get(b'working_dir'):