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 5040aa8
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,50 +1275,30 @@ 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(
// Please don't inline `push_refs` before 2024-06-01 without talking to ilyagr,
// he's working on this code.
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 5040aa8

Please sign in to comment.