static void mark_recent_complete_commits(struct fetch_pack_args *args, unsigned long cutoff) { while (complete && cutoff <= complete->item->date) { if (args->verbose) fprintf(stderr, "Marking %s as complete\n", oid_to_hex(&complete->item->object.oid)); pop_most_recent_commit(&complete, COMPLETE); } }
/* * Write out any suspect information which depends on the path. This must be * handled separately from emit_one_suspect_detail(), because a given commit * may have changes in multiple paths. So this needs to appear each time * we mention a new group. * * To allow LF and other nonportable characters in pathnames, * they are c-style quoted as needed. */ static void write_filename_info(struct blame_origin *suspect) { if (suspect->previous) { struct blame_origin *prev = suspect->previous; printf("previous %s ", oid_to_hex(&prev->commit->object.oid)); write_name_quoted(prev->path, stdout, '\n'); } printf("filename "); write_name_quoted(suspect->path, stdout, '\n'); }
static int show_text_ref(const char *name, const struct object_id *oid, int flag, void *cb_data) { const char *name_nons = strip_namespace(name); struct strbuf *buf = cb_data; struct object *o = parse_object(the_repository, oid); if (!o) return 0; strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons); if (o->type == OBJ_TAG) { o = deref_tag(the_repository, o, name, 0); if (!o) return 0; strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid), name_nons); } return 0; }
static int is_original_commit_empty(struct commit *commit) { const unsigned char *ptree_sha1; if (parse_commit(commit)) return error(_("could not parse commit %s\n"), oid_to_hex(&commit->object.oid)); if (commit->parents) { struct commit *parent = commit->parents->item; if (parse_commit(parent)) return error(_("could not parse parent commit %s\n"), oid_to_hex(&parent->object.oid)); ptree_sha1 = parent->tree->object.oid.hash; } else { ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */ } return !hashcmp(ptree_sha1, commit->tree->object.oid.hash); }
static void feed_object(const struct object_id *oid, FILE *fh, int negative) { if (negative && !has_object_file(oid)) return; if (negative) putc('^', fh); fputs(oid_to_hex(oid), fh); putc('\n', fh); }
static void add_common(struct strbuf *req_buf, struct oidset *common) { struct oidset_iter iter; const struct object_id *oid; oidset_iter_init(common, &iter); while ((oid = oidset_iter_next(&iter))) { packet_buf_write(req_buf, "have %s\n", oid_to_hex(oid)); } }
static void warn_multiple_config(const struct object_id *treeish_name, const char *name, const char *option) { const char *commit_string = "WORKTREE"; if (treeish_name) commit_string = oid_to_hex(treeish_name); warning("%s:.gitmodules, multiple configurations found for " "'submodule.%s.%s'. Skipping second one!", commit_string, name, option); }
static void parse_treeish_arg(const char **argv, struct archiver_args *ar_args, const char *prefix, int remote) { const char *name = argv[0]; const unsigned char *commit_sha1; time_t archive_time; struct tree *tree; const struct commit *commit; struct object_id oid; /* Remotes are only allowed to fetch actual refs */ if (remote && !remote_allow_unreachable) { char *ref = NULL; const char *colon = strchrnul(name, ':'); int refnamelen = colon - name; if (!dwim_ref(name, refnamelen, &oid, &ref)) die(_("no such ref: %.*s"), refnamelen, name); free(ref); } if (get_oid(name, &oid)) die(_("not a valid object name: %s"), name); commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1); if (commit) { commit_sha1 = commit->object.oid.hash; archive_time = commit->date; } else { commit_sha1 = NULL; archive_time = time(NULL); } tree = parse_tree_indirect(&oid); if (tree == NULL) die(_("not a tree object: %s"), oid_to_hex(&oid)); if (prefix) { struct object_id tree_oid; unsigned int mode; int err; err = get_tree_entry(&tree->object.oid, prefix, &tree_oid, &mode); if (err || !S_ISDIR(mode)) die(_("current working directory is untracked")); tree = parse_tree_indirect(&tree_oid); } ar_args->tree = tree; ar_args->commit_sha1 = commit_sha1; ar_args->commit = commit; ar_args->time = archive_time; }
static int add_info_ref(const char *path, const struct object_id *oid, int flag, void *cb_data) { FILE *fp = cb_data; struct object *o = parse_object(oid->hash); if (!o) return -1; if (fprintf(fp, "%s %s\n", oid_to_hex(oid), path) < 0) return -1; if (o->type == OBJ_TAG) { o = deref_tag(o, path, 0); if (o) if (fprintf(fp, "%s %s^{}\n", oid_to_hex(&o->oid), path) < 0) return -1; } return 0; }
static int show_object_fast( const struct object_id *oid, enum object_type type, int exclude, uint32_t name_hash, struct packed_git *found_pack, off_t found_offset) { fprintf(stdout, "%s\n", oid_to_hex(oid)); return 1; }
static void print_bases(struct base_tree_info *bases) { int i; /* Only do this once, either for the cover or for the first one */ if (is_null_oid(&bases->base_commit)) return; /* Show the base commit */ printf("base-commit: %s\n", oid_to_hex(&bases->base_commit)); /* Show the prerequisite patches */ for (i = bases->nr_patch_id - 1; i >= 0; i--) printf("prerequisite-patch-id: %s\n", oid_to_hex(&bases->patch_id[i])); free(bases->patch_id); bases->nr_patch_id = 0; bases->alloc_patch_id = 0; oidclr(&bases->base_commit); }
/* * When we cannot load the full patch-id for both commits for whatever * reason, the function returns -1 (i.e. return error(...)). Despite * the "neq" in the name of this function, the caller only cares about * the return value being zero (a and b are equivalent) or non-zero (a * and b are different), and returning non-zero would keep both in the * result, even if they actually were equivalent, in order to err on * the side of safety. The actual value being negative does not have * any significance; only that it is non-zero matters. */ static int patch_id_neq(const void *cmpfn_data, const void *entry, const void *entry_or_key, const void *unused_keydata) { /* NEEDSWORK: const correctness? */ struct diff_options *opt = (void *)cmpfn_data; struct patch_id *a = (void *)entry; struct patch_id *b = (void *)entry_or_key; if (is_null_oid(&a->patch_id) && commit_patch_id(a->commit, opt, &a->patch_id, 0)) return error("Could not get patch ID for %s", oid_to_hex(&a->commit->object.oid)); if (is_null_oid(&b->patch_id) && commit_patch_id(b->commit, opt, &b->patch_id, 0)) return error("Could not get patch ID for %s", oid_to_hex(&b->commit->object.oid)); return !oideq(&a->patch_id, &b->patch_id); }
static int edit_and_replace(const char *object_ref, int force, int raw) { char *tmpfile; enum object_type type; struct object_id old_oid, new_oid, prev; struct strbuf ref = STRBUF_INIT; if (get_oid(object_ref, &old_oid) < 0) return error("Not a valid object name: '%s'", object_ref); type = oid_object_info(the_repository, &old_oid, NULL); if (type < 0) return error("unable to get object type for %s", oid_to_hex(&old_oid)); if (check_ref_valid(&old_oid, &prev, &ref, force)) { strbuf_release(&ref); return -1; } strbuf_release(&ref); tmpfile = git_pathdup("REPLACE_EDITOBJ"); if (export_object(&old_oid, type, raw, tmpfile)) { free(tmpfile); return -1; } if (launch_editor(tmpfile, NULL, NULL) < 0) { free(tmpfile); return error("editing object file failed"); } if (import_object(&new_oid, type, raw, tmpfile)) { free(tmpfile); return -1; } free(tmpfile); if (!oidcmp(&old_oid, &new_oid)) return error("new object is the same as the old one: '%s'", oid_to_hex(&old_oid)); return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force); }
static void output_refs(struct ref *refs) { struct ref *posn; for (posn = refs; posn; posn = posn->next) { if (posn->symref) printf("@%s %s\n", posn->symref, posn->name); else printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name); } printf("\n"); fflush(stdout); }
static const char *describe_object(struct fsck_options *o, struct object *obj) { static struct strbuf buf = STRBUF_INIT; char *name; strbuf_reset(&buf); strbuf_addstr(&buf, oid_to_hex(&obj->oid)); if (o->object_names && (name = lookup_decoration(o->object_names, obj))) strbuf_addf(&buf, " (%s)", name); return buf.buf; }
static int verify_cache(struct cache_entry **cache, int entries, int flags) { int i, funny; int silent = flags & WRITE_TREE_SILENT; /* Verify that the tree is merged */ funny = 0; for (i = 0; i < entries; i++) { const struct cache_entry *ce = cache[i]; if (ce_stage(ce)) { if (silent) return -1; if (10 < ++funny) { fprintf(stderr, "...\n"); break; } fprintf(stderr, "%s: unmerged (%s)\n", ce->name, oid_to_hex(&ce->oid)); } } if (funny) return -1; /* Also verify that the cache does not have path and path/file * at the same time. At this point we know the cache has only * stage 0 entries. */ funny = 0; for (i = 0; i < entries - 1; i++) { /* path/file always comes after path because of the way * the cache is sorted. Also path can appear only once, * which means conflicting one would immediately follow. */ const char *this_name = cache[i]->name; const char *next_name = cache[i+1]->name; int this_len = strlen(this_name); if (this_len < strlen(next_name) && strncmp(this_name, next_name, this_len) == 0 && next_name[this_len] == '/') { if (10 < ++funny) { fprintf(stderr, "...\n"); break; } fprintf(stderr, "You have both %s and %s\n", this_name, next_name); } } if (funny) return -1; return 0; }
static const char *describe_object(struct object *obj) { static struct strbuf buf = STRBUF_INIT; char *name = name_objects ? lookup_decoration(fsck_walk_options.object_names, obj) : NULL; strbuf_reset(&buf); strbuf_addstr(&buf, oid_to_hex(&obj->oid)); if (name) strbuf_addf(&buf, " (%s)", name); return buf.buf; }
static void send_shallow(struct commit_list *result) { while (result) { struct object *object = &result->item->object; if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { packet_write_fmt(1, "shallow %s", oid_to_hex(&object->oid)); register_shallow(the_repository, &object->oid); shallow_nr++; } result = result->next; } }
struct object *parse_object(const struct object_id *oid) { unsigned long size; enum object_type type; int eaten; const struct object_id *repl = lookup_replace_object(the_repository, oid); void *buffer; struct object *obj; obj = lookup_object(oid->hash); if (obj && obj->parsed) return obj; if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) || (!obj && has_object_file(oid) && oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) { if (check_object_signature(repl, NULL, 0, NULL) < 0) { error("sha1 mismatch %s", oid_to_hex(oid)); return NULL; } parse_blob_buffer(lookup_blob(oid), NULL, 0); return lookup_object(oid->hash); } buffer = read_object_file(oid, &type, &size); if (buffer) { if (check_object_signature(repl, buffer, size, type_name(type)) < 0) { free(buffer); error("sha1 mismatch %s", oid_to_hex(repl)); return NULL; } obj = parse_object_buffer(oid, type, size, buffer, &eaten); if (!eaten) free(buffer); return obj; } return NULL; }
static void debug_stage(const char *label, const struct cache_entry *ce, struct unpack_trees_options *o) { printf("%s ", label); if (!ce) printf("(missing)\n"); else if (ce == o->df_conflict_entry) printf("(conflict)\n"); else printf("%06o #%d %s %.8s\n", ce->ce_mode, ce_stage(ce), ce->name, oid_to_hex(&ce->oid)); }
static void new_parent(struct commit *parent, struct commit_list **parents_p) { struct object_id *oid = &parent->object.oid; struct commit_list *parents; for (parents = *parents_p; parents; parents = parents->next) { if (parents->item == parent) { error("duplicate parent %s ignored", oid_to_hex(oid)); return; } parents_p = &parents->next; } commit_list_insert(parent, parents_p); }
static void update_abort_safety_file(void) { struct object_id head; /* Do nothing on a single-pick */ if (!file_exists(git_path_seq_dir())) return; if (!get_oid("HEAD", &head)) write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head)); else write_file(git_path_abort_safety_file(), "%s", ""); }
int parse_tag(struct tag *item) { enum object_type type; void *data; unsigned long size; int ret; if (item->object.parsed) return 0; data = read_object_file(&item->object.oid, &type, &size); if (!data) return error("Could not read %s", oid_to_hex(&item->object.oid)); if (type != OBJ_TAG) { free(data); return error("Object %s not a tag", oid_to_hex(&item->object.oid)); } ret = parse_tag_buffer(item, data, size); free(data); return ret; }
static int reset_index(const struct object_id *oid, int reset_type, int quiet) { int nr = 1; struct tree_desc desc[2]; struct tree *tree; struct unpack_trees_options opts; memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; opts.fn = oneway_merge; opts.merge = 1; if (!quiet) opts.verbose_update = 1; switch (reset_type) { case KEEP: case MERGE: opts.update = 1; break; case HARD: opts.update = 1; /* fallthrough */ default: opts.reset = 1; } read_cache_unmerged(); if (reset_type == KEEP) { struct object_id head_oid; if (get_oid("HEAD", &head_oid)) return error(_("You do not have a valid HEAD.")); if (!fill_tree_descriptor(desc, head_oid.hash)) return error(_("Failed to find tree of HEAD.")); nr++; opts.fn = twoway_merge; } if (!fill_tree_descriptor(desc + nr - 1, oid->hash)) return error(_("Failed to find tree of %s."), oid_to_hex(oid)); if (unpack_trees(nr, desc, &opts)) return -1; if (reset_type == MIXED || reset_type == HARD) { tree = parse_tree_indirect(oid->hash); prime_cache_tree(&the_index, tree); } return 0; }
static void add_remote_info_ref(struct remote_ls_ctx *ls) { struct strbuf *buf = (struct strbuf *)ls->userData; struct object *o; struct ref *ref; ref = alloc_ref(ls->dentry_name); if (http_fetch_ref(repo->url, ref) != 0) { fprintf(stderr, "Unable to fetch ref %s from %s\n", ls->dentry_name, repo->url); aborted = 1; free(ref); return; } o = parse_object(&ref->old_oid); if (!o) { fprintf(stderr, "Unable to parse object %s for remote ref %s\n", oid_to_hex(&ref->old_oid), ls->dentry_name); aborted = 1; free(ref); return; } strbuf_addf(buf, "%s\t%s\n", oid_to_hex(&ref->old_oid), ls->dentry_name); if (o->type == OBJ_TAG) { o = deref_tag(o, ls->dentry_name, 0); if (o) strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid), ls->dentry_name); } free(ref); }
static void exit_if_skipped_commits(struct commit_list *tried, const struct object_id *bad) { if (!tried) return; printf("There are only 'skip'ped commits left to test.\n" "The first %s commit could be any of:\n", term_bad); print_commit_list(tried, "%s\n", "%s\n"); if (bad) printf("%s\n", oid_to_hex(bad)); printf("We cannot bisect more!\n"); exit(2); }
static void show_worktree_porcelain(struct worktree *wt) { printf("worktree %s\n", wt->path); if (wt->is_bare) printf("bare\n"); else { printf("HEAD %s\n", oid_to_hex(&wt->head_oid)); if (wt->is_detached) printf("detached\n"); else if (wt->head_ref) printf("branch %s\n", wt->head_ref); } printf("\n"); }
static void write_extended_header(struct archiver_args *args, const struct object_id *oid, const void *buffer, unsigned long size) { struct ustar_header header; unsigned int mode; memset(&header, 0, sizeof(header)); *header.typeflag = TYPEFLAG_EXT_HEADER; mode = 0100666; xsnprintf(header.name, sizeof(header.name), "%s.paxheader", oid_to_hex(oid)); prepare_header(args, &header, mode, size); write_blocked(&header, sizeof(header)); write_blocked(buffer, size); }
/* * Returns 1 if every object pointed to by the given remote refs is available * locally and reachable from a local ref, and 0 otherwise. */ static int everything_local(struct fetch_pack_args *args, struct ref **refs) { struct ref *ref; int retval; for (retval = 1, ref = *refs; ref ; ref = ref->next) { const struct object_id *remote = &ref->old_oid; struct object *o; o = lookup_object(the_repository, remote->hash); if (!o || !(o->flags & COMPLETE)) { retval = 0; print_verbose(args, "want %s (%s)", oid_to_hex(remote), ref->name); continue; } print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote), ref->name); } return retval; }
static int grep_source_load_oid(struct grep_source *gs) { enum object_type type; grep_read_lock(); gs->buf = read_sha1_file(gs->identifier, &type, &gs->size); grep_read_unlock(); if (!gs->buf) return error(_("'%s': unable to read %s"), gs->name, oid_to_hex(gs->identifier)); return 0; }