Merge branch 'cr/reset'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Sep 2007 07:42:01 +0000 (00:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Sep 2007 07:42:01 +0000 (00:42 -0700)
* cr/reset:
Simplify cache API
An additional test for "git-reset -- path"
Make "git reset" a builtin.
Move make_cache_entry() from merge-recursive.c into read-cache.c
Add tests for documented features of "git reset".

1  2 
Makefile
builtin-add.c
builtin-apply.c
diff --combined Makefile
index 40567ece1430e6d59c7f877f9f5861505d22d419,e6740fc3928c239f0f16c10c661d190399882ca0..0055eef24d855e9cd3a62620a70cad7c2008ea88
+++ b/Makefile
@@@ -124,9 -124,6 +124,9 @@@ all:
  # If not set it defaults to the bare 'wish'. If it is set to the empty
  # string then NO_TCLTK will be forced (this is used by configure script).
  #
 +# Define THREADED_DELTA_SEARCH if you have pthreads and wish to exploit
 +# parallel delta searching when packing objects.
 +#
  
  GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
@@@ -211,7 -208,7 +211,7 @@@ SCRIPT_SH = 
        git-ls-remote.sh \
        git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \
        git-pull.sh git-rebase.sh git-rebase--interactive.sh \
-       git-repack.sh git-request-pull.sh git-reset.sh \
+       git-repack.sh git-request-pull.sh \
        git-sh-setup.sh \
        git-am.sh \
        git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
@@@ -358,6 -355,7 +358,7 @@@ BUILTIN_OBJS = 
        builtin-reflog.o \
        builtin-config.o \
        builtin-rerere.o \
+       builtin-reset.o \
        builtin-rev-list.o \
        builtin-rev-parse.o \
        builtin-revert.o \
@@@ -678,11 -676,6 +679,11 @@@ ifdef NO_MEMME
        COMPAT_OBJS += compat/memmem.o
  endif
  
 +ifdef THREADED_DELTA_SEARCH
 +      BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
 +      EXTLIBS += -lpthread
 +endif
 +
  ifeq ($(TCLTK_PATH),)
  NO_TCLTK=NoThanks
  endif
diff --combined builtin-add.c
index 3d8b8b4f89514e0a8f7af1c2c7dc2f8ae372129e,866d19dd77e693a1ba77baa802c0e3f3ea85a305..0d7d0ce4209114245ca07842d7d5a4546e5b6cfd
@@@ -95,7 -95,7 +95,7 @@@ static void update_callback(struct diff
                const char *path = p->one->path;
                switch (p->status) {
                default:
 -                      die("unexpacted diff status %c", p->status);
 +                      die("unexpected diff status %c", p->status);
                case DIFF_STATUS_UNMERGED:
                case DIFF_STATUS_MODIFIED:
                case DIFF_STATUS_TYPE_CHANGED:
                        break;
                case DIFF_STATUS_DELETED:
                        remove_file_from_cache(path);
-                       cache_tree_invalidate_path(active_cache_tree, path);
                        if (verbose)
                                printf("remove '%s'\n", path);
                        break;
diff --combined builtin-apply.c
index 5ad371424b8019a97d1fb34045bb8e32134870aa,79a4852bc24077b13bfa5e71fe04ee599717f310..05ce2205f34a6e8fe4ce17ceed6ee2ae7730779a
@@@ -1642,22 -1642,15 +1642,22 @@@ static int apply_line(char *output, con
  
        buf = output;
        if (need_fix_leading_space) {
 +              int consecutive_spaces = 0;
                /* between patch[1..last_tab_in_indent] strip the
                 * funny spaces, updating them to tab as needed.
                 */
                for (i = 1; i < last_tab_in_indent; i++, plen--) {
                        char ch = patch[i];
 -                      if (ch != ' ')
 +                      if (ch != ' ') {
 +                              consecutive_spaces = 0;
                                *output++ = ch;
 -                      else if ((i % 8) == 0)
 -                              *output++ = '\t';
 +                      } else {
 +                              consecutive_spaces++;
 +                              if (consecutive_spaces == 8) {
 +                                      *output++ = '\t';
 +                                      consecutive_spaces = 0;
 +                              }
 +                      }
                }
                fixed = 1;
                i = last_tab_in_indent;
@@@ -2234,20 -2227,6 +2234,20 @@@ static int check_patch_list(struct patc
        return err;
  }
  
 +/* This function tries to read the sha1 from the current index */
 +static int get_current_sha1(const char *path, unsigned char *sha1)
 +{
 +      int pos;
 +
 +      if (read_cache() < 0)
 +              return -1;
 +      pos = cache_name_pos(path, strlen(path));
 +      if (pos < 0)
 +              return -1;
 +      hashcpy(sha1, active_cache[pos]->sha1);
 +      return 0;
 +}
 +
  static void show_index_list(struct patch *list)
  {
        struct patch *patch;
                if (0 < patch->is_new)
                        sha1_ptr = null_sha1;
                else if (get_sha1(patch->old_sha1_prefix, sha1))
 -                      die("sha1 information is lacking or useless (%s).",
 -                          name);
 +                      /* git diff has no index line for mode/type changes */
 +                      if (!patch->lines_added && !patch->lines_deleted) {
 +                              if (get_current_sha1(patch->new_name, sha1) ||
 +                                  get_current_sha1(patch->old_name, sha1))
 +                                      die("mode change for %s, which is not "
 +                                              "in current HEAD", name);
 +                              sha1_ptr = sha1;
 +                      } else
 +                              die("sha1 information is lacking or useless "
 +                                      "(%s).", name);
                else
                        sha1_ptr = sha1;
  
@@@ -2423,7 -2394,6 +2423,6 @@@ static void remove_file(struct patch *p
        if (update_index) {
                if (remove_file_from_cache(patch->old_name) < 0)
                        die("unable to remove %s from index", patch->old_name);
-               cache_tree_invalidate_path(active_cache_tree, patch->old_name);
        }
        if (!cached) {
                if (S_ISGITLINK(patch->old_mode)) {
@@@ -2578,7 -2548,6 +2577,6 @@@ static void create_file(struct patch *p
                mode = S_IFREG | 0644;
        create_one_file(path, mode, buf, size);
        add_index_file(path, mode, buf, size);
-       cache_tree_invalidate_path(active_cache_tree, path);
  }
  
  /* phase zero is to remove, phase one is to create */