summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 59c1e24)
raw | patch | inline | side by side (parent: 59c1e24)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 16:26:55 +0000 (09:26 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sat, 9 Apr 2005 16:26:55 +0000 (09:26 -0700) |
It finds the cache entry position for a given name, and is
generally useful. Sure, everybody can just scan the active
cache array, but since it's sorted, you actually want to
search it with a binary search, so let's not duplicate that
logic all over the place.
generally useful. Sure, everybody can just scan the active
cache array, but since it's sorted, you actually want to
search it with a binary search, so let's not duplicate that
logic all over the place.
cache.h | patch | blob | history | |
read-cache.c | patch | blob | history | |
update-cache.c | patch | blob | history |
index 900824abfab44b8aa0c23d0942a4e0a3d2b00df4..a23ad51ae0b5be6b09af7032ad05aaaa3617854f 100644 (file)
--- a/cache.h
+++ b/cache.h
/* Initialize the cache information */
extern int read_cache(void);
+extern int cache_name_pos(const char *name, int namelen);
/* Return a statically allocated filename matching the sha1 signature */
extern char *sha1_file_name(unsigned char *sha1);
diff --git a/read-cache.c b/read-cache.c
index 50d0be35e80bf53f7df6461be3280653fb626e96..44b4b0fc69cef727b2a35c41b202e3a6bb424869 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
return -1;
}
+static int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
+{
+ int len = len1 < len2 ? len1 : len2;
+ int cmp;
+
+ cmp = memcmp(name1, name2, len);
+ if (cmp)
+ return cmp;
+ if (len1 < len2)
+ return -1;
+ if (len1 > len2)
+ return 1;
+ return 0;
+}
+
+int cache_name_pos(const char *name, int namelen)
+{
+ int first, last;
+
+ first = 0;
+ last = active_nr;
+ 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);
+ if (!cmp)
+ return -next-1;
+ if (cmp < 0) {
+ last = next;
+ continue;
+ }
+ first = next+1;
+ }
+ return first;
+}
+
static int verify_hdr(struct cache_header *hdr, unsigned long size)
{
SHA_CTX c;
diff --git a/update-cache.c b/update-cache.c
index 413e09d48fa0aad26ef4863a47e1c75c08844d81..7a076beafc9e67d90465009f99d2f8c6e8109d75 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
*/
#include "cache.h"
-static int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
-{
- int len = len1 < len2 ? len1 : len2;
- int cmp;
-
- cmp = memcmp(name1, name2, len);
- if (cmp)
- return cmp;
- if (len1 < len2)
- return -1;
- if (len1 > len2)
- return 1;
- return 0;
-}
-
-static int cache_name_pos(const char *name, int namelen)
-{
- int first, last;
-
- first = 0;
- last = active_nr;
- 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);
- if (!cmp)
- return -next-1;
- if (cmp < 0) {
- last = next;
- continue;
- }
- first = next+1;
- }
- return first;
-}
-
static int remove_file_from_cache(char *path)
{
int pos = cache_name_pos(path, strlen(path));