summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9cedd16)
raw | patch | inline | side by side (parent: 9cedd16)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 8 May 2011 08:47:33 +0000 (01:47 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 May 2011 18:58:19 +0000 (11:58 -0700) |
The "format_check" parameter tucked after the existing parameters is too
ugly an afterthought to live in any reasonable API.
Combine it with the other boolean parameter "write_object" into a single
"flags" parameter.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ugly an afterthought to live in any reasonable API.
Combine it with the other boolean parameter "write_object" into a single
"flags" parameter.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hash-object.c | patch | blob | history | |
builtin/update-index.c | patch | blob | history | |
cache.h | patch | blob | history | |
notes-merge.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index b96f46acf52d23f68c1ec164be8264396dea22db..33911fd5e9325210dae63b3252fa3b56d42b545c 100644 (file)
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
{
struct stat st;
unsigned char sha1[20];
+ unsigned flags = (HASH_FORMAT_CHECK |
+ (write_object ? HASH_WRITE_OBJECT : 0));
+
if (fstat(fd, &st) < 0 ||
- index_fd(sha1, fd, &st, write_object, type_from_string(type), path, 1))
+ index_fd(sha1, fd, &st, type_from_string(type), path, flags))
die(write_object
? "Unable to add %s to database"
: "Unable to hash %s", path);
diff --git a/builtin/update-index.c b/builtin/update-index.c
index d7850c6309aec0c1a4f640999fb757d7b32ba1b8..f14bc908309c0bb01ec251d71f26b490b294622c 100644 (file)
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
fill_stat_cache_info(ce, st);
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
- if (index_path(ce->sha1, path, st, !info_only))
+ if (index_path(ce->sha1, path, st,
+ info_only ? 0 : HASH_WRITE_OBJECT))
return -1;
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
index 28899b7b7881474eed4a6f3b6fda8db79d5cbc9c..bc380139590700e88d436e8577d3b433aa4e5d7b 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int init_pathspec(struct pathspec *, const char **);
extern void free_pathspec(struct pathspec *);
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
-extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path, int format_check);
-extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
+
+#define HASH_WRITE_OBJECT 1
+#define HASH_FORMAT_CHECK 2
+extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
+extern int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags);
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
#define REFRESH_REALLY 0x0001 /* ignore_valid */
diff --git a/notes-merge.c b/notes-merge.c
index 28046a998426e88dec9ad6ab431624bb41a81ce1..e1aaf43b438d0cfb6b7b0c723060a662a915bcea 100644 (file)
--- a/notes-merge.c
+++ b/notes-merge.c
/* write file as blob, and add to partial_tree */
if (stat(ent->name, &st))
die_errno("Failed to stat '%s'", ent->name);
- if (index_path(blob_sha1, ent->name, &st, 1))
+ if (index_path(blob_sha1, ent->name, &st, HASH_WRITE_OBJECT))
die("Failed to write blob object from '%s'", ent->name);
if (add_note(partial_tree, obj_sha1, blob_sha1, NULL))
die("Failed to add resolved note '%s' to notes tree",
diff --git a/read-cache.c b/read-cache.c
index f38471cac3ac57d8d52429cde2dcc4cf5b92557b..4ac9a037f478e769a69072c324a47876e298cae4 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
if (fd >= 0) {
unsigned char sha1[20];
- if (!index_fd(sha1, fd, st, 0, OBJ_BLOB, ce->name, 0))
+ if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0))
match = hashcmp(sha1, ce->sha1);
/* index_fd() closed the file descriptor already */
}
return 0;
}
if (!intent_only) {
- if (index_path(ce->sha1, path, st, 1))
+ if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT))
return error("unable to index file %s", path);
} else
record_intent_to_add(ce);
diff --git a/sha1_file.c b/sha1_file.c
index 889fe7183065ae8bc12821aadebb69a17bc7635c..17c179c9fd6e06c8c344332f876f8731c5ea2fb3 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
}
static int index_mem(unsigned char *sha1, void *buf, size_t size,
- int write_object, enum object_type type,
- const char *path, int format_check)
+ enum object_type type,
+ const char *path, unsigned flags)
{
int ret, re_allocated = 0;
+ int write_object = flags & HASH_WRITE_OBJECT;
if (!type)
type = OBJ_BLOB;
re_allocated = 1;
}
}
- if (format_check) {
+ if (flags & HASH_FORMAT_CHECK) {
if (type == OBJ_TREE)
check_tree(buf, size);
if (type == OBJ_COMMIT)
#define SMALL_FILE_SIZE (32*1024)
-int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
- enum object_type type, const char *path, int format_check)
+int index_fd(unsigned char *sha1, int fd, struct stat *st,
+ enum object_type type, const char *path, unsigned flags)
{
int ret;
size_t size = xsize_t(st->st_size);
@@ -2629,33 +2630,29 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
if (!S_ISREG(st->st_mode)) {
struct strbuf sbuf = STRBUF_INIT;
if (strbuf_read(&sbuf, fd, 4096) >= 0)
- ret = index_mem(sha1, sbuf.buf, sbuf.len, write_object,
- type, path, format_check);
+ ret = index_mem(sha1, sbuf.buf, sbuf.len, type, path, flags);
else
ret = -1;
strbuf_release(&sbuf);
} else if (!size) {
- ret = index_mem(sha1, NULL, size, write_object, type, path,
- format_check);
+ ret = index_mem(sha1, NULL, size, type, path, flags);
} else if (size <= SMALL_FILE_SIZE) {
char *buf = xmalloc(size);
if (size == read_in_full(fd, buf, size))
- ret = index_mem(sha1, buf, size, write_object, type,
- path, format_check);
+ ret = index_mem(sha1, buf, size, type, path, flags);
else
ret = error("short read %s", strerror(errno));
free(buf);
} else {
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
- ret = index_mem(sha1, buf, size, write_object, type, path,
- format_check);
+ ret = index_mem(sha1, buf, size, type, path, flags);
munmap(buf, size);
}
close(fd);
return ret;
}
-int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object)
+int index_path(unsigned char *sha1, const char *path, struct stat *st, unsigned flags)
{
int fd;
struct strbuf sb = STRBUF_INIT;
@@ -2666,7 +2663,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
if (fd < 0)
return error("open(\"%s\"): %s", path,
strerror(errno));
- if (index_fd(sha1, fd, st, write_object, OBJ_BLOB, path, 0) < 0)
+ if (index_fd(sha1, fd, st, OBJ_BLOB, path, flags) < 0)
return error("%s: failed to insert into database",
path);
break;
@@ -2676,7 +2673,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
return error("readlink(\"%s\"): %s", path,
errstr);
}
- if (!write_object)
+ if (!(flags & HASH_WRITE_OBJECT))
hash_sha1_file(sb.buf, sb.len, blob_type, sha1);
else if (write_sha1_file(sb.buf, sb.len, blob_type, sha1))
return error("%s: failed to insert into database",