Skip to content

autoformat: change from hg fix to tip commit/amend strategy (Bug 1785004)#212

Merged
cgsheeh merged 8 commits intomozilla-conduit:mainfrom
cgsheeh:1785004
Nov 22, 2022
Merged

autoformat: change from hg fix to tip commit/amend strategy (Bug 1785004)#212
cgsheeh merged 8 commits intomozilla-conduit:mainfrom
cgsheeh:1785004

Conversation

@cgsheeh
Copy link
Member

@cgsheeh cgsheeh commented Aug 16, 2022

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.

@cgsheeh cgsheeh requested a review from zzzeid August 16, 2022 01:46
Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if it would be useful to store the command and its output, and put that in the commit message for verbosity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return None
return

landoapi/hg.py Outdated

logger.info(f"revisions were reformatted: {', '.join(post_formatting_hashes)}")
if formatting_changeset is None:
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
@cgsheeh cgsheeh requested a review from zzzeid November 18, 2022 18:57
@cgsheeh cgsheeh changed the title autoformat: change from hg fix strategy to tip commit strategy (Bug 1785004) autoformat: change from hg fix to tip commit/amend strategy (Bug 1785004) Nov 21, 2022
Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small comments or minor changes.

except hglib.error.CommandError:
pass
try:
self.run_hg(["purge", "--all"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other unforeseen circumstances of removing --all here? (e.g., why did we have it here in the first place?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
return None
return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very certain why we should treat 1-revision stacks any differently than multi-revision stacks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +372 to +373
if repo.autoformat_enabled:
r.run_mach_bootstrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cgsheeh cgsheeh requested a review from zzzeid November 22, 2022 19:33
Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@cgsheeh cgsheeh merged commit 736c94d into mozilla-conduit:main Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants