summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/add.c30
-rw-r--r--builtin/am.c105
-rw-r--r--builtin/apply.c2
-rw-r--r--builtin/archive.c23
-rw-r--r--builtin/bisect--helper.c2
-rw-r--r--builtin/blame.c17
-rw-r--r--builtin/branch.c54
-rw-r--r--builtin/bundle.c7
-rw-r--r--builtin/cat-file.c147
-rw-r--r--builtin/check-attr.c7
-rw-r--r--builtin/checkout-index.c11
-rw-r--r--builtin/checkout.c138
-rw-r--r--builtin/clean.c3
-rw-r--r--builtin/clone.c57
-rw-r--r--builtin/commit-graph.c111
-rw-r--r--builtin/commit-tree.c4
-rw-r--r--builtin/commit.c63
-rw-r--r--builtin/config.c74
-rw-r--r--builtin/count-objects.c6
-rw-r--r--builtin/describe.c29
-rw-r--r--builtin/diff-files.c2
-rw-r--r--builtin/diff-index.c2
-rw-r--r--builtin/diff-tree.c19
-rw-r--r--builtin/diff.c13
-rw-r--r--builtin/difftool.c18
-rw-r--r--builtin/fast-export.c248
-rw-r--r--builtin/fetch-pack.c25
-rw-r--r--builtin/fetch.c326
-rw-r--r--builtin/fmt-merge-msg.c37
-rw-r--r--builtin/fsck.c295
-rw-r--r--builtin/gc.c71
-rw-r--r--builtin/grep.c172
-rw-r--r--builtin/hash-object.c2
-rw-r--r--builtin/help.c36
-rw-r--r--builtin/index-pack.c87
-rw-r--r--builtin/init-db.c10
-rw-r--r--builtin/interpret-trailers.c3
-rw-r--r--builtin/log.c219
-rw-r--r--builtin/ls-files.c45
-rw-r--r--builtin/ls-remote.c15
-rw-r--r--builtin/ls-tree.c5
-rw-r--r--builtin/merge-base.c87
-rw-r--r--builtin/merge-file.c2
-rw-r--r--builtin/merge-ours.c2
-rw-r--r--builtin/merge-recursive.c19
-rw-r--r--builtin/merge-tree.c30
-rw-r--r--builtin/merge.c103
-rw-r--r--builtin/mktree.c2
-rw-r--r--builtin/multi-pack-index.c49
-rw-r--r--builtin/name-rev.c13
-rw-r--r--builtin/notes.c16
-rw-r--r--builtin/pack-objects.c493
-rw-r--r--builtin/pack-redundant.c4
-rw-r--r--builtin/prune-packed.c1
-rw-r--r--builtin/prune.c8
-rw-r--r--builtin/pull.c51
-rw-r--r--builtin/push.c19
-rw-r--r--builtin/range-diff.c101
-rw-r--r--builtin/read-tree.c9
-rw-r--r--builtin/rebase--helper.c88
-rw-r--r--builtin/rebase--interactive.c274
-rw-r--r--builtin/rebase.c1632
-rw-r--r--builtin/receive-pack.c92
-rw-r--r--builtin/reflog.c101
-rw-r--r--builtin/remote.c16
-rw-r--r--builtin/repack.c237
-rw-r--r--builtin/replace.c111
-rw-r--r--builtin/rerere.c23
-rw-r--r--builtin/reset.c26
-rw-r--r--builtin/rev-list.c25
-rw-r--r--builtin/rev-parse.c8
-rw-r--r--builtin/revert.c20
-rw-r--r--builtin/rm.c6
-rw-r--r--builtin/send-pack.c7
-rw-r--r--builtin/shortlog.c9
-rw-r--r--builtin/show-branch.c14
-rw-r--r--builtin/show-ref.c1
-rw-r--r--builtin/stripspace.c3
-rw-r--r--builtin/submodule--helper.c304
-rw-r--r--builtin/tag.c10
-rw-r--r--builtin/unpack-objects.c13
-rw-r--r--builtin/update-index.c77
-rw-r--r--builtin/update-ref.c25
-rw-r--r--builtin/upload-archive.c5
-rw-r--r--builtin/upload-pack.c2
-rw-r--r--builtin/verify-commit.c4
-rw-r--r--builtin/worktree.c166
-rw-r--r--builtin/write-tree.c5
88 files changed, 5051 insertions, 1802 deletions
diff --git a/builtin/add.c b/builtin/add.c
index 8a155dd41e..7c2a7c5a4d 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip)
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = active_cache[i];
- if (pathspec && !ce_path_match(ce, pathspec, NULL))
+ if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue;
if (chmod_cache_entry(ce, flip) < 0)
@@ -110,7 +110,7 @@ int add_files_to_cache(const char *prefix,
memset(&data, 0, sizeof(data));
data.flags = flags;
- init_revisions(&rev, prefix);
+ repo_init_revisions(the_repository, &rev, prefix);
setup_revisions(0, NULL, &rev, NULL);
if (pathspec)
copy_pathspec(&rev.prune_data, pathspec);
@@ -135,9 +135,9 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
continue; /* do not touch unmerged paths */
if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
continue; /* do not touch non blobs */
- if (pathspec && !ce_path_match(ce, pathspec, NULL))
+ if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
continue;
- retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
+ retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);
}
return retval;
@@ -155,7 +155,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
- if (dir_path_match(entry, pathspec, prefix, seen))
+ if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
*dst++ = entry;
}
dir->nr = dst - dir->entries;
@@ -176,7 +176,7 @@ static void refresh(int verbose, const struct pathspec *pathspec)
die(_("pathspec '%s' did not match any files"),
pathspec->items[i].match);
}
- free(seen);
+ free(seen);
}
int run_add_interactive(const char *revision, const char *patch_mode,
@@ -232,14 +232,14 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
if (read_cache() < 0)
die(_("Could not read the index"));
- init_revisions(&rev, prefix);
+ repo_init_revisions(the_repository, &rev, prefix);
rev.diffopt.context = 7;
argc = setup_revisions(argc, argv, &rev, NULL);
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
rev.diffopt.use_color = 0;
rev.diffopt.flags.ignore_dirty_submodules = 1;
- out = open(file, O_CREAT | O_WRONLY, 0666);
+ out = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (out < 0)
die(_("Could not open '%s' for writing."), file);
rev.diffopt.file = xfdopen(out, "w");
@@ -304,7 +304,8 @@ static struct option builtin_add_options[] = {
OPT_BOOL( 0 , "refresh", &refresh_only, N_("don't add, only refresh the index")),
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
- OPT_STRING( 0 , "chmod", &chmod_arg, N_("(+/-)x"), N_("override the executable bit of the listed files")),
+ OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
+ N_("override the executable bit of the listed files")),
OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
N_("warn when adding an embedded repository")),
OPT_END(),
@@ -444,20 +445,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
return 0;
}
- if (read_cache() < 0)
- die(_("index file corrupt"));
-
- die_in_unpopulated_submodule(&the_index, prefix);
-
/*
* Check the "pathspec '%s' did not match any files" block
* below before enabling new magic.
*/
- parse_pathspec(&pathspec, 0,
+ parse_pathspec(&pathspec, PATHSPEC_ATTR,
PATHSPEC_PREFER_FULL |
PATHSPEC_SYMLINK_LEADING_PATH,
prefix, argv);
+ if (read_cache_preload(&pathspec) < 0)
+ die(_("index file corrupt"));
+
+ die_in_unpopulated_submodule(&the_index, prefix);
die_path_inside_submodule(&the_index, &pathspec);
if (add_new_files) {
diff --git a/builtin/am.c b/builtin/am.c
index 6273ea5195..95370313b6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -32,6 +32,7 @@
#include "apply.h"
#include "string-list.h"
#include "packfile.h"
+#include "repository.h"
/**
* Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -260,32 +261,6 @@ static int read_state_file(struct strbuf *sb, const struct am_state *state,
}
/**
- * Take a series of KEY='VALUE' lines where VALUE part is
- * sq-quoted, and append <KEY, VALUE> at the end of the string list
- */
-static int parse_key_value_squoted(char *buf, struct string_list *list)
-{
- while (*buf) {
- struct string_list_item *item;
- char *np;
- char *cp = strchr(buf, '=');
- if (!cp)
- return -1;
- np = strchrnul(cp, '\n');
- *cp++ = '\0';
- item = string_list_append(list, buf);
-
- buf = np + (*np == '\n');
- *np = '\0';
- cp = sq_dequote(cp);
- if (!cp)
- return -1;
- item->util = xstrdup(cp);
- }
- return 0;
-}
-
-/**
* Reads and parses the state directory's "author-script" file, and sets
* state->author_name, state->author_email and state->author_date accordingly.
* Returns 0 on success, -1 if the file could not be parsed.
@@ -301,42 +276,16 @@ static int parse_key_value_squoted(char *buf, struct string_list *list)
* script, and thus if the file differs from what this function expects, it is
* better to bail out than to do something that the user does not expect.
*/
-static int read_author_script(struct am_state *state)
+static int read_am_author_script(struct am_state *state)
{
const char *filename = am_path(state, "author-script");
- struct strbuf buf = STRBUF_INIT;
- struct string_list kv = STRING_LIST_INIT_DUP;
- int retval = -1; /* assume failure */
- int fd;
assert(!state->author_name);
assert(!state->author_email);
assert(!state->author_date);
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- if (errno == ENOENT)
- return 0;
- die_errno(_("could not open '%s' for reading"), filename);
- }
- strbuf_read(&buf, fd, 0);
- close(fd);
- if (parse_key_value_squoted(buf.buf, &kv))
- goto finish;
-
- if (kv.nr != 3 ||
- strcmp(kv.items[0].string, "GIT_AUTHOR_NAME") ||
- strcmp(kv.items[1].string, "GIT_AUTHOR_EMAIL") ||
- strcmp(kv.items[2].string, "GIT_AUTHOR_DATE"))
- goto finish;
- state->author_name = kv.items[0].util;
- state->author_email = kv.items[1].util;
- state->author_date = kv.items[2].util;
- retval = 0;
-finish:
- string_list_clear(&kv, !!retval);
- strbuf_release(&buf);
- return retval;
+ return read_author_script(filename, &state->author_name,
+ &state->author_email, &state->author_date, 1);
}
/**
@@ -410,7 +359,7 @@ static void am_load(struct am_state *state)
BUG("state file 'last' does not exist");
state->last = strtol(sb.buf, NULL, 10);
- if (read_author_script(state) < 0)
+ if (read_am_author_script(state) < 0)
die(_("could not parse author script"));
read_commit_msg(state);
@@ -1243,6 +1192,10 @@ static int parse_mail(struct am_state *state, const char *mail)
fclose(mi.input);
fclose(mi.output);
+ if (mi.format_flowed)
+ warning(_("Patch sent with format=flowed; "
+ "space at the end of lines might be lost."));
+
/* Extract message and author information */
fp = xfopen(am_path(state, "info"), "r");
while (!strbuf_getline_lf(&sb, fp)) {
@@ -1371,7 +1324,7 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
FILE *fp;
fp = xfopen(am_path(state, "patch"), "w");
- init_revisions(&rev_info, NULL);
+ repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diff = 1;
rev_info.abbrev = 0;
rev_info.disable_stdin = 1;
@@ -1400,12 +1353,13 @@ static void write_index_patch(const struct am_state *state)
FILE *fp;
if (!get_oid_tree("HEAD", &head))
- tree = lookup_tree(&head);
+ tree = lookup_tree(the_repository, &head);
else
- tree = lookup_tree(the_hash_algo->empty_tree);
+ tree = lookup_tree(the_repository,
+ the_repository->hash_algo->empty_tree);
fp = xfopen(am_path(state, "patch"), "w");
- init_revisions(&rev_info, NULL);
+ repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diff = 1;
rev_info.disable_stdin = 1;
rev_info.no_commit_id = 1;
@@ -1462,7 +1416,7 @@ static int run_apply(const struct am_state *state, const char *index_file)
int force_apply = 0;
int options = 0;
- if (init_apply_state(&apply_state, NULL))
+ if (init_apply_state(&apply_state, the_repository, NULL))
BUG("init_apply_state() failed");
argv_array_push(&apply_opts, "apply");
@@ -1563,7 +1517,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
struct rev_info rev_info;
const char *diff_filter_str = "--diff-filter=AM";
- init_revisions(&rev_info, NULL);
+ repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
@@ -1596,12 +1550,13 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
o.branch1 = "HEAD";
their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
o.branch2 = their_tree_name;
+ o.detect_directory_renames = 0;
if (state->quiet)
o.verbosity = 0;
if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
- rerere(state->allow_rerere_autoupdate);
+ repo_rerere(the_repository, state->allow_rerere_autoupdate);
free(their_tree_name);
return error(_("Failed to merge in the changes."));
}
@@ -1631,7 +1586,8 @@ static void do_commit(const struct am_state *state)
if (!get_oid_commit("HEAD", &parent)) {
old_oid = &parent;
- commit_list_insert(lookup_commit(&parent), &parents);
+ commit_list_insert(lookup_commit(the_repository, &parent),
+ &parents);
} else {
old_oid = NULL;
say(state, stderr, _("applying to an empty history"));
@@ -1763,7 +1719,7 @@ static void am_run(struct am_state *state, int resume)
refresh_and_write_cache();
- if (index_has_changes(&sb)) {
+ if (index_has_changes(&the_index, NULL, &sb)) {
write_state_bool(state, "dirtyindex", 1);
die(_("Dirty index: cannot apply patches (dirty: %s)"), sb.buf);
}
@@ -1820,7 +1776,8 @@ static void am_run(struct am_state *state, int resume)
* Applying the patch to an earlier tree and merging
* the result may have produced the same tree as ours.
*/
- if (!apply_status && !index_has_changes(NULL)) {
+ if (!apply_status &&
+ !index_has_changes(&the_index, NULL, NULL)) {
say(state, stdout, _("No changes -- Patch already applied."));
goto next;
}
@@ -1874,7 +1831,7 @@ static void am_resolve(struct am_state *state)
say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
- if (!index_has_changes(NULL)) {
+ if (!index_has_changes(&the_index, NULL, NULL)) {
printf_ln(_("No changes - did you forget to use 'git add'?\n"
"If there is nothing left to stage, chances are that something else\n"
"already introduced the same changes; you might want to skip this patch."));
@@ -1894,7 +1851,7 @@ static void am_resolve(struct am_state *state)
goto next;
}
- rerere(0);
+ repo_rerere(the_repository, 0);
do_commit(state);
@@ -2013,7 +1970,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (merge_tree(remote_tree))
return -1;
- remove_branch_state();
+ remove_branch_state(the_repository);
return 0;
}
@@ -2024,7 +1981,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
static void am_rerere_clear(void)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
- rerere_clear(&merge_rr);
+ rerere_clear(the_repository, &merge_rr);
string_list_clear(&merge_rr, 1);
}
@@ -2073