static void get_default_heads(void) { if (head_points_at && !is_null_oid(&head_oid)) fsck_handle_ref("HEAD", &head_oid, 0, NULL); for_each_rawref(fsck_handle_ref, NULL); if (include_reflogs) for_each_reflog(fsck_handle_reflog, NULL); /* * Not having any default heads isn't really fatal, but * it does mean that "--unreachable" no longer makes any * sense (since in this case everything will obviously * be unreachable by definition. * * Showing dangling objects is valid, though (as those * dangling objects are likely lost heads). * * So we just print a warning about it, and clear the * "show_unreachable" flag. */ if (!default_refs) { fprintf(stderr, "notice: No default references\n"); show_unreachable = 0; } }
static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern) { int i; struct append_ref_cb cb; struct ref_list ref_list; memset(&ref_list, 0, sizeof(ref_list)); ref_list.kinds = kinds; ref_list.verbose = verbose; ref_list.abbrev = abbrev; ref_list.with_commit = with_commit; if (merge_filter != NO_FILTER) init_revisions(&ref_list.revs, NULL); cb.ref_list = &ref_list; cb.pattern = pattern; cb.ret = 0; for_each_rawref(append_ref, &cb); if (merge_filter != NO_FILTER) { struct commit *filter; filter = lookup_commit_reference_gently(merge_filter_ref, 0); if (!filter) die(_("object '%s' does not point to a commit"), sha1_to_hex(merge_filter_ref)); filter->object.flags |= UNINTERESTING; add_pending_object(&ref_list.revs, (struct object *) filter, ""); ref_list.revs.limited = 1; if (prepare_revision_walk(&ref_list.revs)) die(_("revision walk setup failed")); if (verbose) ref_list.maxwidth = calc_maxwidth(&ref_list); } qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp); detached = (detached && (kinds & REF_LOCAL_BRANCH)); if (detached && match_patterns(pattern, "HEAD")) show_detached(&ref_list); for (i = 0; i < ref_list.index; i++) { int current = !detached && (ref_list.list[i].kind == REF_LOCAL_BRANCH) && !strcmp(ref_list.list[i].name, head); char *prefix = (kinds != REF_REMOTE_BRANCH && ref_list.list[i].kind == REF_REMOTE_BRANCH) ? "remotes/" : ""; print_ref_item(&ref_list.list[i], ref_list.maxwidth, verbose, abbrev, current, prefix); } free_ref_list(&ref_list); if (cb.ret) error(_("some refs could not be read")); return cb.ret; }
void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname) { struct warn_if_dangling_data data; data.fp = fp; data.refname = refname; data.msg_fmt = msg_fmt; for_each_rawref(warn_if_dangling_symref, &data); }
void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames) { struct warn_if_dangling_data data; data.fp = fp; data.refname = NULL; data.refnames = refnames; data.msg_fmt = msg_fmt; for_each_rawref(warn_if_dangling_symref, &data); }
static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit) { int i; struct ref_list ref_list; memset(&ref_list, 0, sizeof(ref_list)); ref_list.kinds = kinds; ref_list.verbose = verbose; ref_list.abbrev = abbrev; ref_list.with_commit = with_commit; if (merge_filter != NO_FILTER) init_revisions(&ref_list.revs, NULL); for_each_rawref(append_ref, &ref_list); if (merge_filter != NO_FILTER) { struct commit *filter; filter = lookup_commit_reference_gently(merge_filter_ref, 0); filter->object.flags |= UNINTERESTING; add_pending_object(&ref_list.revs, (struct object *) filter, ""); ref_list.revs.limited = 1; prepare_revision_walk(&ref_list.revs); if (verbose) ref_list.maxwidth = calc_maxwidth(&ref_list); } qsort(ref_list.list, ref_list.index, sizeof(struct ref_item), ref_cmp); detached = (detached && (kinds & REF_LOCAL_BRANCH)); if (detached) show_detached(&ref_list); for (i = 0; i < ref_list.index; i++) { int current = !detached && (ref_list.list[i].kind == REF_LOCAL_BRANCH) && !strcmp(ref_list.list[i].name, head); char *prefix = (kinds != REF_REMOTE_BRANCH && ref_list.list[i].kind == REF_REMOTE_BRANCH) ? "remotes/" : ""; print_ref_item(&ref_list.list[i], ref_list.maxwidth, verbose, abbrev, current, prefix); } free_ref_list(&ref_list); }
int cmd_describe(int argc, const char **argv, const char *prefix) { int contains = 0; struct option options[] = { OPT_BOOLEAN(0, "contains", &contains, N_("find the tag that comes after the commit")), OPT_BOOLEAN(0, "debug", &debug, N_("debug search strategy on stderr")), OPT_BOOLEAN(0, "all", &all, N_("use any ref")), OPT_BOOLEAN(0, "tags", &tags, N_("use any tag, even unannotated")), OPT_BOOLEAN(0, "long", &longformat, N_("always use long format")), OPT__ABBREV(&abbrev), OPT_SET_INT(0, "exact-match", &max_candidates, N_("only output exact matches"), 0), OPT_INTEGER(0, "candidates", &max_candidates, N_("consider <n> most recent tags (default: 10)")), OPT_STRING(0, "match", &pattern, N_("pattern"), N_("only consider tags matching <pattern>")), OPT_BOOLEAN(0, "always", &always, N_("show abbreviated commit object as fallback")), {OPTION_STRING, 0, "dirty", &dirty, N_("mark"), N_("append <mark> on dirty working tree (default: \"-dirty\")"), PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"}, OPT_END(), }; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, describe_usage, 0); if (abbrev < 0) abbrev = DEFAULT_ABBREV; if (max_candidates < 0) max_candidates = 0; else if (max_candidates > MAX_TAGS) max_candidates = MAX_TAGS; save_commit_buffer = 0; if (longformat && abbrev == 0) die(_("--long is incompatible with --abbrev=0")); if (contains) { const char **args = xmalloc((7 + argc) * sizeof(char *)); int i = 0; args[i++] = "name-rev"; args[i++] = "--name-only"; args[i++] = "--no-undefined"; if (always) args[i++] = "--always"; if (!all) { args[i++] = "--tags"; if (pattern) { char *s = xmalloc(strlen("--refs=refs/tags/") + strlen(pattern) + 1); sprintf(s, "--refs=refs/tags/%s", pattern); args[i++] = s; } } memcpy(args + i, argv, argc * sizeof(char *)); args[i + argc] = NULL; return cmd_name_rev(i + argc, args, prefix); } init_hash(&names); for_each_rawref(get_name, NULL); if (!names.nr && !always) die(_("No names found, cannot describe anything.")); if (argc == 0) { if (dirty) { static struct lock_file index_lock; int fd; read_cache_preload(NULL); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); fd = hold_locked_index(&index_lock, 0); if (0 <= fd) update_index_if_able(&the_index, &index_lock); if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix)) dirty = NULL; } describe("HEAD", 1); } else if (dirty) { die(_("--dirty is incompatible with committishes")); } else { while (argc-- > 0) { describe(*argv++, argc == 0); } } return 0; }
void warn_dangling_symref(const char *msg_fmt, const char *refname) { struct warn_if_dangling_data data = { refname, msg_fmt }; for_each_rawref(warn_if_dangling_symref, &data); }