Skip to content

Commit

Permalink
Handle git cinnabar reclone internally rather than delegate to git re…
Browse files Browse the repository at this point in the history
…mote update
  • Loading branch information
glandium committed Oct 30, 2023
1 parent a4d67d2 commit e9b6768
Show file tree
Hide file tree
Showing 6 changed files with 431 additions and 105 deletions.
6 changes: 1 addition & 5 deletions src/cinnabar-fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,10 @@ void do_store_metadata(struct object_id *result) {
}

store_changesets_metadata(&changesets);
config("previous-metadata", &buf);
if ((buf.len && !get_oid_hex(buf.buf, &previous))) {
has_previous = 1;
} else if (!is_null_oid(&metadata_oid)) {
if (!is_null_oid(&metadata_oid)) {
oidcpy(&previous, &metadata_oid);
has_previous = 1;
}
strbuf_release(&buf);
oidmap_iter_init(the_repository->objects->replace_map, &iter);
while ((replace = oidmap_iter_next(&iter))) {
strbuf_addf(&buf, "160000 %s%c",
Expand Down
80 changes: 72 additions & 8 deletions src/cinnabar-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ static int count_refs(const char *refname, const struct object_id *oid,
return 0;
}

static void reset_metadata(void)
{
oidcpy(&metadata_oid, null_oid());
oidcpy(&changesets_oid, null_oid());
oidcpy(&manifests_oid, null_oid());
oidcpy(&hg2git_oid, null_oid());
oidcpy(&git2hg_oid, null_oid());
oidcpy(&files_meta_oid, null_oid());
}

static void init_metadata(void)
{
struct commit *c;
Expand All @@ -542,12 +552,7 @@ static void init_metadata(void)

c = lookup_commit_reference_by_name(METADATA_REF);
if (!c) {
oidcpy(&metadata_oid, null_oid());
oidcpy(&changesets_oid, null_oid());
oidcpy(&manifests_oid, null_oid());
oidcpy(&hg2git_oid, null_oid());
oidcpy(&git2hg_oid, null_oid());
oidcpy(&files_meta_oid, null_oid());
reset_metadata();
return;
}
oidcpy(&metadata_oid, &c->object.oid);
Expand Down Expand Up @@ -652,7 +657,7 @@ void dump_ref_updates(void);

extern void reset_changeset_heads(void);

void do_reload(void)
void do_reload(int reset)
{
done_cinnabar();
hashmap_init(&git_tree_cache, oid_map_entry_cmp, NULL, 0);
Expand All @@ -663,7 +668,11 @@ void do_reload(void)

metadata_flags = 0;
reset_replace_map();
init_metadata();
if (reset) {
reset_metadata();
} else {
init_metadata();
}
reset_changeset_heads();
}

Expand Down Expand Up @@ -756,6 +765,61 @@ int remote_skip_default_update(const struct remote *remote)
return remote->skip_default_update;
}

void add_ref(struct ref ***tail, char *name, const struct object_id *oid)
{
struct ref *ref = alloc_ref(name);
if (oid) {
oidcpy(&ref->old_oid, oid);
}
**tail = ref;
*tail = &ref->next;
}

void add_symref(struct ref ***tail, const char *name, const char *sym)
{
struct ref *ref = alloc_ref(name);
ref->symref = xstrdup(sym);
**tail = ref;
*tail = &ref->next;
}

struct ref *get_ref_map(const struct remote *remote,
const struct ref *remote_refs)
{
struct ref *ref_map = NULL;
struct ref **tail = &ref_map;
int i;

for (i = 0; i < remote->fetch.nr; i++) {
get_fetch_map(remote_refs, &remote->fetch.items[i], &tail, 0);
}
apply_negative_refspecs(ref_map, (struct refspec *)&remote->fetch);
ref_map = ref_remove_duplicates(ref_map);
return ref_map;
}

struct ref *get_stale_refs(const struct remote *remote,
const struct ref *ref_map)
{
return get_stale_heads((struct refspec *)&remote->fetch,
(struct ref *)ref_map);
}

const struct ref *get_next_ref(const struct ref *ref)
{
return ref->next;
}

const char *get_ref_name(const struct ref *ref)
{
return ref->name;
}

const struct ref *get_ref_peer_ref(const struct ref *ref)
{
return ref->peer_ref;
}

static int nongit = 0;

extern NORETURN void do_panic(const char *err, size_t len);
Expand Down
20 changes: 19 additions & 1 deletion src/cinnabar-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void create_git_tree(const struct object_id *tree_id,
struct object_id *result);

void reset_manifest_heads(void);
void do_reload(void);
void do_reload(int);
unsigned int replace_map_size(void);

const struct object_id *repo_lookup_replace_object(
Expand All @@ -72,4 +72,22 @@ struct diff_tree_item;

void diff_tree_(int argc, const char **argv, void (*cb)(void *, struct diff_tree_item *), void *context);

struct ref;

void add_ref(struct ref ***tail, char *name, const struct object_id *oid);

void add_symref(struct ref ***tail, const char *name, const char *sym);

struct ref *get_ref_map(const struct remote *remote,
const struct ref *remote_refs);

struct ref *get_stale_refs(const struct remote *remote,
const struct ref *ref_map);

const struct ref *get_next_ref(const struct ref *ref);

const char *get_ref_name(const struct ref *ref);

const struct ref *get_ref_peer_ref(const struct ref *ref);

#endif
5 changes: 3 additions & 2 deletions src/libgit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl From<object_id> for GitObjectId {
}

extern "C" {
pub static metadata_oid: object_id;
pub static mut metadata_oid: object_id;
pub static mut changesets_oid: object_id;
}

#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -1154,7 +1155,7 @@ extern "C" {

fn free_commit_list(list: *mut commit_list);

fn lookup_commit(r: *mut repository, oid: *const object_id) -> *const commit;
pub fn lookup_commit(r: *mut repository, oid: *const object_id) -> *const commit;
}

pub struct CommitList {
Expand Down
Loading

0 comments on commit e9b6768

Please sign in to comment.