Merge branch 'kh/commit' into wc/add-i
authorJunio C Hamano <gitster@pobox.com>
Sun, 25 Nov 2007 16:46:29 +0000 (08:46 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 Nov 2007 16:46:29 +0000 (08:46 -0800)
This is to use a few functions refactored to use in the built-in
commit series.

* kh/commit: (28 commits)
Add a few more tests for git-commit
builtin-commit: Include the diff in the commit message when verbose.
builtin-commit: fix partial-commit support
Fix add_files_to_cache() to take pathspec, not user specified list of files
Export three helper functions from ls-files
builtin-commit: run commit-msg hook with correct message file
builtin-commit: do not color status output shown in the message template
file_exists(): dangling symlinks do exist
Replace "runstatus" with "status" in the tests
t7501-commit: Add test for git commit <file> with dirty index.
builtin-commit: Clean up an unused variable and a debug fprintf().
Call refresh_cache() when updating the user index for --only commits.
builtin-commit: Add newline when showing which commit was created
builtin-commit: resurrect behavior for multiple -m options
builtin-commit --s: add a newline if the last line was not a S-o-b
builtin-commit: fix --signoff
git status: show relative paths when run in a subdirectory
builtin-commit: Refresh cache after adding files.
builtin-commit: fix reflog message generation
launch_editor(): read the file, even when EDITOR=:
...

builtin-add.c
builtin-commit.c
commit.h
git-add--interactive.perl
index 03508d3dcb18d161f799001067d5caf3e54fa160..dd895dfb1d35f7e90d6529821e284d73e912d6d6 100644 (file)
@@ -135,11 +135,17 @@ static void refresh(int verbose, const char **pathspec)
         free(seen);
 }
 
-int interactive_add(void)
+int interactive_add(int argc, const char **argv)
 {
-       const char *argv[2] = { "add--interactive", NULL };
-
-       return run_command_v_opt(argv, RUN_GIT_CMD);
+       int status;
+       const char **args = xmalloc(sizeof(const char *) * (argc + 1));
+       args[0] = "add--interactive";
+       memcpy((void *)args + sizeof(const char *), argv, sizeof(const char *) * argc);
+       args[argc + 1] = NULL;
+
+       status = run_command_v_opt(args, RUN_GIT_CMD);
+       free(args);
+       return status;
 }
 
 static struct lock_file lock_file;
@@ -163,17 +169,14 @@ static struct option builtin_add_options[] = {
 
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
-       int i, newfd, orig_argc = argc;
+       int i, newfd;
        const char **pathspec;
        struct dir_struct dir;
 
        argc = parse_options(argc, argv, builtin_add_options,
                          builtin_add_usage, 0);
-       if (add_interactive) {
-               if (add_interactive != 1 || orig_argc != 2)
-                       die("add --interactive does not take any parameters");
-               exit(interactive_add());
-       }
+       if (add_interactive)
+               exit(interactive_add(argc, argv));
 
        git_config(git_default_config);
 
index 4de316a366d1ee7201d89b776a4a9a4b499d32b8..5d27102a624446030b5b048fa582544def395f21 100644 (file)
@@ -157,7 +157,7 @@ static void add_remove_files(struct path_list *list)
        }
 }
 
-static char *prepare_index(const char **files, const char *prefix)
+static char *prepare_index(int argc, const char **argv, const char *prefix)
 {
        int fd;
        struct tree *tree;
@@ -165,7 +165,7 @@ static char *prepare_index(const char **files, const char *prefix)
        const char **pathspec = NULL;
 
        if (interactive) {
-               interactive_add();
+               interactive_add(argc, argv);
                commit_style = COMMIT_AS_IS;
                return get_index_file();
        }
@@ -173,8 +173,8 @@ static char *prepare_index(const char **files, const char *prefix)
        if (read_cache() < 0)
                die("index file corrupt");
 
-       if (*files)
-               pathspec = get_pathspec(prefix, files);
+       if (*argv)
+               pathspec = get_pathspec(prefix, argv);
 
        /*
         * Non partial, non as-is commit.
@@ -578,7 +578,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        argc = parse_and_validate_options(argc, argv);
 
-       index_file = prepare_index(argv, prefix);
+       index_file = prepare_index(argc, argv, prefix);
 
        commitable = run_status(stdout, index_file, prefix);
 
@@ -670,7 +670,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        argc = parse_and_validate_options(argc, argv);
 
-       index_file = prepare_index(argv, prefix);
+       index_file = prepare_index(argc, argv, prefix);
 
        if (!no_verify && run_hook(index_file, "pre-commit", NULL)) {
                rollback_index_files();
index f450aae8aa38cfc96bce8a55e418a090c44c216d..9f0765bd9c30672dc93b4c3fc0eff816d1b3729b 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -113,7 +113,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 
 int in_merge_bases(struct commit *, struct commit **, int);
 
-extern int interactive_add(void);
+extern int interactive_add(int argc, const char **argv);
 extern int rerere(void);
 
 static inline int single_parent(struct commit *commit)
index fb1e92a7664f77aa5ca4ca30b4711bafaf155466..e3472165503a98572769ac8b28caef39d2f3d6b4 100755 (executable)
@@ -37,7 +37,7 @@ sub list_untracked {
                chomp $_;
                $_;
        }
-       run_cmd_pipe(qw(git ls-files --others --exclude-standard --), @_);
+       run_cmd_pipe(qw(git ls-files --others --exclude-standard --), @ARGV);
 }
 
 my $status_fmt = '%12s %12s %s';
@@ -56,9 +56,17 @@ sub list_modified {
        my ($only) = @_;
        my (%data, @return);
        my ($add, $del, $adddel, $file);
+       my @tracked = ();
+
+       if (@ARGV) {
+               @tracked = map {
+                       chomp $_; $_;
+               } run_cmd_pipe(qw(git ls-files --exclude-standard --), @ARGV);
+               return if (!@tracked);
+       }
 
        for (run_cmd_pipe(qw(git diff-index --cached
-                            --numstat --summary HEAD))) {
+                            --numstat --summary HEAD --), @tracked)) {
                if (($add, $del, $file) =
                    /^([-\d]+)  ([-\d]+)        (.*)/) {
                        my ($change, $bin);
@@ -81,7 +89,7 @@ sub list_modified {
                }
        }
 
-       for (run_cmd_pipe(qw(git diff-files --numstat --summary))) {
+       for (run_cmd_pipe(qw(git diff-files --numstat --summary --), @tracked)) {
                if (($add, $del, $file) =
                    /^([-\d]+)  ([-\d]+)        (.*)/) {
                        if (!exists $data{$file}) {
@@ -252,7 +260,7 @@ sub list_and_choose {
                                $chosen[$i] = $choose;
                        }
                }
-               last if ($opts->{IMMEDIATE});
+               last if ($opts->{IMMEDIATE} || $line eq '*');
        }
        for ($i = 0; $i < @stuff; $i++) {
                if ($chosen[$i]) {
@@ -559,12 +567,12 @@ sub patch_update_cmd {
        @mods = grep { !($_->{BINARY}) } @mods;
        return if (!@mods);
 
-       my ($it) = list_and_choose({ PROMPT => 'Patch update',
-                                    SINGLETON => 1,
-                                    IMMEDIATE => 1,
-                                    HEADER => $status_head, },
-                                  @mods);
-       patch_update_file($it->{VALUE}) if ($it);
+       my (@them) = list_and_choose({ PROMPT => 'Patch update',
+                                      HEADER => $status_head, },
+                                    @mods);
+       for (@them) {
+               patch_update_file($_->{VALUE});
+       }
 }
 
 sub patch_update_file {