Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cargo-shuttle): remove cargo-generate dependency #1281

Merged
merged 8 commits into from
Oct 2, 2023

Conversation

thass0
Copy link
Contributor

@thass0 thass0 commented Sep 28, 2023

Description of change

cargo-generate has been removed as a dependency of cargo-shuttle, and all functionality of cargo-shuttle that was used by the cargo shuttle init command has been re-implemented.

The openssl dependency introduced by cloning the template Git repositories using the git2 crate has also been removed. Instead, gix is used to clone repositories, which uses rustls.

Closes #1269

/claim #1269

How has this been tested? (if applicable)

The applicable tests have been updated where required. Additional tests have been added to ensure that the new parsing-logic accepts many relevant examples (e.g. those in the shuttle-examples README. Also, some previously ignored tests now pass.

Replaces network-based (e.g. clonging) features of git2 with
those provided by gix. Thereby rustls can be used instead of
openssl.
The purpose of the removed configuration was to
prevent test crashes in CI, which were caused by
the inner workings of `cargo-generate` (see the
deleted `CI DEBUG` comment for more info). Thus,
they can now be deleted.
@thass0
Copy link
Contributor Author

thass0 commented Sep 28, 2023

/claim #1269

Copy link
Member

@jonaro00 jonaro00 left a comment

Choose a reason for hiding this comment

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

Looking great! Clean code.

Other things that can be added:

  • Use gix instead of git2 for dirty check
  • Allow passing args or syntax for specifying a branch/tag/commit to clone from

Up to you if you want to add them :)

cargo-shuttle/src/init.rs Outdated Show resolved Hide resolved
cargo-shuttle/src/init.rs Show resolved Hide resolved
cargo-shuttle/src/init.rs Outdated Show resolved Hide resolved
@thass0
Copy link
Contributor Author

thass0 commented Sep 28, 2023

Yes, I want to fully replace git2 with gix. I am still working on the dirty check.

cargo-shuttle/src/init.rs Outdated Show resolved Hide resolved
// dot pattern. This way, conflicts between relative path in the form
// `foo/bar` and repository name in the form `owner/name` are avoided.
match loc.subfolder {
Some(subfolder) => Ok(Self::LocalPath(Path::new(&loc.auto_path).join(subfolder))),
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: if we are to add branch/rev selection to the clone operation, we would need to require a local path to be handled like the other alternatives, so that the clone and checkout can be done correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean in cases where there is a Git repository at the local path? Yes, that's a good idea.

The generate function ought to be divided into a setup which ends in the same generic state, no matter what the initial form of the origin was. This state could be the raw template places in a temporary directory. After the setup, the rest of the code would be the same for local folders and repository clones. This code always uses subfolder.

I actually prefer this design over the current one. It separates the different stages and the information required at each one of them much better.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it's a bit more streamlined.
I wonder if the depth 1 and potential branch/rev parameter clash in some way 🤔

* Add a prefix to the temporary directories used.
* Clone template repositories with a depth of 1 commit.
* Check the output of a few of the test cases for the parser.
The different parts of generating the template
and their use of the arguments passed to
`generate_project` are now divided more clearly.

This decreases the size and overhead of the implementation.

The tests checking the paring are also gone. Instead, the
cloning and the copying of templates is tested. The
integration tests should be sufficient for ensuring that
the paring in this implementation remains correct.
@thass0 thass0 force-pushed the refactor/remove-cargo-generate branch from 8fd999f to 3ac2dee Compare September 29, 2023 14:17
cargo-shuttle/src/init.rs Outdated Show resolved Hide resolved
cargo-shuttle/src/init.rs Show resolved Hide resolved
cargo-shuttle/src/init.rs Show resolved Hide resolved
@thass0
Copy link
Contributor Author

thass0 commented Sep 30, 2023

By replacing git2 with gix, the number of crates used has gone up again. gix is very modular and divided up into many small crates, so that users can choose which features they need very precisely.

Compile times have improved compared to the previous implementation that uses cargo-generate and git2 with openssl.

At the current state of this PR, it takes an average 76.28 s to do a clean build of cargo-shuttle. In comparison, the version of cargo-shuttle that's currently in use compiles in an average of 103.37 s. That's a 1.36x speedup!

@jonaro00
Copy link
Member

Splendid! I'll check out the changes later. Is this PR "done" now?

@thass0
Copy link
Contributor Author

thass0 commented Sep 30, 2023

I'm still figuring out how a --rev flag would best be implemented using gix. Since adding the --rev flag as a whole also requires changes all over cargo-shuttle, I suggest to put it in another issue/PR.

So yes, besides the --rev flag, this PR should now close everything discussed in #1269 😀

Copy link
Member

@jonaro00 jonaro00 left a comment

Choose a reason for hiding this comment

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

Wow, gix was a bit tricky it seems.

I tried a local deploy, but the commit ID was malformed. Maybe the hash you get from gix is the binary data, not encoded to a hex string?

image

Also, the dirty flag did not turn true when having untracked files or staged files, only when having a removed (changed) file. We don't have strict requirements for these, but the former two seem like reasonable triggers, since they cause non-commited files to get deployed.


On my 20 thread CPU.

  • cargo b -r -p cargo-shuttle
  • cargo clean between every build
test main pr 1281
first test 58 s 54 s (should have been less due to partially missing crate downloads and sccache)
hot sccache (wow!!!) 15 s 13 s
registry cached, no sccache 60 s 56 s (ignore the above I guess)

Haha I guess it don't matter much on such a powerful CPU. Not sure how fair my tests were either. The improvement will be bigger for weaker CPUs tho :D

Comment on lines 1819 to 1821
/// It's adapted from the `gitoxide` test suite: https://github.com/
/// Byron/gitoxide/blob/3d60c0245ec4b787cfcb111319d730a6e5031ef4/
/// gix-status/tests/status/index_as_worktree.rs#L259
Copy link
Member

Choose a reason for hiding this comment

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

I would personally not linebreak URLs :D

@thass0
Copy link
Contributor Author

thass0 commented Oct 1, 2023

What are the specific commands you used to get the image you linked? I'd like to know, so I can debug the issue. I'll also take a look at how to determine the strictness of the dirty check.

@thass0
Copy link
Contributor Author

thass0 commented Oct 1, 2023

I just found the tracking issue on gix status while searching for documentation on how to use gix to also set the dirty if changes are staged but not committed or untracked. It says that determining changes of staged and untracked files is not yet implemented 😨.

I guess a reasonable way to go would be to remove my last commit and keep using git2 for now. This should also remove the other gix-related issues mentioned by @jonaro00 in their last comment.

@jonaro00
Copy link
Member

jonaro00 commented Oct 1, 2023

Oh no :(
Yeah, let's keep the changes well isolated and wait with using gix for that part.

If you want, you can move the last commit to a new draft PR, so that the work done can be reused if gix becomes more feature complete.

@thass0 thass0 force-pushed the refactor/remove-cargo-generate branch 2 times, most recently from 0056ff8 to aa9da60 Compare October 1, 2023 09:44
Copy link
Member

@jonaro00 jonaro00 left a comment

Choose a reason for hiding this comment

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

🥳

@jonaro00 jonaro00 merged commit b18b7f3 into shuttle-hq:main Oct 2, 2023
32 of 33 checks passed
@thass0 thass0 deleted the refactor/remove-cargo-generate branch October 2, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor to lighter implementation of cargo-generate cloning
3 participants