Skip to content

Commit

Permalink
Only call dump_ref_updates when leaving the remote helper
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 10, 2023
1 parent c9bc672 commit 57d276a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/cinnabar-fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ static void init(void)
atexit(locked_rollback);
}

extern void dump_ref_updates(void);

static void cleanup(void)
{
if (!initialized)
Expand All @@ -182,7 +180,6 @@ static void cleanup(void)
NULL);
commit_shallow_file(the_repository, &shallow_lock);
}
dump_ref_updates();
}

unkeep_all_packs();
Expand Down
4 changes: 0 additions & 4 deletions src/cinnabar-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ unsigned int replace_map_tablesize(void)

extern void init_metadata(struct commit *c);

void dump_ref_updates(void);

extern void reset_changeset_heads(void);
extern void reset_manifest_heads(void);

Expand All @@ -485,8 +483,6 @@ void do_reload(struct object_id *oid)
done_cinnabar();
hashmap_init(&git_tree_cache, oid_map_entry_cmp, NULL, 0);

dump_ref_updates();

reset_replace_map();
if (oid) {
if (!is_null_oid(oid)) {
Expand Down
24 changes: 14 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,20 @@ extern "C" {
static REF_UPDATES: Lazy<Mutex<HashMap<Box<BStr>, CommitId>>> =
Lazy::new(|| Mutex::new(HashMap::new()));

#[no_mangle]
unsafe extern "C" fn dump_ref_updates() {
let mut transaction = RefTransaction::new().unwrap();
for (refname, oid) in REF_UPDATES.lock().unwrap().drain() {
let refname = OsStr::from_bytes(&refname);
if oid.is_null() {
transaction.delete(refname, None, "update").unwrap();
} else {
transaction.update(refname, oid, None, "update").unwrap();
fn dump_ref_updates() {
let ref_updates = REF_UPDATES.lock().unwrap();
if !ref_updates.is_empty() {
let mut transaction = RefTransaction::new().unwrap();
for (refname, oid) in ref_updates.drain() {

Check failure on line 195 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest, 1.73.0)

cannot borrow `ref_updates` as mutable, as it is not declared as mutable

error[E0596]: cannot borrow `ref_updates` as mutable, as it is not declared as mutable --> src/main.rs:195:31 | 195 | for (refname, oid) in ref_updates.drain() { | ^^^^^^^^^^^ cannot borrow as mutable | help: consider changing this to be mutable | 192 | let mut ref_updates = REF_UPDATES.lock().unwrap(); | +++

Check failure on line 195 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest, 1.73.0)

cannot borrow `ref_updates` as mutable, as it is not declared as mutable

error[E0596]: cannot borrow `ref_updates` as mutable, as it is not declared as mutable --> src/main.rs:195:31 | 195 | for (refname, oid) in ref_updates.drain() { | ^^^^^^^^^^^ cannot borrow as mutable | help: consider changing this to be mutable | 192 | let mut ref_updates = REF_UPDATES.lock().unwrap(); | +++
let refname = OsStr::from_bytes(&refname);
if oid.is_null() {
transaction.delete(refname, None, "update").unwrap();
} else {
transaction.update(refname, oid, None, "update").unwrap();
}
}
transaction.commit().unwrap();
}
transaction.commit().unwrap();
}

static MAYBE_INIT_CINNABAR_2: Lazy<Option<()>> = Lazy::new(|| unsafe {
Expand Down Expand Up @@ -4579,6 +4581,8 @@ fn git_remote_hg(remote: OsString, mut url: OsString) -> Result<c_int, String> {
_ => panic!("unknown command: {}", cmd.as_bstr()),
}
}
// See comment in remote_helper_tags_list.
dump_ref_updates();
Ok(0)
}

Expand Down

0 comments on commit 57d276a

Please sign in to comment.