]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-update-index.c
Drop strbuf's 'eof' marker, and make read_line a first class citizen.
[git.git] / builtin-update-index.c
index 509369e9e7b1719e53ba2dd2d976066fb9513353..45e33f5584b6c61cb64d7b408c89917320487f43 100644 (file)
@@ -4,7 +4,6 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
-#include "strbuf.h"
 #include "quote.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
@@ -86,9 +85,15 @@ static int process_lstat_error(const char *path, int err)
 
 static int add_one_path(struct cache_entry *old, const char *path, int len, struct stat *st)
 {
-       int option, size = cache_entry_size(len);
-       struct cache_entry *ce = xcalloc(1, size);
+       int option, size;
+       struct cache_entry *ce;
+
+       /* Was the old index entry already up-to-date? */
+       if (old && !ce_stage(old) && !ce_match_stat(old, st, 0))
+               return 0;
 
+       size = cache_entry_size(len);
+       ce = xcalloc(1, size);
        memcpy(ce->name, path, len);
        ce->ce_flags = htons(len);
        fill_stat_cache_info(ce, st);
@@ -297,7 +302,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
 static void read_index_info(int line_termination)
 {
        struct strbuf buf;
-       strbuf_init(&buf);
+       strbuf_init(&buf, 0);
        while (1) {
                char *ptr, *tab;
                char *path_name;
@@ -322,8 +327,7 @@ static void read_index_info(int line_termination)
                 * This format is to put higher order stages into the
                 * index file and matches git-ls-files --stage output.
                 */
-               read_line(&buf, stdin, line_termination);
-               if (buf.eof)
+               if (strbuf_getline(&buf, stdin, line_termination) == EOF)
                        break;
 
                errno = 0;
@@ -386,6 +390,7 @@ static void read_index_info(int line_termination)
        bad_line:
                die("malformed index info %s", buf.buf);
        }
+       strbuf_release(&buf);
 }
 
 static const char update_index_usage[] =
@@ -710,12 +715,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
        }
        if (read_from_stdin) {
                struct strbuf buf;
-               strbuf_init(&buf);
+               strbuf_init(&buf, 0);
                while (1) {
                        char *path_name;
                        const char *p;
-                       read_line(&buf, stdin, line_termination);
-                       if (buf.eof)
+                       if (strbuf_getline(&buf, stdin, line_termination) == EOF)
                                break;
                        if (line_termination && buf.buf[0] == '"')
                                path_name = unquote_c_style(buf.buf, NULL);
@@ -730,6 +734,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                        if (path_name != buf.buf)
                                free(path_name);
                }
+               strbuf_release(&buf);
        }
 
  finish: