summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/add.c31
-rw-r--r--builtin/am.c147
-rw-r--r--builtin/apply.c2
-rw-r--r--builtin/archive.c23
-rw-r--r--builtin/bisect--helper.c565
-rw-r--r--builtin/blame.c34
-rw-r--r--builtin/branch.c90
-rw-r--r--builtin/bundle.c6
-rw-r--r--builtin/cat-file.c166
-rw-r--r--builtin/check-attr.c8
-rw-r--r--builtin/check-ignore.c1
-rw-r--r--builtin/checkout-index.c12
-rw-r--r--builtin/checkout.c413
-rw-r--r--builtin/clean.c33
-rw-r--r--builtin/clone.c57
-rw-r--r--builtin/commit-graph.c111
-rw-r--r--builtin/commit-tree.c13
-rw-r--r--builtin/commit.c145
-rw-r--r--builtin/config.c101
-rw-r--r--builtin/count-objects.c6
-rw-r--r--builtin/describe.c50
-rw-r--r--builtin/diff-files.c3
-rw-r--r--builtin/diff-index.c3
-rw-r--r--builtin/diff-tree.c26
-rw-r--r--builtin/diff.c25
-rw-r--r--builtin/difftool.c20
-rw-r--r--builtin/fast-export.c259
-rw-r--r--builtin/fetch-pack.c25
-rw-r--r--builtin/fetch.c425
-rw-r--r--builtin/fmt-merge-msg.c38
-rw-r--r--builtin/fsck.c296
-rw-r--r--builtin/gc.c71
-rw-r--r--builtin/grep.c207
-rw-r--r--builtin/hash-object.c4
-rw-r--r--builtin/help.c52
-rw-r--r--builtin/index-pack.c89
-rw-r--r--builtin/init-db.c10
-rw-r--r--builtin/interpret-trailers.c3
-rw-r--r--builtin/log.c240
-rw-r--r--builtin/ls-files.c46
-rw-r--r--builtin/ls-remote.c15
-rw-r--r--builtin/ls-tree.c6
-rw-r--r--builtin/merge-base.c87
-rw-r--r--builtin/merge-file.c2
-rw-r--r--builtin/merge-index.c1
-rw-r--r--builtin/merge-ours.c3
-rw-r--r--builtin/merge-recursive.c21
-rw-r--r--builtin/merge-tree.c33
-rw-r--r--builtin/merge.c178
-rw-r--r--builtin/mktag.c1
-rw-r--r--builtin/mktree.c3
-rw-r--r--builtin/multi-pack-index.c49
-rw-r--r--builtin/mv.c1
-rw-r--r--builtin/name-rev.c36
-rw-r--r--builtin/notes.c38
-rw-r--r--builtin/pack-objects.c544
-rw-r--r--builtin/pack-redundant.c240
-rw-r--r--builtin/prune-packed.c6
-rw-r--r--builtin/prune.c51
-rw-r--r--builtin/pull.c58
-rw-r--r--builtin/push.c19
-rw-r--r--builtin/range-diff.c101
-rw-r--r--builtin/read-tree.c10
-rw-r--r--builtin/rebase--helper.c88
-rw-r--r--builtin/rebase--interactive.c275
-rw-r--r--builtin/rebase.c1822
-rw-r--r--builtin/receive-pack.c116
-rw-r--r--builtin/reflog.c102
-rw-r--r--builtin/remote.c17
-rw-r--r--builtin/repack.c237
-rw-r--r--builtin/replace.c113
-rw-r--r--builtin/rerere.c23
-rw-r--r--builtin/reset.c35
-rw-r--r--builtin/rev-list.c41
-rw-r--r--builtin/rev-parse.c15
-rw-r--r--builtin/revert.c20
-rw-r--r--builtin/rm.c7
-rw-r--r--builtin/send-pack.c9
-rw-r--r--builtin/shortlog.c9
-rw-r--r--builtin/show-branch.c58
-rw-r--r--builtin/show-index.c86
-rw-r--r--builtin/show-ref.c4
-rw-r--r--builtin/stripspace.c3
-rw-r--r--builtin/submodule--helper.c448
-rw-r--r--builtin/tag.c11
-rw-r--r--builtin/unpack-file.c1
-rw-r--r--builtin/unpack-objects.c14
-rw-r--r--builtin/update-index.c115
-rw-r--r--builtin/update-ref.c50
-rw-r--r--builtin/upload-archive.c5
-rw-r--r--builtin/upload-pack.c2
-rw-r--r--builtin/verify-commit.c5
-rw-r--r--builtin/worktree.c167
-rw-r--r--builtin/write-tree.c6
94 files changed, 6982 insertions, 2281 deletions
diff --git a/builtin/add.c b/builtin/add.c
index 8a155dd41e..db2dfa4350 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Linus Torvalds
*/
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
@@ -40,7 +41,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 +111,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 +136,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 +156,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 +177,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 +233,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 +305,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 +446,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 2fc2d1e82c..86e33495b0 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -3,6 +3,7 @@
*
* Based on git-am.sh by Junio C Hamano.
*/
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
@@ -32,22 +33,7 @@
#include "apply.h"
#include "string-list.h"
#include "packfile.h"
-
-/**
- * Returns 1 if the file is empty or does not exist, 0 otherwise.
- */
-static int is_empty_file(const char *filename)
-{
- struct stat st;
-
- if (stat(filename, &st) < 0) {
- if (errno == ENOENT)
- return 1;
- die_errno(_("could not stat %s"), filename);
- }
-
- return !st.st_size;
-}
+#include "repository.h"
/**
* Returns the length of the first line of msg.
@@ -260,32 +246,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 +261,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 +344,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);
@@ -519,6 +453,7 @@ static int run_post_rewrite_hook(const struct am_state *state)
cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
cp.stdout_to_stderr = 1;
+ cp.trace2_hook_name = "post-rewrite";
ret = run_command(&cp);
@@ -578,7 +513,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
}
finish:
- finish_copy_notes_for_rewrite(c, msg);
+ finish_copy_notes_for_rewrite(the_repository, c, msg);
fclose(fp);
strbuf_release(&sb);
return ret;
@@ -1243,6 +1178,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)) {
@@ -1267,7 +1206,7 @@ static int parse_mail(struct am_state *state, const char *mail)
goto finish;
}
- if (is_empty_file(am_path(state, "patch"))) {
+ if (is_empty_or_missing_file(am_path(state, "patch"))) {
printf_ln(_("Patch is empty."));
die_user_resolve(state);
}
@@ -1371,7 +1310,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 +1339,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 +1402,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(&