-
Notifications
You must be signed in to change notification settings - Fork 319
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
cli: Refactor out get_fetch_remotes
into git_util.rs
#4768
base: main
Are you sure you want to change the base?
Conversation
3a16b88
to
d6df47f
Compare
e43b3b3
to
efe9c65
Compare
d6df47f
to
4a4ac40
Compare
fa6e402
to
e53870d
Compare
1591633
to
0b60444
Compare
cli/src/git_util.rs
Outdated
remotes: &[String], | ||
use_all_remotes: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both jj git sync
and jj git fetch
share command parameters, it might be better to extract common Args
struct. Then, we can pass it in to helper functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
I'm thinking this could actually collapse down to something like:
let fetcher = GitFetcher::new(ui, tx, git_repo, branch, remotes, use_all_remotes);
fetcher.fetch()?;
Inside fetcher.fetch
we'd grab the remotes and then do the fetch. Mainly because I can't think of a good reason why to expose to function calls to the commands instead of just one, as the intermediate result is not used by callers.
Does that feel like overkill?
In the meantime, I'm thinking to merge this PR and make changes in a follow-up to keep things clearer.
Let me know if you think otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. Do we have more methods than fetch()
?
My concern about the current API is that it's hard to tell which String
/bool
argument represents which variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. Do we have more methods than
fetch()
?
I just realized we do need to expose get_fetch_remotes
, since we use the result to build a message after the fetch succeeds further down.
My concern about the current API is that it's hard to tell which
String
/bool
argument represents which variable.
I've added a FetchArgs struct that should make this better and doesn't end up feeling over designed.
wdyt?
4a4ac40
to
f4b6e5b
Compare
0b60444
to
9bde01a
Compare
f4b6e5b
to
1b5a5c0
Compare
9bde01a
to
1fc7ef9
Compare
c9ebe82
to
ae98431
Compare
cli/src/git_util.rs
Outdated
@@ -456,30 +466,36 @@ export or their "parent" bookmarks."#, | |||
Ok(()) | |||
} | |||
|
|||
pub struct FetchArgs<'a> { | |||
pub repo: &'a git2::Repository, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't include git2::Repository
in args struct because it's not a user parameter and has different lifetime.
BTW, what I meant was to extract common clap::Args
struct from GitFetchArgs
. If jj git sync
shares the same help messages, we can "flatten" the common Args struct into GitFetch
/SyncArgs
. If not, we'll need a separate parameter struct as you did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't include
git2::Repository
in args struct because it's not a user parameter and has different lifetime.
Removed.
BTW, what I meant was to extract common
clap::Args
struct fromGitFetchArgs
. Ifjj git sync
shares the same help messages, we can "flatten" the common Args struct intoGitFetch
/SyncArgs
. If not, we'll need a separate parameter struct as you did.
I've gone to flesh out a first draft of the sync command to be sure we need to share the help messages and yeah, it makes sense to share them. So I've extracted these out and flattened them back into GitFetchArgs
.
Is this what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what you meant?
yes, thanks.
c2adc4e
to
084797c
Compare
branch: args.fetch.branch.clone(), | ||
remotes: remotes.clone(), | ||
all_remotes: args.fetch.all_remotes, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we can't use the original args.fetch
? That makes args.fetch
useless..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe FetchRemoteArgs
can be extracted instead of all-in FetchArgs
, but I'm not pretty sure if that makes sense. Sorry for the noise.
084797c
to
845892d
Compare
Similarly to `git_fetch`, this will be used in `jj git sync`, so moving this out to maintain the same behaviour across `fetch` command and `sync`. * Refactor out `get_fetch_remotes` to `git_util.rs`. * inline the different `get_*_remote*` functions into `get_fetch_remotes`; The resulting function is still small enough to be easily readable. * Move `get_single_remote` into `git_util.rs` and update call sites. * Use common FetchArgs to pass arguments both to `get_fetch_remotes` and `git_fetch` * Update use references All tests still pass. Issue: #1039
845892d
to
c1da3c8
Compare
Similarly to
git_fetch
, this will be used injj git sync
, somoving this out to maintain the same behaviour across
fetch
command andsync
.get_fetch_remotes
togit_util.rs
.get_*_remote*
functions intoget_fetch_remotes
;The resulting function is still small enough to be easily readable.
get_single_remote
intogit_util.rs
and update call sites.All tests still pass.
Issue: #1039