static void one_remote_ref(const char *refname) { struct ref *ref; struct object *obj; ref = alloc_ref(refname); if (http_fetch_ref(repo->url, ref) != 0) { fprintf(stderr, "Unable to fetch ref %s from %s\n", refname, repo->url); free(ref); return; } /* * Fetch a copy of the object if it doesn't exist locally - it * may be required for updating server info later. */ if (repo->can_update_info_refs && !has_object_file(&ref->old_oid)) { obj = lookup_unknown_object(ref->old_oid.hash); fprintf(stderr, " fetch %s for %s\n", oid_to_hex(&ref->old_oid), refname); add_fetch_request(obj); } ref->next = remote_refs; remote_refs = ref; }
/* return non-zero if the ref is hidden, otherwise 0 */ static int mark_our_ref(const char *refname, const char *refname_full, const struct object_id *oid) { struct object *o = lookup_unknown_object(oid->hash); if (ref_is_hidden(refname, refname_full)) { o->flags |= HIDDEN_REF; return 1; } o->flags |= OUR_REF; return 0; }
/* return non-zero if the ref is hidden, otherwise 0 */ static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { struct object *o = lookup_unknown_object(sha1); if (ref_is_hidden(refname)) { o->flags |= HIDDEN_REF; return 1; } if (!o) die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1)); o->flags |= OUR_REF; return 0; }
int fsck_finish(struct fsck_options *options) { int ret = 0; struct oidset_iter iter; const struct object_id *oid; oidset_iter_init(&gitmodules_found, &iter); while ((oid = oidset_iter_next(&iter))) { struct blob *blob; enum object_type type; unsigned long size; char *buf; if (oidset_contains(&gitmodules_done, oid)) continue; blob = lookup_blob(oid); if (!blob) { struct object *obj = lookup_unknown_object(oid->hash); ret |= report(options, obj, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); continue; } buf = read_object_file(oid, &type, &size); if (!buf) { if (is_promisor_object(&blob->object.oid)) continue; ret |= report(options, &blob->object, FSCK_MSG_GITMODULES_MISSING, "unable to read .gitmodules blob"); continue; } if (type == OBJ_BLOB) ret |= fsck_blob(blob, buf, size, options); else ret |= report(options, &blob->object, FSCK_MSG_GITMODULES_BLOB, "non-blob found at .gitmodules"); free(buf); } oidset_clear(&gitmodules_found); oidset_clear(&gitmodules_done); return ret; }
enum peel_status peel_object(const unsigned char *name, unsigned char *sha1) { struct object *o = lookup_unknown_object(name); if (o->type == OBJ_NONE) { int type = sha1_object_info(name, NULL); if (type < 0 || !object_as_type(o, type, 0)) return PEEL_INVALID; } if (o->type != OBJ_TAG) return PEEL_NON_TAG; o = deref_tag_noverify(o); if (!o) return PEEL_INVALID; hashcpy(sha1, o->oid.hash); return PEEL_PEELED; }
static int diff_tree_stdin(char *line) { int len = strlen(line); unsigned char sha1[20]; struct object *obj; if (!len || line[len-1] != '\n') return -1; line[len-1] = 0; if (get_sha1_hex(line, sha1)) return -1; obj = lookup_unknown_object(sha1); if (!obj || !obj->parsed) obj = parse_object(sha1); if (!obj) return -1; if (obj->type == OBJ_COMMIT) return stdin_diff_commit((struct commit *)obj, line, len); if (obj->type == OBJ_TREE) return stdin_diff_trees((struct tree *)obj, line, len); error("Object %s is a %s, not a commit or tree", sha1_to_hex(sha1), typename(obj->type)); return -1; }
int walker_fetch(struct walker *walker, int targets, char **target, const char **write_ref, const char *write_ref_log_details) { struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *)); unsigned char *sha1 = xmalloc(targets * 20); char *msg; int ret; int i; save_commit_buffer = 0; for (i = 0; i < targets; i++) { if (!write_ref || !write_ref[i]) continue; lock[i] = lock_ref_sha1(write_ref[i], NULL); if (!lock[i]) { error("Can't lock ref %s", write_ref[i]); goto unlock_and_fail; } } if (!walker->get_recover) for_each_ref(mark_complete, NULL); for (i = 0; i < targets; i++) { if (interpret_target(walker, target[i], &sha1[20 * i])) { error("Could not interpret response from server '%s' as something to pull", target[i]); goto unlock_and_fail; } if (process(walker, lookup_unknown_object(&sha1[20 * i]))) goto unlock_and_fail; } if (loop(walker)) goto unlock_and_fail; if (write_ref_log_details) { msg = xmalloc(strlen(write_ref_log_details) + 12); sprintf(msg, "fetch from %s", write_ref_log_details); } else { msg = NULL; } for (i = 0; i < targets; i++) { if (!write_ref || !write_ref[i]) continue; ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)"); lock[i] = NULL; if (ret) goto unlock_and_fail; } free(msg); return 0; unlock_and_fail: for (i = 0; i < targets; i++) if (lock[i]) unlock_ref(lock[i]); return -1; }
int walker_fetch(struct walker *walker, int targets, char **target, const char **write_ref, const char *write_ref_log_details) { struct strbuf refname = STRBUF_INIT; struct strbuf err = STRBUF_INIT; struct transaction *transaction = NULL; unsigned char *sha1 = xmalloc(targets * 20); char *msg = NULL; int i, ret = -1; save_commit_buffer = 0; if (write_ref) { transaction = transaction_begin(&err); if (!transaction) { error("%s", err.buf); goto done; } } if (!walker->get_recover) { for_each_ref(mark_complete, NULL); commit_list_sort_by_date(&complete); } for (i = 0; i < targets; i++) { if (interpret_target(walker, target[i], &sha1[20 * i])) { error("Could not interpret response from server '%s' as something to pull", target[i]); goto done; } if (process(walker, lookup_unknown_object(&sha1[20 * i]))) goto done; } if (loop(walker)) goto done; if (!write_ref) { ret = 0; goto done; } if (write_ref_log_details) { msg = xstrfmt("fetch from %s", write_ref_log_details); } else { msg = NULL; } for (i = 0; i < targets; i++) { if (!write_ref[i]) continue; strbuf_reset(&refname); strbuf_addf(&refname, "refs/%s", write_ref[i]); if (transaction_update_ref(transaction, refname.buf, &sha1[20 * i], NULL, 0, 0, msg ? msg : "fetch (unknown)", &err)) { error("%s", err.buf); goto done; } } if (transaction_commit(transaction, &err)) { error("%s", err.buf); goto done; } ret = 0; done: transaction_free(transaction); free(msg); free(sha1); strbuf_release(&err); strbuf_release(&refname); return ret; }
static void mark_object_for_connectivity(const struct object_id *oid) { struct object *obj = lookup_unknown_object(oid->hash); obj->flags |= HAS_OBJ; }