mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
Log create_bookmark error in gitimport
Summary: In D41769964, we decided not to stop `gitimport` simply because `create-bookmark` fails cause that could be due to the fact that the bookmark being created already exists. If that is indeed the case, we try to resolve the bookmark and move it to the new value. However, there could be other unrelated reasons for `create_bookmark` to fail in which case we would still try to resolve the bookmark and end up in unexpected situations (e.g. Luibov trying to import `paws` repo faced this problem). This diff does two things: - Performs an early check to determine if the bookmark exists by resolving it. If it does exist, it executes the move bookmark branch of code - If the bookmark doesn't exist, then it creates it. If there are any errors during bookmark creation or movement, they get logged for the user. Reviewed By: mitrandir77 Differential Revision: D46071703 fbshipit-source-id: 446b0bc720d13b9e9314feccdb147b2bab0b7cd9
This commit is contained in:
parent
72eeb1524e
commit
11982fe8da
@ -306,46 +306,53 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
|
||||
BookmarkKey::new(&name)?
|
||||
};
|
||||
let pushvars = None;
|
||||
if repo_context
|
||||
.create_bookmark(&bookmark_key, final_changeset, pushvars)
|
||||
let old_changeset = repo_context
|
||||
.resolve_bookmark(&bookmark_key, BookmarkFreshness::MostRecent)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
let old_changeset = repo_context
|
||||
.resolve_bookmark(&bookmark_key, BookmarkFreshness::MostRecent)
|
||||
.await
|
||||
.with_context(|| format!("failed to resolve bookmark {name}"))?
|
||||
.map(|context| context.id());
|
||||
if old_changeset != Some(final_changeset) {
|
||||
let allow_non_fast_forward = true;
|
||||
repo_context
|
||||
.move_bookmark(
|
||||
&bookmark_key,
|
||||
final_changeset,
|
||||
old_changeset,
|
||||
allow_non_fast_forward,
|
||||
pushvars,
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("failed to move bookmark {name} from {old_changeset:?} to {final_changeset:?}"))?;
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (moved from {old_changeset:?})"
|
||||
);
|
||||
} else {
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (already up-to-date)"
|
||||
);
|
||||
.with_context(|| format!("failed to resolve bookmark {name}"))?
|
||||
.map(|context| context.id());
|
||||
match old_changeset {
|
||||
// The bookmark already exists. Instead of creating it, we need to move it.
|
||||
Some(old_changeset) => {
|
||||
if old_changeset != final_changeset {
|
||||
let allow_non_fast_forward = true;
|
||||
repo_context
|
||||
.move_bookmark(
|
||||
&bookmark_key,
|
||||
final_changeset,
|
||||
Some(old_changeset),
|
||||
allow_non_fast_forward,
|
||||
pushvars,
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("failed to move bookmark {name} from {old_changeset:?} to {final_changeset:?}"))?;
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (moved from {old_changeset:?})"
|
||||
);
|
||||
} else {
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (already up-to-date)"
|
||||
);
|
||||
}
|
||||
}
|
||||
// The bookmark doesn't yet exist. Create it.
|
||||
None => {
|
||||
repo_context
|
||||
.create_bookmark(&bookmark_key, final_changeset, pushvars)
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!("failed to create bookmark {name} during gitimport")
|
||||
})?;
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (created)"
|
||||
)
|
||||
}
|
||||
} else {
|
||||
info!(
|
||||
ctx.logger(),
|
||||
"Bookmark: \"{name}\": {final_changeset:?} (created)"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -127,7 +127,7 @@
|
||||
* Initialized repo: repo (glob)
|
||||
* All repos initialized. * (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)) (created) (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (moved from Some(ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)))) (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (moved from ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c))) (glob)
|
||||
* Bookmark: "tags/empty_tag": ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)) (created) (glob)
|
||||
* Bookmark: "tags/first_tag": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (created) (glob)
|
||||
|
||||
@ -181,8 +181,8 @@
|
||||
* Initializing repo: repo (glob)
|
||||
* Initialized repo: repo (glob)
|
||||
* All repos initialized. * (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)) (moved from Some(ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)))) (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (moved from Some(ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)))) (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)) (moved from ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044))) (glob)
|
||||
* Bookmark: "heads/master": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (moved from ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c))) (glob)
|
||||
* Bookmark: "tags/empty_tag": ChangesetId(Blake2(da93dc81badd8d407db0f3219ec0ec78f1ef750ebfa95735bb483310371af80c)) (already up-to-date) (glob)
|
||||
* Bookmark: "tags/first_tag": ChangesetId(Blake2(032cd4dce0406f1c1dd1362b6c3c9f9bdfa82f2fc5615e237a890be4fe08b044)) (already up-to-date) (glob)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user