summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/branch.c4
-rw-r--r--builtin/config.c81
-rw-r--r--builtin/gc.c12
-rw-r--r--builtin/grep.c1
-rw-r--r--builtin/log.c1
-rw-r--r--builtin/pull.c48
-rw-r--r--builtin/receive-pack.c15
-rw-r--r--builtin/remote.c8
-rw-r--r--builtin/repack.c153
-rw-r--r--builtin/update-ref.c15
10 files changed, 194 insertions, 144 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index efb30b8820..173b736dff 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -829,10 +829,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
die(_("Branch '%s' has no upstream information"), branch->name);
strbuf_addf(&buf, "branch.%s.remote", branch->name);
- git_config_set_multivar(buf.buf, NULL, NULL, 1);
+ git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
strbuf_reset(&buf);
strbuf_addf(&buf, "branch.%s.merge", branch->name);
- git_config_set_multivar(buf.buf, NULL, NULL, 1);
+ git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
strbuf_release(&buf);
} else if (argc > 0 && argc <= 2) {
if (filter.kind != FILTER_REFS_BRANCHES)
diff --git a/builtin/config.c b/builtin/config.c
index 963d65fd3f..f71fa39b38 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -14,6 +14,7 @@ static const char *const builtin_config_usage[] = {
static char *key;
static regex_t *key_regexp;
+static const char *value_pattern;
static regex_t *regexp;
static int show_keys;
static int omit_values;
@@ -34,6 +35,7 @@ static int respect_includes_opt = -1;
static struct config_options config_options;
static int show_origin;
static int show_scope;
+static int fixed_value;
#define ACTION_GET (1<<0)
#define ACTION_GET_ALL (1<<1)
@@ -133,17 +135,18 @@ static struct option builtin_config_options[] = {
OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
OPT_GROUP(N_("Action")),
- OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
- OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL),
- OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP),
+ OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET),
+ OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL),
+ OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP),
OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
- OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL),
+ OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL),
OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
- OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-regex]"), ACTION_UNSET),
- OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL),
+ OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET),
+ OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL),
OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),
+ OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")),
OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR),
OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL),
@@ -296,6 +299,8 @@ static int collect_config(const char *key_, const char *value_, void *cb)
return 0;
if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
return 0;
+ if (fixed_value && strcmp(value_pattern, (value_?value_:"")))
+ return 0;
if (regexp != NULL &&
(do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
return 0;
@@ -306,7 +311,7 @@ static int collect_config(const char *key_, const char *value_, void *cb)
return format_config(&values->items[values->nr++], key_, value_);
}
-static int get_value(const char *key_, const char *regex_)
+static int get_value(const char *key_, const char *regex_, unsigned flags)
{
int ret = CONFIG_GENERIC_ERROR;
struct strbuf_list values = {NULL};
@@ -343,7 +348,9 @@ static int get_value(const char *key_, const char *regex_)
}
}
- if (regex_) {
+ if (regex_ && (flags & CONFIG_FLAGS_FIXED_VALUE))
+ value_pattern = regex_;
+ else if (regex_) {
if (regex_[0] == '!') {
do_not_match = 1;
regex_++;
@@ -631,6 +638,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
{
int nongit = !startup_info->have_repository;
char *value;
+ int flags = 0;
given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
@@ -766,6 +774,42 @@ int cmd_config(int argc, const char **argv, const char *prefix)
usage_builtin_config();
}
+ /* check usage of --fixed-value */
+ if (fixed_value) {
+ int allowed_usage = 0;
+
+ switch (actions) {
+ /* git config --get <name> <value-pattern> */
+ case ACTION_GET:
+ /* git config --get-all <name> <value-pattern> */
+ case ACTION_GET_ALL:
+ /* git config --get-regexp <name-pattern> <value-pattern> */
+ case ACTION_GET_REGEXP:
+ /* git config --unset <name> <value-pattern> */
+ case ACTION_UNSET:
+ /* git config --unset-all <name> <value-pattern> */
+ case ACTION_UNSET_ALL:
+ allowed_usage = argc > 1 && !!argv[1];
+ break;
+
+ /* git config <name> <value> <value-pattern> */
+ case ACTION_SET_ALL:
+ /* git config --replace-all <name> <value> <value-pattern> */
+ case ACTION_REPLACE_ALL:
+ allowed_usage = argc > 2 && !!argv[2];
+ break;
+
+ /* other options don't allow --fixed-value */
+ }
+
+ if (!allowed_usage) {
+ error(_("--fixed-value only applies with 'value-pattern'"));
+ usage_builtin_config();
+ }
+
+ flags |= CONFIG_FLAGS_FIXED_VALUE;
+ }
+
if (actions & PAGING_ACTIONS)
setup_auto_pager("config", 1);
@@ -827,7 +871,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
value = normalize_value(argv[0], argv[1]);
UNLEAK(value);
return git_config_set_multivar_in_file_gently(given_config_source.file,
- argv[0], value, argv[2], 0);
+ argv[0], value, argv[2],
+ flags);
}
else if (actions == ACTION_ADD) {
check_write();
@@ -836,7 +881,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
UNLEAK(value);
return git_config_set_multivar_in_file_gently(given_config_source.file,
argv[0], value,
- CONFIG_REGEX_NONE, 0);
+ CONFIG_REGEX_NONE,
+ flags);
}
else if (actions == ACTION_REPLACE_ALL) {
check_write();
@@ -844,23 +890,24 @@ int cmd_config(int argc, const char **argv, const char *prefix)
value = normalize_value(argv[0], argv[1]);
UNLEAK(value);
return git_config_set_multivar_in_file_gently(given_config_source.file,
- argv[0], value, argv[2], 1);
+ argv[0], value, argv[2],
+ flags | CONFIG_FLAGS_MULTI_REPLACE);
}
else if (actions == ACTION_GET) {
check_argc(argc, 1, 2);
- return get_value(argv[0], argv[1]);
+ return get_value(argv[0], argv[1], flags);
}
else if (actions == ACTION_GET_ALL) {
do_all = 1;
check_argc(argc, 1, 2);
- return get_value(argv[0], argv[1]);
+ return get_value(argv[0], argv[1], flags);
}
else if (actions == ACTION_GET_REGEXP) {
show_keys = 1;
use_key_regexp = 1;
do_all = 1;
check_argc(argc, 1, 2);
- return get_value(argv[0], argv[1]);
+ return get_value(argv[0], argv[1], flags);
}
else if (actions == ACTION_GET_URLMATCH) {
check_argc(argc, 2, 2);
@@ -871,7 +918,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
check_argc(argc, 1, 2);
if (argc == 2)
return git_config_set_multivar_in_file_gently(given_config_source.file,
- argv[0], NULL, argv[1], 0);
+ argv[0], NULL, argv[1],
+ flags);
else
return git_config_set_in_file_gently(given_config_source.file,
argv[0], NULL);
@@ -880,7 +928,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
check_write();
check_argc(argc, 1, 2);
return git_config_set_multivar_in_file_gently(given_config_source.file,
- argv[0], NULL, argv[1], 1);
+ argv[0], NULL, argv[1],
+ flags | CONFIG_FLAGS_MULTI_REPLACE);
}
else if (actions == ACTION_RENAME_SECTION) {
int ret;
diff --git a/builtin/gc.c b/builtin/gc.c
index 3e8d76fd5a..b57fda4924 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1446,10 +1446,6 @@ static int maintenance_register(void)
struct child_process config_set = CHILD_PROCESS_INIT;
struct child_process config_get = CHILD_PROCESS_INIT;
- /* There is no current repository, so skip registering it */
- if (!the_repository || !the_repository->gitdir)
- return 0;
-
/* Disable foreground maintenance */
git_config_set("maintenance.auto", "false");
@@ -1460,7 +1456,8 @@ static int maintenance_register(void)
git_config_set("maintenance.strategy", "incremental");
config_get.git_cmd = 1;
- strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
+ strvec_pushl(&config_get.args, "config", "--global", "--get",
+ "--fixed-value", "maintenance.repo",
the_repository->worktree ? the_repository->worktree
: the_repository->gitdir,
NULL);
@@ -1486,12 +1483,9 @@ static int maintenance_unregister(void)
{
struct child_process config_unset = CHILD_PROCESS_INIT;
- if (!the_repository || !the_repository->gitdir)
- return error(_("no current repository to unregister"));
-
config_unset.git_cmd = 1;
strvec_pushl(&config_unset.args, "config", "--global", "--unset",
- "maintenance.repo",
+ "--fixed-value", "maintenance.repo",
the_repository->worktree ? the_repository->worktree
: the_repository->gitdir,
NULL);
diff --git a/builtin/grep.c b/builtin/grep.c
index e58e57504c..ca259af441 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -950,7 +950,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_END()
};
- init_grep_defaults(the_repository);
git_config(grep_cmd_config, NULL);
grep_init(&opt, the_repository, prefix);
diff --git a/builtin/log.c b/builtin/log.c
index 08204e3196..bd6ff4f9f9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -133,7 +133,6 @@ static int log_line_range_callback(const struct option *option, const char *arg,
static void init_log_defaults(void)
{
- init_grep_defaults(the_repository);
init_diff_ui_defaults();
decoration_style = auto_decoration_style();
diff --git a/builtin/pull.c b/builtin/pull.c
index 1034372f8b..aa56ebcdd0 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -852,21 +852,42 @@ static int get_octopus_merge_base(struct object_id *merge_base,
/**
* Given the current HEAD oid, the merge head returned from git-fetch and the
- * fork point calculated by get_rebase_fork_point(), runs git-rebase with the
- * appropriate arguments and returns its exit status.
+ * fork point calculated by get_rebase_fork_point(), compute the <newbase> and
+ * <upstream> arguments to use for the upcoming git-rebase invocation.
*/
-static int run_rebase(const struct object_id *curr_head,
+static int get_rebase_newbase_and_upstream(struct object_id *newbase,
+ struct object_id *upstream,
+ const struct object_id *curr_head,
const struct object_id *merge_head,
const struct object_id *fork_point)
{
- int ret;
struct object_id oct_merge_base;
- struct strvec args = STRVEC_INIT;
if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))
fork_point = NULL;
+ if (fork_point && !is_null_oid(fork_point))
+ oidcpy(upstream, fork_point);
+ else
+ oidcpy(upstream, merge_head);
+
+ oidcpy(newbase, merge_head);
+
+ return 0;
+}
+
+/**
+ * Given the <newbase> and <upstream> calculated by
+ * get_rebase_newbase_and_upstream(), runs git-rebase with the
+ * appropriate arguments and returns its exit status.
+ */
+static int run_rebase(const struct object_id *newbase,
+ const struct object_id *upstream)
+{
+ int ret;
+ struct strvec args = STRVEC_INIT;
+
strvec_push(&args, "rebase");
/* Shared options */
@@ -894,12 +915,9 @@ static int run_rebase(const struct object_id *curr_head,
warning(_("ignoring --verify-signatures for rebase"));
strvec_push(&args, "--onto");
- strvec_push(&args, oid_to_hex(merge_head));
+ strvec_push(&args, oid_to_hex(newbase));
- if (fork_point && !is_null_oid(fork_point))
- strvec_push(&args, oid_to_hex(fork_point));
- else
- strvec_push(&args, oid_to_hex(merge_head));
+ strvec_push(&args, oid_to_hex(upstream));
ret = run_command_v_opt(args.v, RUN_GIT_CMD);
strvec_clear(&args);
@@ -1011,9 +1029,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
if (opt_rebase) {
int ret = 0;
int ran_ff = 0;
+
+ struct object_id newbase;
+ struct object_id upstream;
+ get_rebase_newbase_and_upstream(&newbase, &upstream, &curr_head,
+ merge_heads.oid, &rebase_fork_point);
+
if ((recurse_submodules == RECURSE_SUBMODULES_ON ||
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) &&
- submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head))
+ submodule_touches_in_range(the_repository, &upstream, &curr_head))
die(_("cannot rebase with locally recorded submodule modifications"));
if (!autostash) {
struct commit_list *list = NULL;
@@ -1034,7 +1058,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
free_commit_list(list);
}
if (!ran_ff)
- ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);
+ ret = run_rebase(&newbase, &upstream);
if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f1f0f7bef6..d49d050e6e 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -54,6 +54,7 @@ static int receive_unpack_limit = -1;
static int transfer_unpack_limit = -1;
static int advertise_atomic_push = 1;
static int advertise_push_options;
+static int advertise_sid;
static int unpack_limit = 100;
static off_t max_input_size;
static int report_status;
@@ -248,6 +249,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return 0;
}
+ if (strcmp(var, "transfer.advertisesid") == 0) {
+ advertise_sid = git_config_bool(var, value);
+ return 0;
+ }
+
return git_default_config(var, value, cb);
}
@@ -268,6 +274,8 @@ static void show_ref(const char *path, const struct object_id *oid)
strbuf_addf(&cap, " push-cert=%s", push_cert_nonce);
if (advertise_push_options)
strbuf_addstr(&cap, " push-options");
+ if (advertise_sid)
+ strbuf_addf(&cap, " session-id=%s", trace2_session_id());
strbuf_addf(&cap, " object-format=%s", the_hash_algo->name);
strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
packet_write_fmt(1, "%s %s%c%s\n",
@@ -2075,6 +2083,7 @@ static struct command *read_head_info(struct packet_reader *reader,
if (linelen < reader->pktlen) {
const char *feature_list = reader->line + linelen + 1;
const char *hash = NULL;
+ const char *client_sid;
int len = 0;
if (parse_feature_request(feature_list, "report-status"))
report_status = 1;
@@ -2097,6 +2106,12 @@ static struct command *read_head_info(struct packet_reader *reader,
}
if (xstrncmpz(the_hash_algo->name, hash, len))
die("error: unsupported object format '%s'", hash);
+ client_sid = parse_feature_value(feature_list, "session-id", &len, NULL);
+ if (client_sid) {
+ char *sid = xstrndup(client_sid, len);
+ trace2_data_string("transfer", NULL, "client-sid", client_sid);
+ free(sid);
+ }
}
if (!strcmp(reader->line, "push-cert")) {
diff --git a/builtin/remote.c b/builtin/remote.c
index c1b211b272..d11a5589e4 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -712,7 +712,7 @@ static int mv(int argc, const char **argv)
strbuf_reset(&buf);
strbuf_addf(&buf, "remote.%s.fetch", rename.new_name);
- git_config_set_multivar(buf.buf, NULL, NULL, 1);
+ git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name);
for (i = 0; i < oldremote->fetch.raw_nr; i++) {
char *ptr;
@@ -1491,7 +1491,8 @@ static int update(int argc, const char **argv)
static int remove_all_fetch_refspecs(const char *key)
{
- return git_config_set_multivar_gently(key, NULL, NULL, 1);
+ return git_config_set_multivar_gently(key, NULL, NULL,
+ CONFIG_FLAGS_MULTI_REPLACE);
}
static void add_branches(struct remote *remote, const char **branches,
@@ -1686,7 +1687,8 @@ static int set_url(int argc, const char **argv)
if (!delete_mode)
git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
else
- git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
+ git_config_set_multivar(name_buf.buf, NULL, oldurl,
+ CONFIG_FLAGS_MULTI_REPLACE);
out:
strbuf_release(&name_buf);
return 0;
diff --git a/builtin/repack.c b/builtin/repack.c
index 01e7767c79..279be11a16 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -202,6 +202,37 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,
return 0;
}
+static struct {
+ const char *name;
+ unsigned optional:1;
+} exts[] = {
+ {".pack"},
+ {".idx"},
+ {".bitmap", 1},
+ {".promisor", 1},
+};
+
+static unsigned populate_pack_exts(char *name)
+{
+ struct stat statbuf;
+ struct strbuf path = STRBUF_INIT;
+ unsigned ret = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(exts); i++) {
+ strbuf_reset(&path);
+ strbuf_addf(&path, "%s-%s%s", packtmp, name, exts[i].name);
+
+ if (stat(path.buf, &statbuf))
+ continue;
+
+ ret |= (1 << i);
+ }
+
+ strbuf_release(&path);
+ return ret;
+}
+
static void repack_promisor_objects(const struct pack_objects_args *args,
struct string_list *names)
{
@@ -230,11 +261,12 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
out = xfdopen(cmd.out, "r");
while (strbuf_getline_lf(&line, out) != EOF) {
+ struct string_list_item *item;
char *promisor_name;
int fd;
if (line.len != the_hash_algo->hexsz)
die(_("repack: Expecting full hex object ID lines only from pack-objects."));
- string_list_append(names, line.buf);
+ item = string_list_append(names, line.buf);
/*
* pack-objects creates the .pack and .idx files, but not the
@@ -253,6 +285,9 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
if (fd < 0)
die_errno(_("unable to create '%s'"), promisor_name);
close(fd);
+
+ item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
+
free(promisor_name);
}
fclose(out);
@@ -265,22 +300,13 @@ static void repack_promisor_objects(const struct pack_objects_args *args,
int cmd_repack(int argc, const char **argv, const char *prefix)
{
- struct {
- const char *name;
- unsigned optional:1;
- } exts[] = {
- {".pack"},
- {".idx"},
- {".bitmap", 1},
- {".promisor", 1},
- };
struct child_process cmd = CHILD_PROCESS_INIT;
struct string_list_item *item;
struct string_list names = STRING_LIST_INIT_DUP;
struct string_list rollback = STRING_LIST_INIT_NODUP;
struct string_list existing_packs = STRING_LIST_INIT_DUP;
struct strbuf line = STRBUF_INIT;
- int i, ext, ret, failed;
+ int i, ext, ret;
FILE *out;
/* variables to be filled by option parsing */
@@ -429,113 +455,42 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
if (!names.nr && !po_args.quiet)
printf_ln(_("Nothing new to pack."));
+ for_each_string_list_item(item, &names) {
+ item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
+ }
+
close_object_store(the_repository->objects);
/*
* Ok we have prepared all new packfiles.
- * First see if there are packs of the same name and if so
- * if we can move them out of the way (this can happen if we
- * repacked immediately after packing fully.
*/
- failed = 0;
for_each_string_list_item(item, &names) {
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
char *fname, *fname_old;
- fname = mkpathdup("%s/pack-%s%s", packdir,
- item->string, exts[ext].name);
- if (!file_exists(fname)) {
- free(fname);
- continue;
- }
-
- fname_old = mkpathdup("%s/old-%s%s", packdir,
- item->string, exts[ext].name);
- if (file_exists(fname_old))
- if (unlink(fname_old))
- failed = 1;
-
- if (!failed && rename(fname, fname_old)) {
- free(fname);
- free(fname_old);
- failed = 1;
- break;
- } else {
- string_list_append(&rollback, fname);
- free(fname_old);
- }
- }
- if (failed)
- break;
- }
- if (failed) {
- struct string_list rollback_failure = STRING_LIST_INIT_DUP;
- for_each_string_list_item(item, &rollback) {
- char *fname, *fname_old;
- fname = mkpathdup("%s/%s", packdir, item->string);
- fname_old = mkpathdup("%s/old-%s", packdir, item->string);
- if (rename(fname_old, fname))
- string_list_append(&rollback_failure, fname);
- free(fname);
- free(fname_old);
- }
-
- if (rollback_failure.nr) {
- int i;
- fprintf(stderr,
- _("WARNING: Some packs in use have been renamed by\n"
- "WARNING: prefixing old- to their name, in order to\n"
- "WARNING: replace them with the new version of the\n"
- "WARNING: file. But the operation failed, and the\n"
- "WARNING: attempt to rename them back to their\n"
- "WARNING: original names also failed.\n"
- "WARNING: Please rename them in %s manually:\n"), packdir);
- for (i = 0; i < rollback_failure.nr; i++)
- fprintf(stderr, "WARNING: old-%s -> %s\n",
- rollback_failure.items[i].string,
- rollback_failure.items[i].string);
- }
- exit(1);
- }
-
- /* Now the ones with the same name are out of the way... */
- for_each_string_list_item(item, &names) {
- for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
- char *fname, *fname_old;
- struct stat statbuffer;
- int exists = 0;
fname = mkpathdup("%s/pack-%s%s",
packdir, item->string, exts[ext].name);
fname_old = mkpathdup("%s-%s%s",
packtmp, item->string, exts[ext].name);
- if (!stat(fname_old, &statbuffer)) {
- statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
- chmod(fname_old, statbuffer.st_mode);
- exists = 1;
- }
- if (exists || !exts[ext].optional) {
+
+ if (((uintptr_t)item->util) & (1 << ext)) {
+ struct stat statbuffer;
+ if (!stat(fname_old, &statbuffer)) {
+ statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
+ chmod(fname_old, statbuffer.st_mode);
+ }
+
if (rename(fname_old, fname))
die_errno(_("renaming '%s' failed"), fname_old);
- }
- free(fname);
- free(fname_old);
- }
- }
+ } else if (!exts[ext].optional)
+ die(_("missing required file: %s"), fname_old);
+ else if (unlink(fname) < 0 && errno != ENOENT)
+ die_errno(_("could not unlink: %s"), fname);
- /* Remove the "old-" files */
- for_each_string_list_item(item, &names) {
- for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
- char *fname;
- fname = mkpathdup("%s/old-%s%s",
- packdir,
- item->string,
- exts[ext].name);
- if (remove_path(fname))
- warning(_("failed to remove '%s'"), fname);
free(fname);
+ free(fname_old);
}
}
-
/* End of pack replacement. */
reprepare_packed_git(the_repository);
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 8a2df4459c..6029a80544 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -436,6 +436,8 @@ static void update_refs_stdin(void)
switch (state) {
case UPDATE_REFS_OPEN:
case UPDATE_REFS_STARTED:
+ if (state == UPDATE_REFS_STARTED && cmd->state == UPDATE_REFS_STARTED)
+ die("cannot restart ongoing transaction");
/* Do not downgrade a transaction to a non-transaction. */
if (cmd->state >= state)
state = cmd->state;
@@ -446,7 +448,18 @@ static void update_refs_stdin(void)
state = cmd->state;
break;
case UPDATE_REFS_CLOSED:
- die("transaction is closed");
+ if (cmd->state != UPDATE_REFS_STARTED)
+ die("transaction is closed");
+
+ /*
+ * Open a new transaction if we're currently closed and
+ * get a "start".
+ */
+ state = cmd->state;
+ transaction = ref_transaction_begin(&err);
+ if (!transaction)
+ die("%s", err.buf);
+
break;
}