summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8d3af1d)
raw | patch | inline | side by side (parent: 8d3af1d)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 19:09:27 +0000 (12:09 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 19:09:27 +0000 (12:09 -0700) |
This is needed for the change to make "read-tree" just read into the
cache (and then you do a "checkout-cache" to update your current dir
contents).
cache (and then you do a "checkout-cache" to update your current dir
contents).
cache.h | patch | blob | history | |
read-cache.c | patch | blob | history | |
update-cache.c | patch | blob | history |
index 0038e8b8e04b287ec876594cbab9df4af09ce131..2581117a185fe5cdce38612d82a737ef0636d433 100644 (file)
--- a/cache.h
+++ b/cache.h
/* Initialize and use the cache information */
extern int read_cache(void);
+extern int write_cache(int newfd, struct cache_entry **cache, int entries);
extern int cache_name_pos(const char *name, int namelen);
+extern int add_cache_entry(struct cache_entry *ce);
+extern int remove_file_from_cache(char *path);
extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
#define MTIME_CHANGED 0x0001
extern int check_sha1_signature(unsigned char *sha1, void *buf, unsigned long size);
/* Convert to/from hex/sha1 representation */
-extern int get_sha1_hex(char *hex, unsigned char *sha1);
-extern char *sha1_to_hex(unsigned char *sha1); /* static buffer! */
+extern int get_sha1_hex(const char *hex, unsigned char *sha1);
+extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
/* General helper functions */
extern void usage(const char *err);
diff --git a/read-cache.c b/read-cache.c
index c42d2de330d20b599527547b1c7f130e8ec530c9..58487b569cf79a11e262ca7f809aa6b277dbd1ee 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
return ~0;
}
-int get_sha1_hex(char *hex, unsigned char *sha1)
+int get_sha1_hex(const char *hex, unsigned char *sha1)
{
int i;
for (i = 0; i < 20; i++) {
return 0;
}
-char * sha1_to_hex(unsigned char *sha1)
+char * sha1_to_hex(const unsigned char *sha1)
{
static char buffer[50];
static const char hex[] = "0123456789abcdef";
return first;
}
+int remove_file_from_cache(char *path)
+{
+ int pos = cache_name_pos(path, strlen(path));
+ if (pos < 0) {
+ pos = -pos-1;
+ active_nr--;
+ if (pos < active_nr)
+ memmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos - 1) * sizeof(struct cache_entry *));
+ }
+ return 0;
+}
+
+int add_cache_entry(struct cache_entry *ce)
+{
+ int pos;
+
+ pos = cache_name_pos(ce->name, ce->namelen);
+
+ /* existing match? Just replace it */
+ if (pos < 0) {
+ active_cache[-pos-1] = ce;
+ return 0;
+ }
+
+ /* Make sure the array is big enough .. */
+ if (active_nr == active_alloc) {
+ active_alloc = alloc_nr(active_alloc);
+ active_cache = realloc(active_cache, active_alloc * sizeof(struct cache_entry *));
+ }
+
+ /* Add it in.. */
+ active_nr++;
+ if (active_nr > pos)
+ memmove(active_cache + pos + 1, active_cache + pos, (active_nr - pos - 1) * sizeof(ce));
+ active_cache[pos] = ce;
+ return 0;
+}
+
static int verify_hdr(struct cache_header *hdr, unsigned long size)
{
SHA_CTX c;
return error("verify header failed");
}
+int write_cache(int newfd, struct cache_entry **cache, int entries)
+{
+ SHA_CTX c;
+ struct cache_header hdr;
+ int i;
+
+ hdr.signature = CACHE_SIGNATURE;
+ hdr.version = 1;
+ hdr.entries = entries;
+
+ SHA1_Init(&c);
+ SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));
+ for (i = 0; i < entries; i++) {
+ struct cache_entry *ce = cache[i];
+ int size = ce_size(ce);
+ SHA1_Update(&c, ce, size);
+ }
+ SHA1_Final(hdr.sha1, &c);
+
+ if (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr))
+ return -1;
+
+ for (i = 0; i < entries; i++) {
+ struct cache_entry *ce = cache[i];
+ int size = ce_size(ce);
+ if (write(newfd, ce, size) != size)
+ return -1;
+ }
+ return 0;
+}
diff --git a/update-cache.c b/update-cache.c
index 7a076beafc9e67d90465009f99d2f8c6e8109d75..03b111bfc074de8494e9937347357aed9d9cfc69 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
*/
#include "cache.h"
-static int remove_file_from_cache(char *path)
-{
- int pos = cache_name_pos(path, strlen(path));
- if (pos < 0) {
- pos = -pos-1;
- active_nr--;
- if (pos < active_nr)
- memmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos - 1) * sizeof(struct cache_entry *));
- }
- return 0;
-}
-
-static int add_cache_entry(struct cache_entry *ce)
-{
- int pos;
-
- pos = cache_name_pos(ce->name, ce->namelen);
-
- /* existing match? Just replace it */
- if (pos < 0) {
- active_cache[-pos-1] = ce;
- return 0;
- }
-
- /* Make sure the array is big enough .. */
- if (active_nr == active_alloc) {
- active_alloc = alloc_nr(active_alloc);
- active_cache = realloc(active_cache, active_alloc * sizeof(struct cache_entry *));
- }
-
- /* Add it in.. */
- active_nr++;
- if (active_nr > pos)
- memmove(active_cache + pos + 1, active_cache + pos, (active_nr - pos - 1) * sizeof(ce));
- active_cache[pos] = ce;
- return 0;
-}
-
static int index_fd(const char *path, int namelen, struct cache_entry *ce, int fd, struct stat *st)
{
z_stream stream;
return add_cache_entry(ce);
}
-static int write_cache(int newfd, struct cache_entry **cache, int entries)
-{
- SHA_CTX c;
- struct cache_header hdr;
- int i;
-
- hdr.signature = CACHE_SIGNATURE;
- hdr.version = 1;
- hdr.entries = entries;
-
- SHA1_Init(&c);
- SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1));
- for (i = 0; i < entries; i++) {
- struct cache_entry *ce = cache[i];
- int size = ce_size(ce);
- SHA1_Update(&c, ce, size);
- }
- SHA1_Final(hdr.sha1, &c);
-
- if (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr))
- return -1;
-
- for (i = 0; i < entries; i++) {
- struct cache_entry *ce = cache[i];
- int size = ce_size(ce);
- if (write(newfd, ce, size) != size)
- return -1;
- }
- return 0;
-}
-
/*
* We fundamentally don't like some paths: we don't want
* dot or dot-dot anywhere, and in fact, we don't even want