]> Pileus Git - ~andy/git/commitdiff
Merge branch 'jc/add-addremove'
authorJunio C Hamano <gitster@pobox.com>
Mon, 21 Jul 2008 00:53:17 +0000 (17:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Jul 2008 00:53:17 +0000 (17:53 -0700)
* jc/add-addremove:
  git-add --all: documentation
  git-add --all: tests
  git-add --all: add all files
  builtin-add.c: restructure the code for maintainability

Conflicts:
builtin-add.c

15 files changed:
Makefile
builtin-add.c
builtin-grep.c
builtin-merge.c
builtin-push.c
builtin-reset.c
cache.h
git-svn.perl
read-cache.c
t/t2103-update-index-ignore-missing.sh [new file with mode: 0755]
t/t7102-reset.sh
t/t7600-merge.sh
t/t9400-git-cvsserver-server.sh
wrapper.c
write_or_die.c

index 2b670d7845ba6993e2ce1ebc517e584e4975a8b4..551bde9ff0745e5da0bc6cfa3ab3cb915c73b298 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -324,6 +324,7 @@ endif
 export PERL_PATH
 
 LIB_FILE=libgit.a
+COMPAT_LIB = compat/lib.a
 XDIFF_LIB=xdiff/lib.a
 
 LIB_H += archive.h
@@ -1203,8 +1204,11 @@ git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
                $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
-git-shell$X: compat/strlcpy.o abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o
-       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^)
+$(COMPAT_LIB): $(COMPAT_OBJS)
+       $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(COMPAT_OBJS)
+
+git-shell$X: abspath.o ctype.o exec_cmd.o quote.o strbuf.o usage.o wrapper.o shell.o $(COMPAT_LIB)
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(COMPAT_LIB)
 
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
 $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
