/** * Sets merge_base to the octopus merge base of curr_head, merge_head and * fork_point. Returns 0 if a merge base is found, 1 otherwise. */ static int get_octopus_merge_base(struct object_id *merge_base, const struct object_id *curr_head, const struct object_id *merge_head, const struct object_id *fork_point) { struct commit_list *revs = NULL, *result; commit_list_insert(lookup_commit_reference(the_repository, curr_head), &revs); commit_list_insert(lookup_commit_reference(the_repository, merge_head), &revs); if (!is_null_oid(fork_point)) commit_list_insert(lookup_commit_reference(the_repository, fork_point), &revs); result = get_octopus_merge_bases(revs); free_commit_list(revs); reduce_heads_replace(&result); if (!result) return 1; oidcpy(merge_base, &result->item->object.oid); free_commit_list(result); return 0; }
static int try_difference(const char *arg) { char *dotdot; struct object_id start_oid; struct object_id end_oid; const char *end; const char *start; int symmetric; static const char head_by_default[] = "HEAD"; if (!(dotdot = strstr(arg, ".."))) return 0; end = dotdot + 2; start = arg; symmetric = (*end == '.'); *dotdot = 0; end += symmetric; if (!*end) end = head_by_default; if (dotdot == arg) start = head_by_default; if (start == head_by_default && end == head_by_default && !symmetric) { /* * Just ".."? That is not a range but the * pathspec for the parent directory. */ *dotdot = '.'; return 0; } if (!get_oid_committish(start, &start_oid) && !get_oid_committish(end, &end_oid)) { show_rev(NORMAL, &end_oid, end); show_rev(symmetric ? NORMAL : REVERSED, &start_oid, start); if (symmetric) { struct commit_list *exclude; struct commit *a, *b; a = lookup_commit_reference(the_repository, &start_oid); b = lookup_commit_reference(the_repository, &end_oid); if (!a || !b) { *dotdot = '.'; return 0; } exclude = get_merge_bases(a, b); while (exclude) { struct commit *commit = pop_commit(&exclude); show_rev(REVERSED, &commit->object.oid, NULL); } } *dotdot = '.'; return 1; } *dotdot = '.'; return 0; }
void show_submodule_summary(FILE *f, const char *path, const char *line_prefix, unsigned char one[20], unsigned char two[20], unsigned dirty_submodule, const char *meta, const char *del, const char *add, const char *reset) { struct rev_info rev; struct commit *left = NULL, *right = NULL; const char *message = NULL; struct strbuf sb = STRBUF_INIT; int fast_forward = 0, fast_backward = 0; if (is_null_sha1(two)) message = "(submodule deleted)"; else if (add_submodule_odb(path)) message = "(not checked out)"; else if (is_null_sha1(one)) message = "(new submodule)"; else if (!(left = lookup_commit_reference(one)) || !(right = lookup_commit_reference(two))) message = "(commits not present)"; else if (prepare_submodule_summary(&rev, path, left, right, &fast_forward, &fast_backward)) message = "(revision walker failed)"; if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) fprintf(f, "%sSubmodule %s contains untracked content\n", line_prefix, path); if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED) fprintf(f, "%sSubmodule %s contains modified content\n", line_prefix, path); if (!hashcmp(one, two)) { strbuf_release(&sb); return; } strbuf_addf(&sb, "%s%sSubmodule %s %s..", line_prefix, meta, path, find_unique_abbrev(one, DEFAULT_ABBREV)); if (!fast_backward && !fast_forward) strbuf_addch(&sb, '.'); strbuf_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV)); if (message) strbuf_addf(&sb, " %s%s\n", message, reset); else strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset); fwrite(sb.buf, sb.len, 1, f); if (!message) /* only NULL if we succeeded in setting up the walk */ print_submodule_summary(&rev, f, line_prefix, del, add, reset); if (left) clear_commit_marks(left, ~0); if (right) clear_commit_marks(right, ~0); strbuf_release(&sb); }
static int try_difference(const char *arg) { char *dotdot; unsigned char sha1[20]; unsigned char end[20]; const char *next; const char *this; int symmetric; static const char head_by_default[] = "HEAD"; if (!(dotdot = strstr(arg, ".."))) return 0; next = dotdot + 2; this = arg; symmetric = (*next == '.'); *dotdot = 0; next += symmetric; if (!*next) next = head_by_default; if (dotdot == arg) this = head_by_default; if (this == head_by_default && next == head_by_default && !symmetric) { /* * Just ".."? That is not a range but the * pathspec for the parent directory. */ *dotdot = '.'; return 0; } if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, end)) { show_rev(NORMAL, end, next); show_rev(symmetric ? NORMAL : REVERSED, sha1, this); if (symmetric) { struct commit_list *exclude; struct commit *a, *b; a = lookup_commit_reference(sha1); b = lookup_commit_reference(end); exclude = get_merge_bases(a, b, 1); while (exclude) { struct commit_list *n = exclude->next; show_rev(REVERSED, exclude->item->object.sha1,NULL); free(exclude); exclude = n; } } *dotdot = '.'; return 1; } *dotdot = '.'; return 0; }
static int try_difference(const char *arg) { char *dotdot; struct object_id oid; struct object_id end; const char *next; const char *this; int symmetric; static const char head_by_default[] = "HEAD"; if (!(dotdot = strstr(arg, ".."))) return 0; next = dotdot + 2; this = arg; symmetric = (*next == '.'); *dotdot = 0; next += symmetric; if (!*next) next = head_by_default; if (dotdot == arg) this = head_by_default; if (this == head_by_default && next == head_by_default && !symmetric) { /* * Just ".."? That is not a range but the * pathspec for the parent directory. */ *dotdot = '.'; return 0; } if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) { show_rev(NORMAL, &end, next); show_rev(symmetric ? NORMAL : REVERSED, &oid, this); if (symmetric) { struct commit_list *exclude; struct commit *a, *b; a = lookup_commit_reference(&oid); b = lookup_commit_reference(&end); exclude = get_merge_bases(a, b); while (exclude) { struct commit *commit = pop_commit(&exclude); show_rev(REVERSED, &commit->object.oid, NULL); } } *dotdot = '.'; return 1; } *dotdot = '.'; return 0; }
static int is_submodule_commit_present(const char *path, unsigned char sha1[20]) { int is_present = 0; if (!add_submodule_odb(path) && lookup_commit_reference(sha1)) { /* Even if the submodule is checked out and the commit is * present, make sure it is reachable from a ref. */ struct child_process cp; const char *argv[] = {"rev-list", "-n", "1", NULL, "--not", "--all", NULL}; struct strbuf buf = STRBUF_INIT; argv[3] = sha1_to_hex(sha1); memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; cp.no_stdin = 1; cp.out = -1; cp.dir = path; if (!run_command(&cp) && !strbuf_read(&buf, cp.out, 1024)) is_present = 1; close(cp.out); strbuf_release(&buf); } return is_present; }
void cgit_print_plain(struct cgit_context *ctx) { const char *rev = ctx->qry.sha1; unsigned char sha1[20]; struct commit *commit; const char *paths[] = {ctx->qry.path, NULL}; if (!rev) rev = ctx->qry.head; if (get_sha1(rev, sha1)) { html_status(404, "Not found", 0); return; } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { html_status(404, "Not found", 0); return; } if (!paths[0]) { paths[0] = ""; match_baselen = -1; print_dir(commit->tree->object.sha1, "", ""); } else match_baselen = basedir_len(paths[0]); read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); if (!match) html_status(404, "Not found", 0); else if (match == 2) print_dir_tail(); }
static int try_parent_shorthands(const char *arg) { char *dotdot; unsigned char sha1[20]; struct commit *commit; struct commit_list *parents; int parent_number; int include_rev = 0; int include_parents = 0; int exclude_parent = 0; if ((dotdot = strstr(arg, "^!"))) { include_rev = 1; if (dotdot[2]) return 0; } else if ((dotdot = strstr(arg, "^@"))) { include_parents = 1; if (dotdot[2]) return 0; } else if ((dotdot = strstr(arg, "^-"))) { include_rev = 1; exclude_parent = 1; if (dotdot[2]) { char *end; exclude_parent = strtoul(dotdot + 2, &end, 10); if (*end != '\0' || !exclude_parent) return 0; } } else return 0; *dotdot = 0; if (get_sha1_committish(arg, sha1)) { *dotdot = '^'; return 0; } commit = lookup_commit_reference(sha1); if (exclude_parent && exclude_parent > commit_list_count(commit->parents)) { *dotdot = '^'; return 0; } if (include_rev) show_rev(NORMAL, sha1, arg); for (parents = commit->parents, parent_number = 1; parents; parents = parents->next, parent_number++) { if (exclude_parent && parent_number != exclude_parent) continue; show_rev(include_parents ? NORMAL : REVERSED, parents->item->object.oid.hash, arg); } *dotdot = '^'; return 1; }
void cgit_print_plain(struct cgit_context *ctx) { const char *rev = ctx->qry.sha1; unsigned char sha1[20]; struct commit *commit; const char *paths[] = {ctx->qry.path, NULL}; if (!rev) rev = ctx->qry.head; curr_rev = xstrdup(rev); if (get_sha1(rev, sha1)) { html_status(404, "Not found", 0); return; } commit = lookup_commit_reference(sha1); if (!commit || parse_commit(commit)) { html_status(404, "Not found", 0); return; } match_path = ctx->qry.path; read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); if (!match) html_status(404, "Not found", 0); }
static int try_parent_shorthands(const char *arg) { char *dotdot; unsigned char sha1[20]; struct commit *commit; struct commit_list *parents; int parents_only; if ((dotdot = strstr(arg, "^!"))) parents_only = 0; else if ((dotdot = strstr(arg, "^@"))) parents_only = 1; if (!dotdot || dotdot[2]) return 0; *dotdot = 0; if (get_sha1_committish(arg, sha1)) return 0; if (!parents_only) show_rev(NORMAL, sha1, arg); commit = lookup_commit_reference(sha1); for (parents = commit->parents; parents; parents = parents->next) show_rev(parents_only ? NORMAL : REVERSED, parents->item->object.sha1, arg); return 1; }
static int handle_fork_point(int argc, const char **argv) { struct object_id oid; char *refname; struct commit *derived, *fork_point; const char *commitname; switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) { case 0: die("No such ref: '%s'", argv[0]); case 1: break; /* good */ default: die("Ambiguous refname: '%s'", argv[0]); } commitname = (argc == 2) ? argv[1] : "HEAD"; if (get_oid(commitname, &oid)) die("Not a valid object name: '%s'", commitname); derived = lookup_commit_reference(the_repository, &oid); fork_point = get_fork_point(refname, derived); if (!fork_point) return 1; printf("%s\n", oid_to_hex(&fork_point->object.oid)); return 0; }
static int get_parent(const char *name, int len, unsigned char *result, int idx) { unsigned char sha1[20]; int ret = get_sha1_1(name, len, sha1); struct commit *commit; struct commit_list *p; if (ret) return ret; commit = lookup_commit_reference(sha1); if (!commit) return -1; if (parse_commit(commit)) return -1; if (!idx) { memcpy(result, commit->object.sha1, 20); return 0; } p = commit->parents; while (p) { if (!--idx) { memcpy(result, p->item->object.sha1, 20); return 0; } p = p->next; } return -1; }
static void update_head(const struct ref *our, const struct ref *remote, const char *msg) { const char *head; if (our && skip_prefix(our->name, "refs/heads/", &head)) { /* Local default branch link */ create_symref("HEAD", our->name, NULL); if (!option_bare) { update_ref(msg, "HEAD", our->old_sha1, NULL, 0, UPDATE_REFS_DIE_ON_ERR); install_branch_config(0, head, option_origin, our->name); } } else if (our) { struct commit *c = lookup_commit_reference(our->old_sha1); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ update_ref(msg, "HEAD", c->object.sha1, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } else if (remote) { /* * We know remote HEAD points to a non-branch, or * HEAD points to a branch but we don't know which one. * Detach HEAD in all these cases. */ update_ref(msg, "HEAD", remote->old_sha1, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } }
static int diff_tree_commit_oid(const struct object_id *oid) { struct commit *commit = lookup_commit_reference(oid); if (!commit) return -1; return log_tree_commit(&log_tree_opt, commit); }
static int diff_tree_commit_sha1(const unsigned char *sha1) { struct commit *commit = lookup_commit_reference(sha1); if (!commit) return -1; return log_tree_commit(&log_tree_opt, commit); }
static struct commit *get_commit_reference(const unsigned char *sha1) { struct commit *r = lookup_commit_reference(sha1); if (!r) die("Not a valid commit name %s", sha1_to_hex(sha1)); return r; }
static int submodule_needs_pushing(const char *path, const unsigned char sha1[20]) { if (add_submodule_odb(path) || !lookup_commit_reference(sha1)) return 0; if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { struct child_process cp; const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL}; struct strbuf buf = STRBUF_INIT; int needs_pushing = 0; argv[1] = sha1_to_hex(sha1); memset(&cp, 0, sizeof(cp)); cp.argv = argv; cp.env = local_repo_env; cp.git_cmd = 1; cp.no_stdin = 1; cp.out = -1; cp.dir = path; if (start_command(&cp)) die("Could not run 'git rev-list %s --not --remotes -n 1' command in submodule %s", sha1_to_hex(sha1), path); if (strbuf_read(&buf, cp.out, 41)) needs_pushing = 1; finish_command(&cp); close(cp.out); strbuf_release(&buf); return needs_pushing; } return 0; }
static int handle_fork_point(int argc, const char **argv) { unsigned char sha1[20]; char *refname; const char *commitname; struct rev_collect revs; struct commit *derived; struct commit_list *bases; int i, ret = 0; switch (dwim_ref(argv[0], strlen(argv[0]), sha1, &refname)) { case 0: die("No such ref: '%s'", argv[0]); case 1: break; /* good */ default: die("Ambiguous refname: '%s'", argv[0]); } commitname = (argc == 2) ? argv[1] : "HEAD"; if (get_sha1(commitname, sha1)) die("Not a valid object name: '%s'", commitname); derived = lookup_commit_reference(sha1); memset(&revs, 0, sizeof(revs)); revs.initial = 1; for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); for (i = 0; i < revs.nr; i++) revs.commit[i]->object.flags &= ~TMP_MARK; bases = get_merge_bases_many_dirty(derived, revs.nr, revs.commit); /* * There should be one and only one merge base, when we found * a common ancestor among reflog entries. */ if (!bases || bases->next) { ret = 1; goto cleanup_return; } /* And the found one must be one of the reflog entries */ for (i = 0; i < revs.nr; i++) if (&bases->item->object == &revs.commit[i]->object) break; /* found */ if (revs.nr <= i) { ret = 1; /* not found */ goto cleanup_return; } printf("%s\n", oid_to_hex(&bases->item->object.oid)); cleanup_return: free_commit_list(bases); return ret; }
static int try_difference(const char *arg) { char *dotdot; unsigned char sha1[20]; unsigned char end[20]; const char *next; const char *this; int symmetric; if (!(dotdot = strstr(arg, ".."))) return 0; next = dotdot + 2; this = arg; symmetric = (*next == '.'); *dotdot = 0; next += symmetric; if (!*next) next = "HEAD"; if (dotdot == arg) this = "HEAD"; if (!get_sha1(this, sha1) && !get_sha1(next, end)) { show_rev(NORMAL, end, next); show_rev(symmetric ? NORMAL : REVERSED, sha1, this); if (symmetric) { struct commit_list *exclude; struct commit *a, *b; a = lookup_commit_reference(sha1); b = lookup_commit_reference(end); exclude = get_merge_bases(a, b, 1); while (exclude) { struct commit_list *n = exclude->next; show_rev(REVERSED, exclude->item->object.sha1,NULL); free(exclude); exclude = n; } } return 1; } *dotdot = '.'; return 0; }
static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) { struct rev_info check_rev; struct commit *commit, *c1, *c2; struct object *o1, *o2; unsigned flags1, flags2; if (rev->pending.nr != 2) die(_("Need exactly one range.")); o1 = rev->pending.objects[0].item; o2 = rev->pending.objects[1].item; flags1 = o1->flags; flags2 = o2->flags; c1 = lookup_commit_reference(o1->oid.hash); c2 = lookup_commit_reference(o2->oid.hash); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); init_patch_ids(ids); /* given a range a..b get all patch ids for b..a */ init_revisions(&check_rev, rev->prefix); check_rev.max_parents = 1; o1->flags ^= UNINTERESTING; o2->flags ^= UNINTERESTING; add_pending_object(&check_rev, o1, "o1"); add_pending_object(&check_rev, o2, "o2"); if (prepare_revision_walk(&check_rev)) die(_("revision walk setup failed")); while ((commit = get_revision(&check_rev)) != NULL) { add_commit_patch_id(commit, ids); } /* reset for next revision walk */ clear_commit_marks(c1, SEEN | UNINTERESTING | SHOWN | ADDED); clear_commit_marks(c2, SEEN | UNINTERESTING | SHOWN | ADDED); o1->flags = flags1; o2->flags = flags2; }
/** * Sets merge_base to the octopus merge base of curr_head, merge_head and * fork_point. Returns 0 if a merge base is found, 1 otherwise. */ static int get_octopus_merge_base(unsigned char *merge_base, const unsigned char *curr_head, const unsigned char *merge_head, const unsigned char *fork_point) { struct commit_list *revs = NULL, *result; commit_list_insert(lookup_commit_reference(curr_head), &revs); commit_list_insert(lookup_commit_reference(merge_head), &revs); if (!is_null_sha1(fork_point)) commit_list_insert(lookup_commit_reference(fork_point), &revs); result = reduce_heads(get_octopus_merge_bases(revs)); free_commit_list(revs); if (!result) return 1; hashcpy(merge_base, result->item->object.oid.hash); return 0; }
static int merge_commit(struct notes_merge_options *o) { struct strbuf msg = STRBUF_INIT; unsigned char sha1[20], parent_sha1[20]; struct notes_tree *t; struct commit *partial; struct pretty_print_context pretty_ctx; void *local_ref_to_free; int ret; /* * Read partial merge result from .git/NOTES_MERGE_PARTIAL, * and target notes ref from .git/NOTES_MERGE_REF. */ if (get_sha1("NOTES_MERGE_PARTIAL", sha1)) die("Failed to read ref NOTES_MERGE_PARTIAL"); else if (!(partial = lookup_commit_reference(sha1))) die("Could not find commit from NOTES_MERGE_PARTIAL."); else if (parse_commit(partial)) die("Could not parse commit from NOTES_MERGE_PARTIAL."); if (partial->parents) hashcpy(parent_sha1, partial->parents->item->object.sha1); else hashclr(parent_sha1); t = xcalloc(1, sizeof(struct notes_tree)); init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); o->local_ref = local_ref_to_free = resolve_refdup("NOTES_MERGE_REF", 0, sha1, NULL); if (!o->local_ref) die("Failed to resolve NOTES_MERGE_REF"); if (notes_merge_commit(o, t, partial, sha1)) die("Failed to finalize notes merge"); /* Reuse existing commit message in reflog message */ memset(&pretty_ctx, 0, sizeof(pretty_ctx)); format_commit_message(partial, "%s", &msg, &pretty_ctx); strbuf_trim(&msg); strbuf_insert(&msg, 0, "notes: ", 7); update_ref(msg.buf, o->local_ref, sha1, is_null_sha1(parent_sha1) ? NULL : parent_sha1, 0, UPDATE_REFS_DIE_ON_ERR); free_notes(t); strbuf_release(&msg); ret = merge_abort(o); free(local_ref_to_free); return ret; }
static int branch_merged(int kind, const char *name, struct commit *rev, struct commit *head_rev) { /* * This checks whether the merge bases of branch and HEAD (or * the other branch this branch builds upon) contains the * branch, which means that the branch has already been merged * safely to HEAD (or the other branch). */ struct commit *reference_rev = NULL; const char *reference_name = NULL; void *reference_name_to_free = NULL; int merged; if (kind == REF_LOCAL_BRANCH) { struct branch *branch = branch_get(name); unsigned char sha1[20]; if (branch && branch->merge && branch->merge[0] && branch->merge[0]->dst && (reference_name = reference_name_to_free = resolve_refdup(branch->merge[0]->dst, RESOLVE_REF_READING, sha1, NULL)) != NULL) reference_rev = lookup_commit_reference(sha1); } if (!reference_rev) reference_rev = head_rev; merged = in_merge_bases(rev, reference_rev); /* * After the safety valve is fully redefined to "check with * upstream, if any, otherwise with HEAD", we should just * return the result of the in_merge_bases() above without * any of the following code, but during the transition period, * a gentle reminder is in order. */ if ((head_rev != reference_rev) && in_merge_bases(rev, head_rev) != merged) { if (merged) warning(_("deleting branch '%s' that has been merged to\n" " '%s', but not yet merged to HEAD."), name, reference_name); else warning(_("not deleting branch '%s' that is not yet merged to\n" " '%s', even though it is merged to HEAD."), name, reference_name); } free(reference_name_to_free); return merged; }
static int create_graft(int argc, const char **argv, int force, int gentle) { struct object_id old_oid, new_oid; const char *old_ref = argv[0]; struct commit *commit; struct strbuf buf = STRBUF_INIT; const char *buffer; unsigned long size; if (get_oid(old_ref, &old_oid) < 0) return error(_("Not a valid object name: '%s'"), old_ref); commit = lookup_commit_reference(&old_oid); if (!commit) return error(_("could not parse %s"), old_ref); buffer = get_commit_buffer(commit, &size); strbuf_add(&buf, buffer, size); unuse_commit_buffer(commit, buffer); if (replace_parents(&buf, argc - 1, &argv[1]) < 0) { strbuf_release(&buf); return -1; } if (remove_signature(&buf)) { warning(_("the original commit '%s' has a gpg signature."), old_ref); warning(_("the signature will be removed in the replacement commit!")); } if (check_mergetags(commit, argc, argv)) { strbuf_release(&buf); return -1; } if (write_object_file(buf.buf, buf.len, commit_type, &new_oid)) { strbuf_release(&buf); return error(_("could not write replacement commit for: '%s'"), old_ref); } strbuf_release(&buf); if (!oidcmp(&old_oid, &new_oid)) { if (gentle) { warning("graft for '%s' unnecessary", oid_to_hex(&old_oid)); return 0; } return error("new commit is the same as the old one: '%s'", oid_to_hex(&old_oid)); } return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force); }
void cgit_print_patch(char *hex, const char *prefix) { struct commit *commit; struct commitinfo *info; unsigned char sha1[20], old_sha1[20]; char *patchname; if (!hex) hex = ctx.qry.head; if (get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); return; } commit = lookup_commit_reference(sha1); if (!commit) { cgit_print_error(fmt("Bad commit reference: %s", hex)); return; } info = cgit_parse_commit(commit); if (commit->parents && commit->parents->item) hashcpy(old_sha1, commit->parents->item->object.sha1); else hashclr(old_sha1); patchname = fmt("%s.patch", sha1_to_hex(sha1)); ctx.page.mimetype = "text/plain"; ctx.page.filename = patchname; cgit_print_http_headers(&ctx); htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); htmlf("From: %s", info->author); if (!ctx.cfg.noplainemail) { htmlf(" %s", info->author_email); } html("\n"); html("Date: "); cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); htmlf("Subject: %s\n\n", info->subject); if (info->msg && *info->msg) { htmlf("%s", info->msg); if (info->msg[strlen(info->msg) - 1] != '\n') html("\n"); } html("---\n"); if (prefix) htmlf("(limited to '%s')\n\n", prefix); cgit_diff_tree(old_sha1, sha1, filepair_cb, prefix, 0); html("--\n"); htmlf("cgit %s\n", CGIT_VERSION); cgit_free_commitinfo(info); }
static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) { unsigned char sha1[20]; if (get_sha1(arg, sha1) == 0) { struct commit *commit = lookup_commit_reference(sha1); if (commit) { commit->object.flags |= flags; add_pending_object(revs, &commit->object, arg); return 0; } } return -1; }
static struct commit *get_commit_reference(const char *arg) { unsigned char revkey[20]; struct commit *r; if (get_sha1(arg, revkey)) die("Not a valid object name %s", arg); r = lookup_commit_reference(revkey); if (!r) die("Not a valid commit name %s", arg); return r; }
static struct commit *get_commit_reference(const char *arg) { struct object_id revkey; struct commit *r; if (get_oid(arg, &revkey)) die("Not a valid object name %s", arg); r = lookup_commit_reference(the_repository, &revkey); if (!r) die("Not a valid commit name %s", arg); return r; }
static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *opts) { unsigned char commit_sha1[20]; enum replay_action action; char *end_of_object_name; int saved, status, padding; if (starts_with(bol, "pick")) { action = REPLAY_PICK; bol += strlen("pick"); } else if (starts_with(bol, "revert")) { action = REPLAY_REVERT; bol += strlen("revert"); } else return NULL; /* Eat up extra spaces/ tabs before object name */ padding = strspn(bol, " \t"); if (!padding) return NULL; bol += padding; end_of_object_name = bol + strcspn(bol, " \t\n"); saved = *end_of_object_name; *end_of_object_name = '\0'; status = get_sha1(bol, commit_sha1); *end_of_object_name = saved; /* * Verify that the action matches up with the one in * opts; we don't support arbitrary instructions */ if (action != opts->action) { if (action == REPLAY_REVERT) error((opts->action == REPLAY_REVERT) ? _("Cannot revert during a another revert.") : _("Cannot revert during a cherry-pick.")); else error((opts->action == REPLAY_REVERT) ? _("Cannot cherry-pick during a revert.") : _("Cannot cherry-pick during another cherry-pick.")); return NULL; } if (status < 0) return NULL; return lookup_commit_reference(commit_sha1); }
void cgit_print_blob(const char *hex, char *path, const char *head) { unsigned char sha1[20]; enum object_type type; unsigned char *buf; unsigned long size; struct commit *commit; const char *paths[] = {path, NULL}; if (hex) { if (get_sha1_hex(hex, sha1)){ cgit_print_error(fmt("Bad hex value: %s", hex)); return; } } else { if (get_sha1(head,sha1)) { cgit_print_error(fmt("Bad ref: %s", head)); return; } } type = sha1_object_info(sha1, &size); if((!hex) && type == OBJ_COMMIT && path) { commit = lookup_commit_reference(sha1); match_path = path; matched_sha1 = sha1; read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree, NULL); type = sha1_object_info(sha1,&size); } if (type == OBJ_BAD) { cgit_print_error(fmt("Bad object name: %s", hex)); return; } buf = read_sha1_file(sha1, &type, &size); if (!buf) { cgit_print_error(fmt("Error reading object %s", hex)); return; } buf[size] = '\0'; ctx.page.mimetype = ctx.qry.mimetype; ctx.page.filename = path; cgit_print_http_headers(&ctx); write(htmlfd, buf, size); }