Merge branch 'dp/hash-literally'
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Aug 2008 04:43:25 +0000 (21:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Aug 2008 04:43:25 +0000 (21:43 -0700)
* dp/hash-literally:
add --no-filters option to git hash-object
add --path option to git hash-object
use parse_options() in git hash-object
correct usage help string for git-hash-object
correct argument checking test for git hash-object
teach index_fd to work with pipes

1  2 
sha1_file.c
diff --combined sha1_file.c
index 32e4664b1b52542bbd77218a4b88cef610f49649,d453b6664e214b29d485ad883cdedf5e5684c87d..2aff59b90f9f290d1260eea1028585f738549d50
@@@ -1929,18 -1929,11 +1929,18 @@@ static int sha1_loose_object_info(cons
  int sha1_object_info(const unsigned char *sha1, unsigned long *sizep)
  {
        struct pack_entry e;
 +      int status;
  
        if (!find_pack_entry(sha1, &e, NULL)) {
 +              /* Most likely it's a loose object. */
 +              status = sha1_loose_object_info(sha1, sizep);
 +              if (status >= 0)
 +                      return status;
 +
 +              /* Not a loose object; someone else may have just packed it. */
                reprepare_packed_git();
                if (!find_pack_entry(sha1, &e, NULL))
 -                      return sha1_loose_object_info(sha1, sizep);
 +                      return status;
        }
        return packed_object_info(e.p, e.offset, sizep);
  }
@@@ -2360,51 -2353,22 +2360,22 @@@ int has_sha1_file(const unsigned char *
        return has_loose_object(sha1);
  }
  
- int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
+ static int index_mem(unsigned char *sha1, void *buf, size_t size,
+                    int write_object, enum object_type type, const char *path)
  {
-       struct strbuf buf;
-       int ret;
-       strbuf_init(&buf, 0);
-       if (strbuf_read(&buf, fd, 4096) < 0) {
-               strbuf_release(&buf);
-               return -1;
-       }
-       if (!type)
-               type = blob_type;
-       if (write_object)
-               ret = write_sha1_file(buf.buf, buf.len, type, sha1);
-       else
-               ret = hash_sha1_file(buf.buf, buf.len, type, sha1);
-       strbuf_release(&buf);
-       return ret;
- }
- int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
-            enum object_type type, const char *path)
- {
-       size_t size = xsize_t(st->st_size);
-       void *buf = NULL;
        int ret, re_allocated = 0;
  
-       if (size)
-               buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
-       close(fd);
        if (!type)
                type = OBJ_BLOB;
  
        /*
         * Convert blobs to git internal format
         */
-       if ((type == OBJ_BLOB) && S_ISREG(st->st_mode)) {
+       if ((type == OBJ_BLOB) && path) {
                struct strbuf nbuf;
                strbuf_init(&nbuf, 0);
                if (convert_to_git(path, buf, size, &nbuf,
                                   write_object ? safe_crlf : 0)) {
-                       munmap(buf, size);
                        buf = strbuf_detach(&nbuf, &size);
                        re_allocated = 1;
                }
                ret = write_sha1_file(buf, size, typename(type), sha1);
        else
                ret = hash_sha1_file(buf, size, typename(type), sha1);
-       if (re_allocated) {
+       if (re_allocated)
                free(buf);
-               return ret;
-       }
-       if (size)
+       return ret;
+ }
+ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
+            enum object_type type, const char *path)
+ {
+       int ret;
+       size_t size = xsize_t(st->st_size);
+       if (!S_ISREG(st->st_mode)) {
+               struct strbuf sbuf;
+               strbuf_init(&sbuf, 0);
+               if (strbuf_read(&sbuf, fd, 4096) >= 0)
+                       ret = index_mem(sha1, sbuf.buf, sbuf.len, write_object,
+                                       type, path);
+               else
+                       ret = -1;
+               strbuf_release(&sbuf);
+       } else if (size) {
+               void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
+               ret = index_mem(sha1, buf, size, write_object, type, path);
                munmap(buf, size);
+       } else
+               ret = index_mem(sha1, NULL, size, write_object, type, path);
+       close(fd);
        return ret;
  }