Merge branch 'lt/apply' into next
authorJunio C Hamano <junkio@cox.net>
Wed, 24 May 2006 21:11:08 +0000 (14:11 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 24 May 2006 21:11:08 +0000 (14:11 -0700)
* lt/apply:
Clean up sha1 file writing
Builtin git-cat-file
apply: force matching at the beginning.
Add a test-case for git-apply trying to add an ending line
apply: treat EOF as proper context.

1  2 
Makefile
builtin-apply.c
diff --combined Makefile
index 355e0ccece3c5b833742c91a517e90bcc8cd808d,dbf19c62775e1a129575fce5281b1a00fb71cdbc..5f8ea1817931eb522a5627d923473fac27c42260
+++ b/Makefile
@@@ -149,7 -149,6 +149,6 @@@ SIMPLE_PROGRAMS = 
  
  # ... and all the rest that could be moved out of bindir to gitexecdir
  PROGRAMS = \
-       git-cat-file$X \
        git-checkout-index$X git-clone-pack$X \
        git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
        git-hash-object$X git-index-pack$X git-local-fetch$X \
@@@ -174,7 -173,7 +173,7 @@@ BUILT_INS = git-log$X git-whatchanged$
        git-ls-files$X git-ls-tree$X \
        git-read-tree$X git-commit-tree$X \
        git-apply$X git-show-branch$X git-diff-files$X \
-       git-diff-index$X git-diff-stages$X git-diff-tree$X
+       git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X
  
  # what 'all' will build and 'install' will install, in gitexecdir
  ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@@ -211,7 -210,7 +210,7 @@@ DIFF_OBJS = 
        diffcore-delta.o log-tree.o
  
  LIB_OBJS = \
 -      blob.o commit.o connect.o csum-file.o base85.o \
 +      blob.o commit.o connect.o csum-file.o cache-tree.o base85.o \
        date.o diff-delta.o entry.o exec_cmd.o ident.o index.o \
        object.o pack-check.o patch-delta.o path.o pkt-line.o \
        quote.o read-cache.o refs.o run-command.o dir.o \
@@@ -228,7 -227,8 +227,8 @@@ BUILTIN_OBJS = 
        builtin-ls-files.o builtin-ls-tree.o \
        builtin-read-tree.o builtin-commit-tree.o \
        builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
-       builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o
+       builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
+       builtin-cat-file.o
  
  GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
  LIBS = $(GITLIBS) -lz
@@@ -620,9 -620,6 +620,9 @@@ test-date$X: test-date.c date.o ctype.
  test-delta$X: test-delta.c diff-delta.o patch-delta.o
        $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^
  
 +test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
 +      $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 +
  check:
        for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
  
diff --combined builtin-apply.c
index f16c753bee7c1a1dda1952282f448d2d6a4099e6,69c8e6a6083456cb3e9c6389d49c7723b8854442..6a4fb9663dbfac93a7c625c13d401f411e8f5178
@@@ -8,7 -8,6 +8,7 @@@
   */
  #include <fnmatch.h>
  #include "cache.h"
 +#include "cache-tree.h"
  #include "quote.h"
  #include "blob.h"
  #include "delta.h"
@@@ -1335,6 -1334,7 +1335,7 @@@ static int apply_line(char *output, con
  
  static int apply_one_fragment(struct buffer_desc *desc, struct fragment *frag)
  {
+       int match_beginning, match_end;
        char *buf = desc->buffer;
        const char *patch = frag->patch;
        int offset, size = frag->size;
        newlines = new;
        leading = frag->leading;
        trailing = frag->trailing;
+       /*
+        * If we don't have any leading/trailing data in the patch,
+        * we want it to match at the beginning/end of the file.
+        */
+       match_beginning = !leading && (frag->oldpos == 1);
+       match_end = !trailing;
        lines = 0;
        pos = frag->newpos;
        for (;;) {
                offset = find_offset(buf, desc->size, oldlines, oldsize, pos, &lines);
+               if (match_end && offset + oldsize != desc->size)
+                       offset = -1;
+               if (match_beginning && offset)
+                       offset = -1;
                if (offset >= 0) {
                        int diff = newsize - oldsize;
                        unsigned long size = desc->size + diff;
                /* Am I at my context limits? */
                if ((leading <= p_context) && (trailing <= p_context))
                        break;
+               if (match_beginning || match_end) {
+                       match_beginning = match_end = 0;
+                       continue;
+               }
                /* Reduce the number of context lines
                 * Reduce both leading and trailing if they are equal
                 * otherwise just reduce the larger context.
@@@ -1919,7 -1935,6 +1936,7 @@@ static void remove_file(struct patch *p
        if (write_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)
                unlink(patch->old_name);
@@@ -2021,9 -2036,8 +2038,9 @@@ static void create_file(struct patch *p
  
        if (!mode)
                mode = S_IFREG | 0644;
 -      create_one_file(path, mode, buf, size); 
 +      create_one_file(path, mode, buf, size);
        add_index_file(path, mode, buf, size);
 +      cache_tree_invalidate_path(active_cache_tree, path);
  }
  
  static void write_out_one_result(struct patch *patch)