autoformat: change from hg fix to tip commit/amend strategy (Bug 1785004)#212
autoformat: change from hg fix to tip commit/amend strategy (Bug 1785004)#212cgsheeh merged 8 commits intomozilla-conduit:mainfrom
Conversation
zzzeid
left a comment
There was a problem hiding this comment.
Couple of small comments.
landoapi/hg.py
Outdated
|
|
||
| fix_hg_command += ["--config", f"fix.{key}={value}"] | ||
| # Run linters. | ||
| subprocess.run([mach_path, "lint", "-r", "stack()"], check=True) |
There was a problem hiding this comment.
Wondering if it would be useful to store the command and its output, and put that in the commit message for verbosity?
There was a problem hiding this comment.
That's not a bad idea - we should definitely at least log the command output.
landoapi/hg.py
Outdated
| except hglib.error.CommandError as exc: | ||
| if exc.out.strip() == b"nothing changed": | ||
| # If nothing changed after formatting we can just return. | ||
| return None |
There was a problem hiding this comment.
| return None | |
| return |
landoapi/hg.py
Outdated
|
|
||
| logger.info(f"revisions were reformatted: {', '.join(post_formatting_hashes)}") | ||
| if formatting_changeset is None: | ||
| return None |
There was a problem hiding this comment.
| return None | |
| return |
…85004) Remove the `hg fix` based autoformatting and replace with running raw `mach lint` on the tip commit, creating a tip autoformat commit for stacks of changes and amending the commit for landings of a single changeset. Add a call to `mach bootstrap` in the repo clone subsystem when autoformat is enabled for a given repo, to enabled downloading required packages. Since we now run `mach` from within the landing repo, stop running `hg purge` with `--all` since that will remove the existing objdir required for linting virtualenvs. Add the `MOZBUILD_STATE_PATH` environment variable to the Dockerfile to avoid a prompt during `mach bootstrap`.
hg fix strategy to tip commit strategy (Bug 1785004)
zzzeid
left a comment
There was a problem hiding this comment.
Mostly small comments or minor changes.
| except hglib.error.CommandError: | ||
| pass | ||
| try: | ||
| self.run_hg(["purge", "--all"]) |
There was a problem hiding this comment.
Are there other unforeseen circumstances of removing --all here? (e.g., why did we have it here in the first place?)
There was a problem hiding this comment.
We wanted the working copy to be clean after calling clean_repo, so I assume it was added since we didn't have a need for any VCS ignored files to be retained after cleaning. However we now need to keep at least the objdir and parts of third_party in central, so just running purge should be good enough for our purposes.
landoapi/hg.py
Outdated
| except hglib.error.CommandError as exc: | ||
| if exc.out.strip() == b"nothing changed": | ||
| # If nothing changed after formatting we can just return. | ||
| return None |
There was a problem hiding this comment.
nit
| return None | |
| return |
There was a problem hiding this comment.
Meh, personally I prefer to be explicit that None is going to be returned from a function, especially when the type is an Optional. I usually only ever do a generic return when the function itself would never return something. I'll change it in this case. 👍
| # Exit if no revisions were reformatted. | ||
| pre_formatting_hashes = check_fix_output_for_replacements(fix_output) | ||
| if not pre_formatting_hashes: | ||
| def format_stack_amend(self) -> Optional[List[str]]: |
There was a problem hiding this comment.
Not very certain why we should treat 1-revision stacks any differently than multi-revision stacks.
There was a problem hiding this comment.
Since we know formatting changes made to 1-revision stacks all apply to the revision, we can just amend them in. This avoids creating any autoformatting commits for the most common type of landings.
| if repo.autoformat_enabled: | ||
| r.run_mach_bootstrap() |
There was a problem hiding this comment.
This my cause some problems if there are changes to mach bootstrap that need to be applied after the instance is started (since the ready method is only triggered once per restart).
There was a problem hiding this comment.
For now I think we can run this at repo setup time - we may need to add a mechanism to periodically re-call mach bootstrap to keep toolchains up to date. I'd like to land these changes first before optimizing too much. :)
|
|
||
| # Run `hg fix` configured formatters if enabled | ||
| # Run automated code formatters if enabled. | ||
| if repo.autoformat_enabled: |
There was a problem hiding this comment.
As discussed offline, this may be a good candidate to move to the Revision Worker (based on PR #224) in the future, and implement a way for the revision worker to store updated stacks for the landing worker to use.
Remove the
hg fixbased autoformatting and replace withrunning raw
mach linton the tip commit, creating a tipautoformat commit for stacks of changes and amending the
commit for landings of a single changeset. Add a call to
mach bootstrapin the repo clone subsystem when autoformatis enabled for a given repo, to enabled downloading required
packages. Since we now run
machfrom within the landing repo,stop running
hg purgewith--allsince that will removethe existing objdir required for linting virtualenvs. Add the
MOZBUILD_STATE_PATHenvironment variable to the Dockerfileto avoid a prompt during
mach bootstrap.