summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c6
-rw-r--r--builtin/branch.c2
-rw-r--r--builtin/clone.c4
-rw-r--r--builtin/commit.c6
-rw-r--r--builtin/gc.c74
-rw-r--r--builtin/merge.c2
-rw-r--r--builtin/notes.c6
-rw-r--r--builtin/prune.c3
-rw-r--r--builtin/repack.c3
-rw-r--r--builtin/stripspace.c124
-rw-r--r--builtin/tag.c2
11 files changed, 118 insertions, 114 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 3bd4fd7..98e29e0 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1343,7 +1343,7 @@ static int parse_mail(struct am_state *state, const char *mail)
strbuf_addstr(&msg, "\n\n");
if (strbuf_read_file(&msg, am_path(state, "msg"), 0) < 0)
die_errno(_("could not read '%s'"), am_path(state, "msg"));
- stripspace(&msg, 0);
+ strbuf_stripspace(&msg, 0);
if (state->signoff)
am_signoff(&msg);
@@ -2229,8 +2229,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
int in_progress;
const char * const usage[] = {
- N_("git am [options] [(<mbox>|<Maildir>)...]"),
- N_("git am [options] (--continue | --skip | --abort)"),
+ N_("git am [<options>] [(<mbox>|<Maildir>)...]"),
+ N_("git am [<options>] (--continue | --skip | --abort)"),
NULL
};
diff --git a/builtin/branch.c b/builtin/branch.c
index ff05869..baaa44c 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -786,7 +786,7 @@ static int edit_branch_description(const char *branch_name)
strbuf_release(&buf);
return -1;
}
- stripspace(&buf, 1);
+ strbuf_stripspace(&buf, 1);
strbuf_addf(&name, "branch.%s.description", branch_name);
status = git_config_set(name.buf, buf.len ? buf.buf : NULL);
diff --git a/builtin/clone.c b/builtin/clone.c
index 578da85..cc896e2 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1064,8 +1064,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport_unlock_pack(transport);
transport_disconnect(transport);
- if (option_dissociate)
+ if (option_dissociate) {
+ close_all_packs();
dissociate_from_references();
+ }
junk_mode = JUNK_LEAVE_REPO;
err = checkout();
diff --git a/builtin/commit.c b/builtin/commit.c
index 63772d0..dca09e2 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -775,7 +775,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
s->hints = 0;
if (clean_message_contents)
- stripspace(&sb, 0);
+ strbuf_stripspace(&sb, 0);
if (signoff)
append_signoff(&sb, ignore_non_trailer(&sb), 0);
@@ -1014,7 +1014,7 @@ static int template_untouched(struct strbuf *sb)
if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
return 0;
- stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
+ strbuf_stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
if (!skip_prefix(sb->buf, tmpl.buf, &start))
start = sb->buf;
strbuf_release(&tmpl);
@@ -1726,7 +1726,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
wt_status_truncate_message_at_cut_line(&sb);
if (cleanup_mode != CLEANUP_NONE)
- stripspace(&sb, cleanup_mode == CLEANUP_ALL);
+ strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
if (template_untouched(&sb) && !allow_empty_message) {
rollback_index_files();
fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
diff --git a/builtin/gc.c b/builtin/gc.c
index 0ad8d30..9216f7b 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -44,6 +44,7 @@ static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
static struct argv_array rerere = ARGV_ARRAY_INIT;
static struct tempfile pidfile;
+static struct lock_file log_lock;
static void git_config_date_string(const char *key, const char **output)
{
@@ -56,6 +57,28 @@ static void git_config_date_string(const char *key, const char **output)
}
}
+static void process_log_file(void)
+{
+ struct stat st;
+ if (!fstat(get_lock_file_fd(&log_lock), &st) && st.st_size)
+ commit_lock_file(&log_lock);
+ else
+ rollback_lock_file(&log_lock);
+}
+
+static void process_log_file_at_exit(void)
+{
+ fflush(stderr);
+ process_log_file();
+}
+
+static void process_log_file_on_signal(int signo)
+{
+ process_log_file();
+ sigchain_pop(signo);
+ raise(signo);
+}
+
static void gc_config(void)
{
const char *value;
@@ -241,6 +264,24 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
return NULL;
}
+static int report_last_gc_error(void)
+{
+ struct strbuf sb = STRBUF_INIT;
+ int ret;
+
+ ret = strbuf_read_file(&sb, git_path("gc.log"), 0);
+ if (ret > 0)
+ return error(_("The last gc run reported the following. "
+ "Please correct the root cause\n"
+ "and remove %s.\n"
+ "Automatic cleanup will not be performed "
+ "until the file is removed.\n\n"
+ "%s"),
+ git_path("gc.log"), sb.buf);
+ strbuf_release(&sb);
+ return 0;
+}
+
static int gc_before_repack(void)
{
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
@@ -262,6 +303,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
int force = 0;
const char *name;
pid_t pid;
+ int daemonized = 0;
struct option builtin_gc_options[] = {
OPT__QUIET(&quiet, N_("suppress progress reporting")),
@@ -318,13 +360,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
}
if (detach_auto) {
+ if (report_last_gc_error())
+ return -1;
+
if (gc_before_repack())
return -1;
/*
* failure to daemonize is ok, we'll continue
* in foreground
*/
- daemonize();
+ daemonized = !daemonize();
}
} else
add_repack_all_option();
@@ -337,18 +382,29 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
name, (uintmax_t)pid);
}
+ if (daemonized) {
+ hold_lock_file_for_update(&log_lock,
+ git_path("gc.log"),
+ LOCK_DIE_ON_ERROR);
+ dup2(get_lock_file_fd(&log_lock), 2);
+ sigchain_push_common(process_log_file_on_signal);
+ atexit(process_log_file_at_exit);
+ }
+
if (gc_before_repack())
return -1;
- if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
- return error(FAILED_RUN, repack.argv[0]);
+ if (!repository_format_precious_objects) {
+ if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
+ return error(FAILED_RUN, repack.argv[0]);
- if (prune_expire) {
- argv_array_push(&prune, prune_expire);
- if (quiet)
- argv_array_push(&prune, "--no-progress");
- if (run_command_v_opt(prune.argv, RUN_GIT_CMD))
- return error(FAILED_RUN, prune.argv[0]);
+ if (prune_expire) {
+ argv_array_push(&prune, prune_expire);
+ if (quiet)
+ argv_array_push(&prune, "--no-progress");
+ if (run_command_v_opt(prune.argv, RUN_GIT_CMD))
+ return error(FAILED_RUN, prune.argv[0]);
+ }
}
if (prune_worktrees_expire) {
diff --git a/builtin/merge.c b/builtin/merge.c
index a0edaca..e6741f3 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -806,7 +806,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)
abort_commit(remoteheads, NULL);
}
read_merge_msg(&msg);
- stripspace(&msg, 0 < option_edit);
+ strbuf_stripspace(&msg, 0 < option_edit);
if (!msg.len)
abort_commit(remoteheads, _("Empty commit message."));
strbuf_release(&merge_msg);
diff --git a/builtin/notes.c b/builtin/notes.c
index 3608c64..bb23d55 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -192,7 +192,7 @@ static void prepare_note_data(const unsigned char *object, struct note_data *d,
if (launch_editor(d->edit_path, &d->buf, NULL)) {
die(_("Please supply the note contents using either -m or -F option"));
}
- stripspace(&d->buf, 1);
+ strbuf_stripspace(&d->buf, 1);
}
}
@@ -215,7 +215,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
if (d->buf.len)
strbuf_addch(&d->buf, '\n');
strbuf_addstr(&d->buf, arg);
- stripspace(&d->buf, 0);
+ strbuf_stripspace(&d->buf, 0);
d->given = 1;
return 0;
@@ -232,7 +232,7 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset)
die_errno(_("cannot read '%s'"), arg);
} else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
die_errno(_("could not open or read '%s'"), arg);
- stripspace(&d->buf, 0);
+ strbuf_stripspace(&d->buf, 0);
d->given = 1;
return 0;
diff --git a/builtin/prune.c b/builtin/prune.c
index 10b03d3..8f4f052 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -119,6 +119,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
+ if (repository_format_precious_objects)
+ die(_("cannot prune in a precious-objects repo"));
+
while (argc--) {
unsigned char sha1[20];
const char *name = *argv++;
diff --git a/builtin/repack.c b/builtin/repack.c
index 70b9b1e..9456110 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -193,6 +193,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, builtin_repack_options,
git_repack_usage, 0);
+ if (delete_redundant && repository_format_precious_objects)
+ die(_("cannot delete packs in a precious-objects repo"));
+
if (pack_kept_objects < 0)
pack_kept_objects = write_bitmaps;
diff --git a/builtin/stripspace.c b/builtin/stripspace.c
index 958567a..7ff8434 100644
--- a/builtin/stripspace.c
+++ b/builtin/stripspace.c
@@ -1,71 +1,7 @@
#include "builtin.h"
#include "cache.h"
-
-/*
- * Returns the length of a line, without trailing spaces.
- *
- * If the line ends with newline, it will be removed too.
- */
-static size_t cleanup(char *line, size_t len)
-{
- while (len) {
- unsigned char c = line[len - 1];
- if (!isspace(c))
- break;
- len--;
- }
-
- return len;
-}
-
-/*
- * Remove empty lines from the beginning and end
- * and also trailing spaces from every line.
- *
- * Turn multiple consecutive empty lines between paragraphs
- * into just one empty line.
- *
- * If the input has only empty lines and spaces,
- * no output will be produced.
- *
- * If last line does not have a newline at the end, one is added.
- *
- * Enable skip_comments to skip every line starting with comment
- * character.
- */
-void stripspace(struct strbuf *sb, int skip_comments)
-{
- int empties = 0;
- size_t i, j, len, newlen;
- char *eol;
-
- /* We may have to add a newline. */
- strbuf_grow(sb, 1);
-
- for (i = j = 0; i < sb->len; i += len, j += newlen) {
- eol = memchr(sb->buf + i, '\n', sb->len - i);
- len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
-
- if (skip_comments && len && sb->buf[i] == comment_line_char) {
- newlen = 0;
- continue;
- }
- newlen = cleanup(sb->buf + i, len);
-
- /* Not just an empty line? */
- if (newlen) {
- if (empties > 0 && j > 0)
- sb->buf[j++] = '\n';
- empties = 0;
- memmove(sb->buf + j, sb->buf + i, newlen);
- sb->buf[newlen + j++] = '\n';
- } else {
- empties++;
- }
- }
-
- strbuf_setlen(sb, j);
-}
+#include "parse-options.h"
+#include "strbuf.h"
static void comment_lines(struct strbuf *buf)
{
@@ -77,41 +13,45 @@ static void comment_lines(struct strbuf *buf)
free(msg);
}
-static const char *usage_msg = "\n"
-" git stripspace [-s | --strip-comments]\n"
-" git stripspace [-c | --comment-lines]";
+static const char * const stripspace_usage[] = {
+ N_("git stripspace [-s | --strip-comments]"),
+ N_("git stripspace [-c | --comment-lines]"),
+ NULL
+};
+
+enum stripspace_mode {
+ STRIP_DEFAULT = 0,
+ STRIP_COMMENTS,
+ COMMENT_LINES
+};
int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
- int strip_comments = 0;
- enum { INVAL = 0, STRIP_SPACE = 1, COMMENT_LINES = 2 } mode = STRIP_SPACE;
-
- if (argc == 2) {
- if (!strcmp(argv[1], "-s") ||
- !strcmp(argv[1], "--strip-comments")) {
- strip_comments = 1;
- } else if (!strcmp(argv[1], "-c") ||
- !strcmp(argv[1], "--comment-lines")) {
- mode = COMMENT_LINES;
- } else {
- mode = INVAL;
- }
- } else if (argc > 1) {
- mode = INVAL;
- }
-
- if (mode == INVAL)
- usage(usage_msg);
-
- if (strip_comments || mode == COMMENT_LINES)
+ enum stripspace_mode mode = STRIP_DEFAULT;
+
+ const struct option options[] = {
+ OPT_CMDMODE('s', "strip-comments", &mode,
+ N_("skip and remove all lines starting with comment character"),
+ STRIP_COMMENTS),
+ OPT_CMDMODE('c', "comment-lines", &mode,
+ N_("prepend comment character and blank to each line"),
+ COMMENT_LINES),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, prefix, options, stripspace_usage, 0);
+ if (argc)
+ usage_with_options(stripspace_usage, options);
+
+ if (mode == STRIP_COMMENTS || mode == COMMENT_LINES)
git_config(git_default_config, NULL);
if (strbuf_read(&buf, 0, 1024) < 0)
die_errno("could not read the input");
- if (mode == STRIP_SPACE)
- stripspace(&buf, strip_comments);
+ if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS)
+ strbuf_stripspace(&buf, mode == STRIP_COMMENTS);
else
comment_lines(&buf);
diff --git a/builtin/tag.c b/builtin/tag.c
index cba0e22..f048cae 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -498,7 +498,7 @@ static void create_tag(const unsigned char *object, const char *tag,
}
if (opt->cleanup_mode != CLEANUP_NONE)
- stripspace(buf, opt->cleanup_mode == CLEANUP_ALL);
+ strbuf_stripspace(buf, opt->cleanup_mode == CLEANUP_ALL);
if (!opt->message_given && !buf->len)
die(_("no tag message?"));