@@ -1402,7 +1406,7 @@ distclean: clean
 
 clean:
        $(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
-               $(LIB_FILE) $(XDIFF_LIB)
+               $(LIB_FILE) $(XDIFF_LIB) $(COMPAT_LIB)
        $(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X
        $(RM) $(TEST_PROGRAMS)
        $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
index 6f5672a6161e9fb1ad8db044e1c318f7594e9e10..fc3f96eaefff91e4e85adb92162716939f0ecd72 100644 (file)
@@ -140,7 +140,8 @@ static void refresh(int verbose, const char **pathspec)
        for (specs = 0; pathspec[specs];  specs++)
                /* nothing */;
        seen = xcalloc(specs, 1);
-       refresh_index(&the_index, verbose ? 0 : REFRESH_QUIET, pathspec, seen);
+       refresh_index(&the_index, verbose ? REFRESH_SAY_CHANGED : REFRESH_QUIET,
+                     pathspec, seen);
        for (i = 0; i < specs; i++) {
                if (!seen[i])
                        die("pathspec '%s' did not match any files", pathspec[i]);
index 7bf6a7156cdd8e236d451b9be4d4754c2c517e66..631129ddfd0ffe06f919882d22cfc494d9553f50 100644 (file)
@@ -498,7 +498,7 @@ static int grep_object(struct grep_opt *opt, const char **paths,
 }
 
 static const char builtin_grep_usage[] =
-"git grep <option>* <rev>* [-e] <pattern> [<path>...]";
+"git grep <option>* [-e] <pattern> <rev>* [[--] <path>...]";
 
 static const char emsg_invalid_context_len[] =
 "%s: invalid context length argument";
index 129b4e62dd3bc3662f8f076e39c90b109f4bd669..e97c79e60cdb8227ad682a3927ae955005cbe1f3 100644 (file)
@@ -50,11 +50,9 @@ static size_t use_strategies_nr, use_strategies_alloc;
 static const char *branch;
 
 static struct strategy all_strategy[] = {
-       { "recur",      NO_TRIVIAL },
        { "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
        { "octopus",    DEFAULT_OCTOPUS },
        { "resolve",    0 },
-       { "stupid",     0 },
        { "ours",       NO_FAST_FORWARD | NO_TRIVIAL },
        { "subtree",    NO_FAST_FORWARD | NO_TRIVIAL },
 };
@@ -68,10 +66,11 @@ static int option_parse_message(const struct option *opt,
 
        if (unset)
                strbuf_setlen(buf, 0);
-       else {
+       else if (arg) {
                strbuf_addf(buf, "%s\n\n", arg);
                have_message = 1;
-       }
+       } else
+               return error("switch `m' requires a value");
        return 0;
 }
 
index 03db28cc3614e83bb141a8d7de190308b3d81331..c1ed68d938f67343c6938cfef54d5ff69a522a63 100644 (file)
@@ -14,7 +14,7 @@ static const char * const push_usage[] = {
        NULL,
 };
 
-static int thin, verbose;
+static int thin;
 static const char *receivepack;
 
 static const char **refspec;
@@ -84,7 +84,7 @@ static int do_push(const char *repo, int flags)
                if (thin)
                        transport_set_option(transport, TRANS_OPT_THIN, "yes");
 
-               if (verbose)
+               if (flags & TRANSPORT_PUSH_VERBOSE)
                        fprintf(stderr, "Pushing to %s\n", remote->url[i]);
                err = transport_push(transport, refspec_nr, refspec, flags);
                err |= transport_disconnect(transport);
@@ -101,22 +101,19 @@ static int do_push(const char *repo, int flags)
 int cmd_push(int argc, const char **argv, const char *prefix)
 {
        int flags = 0;
-       int all = 0;
-       int mirror = 0;
-       int dry_run = 0;
-       int force = 0;
        int tags = 0;
        int rc;
        const char *repo = NULL;        /* default repository */
 
        struct option options[] = {
-               OPT__VERBOSE(&verbose),
+               OPT_BIT('v', "verbose", &flags, "be verbose", TRANSPORT_PUSH_VERBOSE),
                OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
-               OPT_BOOLEAN( 0 , "all", &all, "push all refs"),
-               OPT_BOOLEAN( 0 , "mirror", &mirror, "mirror all refs"),
+               OPT_BIT( 0 , "all", &flags, "push all refs", TRANSPORT_PUSH_ALL),
+               OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
+                           (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
                OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
-               OPT_BOOLEAN( 0 , "dry-run", &dry_run, "dry run"),
-               OPT_BOOLEAN('f', "force", &force, "force updates"),
+               OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
+               OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
                OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
                OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
                OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
@@ -125,18 +122,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 
        argc = parse_options(argc, argv, options, push_usage, 0);
 
-       if (force)
-               flags |= TRANSPORT_PUSH_FORCE;
-       if (dry_run)
-               flags |= TRANSPORT_PUSH_DRY_RUN;
-       if (verbose)
-               flags |= TRANSPORT_PUSH_VERBOSE;
        if (tags)
                add_refspec("refs/tags/*");
-       if (all)
-               flags |= TRANSPORT_PUSH_ALL;
-       if (mirror)
-               flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
 
        if (argc > 0) {
                repo = argv[0];
index 2e5a8867ac74fd1bc2ab8d5121baa7971b3b69d0..4d246c31b19381778848024ff49aebf3e77fdbbc 100644 (file)
@@ -96,7 +96,7 @@ static int update_index_refresh(int fd, struct lock_file *index_lock)
 
        if (read_cache() < 0)
                return error("Could not read index");
-       result = refresh_cache(0) ? 1 : 0;
+       result = refresh_cache(REFRESH_SAY_CHANGED) ? 1 : 0;
        if (write_cache(fd, active_cache, active_nr) ||
                        commit_locked_index(index_lock))
                return error ("Could not refresh index");
diff --git a/cache.h b/cache.h
index a779d9207c8ea4d4e8455a89b17f312e0e71332d..38985aa63eaa41ee7ddc322c682a7482a8204cbe 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -397,7 +397,8 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 #define REFRESH_UNMERGED       0x0002  /* allow unmerged */
 #define REFRESH_QUIET          0x0004  /* be quiet about it */
 #define REFRESH_IGNORE_MISSING 0x0008  /* ignore non-existent */
-#define REFRESH_IGNORE_SUBMODULES      0x0008  /* ignore submodules */
+#define REFRESH_IGNORE_SUBMODULES      0x0010  /* ignore submodules */
+#define REFRESH_SAY_CHANGED    0x0020  /* say "changed" not "needs update" */
 extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen);
 
 struct lock_file {
index 28aeb03fdcb65d8b63851cc92e74327b3325d8b8..2e0e55242ff089cda3c87ae57f7c776c13508a56 100755 (executable)
@@ -1226,7 +1226,7 @@ sub linearize_history {
 
 sub find_file_type_and_diff_status {
        my ($path) = @_;
-       return ('dir', '') if $path eq '.';
+       return ('dir', '') if $path eq '';
 
        my $diff_output =
            command_oneline(qw(diff --cached --name-status --), $path) || "";
index 16484281f7ea051a41e4352a3e6a1c0fdc746a9a..a50a851125db765f06f3869873623bf7592de405 100644 (file)
@@ -980,7 +980,10 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
        int not_new = (flags & REFRESH_IGNORE_MISSING) != 0;
        int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
        unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
+       const char *needs_update_message;
 
+       needs_update_message = ((flags & REFRESH_SAY_CHANGED)
+                               ? "locally modified" : "needs update");
        for (i = 0; i < istate->cache_nr; i++) {
                struct cache_entry *ce, *new;
                int cache_errno = 0;
@@ -1019,7 +1022,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
                        }
                        if (quiet)
                                continue;
-                       printf("%s: needs update\n", ce->name);
+                       printf("%s: %s\n", ce->name, needs_update_message);
                        has_errors = 1;
                        continue;
                }
diff --git a/t/t2103-update-index-ignore-missing.sh b/t/t2103-update-index-ignore-missing.sh
new file mode 100755 (executable)
index 0000000..332694e
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/sh
+
+test_description='update-index with options'
+
+. ./test-lib.sh
+
+test_expect_success basics '
+       >one &&
+       >two &&
+       >three &&
+
+       # need --add when adding
+       test_must_fail git update-index one &&
+       test -z "$(git ls-files)" &&
+       git update-index --add one &&
+       test zone = "z$(git ls-files)" &&
+
+       # update-index is atomic
+       echo 1 >one &&
+       test_must_fail git update-index one two &&
+       echo "M one" >expect &&
+       git diff-files --name-status >actual &&
+       test_cmp expect actual &&
+
+       git update-index --add one two three &&
+       for i in one three two; do echo $i; done >expect &&
+       git ls-files >actual &&
+       test_cmp expect actual &&
+
+       test_tick &&
+       (
+               test_create_repo xyzzy &&
+               cd xyzzy &&
+               >file &&
+               git add file
+               git commit -m "sub initial"
+       ) &&
+       git add xyzzy &&
+
+       test_tick &&
+       git commit -m initial &&
+       git tag initial
+'
+
+test_expect_success '--ignore-missing --refresh' '
+       git reset --hard initial &&
+       echo 2 >one &&
+       test_must_fail git update-index --refresh &&
+       echo 1 >one &&
+       git update-index --refresh &&
+       rm -f two &&
+       test_must_fail git update-index --refresh &&
+       git update-index --ignore-missing --refresh
+
+'
+
+test_expect_success '--unmerged --refresh' '
+       git reset --hard initial &&
+       info=$(git ls-files -s one | sed -e "s/ 0       / 1     /") &&
+       git rm --cached one &&
+       echo "$info" | git update-index --index-info &&
+       test_must_fail git update-index --refresh &&
+       git update-index --unmerged --refresh &&
+       echo 2 >two &&
+       test_must_fail git update-index --unmerged --refresh >actual &&
+       grep two actual &&
+       ! grep one actual &&
+       ! grep three actual
+'
+
+test_expect_success '--ignore-submodules --refresh (1)' '
+       git reset --hard initial &&
+       rm -f two &&
+       test_must_fail git update-index --ignore-submodules --refresh
+'
+
+test_expect_success '--ignore-submodules --refresh (2)' '
+       git reset --hard initial &&
+       test_tick &&
+       (
+               cd xyzzy &&
+               git commit -m "sub second" --allow-empty
+       ) &&
+       test_must_fail git update-index --refresh &&
+       test_must_fail git update-index --ignore-missing --refresh &&
+       git update-index --ignore-submodules --refresh
+'
+
+test_done
index 0bfc1e9be49110ac0e8130fcdef440eecbaff2c9..29f5678b4c93485ad492fa865a5da58a3cc05b7c 100755 (executable)
@@ -419,7 +419,7 @@ test_expect_success 'resetting an unmodified path is a no-op' '
 '
 
 cat > expect << EOF
-file2: needs update
+file2: locally modified
 EOF
 
 test_expect_success '--mixed refreshes the index' '
index 26cf8dc7c15ce397d7c36b2dd39a9d38db9856d7..5eeb6c2b2708d582a6e86cd2e06e2b00b7b7b391 100755 (executable)
@@ -221,7 +221,7 @@ test_expect_success 'setup' '
 
 test_debug 'gitk --all'
 
-test_expect_failure 'test option parsing' '
+test_expect_success 'test option parsing' '
        test_must_fail git merge -$ c1 &&
        test_must_fail git merge --no-such c1 &&
        test_must_fail git merge -s foobar c1 &&
index d49f0df8c45c4ad258d22f560919ba230b5d3350..4b91f8d4c45dad075d69028c9c70aa9cb1959e2b 100755 (executable)
@@ -438,6 +438,13 @@ test_expect_success 'cvs update (-p)' '
     test -z "$(cat failures)"
 '
 
+cd "$WORKDIR"
+test_expect_success 'cvs update (module list supports packed refs)' '
+    GIT_DIR="$SERVERDIR" git pack-refs --all &&
+    GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
+    grep "cvs update: New directory \`master'\''" < out
+'
+
 #------------
 # CVS STATUS
 #------------
index 4e04f7661b4943059243fa5f8a33baeec4a96583..93562f03eef21b26945d2d9bbdc96818f4de6567 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -133,6 +133,44 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
        }
 }
 
+ssize_t read_in_full(int fd, void *buf, size_t count)
+{
+       char *p = buf;
+       ssize_t total = 0;
+
+       while (count > 0) {
+               ssize_t loaded = xread(fd, p, count);
+               if (loaded <= 0)
+                       return total ? total : loaded;
+               count -= loaded;
+               p += loaded;
+               total += loaded;
+       }
+
+       return total;
+}
+
+ssize_t write_in_full(int fd, const void *buf, size_t count)
+{
+       const char *p = buf;
+       ssize_t total = 0;
+
+       while (count > 0) {
+               ssize_t written = xwrite(fd, p, count);
+               if (written < 0)
+                       return -1;
+               if (!written) {
+                       errno = ENOSPC;
+                       return -1;
+               }
+               count -= written;
+               p += written;
+               total += written;
+       }
+
+       return total;
+}
+
 int xdup(int fd)
 {
        int ret = dup(fd);
index e4c8e225fd232dfd642aa13d7ae5b64b9827c915..4c29255df1b637f93ab3d59e0dcab1fa3b40e10b 100644 (file)
@@ -45,44 +45,6 @@ void maybe_flush_or_die(FILE *f, const char *desc)
        }
 }
 
-ssize_t read_in_full(int fd, void *buf, size_t count)
-{
-       char *p = buf;
-       ssize_t total = 0;
-
-       while (count > 0) {
-               ssize_t loaded = xread(fd, p, count);
-               if (loaded <= 0)
-                       return total ? total : loaded;
-               count -= loaded;
-               p += loaded;
-               total += loaded;
-       }
-
-       return total;
-}
-
-ssize_t write_in_full(int fd, const void *buf, size_t count)
-{
-       const char *p = buf;
-       ssize_t total = 0;
-
-       while (count > 0) {
-               ssize_t written = xwrite(fd, p, count);
-               if (written < 0)
-                       return -1;
-               if (!written) {
-                       errno = ENOSPC;
-                       return -1;
-               }
-               count -= written;
-               p += written;
-               total += written;
-       }
-
-       return total;
-}
-
 void fsync_or_die(int fd, const char *msg)
 {
        if (fsync(fd) < 0) {