summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/add.c68
-rw-r--r--builtin/am.c362
-rw-r--r--builtin/apply.c4861
-rw-r--r--builtin/archive.c10
-rw-r--r--builtin/blame.c2165
-rw-r--r--builtin/branch.c374
-rw-r--r--builtin/bundle.c8
-rw-r--r--builtin/cat-file.c197
-rw-r--r--builtin/check-attr.c67
-rw-r--r--builtin/check-ignore.c10
-rw-r--r--builtin/check-mailmap.c1
-rw-r--r--builtin/checkout-index.c5
-rw-r--r--builtin/checkout.c135
-rw-r--r--builtin/clean.c79
-rw-r--r--builtin/clone.c223
-rw-r--r--builtin/column.c1
-rw-r--r--builtin/commit-tree.c21
-rw-r--r--builtin/commit.c210
-rw-r--r--builtin/config.c62
-rw-r--r--builtin/count-objects.c17
-rw-r--r--builtin/credential.c4
-rw-r--r--builtin/describe.c166
-rw-r--r--builtin/diff-files.c6
-rw-r--r--builtin/diff-index.c6
-rw-r--r--builtin/diff-tree.c93
-rw-r--r--builtin/diff.c131
-rw-r--r--builtin/difftool.c749
-rw-r--r--builtin/fast-export.c77
-rw-r--r--builtin/fetch-pack.c36
-rw-r--r--builtin/fetch.c118
-rw-r--r--builtin/fmt-merge-msg.c81
-rw-r--r--builtin/for-each-ref.c11
-rw-r--r--builtin/fsck.c219
-rw-r--r--builtin/gc.c102
-rw-r--r--builtin/grep.c543
-rw-r--r--builtin/hash-object.c20
-rw-r--r--builtin/help.c31
-rw-r--r--builtin/index-pack.c142
-rw-r--r--builtin/init-db.c116
-rw-r--r--builtin/log.c113
-rw-r--r--builtin/ls-files.c364
-rw-r--r--builtin/ls-remote.c10
-rw-r--r--builtin/ls-tree.c23
-rw-r--r--builtin/mailinfo.c12
-rw-r--r--builtin/mailsplit.c10
-rw-r--r--builtin/merge-base.c33
-rw-r--r--builtin/merge-file.c19
-rw-r--r--builtin/merge-index.c4
-rw-r--r--builtin/merge-recursive.c19
-rw-r--r--builtin/merge-tree.c10
-rw-r--r--builtin/merge.c230
-rw-r--r--builtin/mktree.c7
-rw-r--r--builtin/mv.c53
-rw-r--r--builtin/name-rev.c189
-rw-r--r--builtin/notes.c234
-rw-r--r--builtin/pack-objects.c485
-rw-r--r--builtin/pack-redundant.c1
-rw-r--r--builtin/pack-refs.c2
-rw-r--r--builtin/patch-id.c3
-rw-r--r--builtin/prune-packed.c4
-rw-r--r--builtin/prune.c19
-rw-r--r--builtin/pull.c194
-rw-r--r--builtin/push.c19
-rw-r--r--builtin/read-tree.c75
-rw-r--r--builtin/rebase--helper.c41
-rw-r--r--builtin/receive-pack.c408
-rw-r--r--builtin/reflog.c63
-rw-r--r--builtin/remote-ext.c9
-rw-r--r--builtin/remote-fd.c5
-rw-r--r--builtin/remote.c37
-rw-r--r--builtin/repack.c15
-rw-r--r--builtin/replace.c148
-rw-r--r--builtin/rerere.c1
-rw-r--r--builtin/reset.c79
-rw-r--r--builtin/rev-list.c86
-rw-r--r--builtin/rev-parse.c283
-rw-r--r--builtin/revert.c68
-rw-r--r--builtin/rm.c106
-rw-r--r--builtin/send-pack.c10
-rw-r--r--builtin/shortlog.c21
-rw-r--r--builtin/show-branch.c100
-rw-r--r--builtin/show-ref.c49
-rw-r--r--builtin/stripspace.c5
-rw-r--r--builtin/submodule--helper.c413
-rw-r--r--builtin/symbolic-ref.c3
-rw-r--r--builtin/tag.c207
-rw-r--r--builtin/unpack-file.c1
-rw-r--r--builtin/unpack-objects.c76
-rw-r--r--builtin/update-index.c114
-rw-r--r--builtin/update-ref.c3
-rw-r--r--builtin/update-server-info.c1
-rw-r--r--builtin/upload-archive.c11
-rw-r--r--builtin/var.c1
-rw-r--r--builtin/verify-commit.c13
-rw-r--r--builtin/verify-pack.c1
-rw-r--r--builtin/verify-tag.c23
-rw-r--r--builtin/worktree.c59
-rw-r--r--builtin/write-tree.c1
98 files changed, 6052 insertions, 10068 deletions
diff --git a/builtin/add.c b/builtin/add.c
index e8fb80b36e..e888fb8c5f 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -4,6 +4,7 @@
* Copyright (C) 2006 Linus Torvalds
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "lockfile.h"
#include "dir.h"
@@ -17,6 +18,7 @@
#include "revision.h"
#include "bulk-checkin.h"
#include "argv-array.h"
+#include "submodule.h"
static const char * const builtin_add_usage[] = {
N_("git add [<options>] [--] <pathspec>..."),
@@ -135,7 +137,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
*dst++ = entry;
}
dir->nr = dst - dir->entries;
- add_pathspec_matches_against_index(pathspec, seen);
+ add_pathspec_matches_against_index(pathspec, &the_index, seen);
return seen;
}
@@ -248,6 +250,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
static int verbose, show_only, ignored_too, refresh_only;
static int ignore_add_errors, intent_to_add, ignore_missing;
+static int warn_on_embedded_repo = 1;
#define ADDREMOVE_DEFAULT 1
static int addremove = ADDREMOVE_DEFAULT;
@@ -281,6 +284,8 @@ static struct option builtin_add_options[] = {
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_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
+ N_("warn when adding an embedded repository")),
OPT_END(),
};
@@ -294,6 +299,45 @@ static int add_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb);
}
+static const char embedded_advice[] = N_(
+"You've added another git repository inside your current repository.\n"
+"Clones of the outer repository will not contain the contents of\n"
+"the embedded repository and will not know how to obtain it.\n"
+"If you meant to add a submodule, use:\n"
+"\n"
+" git submodule add <url> %s\n"
+"\n"
+"If you added this path by mistake, you can remove it from the\n"
+"index with:\n"
+"\n"
+" git rm --cached %s\n"
+"\n"
+"See \"git help submodule\" for more information."
+);
+
+static void check_embedded_repo(const char *path)
+{
+ struct strbuf name = STRBUF_INIT;
+
+ if (!warn_on_embedded_repo)
+ return;
+ if (!ends_with(path, "/"))
+ return;
+
+ /* Drop trailing slash for aesthetics */
+ strbuf_addstr(&name, path);
+ strbuf_strip_suffix(&name, "/");
+
+ warning(_("adding embedded git repository: %s"), name.buf);
+ if (advice_add_embedded_repo) {
+ advise(embedded_advice, name.buf, name.buf);
+ /* there may be multiple entries; advise only once */
+ advice_add_embedded_repo = 0;
+ }
+
+ strbuf_release(&name);
+}
+
static int add_files(struct dir_struct *dir, int flags)
{
int i, exit_status = 0;
@@ -306,12 +350,14 @@ static int add_files(struct dir_struct *dir, int flags)
exit_status = 1;
}
- for (i = 0; i < dir->nr; i++)
+ for (i = 0; i < dir->nr; i++) {
+ check_embedded_repo(dir->entries[i]->name);
if (add_file_to_index(&the_index, dir->entries[i]->name, flags)) {
if (!ignore_add_errors)
die(_("adding files failed"));
exit_status = 1;
}
+ }
return exit_status;
}
@@ -361,7 +407,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
add_new_files = !take_worktree_changes && !refresh_only;
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
- hold_locked_index(&lock_file, 1);
+ hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
(show_only ? ADD_CACHE_PRETEND : 0) |
@@ -379,16 +425,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
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,
PATHSPEC_PREFER_FULL |
- PATHSPEC_SYMLINK_LEADING_PATH |
- PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE,
+ PATHSPEC_SYMLINK_LEADING_PATH,
prefix, argv);
+ die_path_inside_submodule(&the_index, &pathspec);
+
if (add_new_files) {
int baselen;
@@ -400,7 +449,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
/* This picks up the paths that are not tracked */
- baselen = fill_directory(&dir, &pathspec);
+ baselen = fill_directory(&dir, &the_index, &pathspec);
if (pathspec.nr)
seen = prune_directory(&dir, &pathspec, baselen);
}
@@ -414,7 +463,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
int i;
if (!seen)
- seen = find_pathspecs_matching_against_index(&pathspec);
+ seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
/*
* file_exists() assumes exact match
@@ -436,8 +485,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
!file_exists(path))) {
if (ignore_missing) {
int dtype = DT_UNKNOWN;
- if (is_excluded(&dir, path, &dtype))
- dir_add_ignored(&dir, path, pathspec.items[i].len);
+ if (is_excluded(&dir, &the_index, path, &dtype))
+ dir_add_ignored(&dir, &the_index,
+ path, pathspec.items[i].len);
} else
die(_("pathspec '%s' did not match any files"),
pathspec.items[i].original);
diff --git a/builtin/am.c b/builtin/am.c
index 9daeb27225..c973bd96dc 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -4,6 +4,7 @@
* Based on git-am.sh by Junio C Hamano.
*/
#include "cache.h"
+#include "config.h"
#include "builtin.h"
#include "exec_cmd.h"
#include "parse-options.h"
@@ -28,6 +29,7 @@
#include "rerere.h"
#include "prompt.h"
#include "mailinfo.h"
+#include "apply.h"
#include "string-list.h"
/**
@@ -109,7 +111,7 @@ struct am_state {
size_t msg_len;
/* when --rebasing, records the original commit the patch came from */
- unsigned char orig_commit[GIT_SHA1_RAWSZ];
+ struct object_id orig_commit;
/* number of digits in patch filename */
int prec;
@@ -133,17 +135,15 @@ struct am_state {
};
/**
- * Initializes am_state with the default values. The state directory is set to
- * dir.
+ * Initializes am_state with the default values.
*/
-static void am_state_init(struct am_state *state, const char *dir)
+static void am_state_init(struct am_state *state)
{
int gpgsign;
memset(state, 0, sizeof(*state));
- assert(dir);
- state->dir = xstrdup(dir);
+ state->dir = git_pathdup("rebase-apply");
state->prec = 4;
@@ -415,8 +415,8 @@ static void am_load(struct am_state *state)
read_commit_msg(state);
if (read_state_file(&sb, state, "original-commit", 1) < 0)
- hashclr(state->orig_commit);
- else if (get_sha1_hex(sb.buf, state->orig_commit) < 0)
+ oidclr(&state->orig_commit);
+ else if (get_oid_hex(sb.buf, &state->orig_commit) < 0)
die(_("could not parse %s"), am_path(state, "original-commit"));
read_state_file(&sb, state, "threeway", 1);
@@ -484,8 +484,7 @@ static int run_applypatch_msg_hook(struct am_state *state)
ret = run_hook_le(NULL, "applypatch-msg", am_path(state, "final-commit"), NULL);
if (!ret) {
- free(state->msg);
- state->msg = NULL;
+ FREE_AND_NULL(state->msg);
if (read_commit_msg(state) < 0)
die(_("'%s' was deleted by the applypatch-msg hook"),
am_path(state, "final-commit"));
@@ -542,14 +541,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
fp = xfopen(am_path(state, "rewritten"), "r");
while (!strbuf_getline_lf(&sb, fp)) {
- unsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ];
+ struct object_id from_obj, to_obj;
if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
ret = error(invalid_line, sb.buf);
goto finish;
}
- if (get_sha1_hex(sb.buf, from_obj)) {
+ if (get_oid_hex(sb.buf, &from_obj)) {
ret = error(invalid_line, sb.buf);
goto finish;
}
@@ -559,14 +558,14 @@ static int copy_notes_for_rebase(const struct am_state *state)
goto finish;
}
- if (get_sha1_hex(sb.buf + GIT_SHA1_HEXSZ + 1, to_obj)) {
+ if (get_oid_hex(sb.buf + GIT_SHA1_HEXSZ + 1, &to_obj)) {
ret = error(invalid_line, sb.buf);
goto finish;
}
- if (copy_note_for_rewrite(c, from_obj, to_obj))
+ if (copy_note_for_rewrite(c, &from_obj, &to_obj))
ret = error(_("Failed to copy notes from '%s' to '%s'"),
- sha1_to_hex(from_obj), sha1_to_hex(to_obj));
+ oid_to_hex(&from_obj), oid_to_hex(&to_obj));
}
finish:
@@ -761,14 +760,18 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,
mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
out = fopen(mail, "w");
- if (!out)
+ if (!ou