summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 27de946)
raw | patch | inline | side by side (parent: 27de946)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Fri, 15 Apr 2005 17:44:27 +0000 (10:44 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Fri, 15 Apr 2005 17:44:27 +0000 (10:44 -0700) |
This allows using a git tree over NFS with different byte order, and
makes it possible to just copy a fully populated repository and have
the end result immediately usable (needing just a refresh to update
the stat information).
makes it possible to just copy a fully populated repository and have
the end result immediately usable (needing just a refresh to update
the stat information).
cache.h | patch | blob | history | |
checkout-cache.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
read-tree.c | patch | blob | history | |
show-diff.c | patch | blob | history | |
update-cache.c | patch | blob | history | |
write-tree.c | patch | blob | history |
index 35b26c7d87c04497c84a08a9b29d93f09fcafbe8..5b3cd95aa19e8028a9a5b921135356f30b83a02e 100644 (file)
--- a/cache.h
+++ b/cache.h
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
+#include <netinet/in.h>
#include <openssl/sha.h>
#include <zlib.h>
#define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
struct cache_header {
- unsigned int signature;
- unsigned int version;
- unsigned int entries;
+ unsigned int hdr_signature;
+ unsigned int hdr_version;
+ unsigned int hdr_entries;
unsigned char sha1[20];
};
* dev/ino/uid/gid/size are also just tracked to the low 32 bits
* Again - this is just a (very strong in practice) heuristic that
* the inode hasn't changed.
+ *
+ * We save the fields in big-endian order to allow using the
+ * index file over NFS transparently.
*/
struct cache_entry {
- struct cache_time ctime;
- struct cache_time mtime;
- unsigned int st_dev;
- unsigned int st_ino;
- unsigned int st_mode;
- unsigned int st_uid;
- unsigned int st_gid;
- unsigned int st_size;
+ struct cache_time ce_ctime;
+ struct cache_time ce_mtime;
+ unsigned int ce_dev;
+ unsigned int ce_ino;
+ unsigned int ce_mode;
+ unsigned int ce_uid;
+ unsigned int ce_gid;
+ unsigned int ce_size;
unsigned char sha1[20];
- unsigned short namelen;
+ unsigned short ce_namelen;
char name[0];
};
#define DEFAULT_DB_ENVIRONMENT ".git/objects"
#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
-#define ce_size(ce) cache_entry_size((ce)->namelen)
+#define ce_namelen(ce) ntohs((ce)->ce_namelen)
+#define ce_size(ce) cache_entry_size(ce_namelen(ce))
#define alloc_nr(x) (((x)+16)*3/2)
diff --git a/checkout-cache.c b/checkout-cache.c
index fa7864590fb70b755ebb1c9a257d33ca2bd6656d..8d5e4cd148f6111ab7e0bfb7f9142693e08f66bd 100644 (file)
--- a/checkout-cache.c
+++ b/checkout-cache.c
return error("checkout-cache: unable to read sha1 file of %s (%s)",
ce->name, sha1_to_hex(ce->sha1));
}
- fd = create_file(ce->name, ce->st_mode);
+ fd = create_file(ce->name, ntohl(ce->ce_mode));
if (fd < 0) {
free(new);
return error("checkout-cache: unable to create %s (%s)",
diff --git a/read-cache.c b/read-cache.c
index 8e90d2c3b6ae056d2b8f0410b4f12f0992bb7baf..4173b4e454f2a44babedd753894f7ba65ab56880 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
{
unsigned int changed = 0;
- /* nsec seems unreliable - not all filesystems support it, so
- * as long as it is in the inode cache you get right nsec
- * but after it gets flushed, you get zero nsec. */
- if (ce->mtime.sec != (unsigned int)st->st_mtim.tv_sec
-#ifdef NSEC
- || ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec
-#endif
- )
+ if (ce->ce_mtime.sec != htonl(st->st_mtime))
changed |= MTIME_CHANGED;
- if (ce->ctime.sec != (unsigned int)st->st_ctim.tv_sec
+ if (ce->ce_ctime.sec != htonl(st->st_ctime))
+ changed |= CTIME_CHANGED;
+
#ifdef NSEC
- || ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec
-#endif
- )
+ /*
+ * nsec seems unreliable - not all filesystems support it, so
+ * as long as it is in the inode cache you get right nsec
+ * but after it gets flushed, you get zero nsec.
+ */
+ if (ce->ce_mtime.nsec != htonl(st->st_mtim.tv_nsec)
+ changed |= MTIME_CHANGED;
+ if (ce->ce_ctime.nsec != htonl(st->st_ctim.tv_nsec)
changed |= CTIME_CHANGED;
- if (ce->st_uid != (unsigned int)st->st_uid ||
- ce->st_gid != (unsigned int)st->st_gid)
+#endif
+
+ if (ce->ce_uid != htonl(st->st_uid) ||
+ ce->ce_gid != htonl(st->st_gid))
changed |= OWNER_CHANGED;
- if (ce->st_mode != (unsigned int)st->st_mode)
+ if (ce->ce_mode != htonl(st->st_mode))
changed |= MODE_CHANGED;
- if (ce->st_dev != (unsigned int)st->st_dev ||
- ce->st_ino != (unsigned int)st->st_ino)
+ if (ce->ce_dev != htonl(st->st_dev) ||
+ ce->ce_ino != htonl(st->st_ino))
changed |= INODE_CHANGED;
- if (ce->st_size != (unsigned int)st->st_size)
+ if (ce->ce_size != htonl(st->st_size))
changed |= DATA_CHANGED;
return changed;
}
while (last > first) {
int next = (last + first) >> 1;
struct cache_entry *ce = active_cache[next];
- int cmp = cache_name_compare(name, namelen, ce->name, ce->namelen);
+ int cmp = cache_name_compare(name, namelen, ce->name, ce_namelen(ce));
if (!cmp)
return next;
if (cmp < 0) {
{
int pos;
- pos = cache_name_pos(ce->name, ce->namelen);
+ pos = cache_name_pos(ce->name, ce_namelen(ce));
/* existing match? Just replace it */
if (pos >= 0) {
SHA_CTX c;
unsigned char sha1[20];
- if (hdr->signature != CACHE_SIGNATURE)
+ if (hdr->hdr_signature != htonl(CACHE_SIGNATURE))
return error("bad signature");
- if (hdr->version != 1)
+ if (hdr->hdr_version != htonl(1))
return error("bad version");
SHA1_Init(&c);
SHA1_Update(&c, hdr, offsetof(struct cache_header, sha1));
if (verify_hdr(hdr, size) < 0)
goto unmap;
- active_nr = hdr->entries;
+ active_nr = ntohl(hdr->hdr_entries);
active_alloc = alloc_nr(active_nr);
active_cache = calloc(active_alloc, sizeof(struct cache_entry *));
offset = sizeof(*hdr);
- for (i = 0; i < hdr->entries; i++) {
+ for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = map + offset;
offset = offset + ce_size(ce);
active_cache[i] = ce;
struct cache_header hdr;
int i;
- hdr.signature = CACHE_SIGNATURE;
- hdr.version = 1;
- hdr.entries = entries;
+ hdr.hdr_signature = htonl(CACHE_SIGNATURE);
+ hdr.hdr_version = htonl(1);
+ hdr.hdr_entries = htonl(entries);
SHA1_Init(&c);
SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));
diff --git a/read-tree.c b/read-tree.c
index 9aec97fa73d4e6bd2354988536af8826dbb9ed04..5c6588da4fc95c39e8f5ec8209780509903e56e4 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
memset(ce, 0, size);
- ce->st_mode = mode;
- ce->namelen = baselen + len;
+ ce->ce_mode = htonl(mode);
+ ce->ce_namelen = htons(baselen + len);
memcpy(ce->name, base, baselen);
memcpy(ce->name + baselen, pathname, len+1);
memcpy(ce->sha1, sha1, 20);
diff --git a/show-diff.c b/show-diff.c
index 1286dd1217582df17df629413f781010bc41f314..a15e9b4cf0be5f67373d08fb5c833dd5c1d3eeb8 100644 (file)
--- a/show-diff.c
+++ b/show-diff.c
changed = cache_match_stat(ce, &st);
if (!changed)
continue;
- printf("%.*s: ", ce->namelen, ce->name);
+ printf("%.*s: ", ce_namelen(ce), ce->name);
for (n = 0; n < 20; n++)
printf("%02x", ce->sha1[n]);
printf("\n");
diff --git a/update-cache.c b/update-cache.c
index 6d37c55a26690dfc10cb2e65e7300b84926fc67f..85d0591c8500ac916b573ca3934cea84fe0f8106 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
@@ -68,18 +68,17 @@ static int index_fd(const char *path, int namelen, struct cache_entry *ce, int f
*/
static void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
{
- ce->ctime.sec = st->st_ctime;
+ ce->ce_ctime.sec = htonl(st->st_ctime);
+ ce->ce_mtime.sec = htonl(st->st_mtime);
#ifdef NSEC
- ce->ctime.nsec = st->st_ctim.tv_nsec;
+ ce->ce_ctime.nsec = htonl(st->st_ctim.tv_nsec);
+ ce->ce_mtime.nsec = htonl(st->st_mtim.tv_nsec);
#endif
- ce->mtime.sec = st->st_mtime;
-#ifdef NSEC
- ce->mtime.nsec = st->st_mtim.tv_nsec;
-#endif
- ce->st_dev = st->st_dev;
- ce->st_ino = st->st_ino;
- ce->st_uid = st->st_uid;
- ce->st_gid = st->st_gid;
+ ce->ce_dev = htonl(st->st_dev);
+ ce->ce_ino = htonl(st->st_ino);
+ ce->ce_uid = htonl(st->st_uid);
+ ce->ce_gid = htonl(st->st_gid);
+ ce->ce_size = htonl(st->st_size);
}
static int add_file_to_cache(char *path)
memset(ce, 0, size);
memcpy(ce->name, path, namelen);
fill_stat_cache_info(ce, &st);
- ce->st_mode = st.st_mode;
- ce->st_size = st.st_size;
- ce->namelen = namelen;
+ ce->ce_mode = htonl(st.st_mode);
+ ce->ce_namelen = htons(namelen);
if (index_fd(path, namelen, ce, fd, &st) < 0)
return -1;
updated = malloc(size);
memcpy(updated, ce, size);
fill_stat_cache_info(updated, &st);
- updated->st_size = st.st_size;
return updated;
}
diff --git a/write-tree.c b/write-tree.c
index 881c8c2b5821475b41c77ed3e44b385949fbffc0..e2bbbd261e76800df8882c2bb9f15dda953804d2 100644 (file)
--- a/write-tree.c
+++ b/write-tree.c
do {
struct cache_entry *ce = cachep[nr];
const char *pathname = ce->name, *filename, *dirname;
- int pathlen = ce->namelen, entrylen;
+ int pathlen = ce_namelen(ce), entrylen;
unsigned char *sha1;
unsigned int mode;
break;
sha1 = ce->sha1;
- mode = ce->st_mode;
+ mode = ntohl(ce->ce_mode);
/* Do we have _further_ subdirectories? */
filename = pathname + baselen;