D2897: fix: new extension for automatically modifying file contents
This revision was automatically updated to reflect the committed changes. Closed by commit rHGded5ea279a93: fix: new extension for automatically modifying file contents (authored by hooper, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2897?vs=7366&id=7406 REVISION DETAIL https://phab.mercurial-scm.org/D2897 AFFECTED FILES hgext/fix.py tests/test-doctest.py tests/test-fix-clang-format.t tests/test-fix-topology.t tests/test-fix.t CHANGE DETAILS diff --git a/tests/test-fix.t b/tests/test-fix.t new file mode 100644 --- /dev/null +++ b/tests/test-fix.t @@ -0,0 +1,969 @@ +Set up the config with two simple fixers: one that fixes specific line ranges, +and one that always fixes the whole file. They both "fix" files by converting +letters to uppercase. They use different file extensions, so each test case can +choose which behavior to use by naming files. + + $ cat >> $HGRCPATH < [extensions] + > fix = + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > [fix] + > uppercase-whole-file:command=sed -e 's/.*/\U&/' + > uppercase-whole-file:fileset=set:**.whole + > uppercase-changed-lines:command=sed + > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' + > uppercase-changed-lines:fileset=set:**.changed + > EOF + +Help text for fix. + + $ hg help fix + hg fix [OPTION]... [FILE]... + + rewrite file content in changesets or working directory + + Runs any configured tools to fix the content of files. Only affects files + with changes, unless file arguments are provided. Only affects changed + lines of files, unless the --whole flag is used. Some tools may always + affect the whole file regardless of --whole. + + If revisions are specified with --rev, those revisions will be checked, + and they may be replaced with new revisions that have fixed file content. + It is desirable to specify all descendants of each specified revision, so + that the fixes propagate to the descendants. If all descendants are fixed + at the same time, no merging, rebasing, or evolution will be required. + + If --working-dir is used, files with uncommitted changes in the working + copy will be fixed. If the checked-out revision is also fixed, the working + directory will update to the replacement revision. + + When determining what lines of each file to fix at each revision, the + whole set of revisions being fixed is considered, so that fixes to earlier + revisions are not forgotten in later ones. The --base flag can be used to + override this default behavior, though it is not usually desirable to do + so. + + (use 'hg help -e fix' to show help for the fix extension) + + options ([+] can be repeated): + + --base REV [+] revisions to diff against (overrides automatic selection, + and applies to every revision being fixed) + -r --rev REV [+] revisions to fix + -w --working-dir fix the working directory + --wholealways fix every line of a file + + (some details hidden, use --verbose to show complete help) + + $ hg help -e fix + fix extension - rewrite file content in changesets or working copy + (EXPERIMENTAL) + + Provides a command that runs configured tools on the contents of modified + files, writing back any fixes to the working copy or replacing changesets. + + Here is an example configuration that causes 'hg fix' to apply automatic + formatting fixes to modified lines in C++ code: + +[fix] +clang-format:command=clang-format --assume-filename={rootpath} +clang-format:linerange=--lines={first}:{last} +clang-format:fileset=set:**.cpp or **.hpp + + The :command suboption forms the first part of the shell command that will be + used to fix a file. The content of the file is passed on standard input, and + the fixed file content is expected on standard output. If there is any output + on standard error, the file will not be affected. Some values may be + substituted into the command: + +{rootpath} The path of the file being fixed, relative to the repo root +{basename} The name of the file being fixed, without the directory path + + If the :linerange suboption is set, the tool will only be run if there are + changed lines in a file. The value of this suboption is appended to the shell + command once for every range of changed lines in the file. Some values may be + substituted into the command: + +{first} The 1-based line number of the first line in the modified range +{last}The 1-based line number of the last line in the modified range + + The :fileset suboption determines which files will be passed through each + configured tool. See 'hg help fileset' for possible values. If there are file + arguments to 'hg fix', the intersection of these filesets is used. + + There is also a configu
D2897: fix: new extension for automatically modifying file contents
pulkit accepted this revision. pulkit added inline comments. INLINE COMMENTS > hooper wrote in test-fix.t:857 > Would it abort or merge if the working copy is dirty? Is that behavior > expected to end up in cleanupnodes? It could also just force --working-dir. > It's similar to creating an orphan if we don't fix the dirty working copy. > > One of my goals is to avoid any need for merging or conflict resolution in > this command. > One of my goals is to avoid any need for merging or conflict resolution in > this command. That makes sense. I am good with current behavior then. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers, pulkit Cc: durin42, krbullock, martinvonz, yuja, indygreg, pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
hooper updated this revision to Diff 7366. hooper marked an inline comment as done. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2897?vs=7329&id=7366 REVISION DETAIL https://phab.mercurial-scm.org/D2897 AFFECTED FILES hgext/fix.py tests/test-doctest.py tests/test-fix-clang-format.t tests/test-fix-topology.t tests/test-fix.t CHANGE DETAILS diff --git a/tests/test-fix.t b/tests/test-fix.t new file mode 100644 --- /dev/null +++ b/tests/test-fix.t @@ -0,0 +1,969 @@ +Set up the config with two simple fixers: one that fixes specific line ranges, +and one that always fixes the whole file. They both "fix" files by converting +letters to uppercase. They use different file extensions, so each test case can +choose which behavior to use by naming files. + + $ cat >> $HGRCPATH < [extensions] + > fix = + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > [fix] + > uppercase-whole-file:command=sed -e 's/.*/\U&/' + > uppercase-whole-file:fileset=set:**.whole + > uppercase-changed-lines:command=sed + > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' + > uppercase-changed-lines:fileset=set:**.changed + > EOF + +Help text for fix. + + $ hg help fix + hg fix [OPTION]... [FILE]... + + rewrite file content in changesets or working directory + + Runs any configured tools to fix the content of files. Only affects files + with changes, unless file arguments are provided. Only affects changed + lines of files, unless the --whole flag is used. Some tools may always + affect the whole file regardless of --whole. + + If revisions are specified with --rev, those revisions will be checked, + and they may be replaced with new revisions that have fixed file content. + It is desirable to specify all descendants of each specified revision, so + that the fixes propagate to the descendants. If all descendants are fixed + at the same time, no merging, rebasing, or evolution will be required. + + If --working-dir is used, files with uncommitted changes in the working + copy will be fixed. If the checked-out revision is also fixed, the working + directory will update to the replacement revision. + + When determining what lines of each file to fix at each revision, the + whole set of revisions being fixed is considered, so that fixes to earlier + revisions are not forgotten in later ones. The --base flag can be used to + override this default behavior, though it is not usually desirable to do + so. + + (use 'hg help -e fix' to show help for the fix extension) + + options ([+] can be repeated): + + --base REV [+] revisions to diff against (overrides automatic selection, + and applies to every revision being fixed) + -r --rev REV [+] revisions to fix + -w --working-dir fix the working directory + --wholealways fix every line of a file + + (some details hidden, use --verbose to show complete help) + + $ hg help -e fix + fix extension - rewrite file content in changesets or working copy + (EXPERIMENTAL) + + Provides a command that runs configured tools on the contents of modified + files, writing back any fixes to the working copy or replacing changesets. + + Here is an example configuration that causes 'hg fix' to apply automatic + formatting fixes to modified lines in C++ code: + +[fix] +clang-format:command=clang-format --assume-filename={rootpath} +clang-format:linerange=--lines={first}:{last} +clang-format:fileset=set:**.cpp or **.hpp + + The :command suboption forms the first part of the shell command that will be + used to fix a file. The content of the file is passed on standard input, and + the fixed file content is expected on standard output. If there is any output + on standard error, the file will not be affected. Some values may be + substituted into the command: + +{rootpath} The path of the file being fixed, relative to the repo root +{basename} The name of the file being fixed, without the directory path + + If the :linerange suboption is set, the tool will only be run if there are + changed lines in a file. The value of this suboption is appended to the shell + command once for every range of changed lines in the file. Some values may be + substituted into the command: + +{first} The 1-based line number of the first line in the modified range +{last}The 1-based line number of the last line in the modified range + + The :fileset suboption determines which files will be passed through each + configured tool. See 'hg help fileset' for possible values. If there are file + arguments to 'hg fix', the intersection of these filesets is used. + + There is also a configurable limit for the maximum size of file that will be + processed by 'hg fix': + +[fix] +maxfilesize=2MB + +
D2897: fix: new extension for automatically modifying file contents
hooper added inline comments. INLINE COMMENTS > pulkit wrote in test-fix.t:813 > This should respect `experimental.evolution.allowunstable` and error out if > set to False. Maybe the comment is poorly worded. I mean that an incorrect implementation could create an orphan in this case, even though both commits were meant to be replaced. I'm adding a separate test case for aborting if the user asks to create an orphan. I imitated an abort from histedit, which seems like it should be a utility function (checknodescendants). > pulkit wrote in test-fix.t:857 > When the working directory parent get obsoleted because of `fix`, we should > update to it's successor similar to what other commands do. Would it abort or merge if the working copy is dirty? Is that behavior expected to end up in cleanupnodes? It could also just force --working-dir. It's similar to creating an orphan if we don't fix the dirty working copy. One of my goals is to avoid any need for merging or conflict resolution in this command. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: durin42, krbullock, martinvonz, yuja, indygreg, pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
hooper added a comment. In https://phab.mercurial-scm.org/D2897#47944, @yuja wrote: > In https://phab.mercurial-scm.org/D2897#47875, @pulkit wrote: > > > The code except of minor nits looks good to me. I will like others to chime in on whether we should rename the command and extension to `format` because `fix` is too generic. > > > I agree the extension name `fix` is too generic, but I have no strong opinion. > It could be `format`, `formatter`, `extfmt`, `extformatter`, etc., but I guess > this isn't just for "formatting" in Google? And `hg fix` is easy to type. ;) One possibility to consider is a config that runs a linter tool on the changed lines, but makes no edits. In the proposal I also gave the example of a config to sort the lines in a file. Another thought was spell checking/fixing. Implying that the command is only useful for source code formatting is selling the feature short, but still I wouldn't know what else to call it. We had picked "fix" because our users are familiar with the term. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: durin42, krbullock, martinvonz, yuja, indygreg, pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
yuja added a comment. In https://phab.mercurial-scm.org/D2897#47875, @pulkit wrote: > The code except of minor nits looks good to me. I will like others to chime in on whether we should rename the command and extension to `format` because `fix` is too generic. I agree the extension name `fix` is too generic, but I have no strong opinion. It could be `format`, `formatter`, `extfmt`, `extformatter`, etc., but I guess this isn't just for "formatting" in Google? And `hg fix` is easy to type. ;) REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: durin42, krbullock, martinvonz, yuja, indygreg, pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
pulkit added subscribers: indygreg, yuja, martinvonz, krbullock, durin42. pulkit added a comment. The code except of minor nits looks good to me. I will like others to chime in on whether we should rename the command and extension to `format` because `fix` is too generic. I will push it once we get the naming and these comments sorted out. cc: @yuja @indygreg @martinvonz @durin42 @krbullock INLINE COMMENTS > test-fix.t:813 > + > +It's also possible that the child needs absolutely no changes, but we still > +need to replace it to update its parent. If we simply skip replacing it > because This should respect `experimental.evolution.allowunstable` and error out if set to False. > test-fix.t:838 > + > +Similar to the case above, the child revision may become empty as a result of > +fixing its parent. We should still create an empty replacement child. I am not sure how it should interact with `ui.allowemptycommit`. Maybe add a TODO here about this. > test-fix.t:857 > + > + @ 1 edit foo > + | foo.whole | 2 +- When the working directory parent get obsoleted because of `fix`, we should update to it's successor similar to what other commands do. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: durin42, krbullock, martinvonz, yuja, indygreg, pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
hooper marked 2 inline comments as done. hooper added a comment. In https://phab.mercurial-scm.org/D2897#47695, @pulkit wrote: > Can you add a test where fixing of one parent commit leads to a child commit becoming empty. For example: > > Commit 1: echo foo> a > Commit 2: echo Foo > a > > And I run a lexer on commit 1 and 2, to change everything to uppercase. Done. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
hooper updated this revision to Diff 7329. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2897?vs=7165&id=7329 REVISION DETAIL https://phab.mercurial-scm.org/D2897 AFFECTED FILES hgext/fix.py tests/test-doctest.py tests/test-fix-clang-format.t tests/test-fix-topology.t tests/test-fix.t CHANGE DETAILS diff --git a/tests/test-fix.t b/tests/test-fix.t new file mode 100644 --- /dev/null +++ b/tests/test-fix.t @@ -0,0 +1,981 @@ +Set up the config with two simple fixers: one that fixes specific line ranges, +and one that always fixes the whole file. They both "fix" files by converting +letters to uppercase. They use different file extensions, so each test case can +choose which behavior to use by naming files. + + $ cat >> $HGRCPATH < [extensions] + > fix = + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > [fix] + > uppercase-whole-file:command=sed -e 's/.*/\U&/' + > uppercase-whole-file:fileset=set:**.whole + > uppercase-changed-lines:command=sed + > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' + > uppercase-changed-lines:fileset=set:**.changed + > EOF + +Help text for fix. + + $ hg help fix + hg fix [OPTION]... [FILE]... + + rewrite file content in changesets or working directory + + Runs any configured tools to fix the content of files. Only affects files + with changes, unless file arguments are provided. Only affects changed + lines of files, unless the --whole flag is used. Some tools may always + affect the whole file regardless of --whole. + + If revisions are specified with --rev, those revisions will be checked, + and they may be replaced with new revisions that have fixed file content. + It is desirable to specify all descendants of each specified revision, so + that the fixes propagate to the descendants. If all descendants are fixed + at the same time, no merging, rebasing, or evolution will be required. + + If --working-dir is used, files with uncommitted changes in the working + copy will be fixed. If the checked-out revision is also fixed, the working + directory will update to the replacement revision. + + When determining what lines of each file to fix at each revision, the + whole set of revisions being fixed is considered, so that fixes to earlier + revisions are not forgotten in later ones. The --base flag can be used to + override this default behavior, though it is not usually desirable to do + so. + + (use 'hg help -e fix' to show help for the fix extension) + + options ([+] can be repeated): + + --base REV [+] revisions to diff against (overrides automatic selection, + and applies to every revision being fixed) + -r --rev REV [+] revisions to fix + -w --working-dir fix the working directory + --wholealways fix every line of a file + + (some details hidden, use --verbose to show complete help) + + $ hg help -e fix + fix extension - rewrite file content in changesets or working copy + (EXPERIMENTAL) + + Provides a command that runs configured tools on the contents of modified + files, writing back any fixes to the working copy or replacing changesets. + + Here is an example configuration that causes 'hg fix' to apply automatic + formatting fixes to modified lines in C++ code: + +[fix] +clang-format:command=clang-format --assume-filename={rootpath} +clang-format:linerange=--lines={first}:{last} +clang-format:fileset=set:**.cpp or **.hpp + + The :command suboption forms the first part of the shell command that will be + used to fix a file. The content of the file is passed on standard input, and + the fixed file content is expected on standard output. If there is any output + on standard error, the file will not be affected. Some values may be + substituted into the command: + +{rootpath} The path of the file being fixed, relative to the repo root +{basename} The name of the file being fixed, without the directory path + + If the :linerange suboption is set, the tool will only be run if there are + changed lines in a file. The value of this suboption is appended to the shell + command once for every range of changed lines in the file. Some values may be + substituted into the command: + +{first} The 1-based line number of the first line in the modified range +{last}The 1-based line number of the last line in the modified range + + The :fileset suboption determines which files will be passed through each + configured tool. See 'hg help fileset' for possible values. If there are file + arguments to 'hg fix', the intersection of these filesets is used. + + There is also a configurable limit for the maximum size of file that will be + processed by 'hg fix': + +[fix] +maxfilesize=2MB + + list of commands: + + fix r
D2897: fix: new extension for automatically modifying file contents
pulkit added a comment. Can you add a test where fixing of one parent commit leads to a child commit becoming empty. For example: Commit 1: echo foo> a Commit 2: echo Foo > a And I run a lexer on commit 1 and 2, to change everything to uppercase. INLINE COMMENTS > fix.py:460 > +ctxmandatory = varnames[2] == 'changectx' > +if ctxmandatory: > +return context.memfilectx(repo, ctx, path, data, islink, isexec, we can drop this if-else now since things are moved to core. > test-fix-topology.t:18 > +#testcases no-evolution evolution > +#if evolution > + $ cat >> $HGRCPATH
D2897: fix: new extension for automatically modifying file contents
hooper updated this revision to Diff 7165. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2897?vs=7123&id=7165 REVISION DETAIL https://phab.mercurial-scm.org/D2897 AFFECTED FILES hgext/fix.py tests/test-doctest.py tests/test-fix-clang-format.t tests/test-fix-topology.t tests/test-fix.t CHANGE DETAILS diff --git a/tests/test-fix.t b/tests/test-fix.t new file mode 100644 --- /dev/null +++ b/tests/test-fix.t @@ -0,0 +1,951 @@ +Set up the config with two simple fixers: one that fixes specific line ranges, +and one that always fixes the whole file. They both "fix" files by converting +letters to uppercase. They use different file extensions, so each test case can +choose which behavior to use by naming files. + + $ cat >> $HGRCPATH < [extensions] + > fix = + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > [fix] + > uppercase-whole-file:command=sed -e 's/.*/\U&/' + > uppercase-whole-file:fileset=set:**.whole + > uppercase-changed-lines:command=sed + > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' + > uppercase-changed-lines:fileset=set:**.changed + > EOF + +Help text for fix. + + $ hg help fix + hg fix [OPTION]... [FILE]... + + rewrite file content in changesets or working directory + + Runs any configured tools to fix the content of files. Only affects files + with changes, unless file arguments are provided. Only affects changed + lines of files, unless the --whole flag is used. Some tools may always + affect the whole file regardless of --whole. + + If revisions are specified with --rev, those revisions will be checked, + and they may be replaced with new revisions that have fixed file content. + It is desirable to specify all descendants of each specified revision, so + that the fixes propagate to the descendants. If all descendants are fixed + at the same time, no merging, rebasing, or evolution will be required. + + If --working-dir is used, files with uncommitted changes in the working + copy will be fixed. If the checked-out revision is also fixed, the working + directory will update to the replacement revision. + + When determining what lines of each file to fix at each revision, the + whole set of revisions being fixed is considered, so that fixes to earlier + revisions are not forgotten in later ones. The --base flag can be used to + override this default behavior, though it is not usually desirable to do + so. + + (use 'hg help -e fix' to show help for the fix extension) + + options ([+] can be repeated): + + --base REV [+] revisions to diff against (overrides automatic selection, + and applies to every revision being fixed) + -r --rev REV [+] revisions to fix + -w --working-dir fix the working directory + --wholealways fix every line of a file + + (some details hidden, use --verbose to show complete help) + + $ hg help -e fix + fix extension - rewrite file content in changesets or working copy + (EXPERIMENTAL) + + Provides a command that runs configured tools on the contents of modified + files, writing back any fixes to the working copy or replacing changesets. + + Here is an example configuration that causes 'hg fix' to apply automatic + formatting fixes to modified lines in C++ code: + +[fix] +clang-format:command=clang-format --assume-filename={rootpath} +clang-format:linerange=--lines={first}:{last} +clang-format:fileset=set:**.cpp or **.hpp + + The :command suboption forms the first part of the shell command that will be + used to fix a file. The content of the file is passed on standard input, and + the fixed file content is expected on standard output. If there is any output + on standard error, the file will not be affected. Some values may be + substituted into the command: + +{rootpath} The path of the file being fixed, relative to the repo root +{basename} The name of the file being fixed, without the directory path + + If the :linerange suboption is set, the tool will only be run if there are + changed lines in a file. The value of this suboption is appended to the shell + command once for every range of changed lines in the file. Some values may be + substituted into the command: + +{first} The 1-based line number of the first line in the modified range +{last}The 1-based line number of the last line in the modified range + + The :fileset suboption determines which files will be passed through each + configured tool. See 'hg help fileset' for possible values. If there are file + arguments to 'hg fix', the intersection of these filesets is used. + + There is also a configurable limit for the maximum size of file that will be + processed by 'hg fix': + +[fix] +maxfilesize=2MB + + list of commands: + + fix r
D2897: fix: new extension for automatically modifying file contents
hooper added a comment. In https://phab.mercurial-scm.org/D2897#46656, @pulkit wrote: > Haven't reviewed the patch but I think `fix` is too generic for this use case. What about `format`? Sorry for not having this idea when we had couple of discussion on it. I will do a final pass to rename it if desired, but I would like to wait for any other feedback before doing so. I think "format" is accurate for how we expect this to be used, but I also think it may be overly specific. I don't have any good alternatives in mind. "fix" is problematic because it is confusing in contexts like commit messages. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
pulkit added a comment. Haven't reviewed the patch but I think `fix` is too generic for this use case. What about `format`? Sorry for not having this idea when we had couple of discussion on it. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 To: hooper, #hg-reviewers Cc: pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2897: fix: new extension for automatically modifying file contents
hooper created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY This change implements most of the corresponding proposal as discussed at the 4.4 and 4.6 sprints: https://www.mercurial-scm.org/wiki/AutomaticFormattingPlan This change notably does not include parallel execution of the formatter/fixer tools. It does allow for implementing that without affecting other areas of the code. I believe the test coverage to be good, but this is a hotbed of corner cases. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2897 AFFECTED FILES hgext/fix.py tests/test-doctest.py tests/test-fix-clang-format.t tests/test-fix-topology.t tests/test-fix.t CHANGE DETAILS diff --git a/tests/test-fix.t b/tests/test-fix.t new file mode 100644 --- /dev/null +++ b/tests/test-fix.t @@ -0,0 +1,927 @@ +Set up the config with two simple fixers: one that fixes specific line ranges, +and one that always fixes the whole file. They both "fix" files by converting +letters to uppercase. They use different file extensions, so each test case can +choose which behavior to use by naming files. + + $ cat >> $HGRCPATH < [extensions] + > fix = + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > [fix] + > uppercase-whole-file:command=sed -e 's/.*/\U&/' + > uppercase-whole-file:fileset=set:**.whole + > uppercase-changed-lines:command=sed + > uppercase-changed-lines:linerange=-e '{first},{last} s/.*/\U&/' + > uppercase-changed-lines:fileset=set:**.changed + > EOF + +Help text for fix. + + $ hg help fix + hg fix [OPTION]... [FILE]... + + rewrite file content in changesets or working directory + + Runs any configured tools to fix the content of files. Only affects files + with changes, unless file arguments are provided. Only affects changed + lines of files, unless the --whole flag is used. Some tools may always + affect the whole file regardless of --whole. + + If revisions are specified with --rev, those revisions will be checked, + and they may be replaced with new revisions that have fixed file content. + It is desirable to specify all descendants of each specified revision, so + that the fixes propagate to the descendants. If all descendants are fixed + at the same time, no merging, rebasing, or evolution will be required. + + If --working-dir is used, files with uncommitted changes in the working + copy will be fixed. If the checked-out revision is also fixed, the working + directory will update to the replacement revision. + + When determining what lines of each file to fix at each revision, the + whole set of revisions being fixed is considered, so that fixes to earlier + revisions are not forgotten in later ones. The --base flag can be used to + override this default behavior, though it is not usually desirable to do + so. + + (use 'hg help -e fix' to show help for the fix extension) + + options ([+] can be repeated): + + --base REV [+] revisions to diff against (overrides automatic selection, + and applies to every revision being fixed) + -r --rev REV [+] revisions to fix + -w --working-dir fix the working directory + --wholealways fix every line of a file + + (some details hidden, use --verbose to show complete help) + + $ hg help -e fix + fix extension - rewrite file content in changesets or working copy + (EXPERIMENTAL) + + Provides a command that runs configured tools on the contents of modified + files, writing back any fixes to the working copy or replacing changesets. + + Here is an example configuration that causes 'hg fix' to apply automatic + formatting fixes to modified lines in C++ code: + +[fix] +clang-format:command=clang-format --assume-filename={rootpath} +clang-format:linerange=--lines={first}:{last} +clang-format:fileset=set:**.cpp or **.hpp + + The :command suboption forms the first part of the shell command that will be + used to fix a file. The content of the file is passed on standard input, and + the fixed file content is expected on standard output. If there is any output + on standard error, the file will not be affected. Some values may be + substituted into the command: + +{rootpath} The path of the file being fixed, relative to the repo root +{basename} The name of the file being fixed, without the directory path + + If the :linerange suboption is set, the tool will only be run if there are + changed lines in a file. The value of this suboption is appended to the shell + command once for every range of changed lines in the file. Some values may be + substituted into the command: + +{first} The 1-based line number of the first line in the modified range +{last}The 1-based line number of the last line in the modified range