Skip to content

Commit

Permalink
lib git.rs: remove workaround for a now-fixed libgit2 bug
Browse files Browse the repository at this point in the history
libgit2/libgit2#3178 is now fixed.
  • Loading branch information
ilyagr committed Apr 17, 2024
1 parent 87c4a2e commit 1975acb
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,50 +1275,31 @@ pub fn push_updates(
updates: &[GitRefUpdate],
callbacks: RemoteCallbacks<'_>,
) -> Result<(), GitPushError> {
let mut temp_refs = vec![];
let mut qualified_remote_refs = vec![];
let mut refspecs = vec![];
for update in updates {
qualified_remote_refs.push(update.qualified_name.as_str());
if let Some(new_target) = &update.new_target {
// Create a temporary ref to work around https://github.com/libgit2/libgit2/issues/3178
let temp_ref_name = format!("refs/jj/git-push/{}", new_target.hex());
temp_refs.push(git_repo.reference(
&temp_ref_name,
git2::Oid::from_bytes(new_target.as_bytes()).unwrap(),
true,
"temporary reference for git push",
)?);
refspecs.push(format!(
"{}{}:{}",
(if update.force { "+" } else { "" }),
temp_ref_name,
git2::Oid::from_bytes(new_target.as_bytes()).unwrap(),
update.qualified_name
));
} else {
refspecs.push(format!(":{}", update.qualified_name));
}
}
let result = push_refs(
// TODO(ilyagr): this function will be reused to implement force-with-lease, so
// don't inline for now. If it's after 2024-06-01 or so, ilyagr may have
// fogotten to delete this comment.

Check failure on line 1295 in lib/src/git.rs

View workflow job for this annotation

GitHub Actions / Codespell

fogotten ==> forgotten
push_refs(
git_repo,
remote_name,
&qualified_remote_refs,
&refspecs,
callbacks,
);
for mut temp_ref in temp_refs {
// TODO: Figure out how to do the equivalent of absl::Cleanup for
// temp_ref.delete().
if let Err(err) = temp_ref.delete() {
// Propagate error only if we don't already have an error to return and it's not
// NotFound (there may be duplicates if the list if multiple branches moved to
// the same commit).
if result.is_ok() && err.code() != git2::ErrorCode::NotFound {
return Err(GitPushError::InternalGitError(err));
}
}
}
result
)
}

fn push_refs(
Expand Down

0 comments on commit 1975acb

Please sign in to comment.