void credential_clear(struct credential *c) { free(c->protocol); free(c->host); free(c->path); free(c->username); free(c->password); string_list_clear(&c->helpers, 0); credential_init(c); }
static int check_repository_format_gently(const char *gitdir, int *nongit_ok) { struct strbuf sb = STRBUF_INIT; const char *repo_config; config_fn_t fn; int ret = 0; string_list_clear(&unknown_extensions, 0); if (get_common_dir(&sb, gitdir)) fn = check_repo_format; else fn = check_repository_format_version; strbuf_addstr(&sb, "/config"); repo_config = sb.buf; /* * git_config() can't be used here because it calls git_pathdup() * to get $GIT_CONFIG/config. That call will make setup_git_env() * set git_dir to ".git". * * We are in gitdir setup, no git dir has been found useable yet. * Use a gentler version of git_config() to check if this repo * is a good one. */ git_config_early(fn, NULL, repo_config); if (GIT_REPO_VERSION_READ < repository_format_version) { if (!nongit_ok) die ("Expected git repo version <= %d, found %d", GIT_REPO_VERSION_READ, repository_format_version); warning("Expected git repo version <= %d, found %d", GIT_REPO_VERSION_READ, repository_format_version); warning("Please upgrade Git"); *nongit_ok = -1; ret = -1; } if (repository_format_version >= 1 && unknown_extensions.nr) { int i; if (!nongit_ok) die("unknown repository extension: %s", unknown_extensions.items[0].string); for (i = 0; i < unknown_extensions.nr; i++) warning("unknown repository extension: %s", unknown_extensions.items[i].string); *nongit_ok = -1; ret = -1; } strbuf_release(&sb); return ret; }
int cmd_fetch(int argc, const char **argv, const char *prefix) { int i; struct string_list list = { NULL, 0, 0, 0 }; struct remote *remote; int result = 0; /* Record the command line for the reflog */ strbuf_addstr(&default_rla, "fetch"); for (i = 1; i < argc; i++) strbuf_addf(&default_rla, " %s", argv[i]); argc = parse_options(argc, argv, prefix, builtin_fetch_options, builtin_fetch_usage, 0); if (all) { if (argc == 1) die("fetch --all does not take a repository argument"); else if (argc > 1) die("fetch --all does not make sense with refspecs"); (void) for_each_remote(get_one_remote_for_fetch, &list); result = fetch_multiple(&list); } else if (argc == 0) { /* No arguments -- use default remote */ remote = remote_get(NULL); result = fetch_one(remote, argc, argv); } else if (multiple) { /* All arguments are assumed to be remotes or groups */ for (i = 0; i < argc; i++) if (!add_remote_or_group(argv[i], &list)) die("No such remote or remote group: %s", argv[i]); result = fetch_multiple(&list); } else { /* Single remote or group */ (void) add_remote_or_group(argv[0], &list); if (list.nr > 1) { /* More than one remote */ if (argc > 1) die("Fetching a group and specifying refspecs does not make sense"); result = fetch_multiple(&list); } else { /* Zero or one remotes */ remote = remote_get(argv[0]); result = fetch_one(remote, argc-1, argv+1); } } /* All names were strdup()ed or strndup()ed */ list.strdup_strings = 1; string_list_clear(&list, 0); return result; }
static int git_push_config(const char *k, const char *v, void *cb) { int *flags = cb; int status; status = git_gpg_config(k, v, NULL); if (status) return status; if (!strcmp(k, "push.followtags")) { if (git_config_bool(k, v)) *flags |= TRANSPORT_PUSH_FOLLOW_TAGS; else *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS; return 0; } else if (!strcmp(k, "push.gpgsign")) { const char *value; if (!git_config_get_value("push.gpgsign", &value)) { switch (git_parse_maybe_bool(value)) { case 0: set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER); break; case 1: set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS); break; default: if (value && !strcasecmp(value, "if-asked")) set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED); else return error("Invalid value for '%s'", k); } } } else if (!strcmp(k, "push.recursesubmodules")) { const char *value; if (!git_config_get_value("push.recursesubmodules", &value)) recurse_submodules = parse_push_recurse_submodules_arg(k, value); } else if (!strcmp(k, "submodule.recurse")) { int val = git_config_bool(k, v) ? RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; recurse_submodules = val; } else if (!strcmp(k, "push.pushoption")) { if (!v) return config_error_nonbool(k); else if (!*v) string_list_clear(&push_options_config, 0); else string_list_append(&push_options_config, v); return 0; } return git_default_config(k, v, NULL); }
struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd) { struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg)); const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT); const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT); c->cmd = cmd; c->enabled = 1; c->combine = combine_notes_concatenate; c->refs = xcalloc(1, sizeof(struct string_list)); c->refs->strdup_strings = 1; c->refs_from_env = 0; c->mode_from_env = 0; if (rewrite_mode_env) { c->mode_from_env = 1; c->combine = parse_combine_notes_fn(rewrite_mode_env); if (!c->combine) /* * TRANSLATORS: The first %s is the name of * the environment variable, the second %s is * its value. */ error(_("Bad %s value: '%s'"), GIT_NOTES_REWRITE_MODE_ENVIRONMENT, rewrite_mode_env); } if (rewrite_refs_env) { c->refs_from_env = 1; string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env); } git_config(notes_rewrite_config, c); if (!c->enabled || !c->refs->nr) { string_list_clear(c->refs, 0); free(c->refs); free(c); return NULL; } c->trees = load_notes_trees(c->refs, NOTES_INIT_WRITABLE); string_list_clear(c->refs, 0); free(c->refs); return c; }
void shortlog_output(struct shortlog *log) { int i, j; struct strbuf sb = STRBUF_INIT; if (log->sort_by_number) qsort(log->list.items, log->list.nr, sizeof(struct string_list_item), compare_by_number); for (i = 0; i < log->list.nr; i++) { struct string_list *onelines = log->list.items[i].util; if (log->summary) { printf("%6d\t%s\n", onelines->nr, log->list.items[i].string); } else { printf("%s (%d):\n", log->list.items[i].string, onelines->nr); for (j = onelines->nr - 1; j >= 0; j--) { const char *msg = onelines->items[j].string; if (log->wrap_lines) { strbuf_reset(&sb); add_wrapped_shortlog_msg(&sb, msg, log); fwrite(sb.buf, sb.len, 1, stdout); } else printf(" %s\n", msg); } putchar('\n'); } onelines->strdup_strings = 1; string_list_clear(onelines, 0); free(onelines); log->list.items[i].util = NULL; } strbuf_release(&sb); log->list.strdup_strings = 1; string_list_clear(&log->list, 1); clear_mailmap(&log->mailmap); }
void list_all_cmds_help(void) { struct string_list others = STRING_LIST_INIT_DUP; struct string_list alias_list = STRING_LIST_INIT_DUP; struct cmdname_help *aliases; int i, longest; printf_ln(_("See 'git help <command>' to read about a specific subcommand")); print_cmd_by_category(main_categories, &longest); list_all_other_cmds(&others); if (others.nr) printf("\n%s\n", _("External commands")); for (i = 0; i < others.nr; i++) printf(" %s\n", others.items[i].string); string_list_clear(&others, 0); git_config(get_alias, &alias_list); string_list_sort(&alias_list); for (i = 0; i < alias_list.nr; i++) { size_t len = strlen(alias_list.items[i].string); if (longest < len) longest = len; } if (alias_list.nr) { printf("\n%s\n", _("Command aliases")); ALLOC_ARRAY(aliases, alias_list.nr + 1); for (i = 0; i < alias_list.nr; i++) { aliases[i].name = alias_list.items[i].string; aliases[i].help = alias_list.items[i].util; aliases[i].category = 1; } aliases[alias_list.nr].name = NULL; print_command_list(aliases, 1, longest); free(aliases); } string_list_clear(&alias_list, 1); }
struct string_list *resolve_undo_read(const char *data, unsigned long size) { struct string_list *resolve_undo; size_t len; char *endptr; int i; resolve_undo = xcalloc(1, sizeof(*resolve_undo)); resolve_undo->strdup_strings = 1; while (size) { struct string_list_item *lost; struct resolve_undo_info *ui; len = strlen(data) + 1; if (size <= len) goto error; lost = string_list_insert(resolve_undo, data); if (!lost->util) lost->util = xcalloc(1, sizeof(*ui)); ui = lost->util; size -= len; data += len; for (i = 0; i < 3; i++) { ui->mode[i] = strtoul(data, &endptr, 8); if (!endptr || endptr == data || *endptr) goto error; len = (endptr + 1) - (char*)data; if (size <= len) goto error; size -= len; data += len; } for (i = 0; i < 3; i++) { if (!ui->mode[i]) continue; if (size < 20) goto error; hashcpy(ui->sha1[i], (const unsigned char *)data); size -= 20; data += 20; } } return resolve_undo; error: string_list_clear(resolve_undo, 1); error("Index records invalid resolve-undo information"); return NULL; }
static void error_removing_concrete_submodules(struct string_list *files, int *errs) { print_error_files(files, Q_("the following submodule (or one of its nested " "submodules)\n" "uses a .git directory:", "the following submodules (or one of their nested " "submodules)\n" "use a .git directory:", files->nr), _("\n(use 'rm -rf' if you really want to remove " "it including all of its history)"), errs); string_list_clear(files, 0); }
int main(int argc, char **argv) { const char * const usage[] = { "git credential-store [<options>] <action>", NULL }; const char *op; struct credential c = CREDENTIAL_INIT; struct string_list fns = STRING_LIST_INIT_DUP; char *file = NULL; struct option options[] = { OPT_STRING(0, "file", &file, "path", "fetch and store credentials in <path>"), OPT_END() }; umask(077); argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0); if (argc != 1) usage_with_options(usage, options); op = argv[0]; if (file) { string_list_append(&fns, file); } else { if ((file = expand_user_path("~/.git-credentials"))) string_list_append_nodup(&fns, file); file = xdg_config_home("credentials"); if (file) string_list_append_nodup(&fns, file); } if (!fns.nr) die("unable to set up default path; use --file"); if (credential_read(&c, stdin) < 0) die("unable to read credential"); if (!strcmp(op, "get")) lookup_credential(&fns, &c); else if (!strcmp(op, "erase")) remove_credential(&fns, &c); else if (!strcmp(op, "store")) store_credential(&fns, &c); else ; /* Ignore unknown operation. */ string_list_clear(&fns, 0); return 0; }
void rerere_gc(struct string_list *rr) { struct string_list to_remove = STRING_LIST_INIT_DUP; DIR *dir; struct dirent *e; int i; timestamp_t now = time(NULL); timestamp_t cutoff_noresolve = now - 15 * 86400; timestamp_t cutoff_resolve = now - 60 * 86400; if (setup_rerere(rr, 0) < 0) return; git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now); git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now); git_config(git_default_config, NULL); dir = opendir(git_path("rr-cache")); if (!dir) die_errno(_("unable to open rr-cache directory")); /* Collect stale conflict IDs ... */ while ((e = readdir(dir))) { struct rerere_dir *rr_dir; struct rerere_id id; int now_empty; if (is_dot_or_dotdot(e->d_name)) continue; rr_dir = find_rerere_dir(e->d_name); if (!rr_dir) continue; /* or should we remove e->d_name? */ now_empty = 1; for (id.variant = 0, id.collection = rr_dir; id.variant < id.collection->status_nr; id.variant++) { prune_one(&id, cutoff_resolve, cutoff_noresolve); if (id.collection->status[id.variant]) now_empty = 0; } if (now_empty) string_list_append(&to_remove, e->d_name); } closedir(dir); /* ... and then remove the empty directories */ for (i = 0; i < to_remove.nr; i++) rmdir(git_path("rr-cache/%s", to_remove.items[i].string)); string_list_clear(&to_remove, 0); rollback_lock_file(&write_lock); }
void shortlog_output(struct shortlog *log) { int i, j; if (log->sort_by_number) qsort(log->list.items, log->list.nr, sizeof(struct string_list_item), compare_by_number); for (i = 0; i < log->list.nr; i++) { struct string_list *onelines = log->list.items[i].util; if (log->summary) { printf("%6d\t%s\n", onelines->nr, log->list.items[i].string); } else { printf("%s (%d):\n", log->list.items[i].string, onelines->nr); for (j = onelines->nr - 1; j >= 0; j--) { const char *msg = onelines->items[j].string; if (log->wrap_lines) { int col = print_wrapped_text(msg, log->in1, log->in2, log->wrap); if (col != log->wrap) putchar('\n'); } else printf(" %s\n", msg); } putchar('\n'); } onelines->strdup_strings = 1; string_list_clear(onelines, 0); free(onelines); log->list.items[i].util = NULL; } log->list.strdup_strings = 1; string_list_clear(&log->list, 1); clear_mailmap(&log->mailmap); }
static int check_repository_format_gently(const char *gitdir, int *nongit_ok) { struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; struct repository_format candidate; int has_common; has_common = get_common_dir(&sb, gitdir); strbuf_addstr(&sb, "/config"); read_repository_format(&candidate, sb.buf); strbuf_release(&sb); /* * For historical use of check_repository_format() in git-init, * we treat a missing config as a silent "ok", even when nongit_ok * is unset. */ if (candidate.version < 0) return 0; if (verify_repository_format(&candidate, &err) < 0) { if (nongit_ok) { warning("%s", err.buf); strbuf_release(&err); *nongit_ok = -1; return -1; } die("%s", err.buf); } repository_format_precious_objects = candidate.precious_objects; string_list_clear(&candidate.unknown_extensions, 0); if (!has_common) { if (candidate.is_bare != -1) { is_bare_repository_cfg = candidate.is_bare; if (is_bare_repository_cfg == 1) inside_work_tree = -1; } if (candidate.work_tree) { free(git_work_tree_cfg); git_work_tree_cfg = candidate.work_tree; inside_work_tree = -1; } } else { free(candidate.work_tree); } return 0; }
int parse_opt_string_list(const struct option *opt, const char *arg, int unset) { struct string_list *v = opt->value; if (unset) { string_list_clear(v, 0); return 0; } if (!arg) return -1; string_list_append(v, arg); return 0; }
int show_range_diff(const char *range1, const char *range2, int creation_factor, struct diff_options *diffopt) { int res = 0; struct string_list branch1 = STRING_LIST_INIT_DUP; struct string_list branch2 = STRING_LIST_INIT_DUP; if (read_patches(range1, &branch1)) res = error(_("could not parse log for '%s'"), range1); if (!res && read_patches(range2, &branch2)) res = error(_("could not parse log for '%s'"), range2); if (!res) { find_exact_matches(&branch1, &branch2); get_correspondences(&branch1, &branch2, creation_factor); output(&branch1, &branch2, diffopt); } string_list_clear(&branch1, 1); string_list_clear(&branch2, 1); return res; }
int rename_ref_available(const char *old_refname, const char *new_refname) { struct string_list skip = STRING_LIST_INIT_NODUP; struct strbuf err = STRBUF_INIT; int ok; string_list_insert(&skip, old_refname); ok = !verify_refname_available(new_refname, NULL, &skip, &err); if (!ok) error("%s", err.buf); string_list_clear(&skip, 0); strbuf_release(&err); return ok; }
static void wt_status_print_other(struct wt_status *s, struct string_list *l, const char *what, const char *how) { int i; struct strbuf buf = STRBUF_INIT; static struct string_list output = STRING_LIST_INIT_DUP; struct column_options copts; if (!l->nr) return; wt_status_print_other_header(s, what, how); for (i = 0; i < l->nr; i++) { struct string_list_item *it; const char *path; it = &(l->items[i]); path = quote_path(it->string, s->prefix, &buf); if (column_active(s->colopts)) { string_list_append(&output, path); continue; } status_printf(s, color(WT_STATUS_HEADER, s), "\t"); status_printf_more(s, color(WT_STATUS_UNTRACKED, s), "%s\n", path); } strbuf_release(&buf); if (!column_active(s->colopts)) goto conclude; strbuf_addf(&buf, "%s%s\t%s", color(WT_STATUS_HEADER, s), s->display_comment_prefix ? "#" : "", color(WT_STATUS_UNTRACKED, s)); memset(&copts, 0, sizeof(copts)); copts.padding = 1; copts.indent = buf.buf; if (want_color(s->use_color)) copts.nl = GIT_COLOR_RESET "\n"; print_columns(&output, s->colopts, &copts); string_list_clear(&output, 0); strbuf_release(&buf); conclude: status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); }
void string_list_add_refs_from_colon_sep(struct string_list *list, const char *globs) { struct string_list split = STRING_LIST_INIT_NODUP; char *globs_copy = xstrdup(globs); int i; string_list_split_in_place(&split, globs_copy, ':', -1); string_list_remove_empty_items(&split, 0); for (i = 0; i < split.nr; i++) string_list_add_refs_by_glob(list, split.items[i].string); string_list_clear(&split, 0); free(globs_copy); }
static int sequencer_rollback(struct replay_opts *opts) { const char *filename; FILE *f; unsigned char sha1[20]; struct strbuf buf = STRBUF_INIT; struct string_list merge_rr = STRING_LIST_INIT_DUP; if (setup_rerere(&merge_rr, 0) >= 0) { rerere_clear(&merge_rr); string_list_clear(&merge_rr, 1); } filename = git_path(SEQ_HEAD_FILE); f = fopen(filename, "r"); if (!f && errno == ENOENT) { /* * There is no multiple-cherry-pick in progress. * If CHERRY_PICK_HEAD or REVERT_HEAD indicates * a single-cherry-pick in progress, abort that. */ return rollback_single_pick(); } if (!f) return error(_("cannot open %s: %s"), filename, strerror(errno)); if (strbuf_getline(&buf, f, '\n')) { error(_("cannot read %s: %s"), filename, ferror(f) ? strerror(errno) : _("unexpected end of file")); fclose(f); goto fail; } fclose(f); if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') { error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"), filename); goto fail; } if (reset_for_rollback(sha1)) goto fail; remove_sequencer_state(); strbuf_release(&buf); return 0; fail: strbuf_release(&buf); return -1; }
static int fetch_refs_via_pack(struct transport *transport, int nr_heads, struct ref **to_fetch) { struct git_transport_data *data = transport->data; struct string_list sought = STRING_LIST_INIT_DUP; const struct ref *refs; char *dest = xstrdup(transport->url); struct fetch_pack_args args; int i; struct ref *refs_tmp = NULL; memset(&args, 0, sizeof(args)); args.uploadpack = data->options.uploadpack; args.keep_pack = data->options.keep; args.lock_pack = 1; args.use_thin_pack = data->options.thin; args.include_tag = data->options.followtags; args.verbose = (transport->verbose > 1); args.quiet = (transport->verbose < 0); args.no_progress = !transport->progress; args.depth = data->options.depth; for (i = 0; i < nr_heads; i++) string_list_append(&sought, to_fetch[i]->name); if (!data->got_remote_heads) { connect_setup(transport, 0, 0); get_remote_heads(data->fd[0], &refs_tmp, 0, NULL); data->got_remote_heads = 1; } refs = fetch_pack(&args, data->fd, data->conn, refs_tmp ? refs_tmp : transport->remote_refs, dest, &sought, &transport->pack_lockfile); close(data->fd[0]); close(data->fd[1]); if (finish_connect(data->conn)) refs = NULL; data->conn = NULL; data->got_remote_heads = 0; free_refs(refs_tmp); string_list_clear(&sought, 0); free(dest); return (refs ? 0 : -1); }
static void check_aliased_updates(struct command *commands) { struct command *cmd; struct string_list ref_list = STRING_LIST_INIT_NODUP; for (cmd = commands; cmd; cmd = cmd->next) { struct string_list_item *item = string_list_append(&ref_list, cmd->ref_name); item->util = (void *)cmd; } sort_string_list(&ref_list); for (cmd = commands; cmd; cmd = cmd->next) check_aliased_update(cmd, &ref_list); string_list_clear(&ref_list, 0); }
static int do_command(struct strbuf *line) { const struct input_command_entry *p = input_command_list; static struct string_list batchlines = STRING_LIST_INIT_DUP; static const struct input_command_entry *batch_cmd; /* * commands can be grouped together in a batch. * Batches are ended by \n. If no batch is active the program ends. * During a batch all lines are buffered and passed to the handler function * when the batch is terminated. */ if (line->len == 0) { if (batch_cmd) { struct string_list_item *item; for_each_string_list_item(item, &batchlines) batch_cmd->fn(item->string); terminate_batch(); batch_cmd = NULL; string_list_clear(&batchlines, 0); return 0; /* end of the batch, continue reading other commands. */ } return 1; /* end of command stream, quit */ } if (batch_cmd) { if (!starts_with(batch_cmd->name, line->buf)) die("Active %s batch interrupted by %s", batch_cmd->name, line->buf); /* buffer batch lines */ string_list_append(&batchlines, line->buf); return 0; } for (p = input_command_list; p->name; p++) { if (starts_with(line->buf, p->name) && (strlen(p->name) == line->len || line->buf[strlen(p->name)] == ' ')) { if (p->batchable) { batch_cmd = p; string_list_append(&batchlines, line->buf); return 0; } return p->fn(line->buf); } } die("Unknown command '%s'\n", line->buf); return 0; }
static void die_with_unpushed_submodules(struct string_list *needs_pushing) { int i; fprintf(stderr, _("The following submodule paths contain changes that can\n" "not be found on any remote:\n")); for (i = 0; i < needs_pushing->nr; i++) fprintf(stderr, " %s\n", needs_pushing->items[i].string); fprintf(stderr, _("\nPlease try\n\n" " git push --recurse-submodules=on-demand\n\n" "or cd to the path and use\n\n" " git push\n\n" "to push them to a remote.\n\n")); string_list_clear(needs_pushing, 0); die(_("Aborting.")); }
static void pretty_print_cmdnames(struct cmdnames *cmds, unsigned int colopts) { struct string_list list = STRING_LIST_INIT_NODUP; struct column_options copts; int i; for (i = 0; i < cmds->cnt; i++) string_list_append(&list, cmds->names[i]->name); /* * always enable column display, we only consult column.* * about layout strategy and stuff */ colopts = (colopts & ~COL_ENABLE_MASK) | COL_ENABLED; memset(&copts, 0, sizeof(copts)); copts.indent = " "; copts.padding = 2; print_columns(&list, colopts, &copts); string_list_clear(&list, 0); }
void help_unknown_ref(const char *ref, const char *cmd, const char *error) { int i; struct string_list suggested_refs = guess_refs(ref); fprintf_ln(stderr, _("%s: %s - %s"), cmd, ref, error); if (suggested_refs.nr > 0) { fprintf_ln(stderr, Q_("\nDid you mean this?", "\nDid you mean one of these?", suggested_refs.nr)); for (i = 0; i < suggested_refs.nr; i++) fprintf(stderr, "\t%s\n", suggested_refs.items[i].string); } string_list_clear(&suggested_refs, 0); exit(1); }
/* * display all the error messages stored in a nice way */ static void display_error_msgs(struct unpack_trees_options *o) { int e, i; int something_displayed = 0; for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) { struct string_list *rejects = &o->unpack_rejects[e]; if (rejects->nr > 0) { struct strbuf path = STRBUF_INIT; something_displayed = 1; for (i = 0; i < rejects->nr; i++) strbuf_addf(&path, "\t%s\n", rejects->items[i].string); error(ERRORMSG(o, e), path.buf); strbuf_release(&path); } string_list_clear(rejects, 0); } if (something_displayed) fprintf(stderr, "Aborting\n"); }
void rerere_gc(struct string_list *rr) { struct string_list to_remove = STRING_LIST_INIT_DUP; DIR *dir; struct dirent *e; int i, cutoff; time_t now = time(NULL), then; int cutoff_noresolve = 15; int cutoff_resolve = 60; if (setup_rerere(rr, 0) < 0) return; git_config_get_int("gc.rerereresolved", &cutoff_resolve); git_config_get_int("gc.rerereunresolved", &cutoff_noresolve); git_config(git_default_config, NULL); dir = opendir(git_path("rr-cache")); if (!dir) die_errno("unable to open rr-cache directory"); /* Collect stale conflict IDs ... */ while ((e = readdir(dir))) { if (is_dot_or_dotdot(e->d_name)) continue; then = rerere_last_used_at(e->d_name); if (then) { cutoff = cutoff_resolve; } else { then = rerere_created_at(e->d_name); if (!then) continue; cutoff = cutoff_noresolve; } if (then < now - cutoff * 86400) string_list_append(&to_remove, e->d_name); } closedir(dir); /* ... and then remove them one-by-one */ for (i = 0; i < to_remove.nr; i++) unlink_rr_item(dirname_to_id(to_remove.items[i].string)); string_list_clear(&to_remove, 0); rollback_lock_file(&write_lock); }
static int credential_config_callback(const char *var, const char *value, void *data) { struct credential *c = data; const char *key, *dot; if (!skip_prefix(var, "credential.", &key)) return 0; if (!value) return config_error_nonbool(var); dot = strrchr(key, '.'); if (dot) { struct credential want = CREDENTIAL_INIT; char *url = xmemdupz(key, dot - key); int matched; credential_from_url(&want, url); matched = credential_match(&want, c); credential_clear(&want); free(url); if (!matched) return 0; key = dot + 1; } if (!strcmp(key, "helper")) { if (*value) string_list_append(&c->helpers, value); else string_list_clear(&c->helpers, 0); } else if (!strcmp(key, "username")) { if (!c->username) c->username = xstrdup(value); } else if (!strcmp(key, "usehttppath")) c->use_http_path = git_config_bool(var, value); return 0; }
static int remove_duplicates_in_refs(struct ref **ref, int nr) { struct string_list names = STRING_LIST_INIT_NODUP; int src, dst; for (src = dst = 0; src < nr; src++) { struct string_list_item *item; item = string_list_insert(&names, ref[src]->name); if (item->util) continue; /* already have it */ item->util = ref[src]; if (src != dst) ref[dst] = ref[src]; dst++; } for (src = dst; src < nr; src++) ref[src] = NULL; string_list_clear(&names, 0); return dst; }
int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name) { int i, ret = 1; struct string_list needs_pushing = STRING_LIST_INIT_DUP; if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing)) return 1; for (i = 0; i < needs_pushing.nr; i++) { const char *path = needs_pushing.items[i].string; fprintf(stderr, "Pushing submodule '%s'\n", path); if (!push_submodule(path)) { fprintf(stderr, "Unable to push submodule '%s'\n", path); ret = 0; } } string_list_clear(&needs_pushing, 0); return ret; }