]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-commit.c
t7502-commit.sh: rearrange test to make more portable
[git.git] / builtin-commit.c
index a33f43a209efc2abef209b10b55fa2fce1c7ce18..97e64de31228c254f0fe073494dd1f823070bf8e 100644 (file)
 #include "strbuf.h"
 #include "utf8.h"
 #include "parse-options.h"
-#include "path-list.h"
+#include "string-list.h"
+#include "rerere.h"
 #include "unpack-trees.h"
 
 static const char * const builtin_commit_usage[] = {
-       "git-commit [options] [--] <filepattern>...",
+       "git commit [options] [--] <filepattern>...",
        NULL
 };
 
 static const char * const builtin_status_usage[] = {
-       "git-status [options] [--] <filepattern>...",
+       "git status [options] [--] <filepattern>...",
        NULL
 };
 
@@ -45,11 +46,13 @@ static enum {
        COMMIT_PARTIAL,
 } commit_style;
 
-static char *logfile, *force_author, *template_file;
+static char *logfile, *force_author;
+static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, untracked_files, no_verify, allow_empty;
+static int quiet, verbose, no_verify, allow_empty;
+static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
  * beginning with # (shell comments) and leading and trailing
@@ -102,7 +105,7 @@ static struct option builtin_commit_options[] = {
        OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
        OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
-       OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"),
+       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
        OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
        OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
 
@@ -147,7 +150,7 @@ static int commit_index_files(void)
  * Take a union of paths in the index and the named tree (typically, "HEAD"),
  * and return the paths that match the given pattern in list.
  */
-static int list_paths(struct path_list *list, const char *with_tree,
+static int list_paths(struct string_list *list, const char *with_tree,
                      const char *prefix, const char **pattern)
 {
        int i;
@@ -166,24 +169,24 @@ static int list_paths(struct path_list *list, const char *with_tree,
                        continue;
                if (!pathspec_match(pattern, m, ce->name, 0))
                        continue;
-               path_list_insert(ce->name, list);
+               string_list_insert(ce->name, list);
        }
 
        return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
 }
 
-static void add_remove_files(struct path_list *list)
+static void add_remove_files(struct string_list *list)
 {
        int i;
        for (i = 0; i < list->nr; i++) {
                struct stat st;
-               struct path_list_item *p = &(list->items[i]);
+               struct string_list_item *p = &(list->items[i]);
 
-               if (!lstat(p->path, &st)) {
-                       if (add_to_cache(p->path, &st, 0))
+               if (!lstat(p->string, &st)) {
+                       if (add_to_cache(p->string, &st, 0))
                                die("updating files failed");
                } else
-                       remove_file_from_cache(p->path);
+                       remove_file_from_cache(p->string);
        }
 }
 
@@ -218,7 +221,7 @@ static void create_base_index(void)
 static char *prepare_index(int argc, const char **argv, const char *prefix)
 {
        int fd;
-       struct path_list partial;
+       struct string_list partial;
        const char **pathspec = NULL;
 
        if (interactive) {
@@ -302,7 +305,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
                die("cannot do a partial commit during a merge.");
 
        memset(&partial, 0, sizeof(partial));
-       partial.strdup_paths = 1;
+       partial.strdup_strings = 1;
        if (list_paths(&partial, initial_commit ? NULL : "HEAD", prefix, pathspec))
                exit(1);
 
@@ -347,7 +350,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
                s.reference = "HEAD^1";
        }
        s.verbose = verbose;
-       s.untracked = untracked_files;
+       s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
        s.index_file = index_file;
        s.fp = fp;
        s.nowarn = nowarn;
@@ -796,6 +799,17 @@ static int parse_and_validate_options(int argc, const char *argv[],
        else
                die("Invalid cleanup mode %s", cleanup_arg);
 
+       if (!untracked_files_arg)
+               ; /* default already initialized */
+       else if (!strcmp(untracked_files_arg, "no"))
+               show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+       else if (!strcmp(untracked_files_arg, "normal"))
+               show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+       else if (!strcmp(untracked_files_arg, "all"))
+               show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+       else
+               die("Invalid untracked files mode '%s'", untracked_files_arg);
+
        if (all && argc > 0)
                die("Paths with -a does not make sense.");
        else if (interactive && argc > 0)
@@ -865,12 +879,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 
 int git_commit_config(const char *k, const char *v, void *cb)
 {
-       if (!strcmp(k, "commit.template")) {
-               if (!v)
-                       return config_error_nonbool(v);
-               template_file = xstrdup(v);
-               return 0;
-       }
+       if (!strcmp(k, "commit.template"))
+               return git_config_string(&template_file, k, v);
 
        return git_status_config(k, v, cb);
 }