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

git: update jj git clone|fetch to use new GitFetch api directly. #4960

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

essiene
Copy link
Contributor

@essiene essiene commented Nov 24, 2024

  • Make the new GitFetch api public.
  • Rewrite all tests that used git::fetch* to use the new API.
    One interesting artifact of the new API is that it holds onto a reference
    of the tx.repo_mut(), so the GitFetch object needs to fall go of scope
    completely before we can make any other mutable calls to tx.
  • Delete the git::fetch
  • Update jj git clone and git_fetch in cli/src/git_utils.rs to use
    the new api directly. Removing one redundant layer of indirection.
  • This fixes jj git fetch with multiple remotes can abandon reachable commits (and rebase reachable descendants) #4920 as it first fetches from all remotes before import_refs()
    is called, so there is no race condition if the same commit is treated
    differently in different remotes specified in the same command.

Fixes: #4920

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have added tests to cover my changes

@essiene essiene requested a review from yuja November 24, 2024 03:20
lib/src/git.rs Outdated Show resolved Hide resolved
@essiene essiene force-pushed the essiene/nwtzqzumrzyw branch 3 times, most recently from c35a6f7 to c2e4cb0 Compare November 30, 2024 18:35
@essiene essiene force-pushed the essiene/knwwrnytzrry branch from 08525a0 to a846163 Compare November 30, 2024 22:49
@essiene essiene force-pushed the essiene/nwtzqzumrzyw branch 4 times, most recently from ed6876d to d5c1a07 Compare December 1, 2024 11:48
@essiene essiene force-pushed the essiene/knwwrnytzrry branch 2 times, most recently from 4950b09 to 336bbdd Compare December 1, 2024 12:09
@essiene essiene force-pushed the essiene/nwtzqzumrzyw branch from d5c1a07 to 5275f9a Compare December 1, 2024 12:09
Base automatically changed from essiene/nwtzqzumrzyw to main December 1, 2024 12:22
@essiene essiene force-pushed the essiene/knwwrnytzrry branch from 336bbdd to 11bf992 Compare December 1, 2024 12:23
@essiene essiene changed the title jj-lib: git::fetch takes multiple remotes. jj-lib: refactor jj git clone|fetch and `to use new GitFetch api directly. Dec 1, 2024
@essiene essiene force-pushed the essiene/knwwrnytzrry branch 2 times, most recently from 0f2cc4d to 6182c03 Compare December 1, 2024 12:26
@essiene essiene changed the title jj-lib: refactor jj git clone|fetch and `to use new GitFetch api directly. jj-lib: refactor jj git clone|fetch to use new GitFetch api directly. Dec 1, 2024
@essiene essiene force-pushed the essiene/knwwrnytzrry branch 2 times, most recently from 813822d to 51d8892 Compare December 1, 2024 12:32
CHANGELOG.md Show resolved Hide resolved
CHANGELOG.md Outdated
* `jj git fetch` with multiple remotes will now fetch from all remotes before
importing refs into the jj repo. This fixes a race condition where the treatment
of a commit that is found in multiple fetch remotes depended on the order the
remotes where specified.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for this issue?

cli/src/commands/git/clone.rs Outdated Show resolved Hide resolved
cli/src/git_util.rs Outdated Show resolved Hide resolved
lib/src/git.rs Show resolved Hide resolved
@essiene essiene changed the title jj-lib: refactor jj git clone|fetch to use new GitFetch api directly. git: refactor jj git clone|fetch to use new GitFetch api directly. Dec 1, 2024
@essiene essiene force-pushed the essiene/knwwrnytzrry branch 5 times, most recently from d661392 to d96eb38 Compare December 8, 2024 19:44
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

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

git: refactor jj git clone|fetch to use new GitFetch api directly.
[...]
This fixes #4920 as it first fetches from all remotes before import_refs()

nit: I think "refactor" is supposed to mean that it has no impact on functionality, so just say "git: use new GitFetch api directly in jj git clone|fetch" or something instead

@essiene essiene force-pushed the essiene/knwwrnytzrry branch 2 times, most recently from ba5b940 to b2e66aa Compare December 15, 2024 21:32
@essiene essiene changed the title git: refactor jj git clone|fetch to use new GitFetch api directly. git: update jj git clone|fetch to use new GitFetch api directly. Dec 15, 2024
@essiene
Copy link
Contributor Author

essiene commented Dec 15, 2024

git: refactor jj git clone|fetch to use new GitFetch api directly.
[...]
This fixes #4920 as it first fetches from all remotes before import_refs()

nit: I think "refactor" is supposed to mean that it has no impact on functionality, so just say "git: use new GitFetch api directly in jj git clone|fetch" or something instead

makes sense. Updated.

@essiene essiene force-pushed the essiene/knwwrnytzrry branch from b2e66aa to b733e17 Compare December 15, 2024 21:45
* Make the new `GitFetch` api public.
* Move `git::fetch` to `lib/tests/test_git.rs` as `git_fetch`, to minimize
  churn in the tests. Update test call sites to use `git_fetch`
* Delete the `git::fetch` from `lib/src/git.rs`.
* Update `jj git clone` and `git_fetch` in `cli/src/git_utils.rs` to use
  the new api directly. Removing one redundant layer of indirection.
* This fixes #4920 as it first fetches from all remotes before `import_refs()`
  is called, so there is no race condition if the same commit is treated
  differently in different remotes specified in the same command.
* Add test for the race condition.

Fixes: #4920
@essiene essiene force-pushed the essiene/knwwrnytzrry branch from b733e17 to 6757530 Compare December 15, 2024 21:49
Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Restore formatting changes in CHANGELOG.md

})?;
print_git_import_stats(ui, fetch_tx.repo(), &stats.import_stats, true)?;
let default_branch =
with_remote_git_callbacks(ui, None, |cb| -> Result<Option<String>, CommandError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: type annotation isn't needed

Comment on lines +240 to +243
GitFetchStats {
default_branch,
import_stats,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we don't need to return import_stats. It will help remove struct GitFetchStats. (can be addressed later)

GitFetchError::GitImportError(err) => err.into(),
GitFetchError::InternalGitError(err) => map_git_error(err),
_ => user_error(err),
with_remote_git_callbacks(ui, None, |cb| -> Result<(), CommandError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: type annotation isn't needed if ?; Ok(()) is removed

@rem1: qxosxrvv 6a211027 message
rem2: yszkquru 2497a8a0 message
@rem2: yszkquru 2497a8a0 message
"###);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this test fail without this patch? iirc, the issue was that a bookmark was moved in one remote, and descendant commit of that bookmark was added by the other remote, or something like that.

@@ -1394,31 +1393,6 @@ pub struct GitFetchStats {
pub import_stats: GitImportStats,
}

#[tracing::instrument(skip(mut_repo, git_repo, callbacks))]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: perhaps, tracing::instruments() will have to be moved to fetch() (and maybe import_refs())

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.

jj git fetch with multiple remotes can abandon reachable commits (and rebase reachable descendants)
3 participants