Re: git reveals a bug in (some versions) BSD diff

2005-08-13 Thread Brad Roberts
I'm seeing this on a standard os/x 10.3.9 install which seems to have an
old, but still GNU based, diff.

$ which diff
/usr/bin/diff

$ diff --version
diff - GNU diffutils version 2.7

$ sh ./t4101-apply-nonl.sh
*   ok 1: apply diff between 0 and 1
*   ok 2: apply diff between 0 and 2
*   ok 3: apply diff between 0 and 3
*   ok 4: apply diff between 1 and 0
*   ok 5: apply diff between 1 and 2
*   ok 6: apply diff between 1 and 3
*   ok 7: apply diff between 2 and 0
*   ok 8: apply diff between 2 and 1
* FAIL 9: apply diff between 2 and 3
git-apply http://vger.kernel.org/majordomo-info.html


[PATCH] fix null TZ problems on os/x

2005-08-13 Thread Brad Roberts
[PATCH] Fix TZ handling in tests, "" isn't a valid timezone at least on os/x

It seems that the localtime() libc routine doesn't care for finding a TZ
that's empty.  It's ok with TZ not being set.  Setting the TZ to GMT allowed
these tests to pass.

$ uname -v
Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; 
root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>

---
diff --git a/t/t1100-commit-tree-options.sh b/t/t1100-commit-tree-options.sh
--- a/t/t1100-commit-tree-options.sh
+++ b/t/t1100-commit-tree-options.sh
@@ -32,7 +32,7 @@ test_expect_success \
  GIT_COMMITTER_NAME="Committer Name" \
  GIT_COMMITTER_EMAIL="[EMAIL PROTECTED]" \
  GIT_COMMITTER_DATE="2005-05-26 23:30" \
- TZ= git-commit-tree `cat treeid` >commitid 2>/dev/null'
+ TZ=GMT git-commit-tree `cat treeid` >commitid 2>/dev/null'

 test_expect_success \
 'read commit' \
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -41,7 +41,7 @@ test_expect_success \
  find a -type l | xargs git-update-cache --add &&
  treeid=`git-write-tree` &&
  echo $treeid >treeid &&
- TZ= GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
+ TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
  git-commit-tree $treeid .git/HEAD'

 test_expect_success \
@@ -50,7 +50,7 @@ test_expect_success \

 test_expect_success \
 'validate file modification time' \
-'TZ= tar tvf b.tar a/a |
+'TZ=GMT tar tvf b.tar a/a |
  awk \{print\ \$4,\ \(length\(\$5\)\<7\)\ ?\ \$5\":00\"\ :\ \$5\} \
  >b.mtime &&
  echo "2005-05-27 22:00:00" >expected.mtime &&



-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01-19/19] All of the above combined

2005-04-21 Thread Brad Roberts
Make the cache management code behave more like a library.  There are no
longer any global variables in read-cache.c.  Nothing ever uses more than
one cache yet, but I can see how it might simplify some of the merge code.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---
 
 cache.h  |   36 +++--
 check-files.c|   12 +--
 checkout-cache.c |   22 +++---
 diff-cache.c |   36 -
 merge-cache.c|   29 ---
 read-cache.c |  200 ---
 read-tree.c  |   71 +++
 show-diff.c  |   19 +++--
 show-files.c |   27 +++
 update-cache.c   |   39 +-
 write-tree.c |   24 +++---
11 files changed, 292 insertions(+), 223 deletions(-)

Index: cache.h
===
--- c0260bfb82da04aeff4e598ced5295d6ae2e262d/cache.h  (mode:100644 
sha1:828d660ab82bb35a1ca632a2ba4620dc483889bd)
+++ 38adb888a4c1adfe083f24d4ec51018e0b5a8335/cache.h  (mode:100644 
sha1:d8ade9f4b9bd9b6045f97b4df5bef8356c767d46)
@@ -17,21 +17,6 @@
 #include 
 
 /*
- * Basic data structures for the directory cache
- *
- * NOTE NOTE NOTE! This is all in the native CPU byte format. It's
- * not even trying to be portable. It's trying to be efficient. It's
- * just a cache, after all.
- */
-
-#define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
-struct cache_header {
-   unsigned int hdr_signature;
-   unsigned int hdr_version;
-   unsigned int hdr_entries;
-};
-
-/*
  * The "cache_time" is just the low 32 bits of the
  * time. It doesn't matter if it overflows - we only
  * check it for equality in the 32 bits we save.
@@ -67,6 +52,8 @@
 #define CE_STAGEMASK (0x3000)
 #define CE_STAGESHIFT 12
 
+extern int ce_match_stat(struct cache_entry *ce, struct stat *st);
+
 #define create_ce_flags(len, stage) htons((len) | ((stage) << CE_STAGESHIFT))
 #define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags))
 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
@@ -78,8 +65,6 @@
 #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) 
& ~7)
 
 const char *sha1_file_directory;
-struct cache_entry **active_cache;
-unsigned int active_nr, active_alloc;
 
 #define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
 #define DEFAULT_DB_ENVIRONMENT ".git/objects"
@@ -87,12 +72,17 @@
 #define alloc_nr(x) (((x)+16)*3/2)
 
 /* 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, int ok_to_add);
-extern int remove_file_from_cache(char *path);
-extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
+extern struct cache *new_cache(void);
+extern struct cache *read_cache(void);
+extern int write_cache(struct cache *cache, int newfd);
+extern void free_cache(struct cache *cache);
+extern int cache_name_pos(struct cache *cache, const char *name, int namelen);
+extern int add_cache_entry(struct cache *cache, struct cache_entry *ce, int 
ok_to_add);
+extern int remove_file_from_cache(struct cache *cache, char *path);
+extern int get_num_cache_entries(struct cache *cache);
+extern struct cache_entry * get_cache_entry(struct cache *cache, int pos);
+extern void set_cache_entry(struct cache *cache, struct cache_entry *ce, int 
pos);
+extern int remove_cache_entry_at(struct cache *cache, int pos);
 
 #define MTIME_CHANGED  0x0001
 #define CTIME_CHANGED  0x0002
Index: check-files.c
===
--- c0260bfb82da04aeff4e598ced5295d6ae2e262d/check-files.c  (mode:100644 
sha1:7d16691aa9d51b5b4670d5837b3527ee7c7da79c)
+++ 38adb888a4c1adfe083f24d4ec51018e0b5a8335/check-files.c  (mode:100644 
sha1:4de6d39e4997d29f13261c21eeb378f74b3f8a8f)
@@ -8,7 +8,7 @@
  */
 #include "cache.h"
 
-static void check_file(const char *path)
+static void check_file(struct cache *cache, const char *path)
 {
int fd = open(path, O_RDONLY);
struct cache_entry *ce;
@@ -23,15 +23,15 @@
}
 
/* Exists but is not in the cache is not fine */
-   pos = cache_name_pos(path, strlen(path));
+   pos = cache_name_pos(cache, path, strlen(path));
if (pos < 0)
die("preparing to update existing file '%s' not in cache", 
path);
-   ce = active_cache[pos];
+   ce = get_cache_entry(cache, pos);
 
if (fstat(fd, &st) < 0)
die("fstat(%s): %s", path, strerror(errno));
 
-   changed = cache_match_stat(ce, &st);
+   changed = ce_match_stat(ce, &st);
if (changed)
die("preparing to update file '%s' not uptodate in cache", 
path);
 }
@@ -39,9 +39,9 @@
 int main(int argc, char **

[PATCH 19/19] the end goal of the last dozen or so commits, there's no longer a global cache variable

2005-04-21 Thread Brad Roberts
tree 38adb888a4c1adfe083f24d4ec51018e0b5a8335
parent 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac
author Brad Roberts <[EMAIL PROTECTED]> 1114093024 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114093024 -0700

[PATCH] the end goal of the last dozen or so commits, there's no longer a 
global cache variable

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |   21 +++---
 check-files.c|   10 +++---
 checkout-cache.c |   20 ++---
 diff-cache.c |   20 ++---
 merge-cache.c|   29 ++-
 read-cache.c |   82 ---
 read-tree.c  |   51 ++
 show-diff.c  |8 ++---
 show-files.c |   27 +-
 update-cache.c   |   35 ---
 write-tree.c |   20 ++---
 11 files changed, 167 insertions(+), 156 deletions(-)

Index: cache.h
===
--- 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/cache.h  (mode:100644 
sha1:c64969602d80a0e9d7137b2716fb808c912b075c)
+++ 7e396358c12c0129bcb4945e3e35a4fa76890a0c:1/cache.h  (mode:100644 
sha1:d8ade9f4b9bd9b6045f97b4df5bef8356c767d46)
@@ -72,16 +72,17 @@
 #define alloc_nr(x) (((x)+16)*3/2)
 
 /* Initialize and use the cache information */
-extern int read_cache(void);
-extern int write_cache(int newfd);
-extern void free_cache();
-extern int cache_name_pos(const char *name, int namelen);
-extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
-extern int remove_file_from_cache(char *path);
-extern int get_num_cache_entries();
-extern struct cache_entry * get_cache_entry(int pos);
-extern void set_cache_entry(struct cache_entry *ce, int pos);
-extern int remove_cache_entry_at(int pos);
+extern struct cache *new_cache(void);
+extern struct cache *read_cache(void);
+extern int write_cache(struct cache *cache, int newfd);
+extern void free_cache(struct cache *cache);
+extern int cache_name_pos(struct cache *cache, const char *name, int namelen);
+extern int add_cache_entry(struct cache *cache, struct cache_entry *ce, int 
ok_to_add);
+extern int remove_file_from_cache(struct cache *cache, char *path);
+extern int get_num_cache_entries(struct cache *cache);
+extern struct cache_entry * get_cache_entry(struct cache *cache, int pos);
+extern void set_cache_entry(struct cache *cache, struct cache_entry *ce, int 
pos);
+extern int remove_cache_entry_at(struct cache *cache, int pos);
 
 #define MTIME_CHANGED  0x0001
 #define CTIME_CHANGED  0x0002
Index: check-files.c
===
--- 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/check-files.c  (mode:100644 
sha1:0973e81fbbc0f9f98031fb249254bd89d809)
+++ 7e396358c12c0129bcb4945e3e35a4fa76890a0c:1/check-files.c  (mode:100644 
sha1:4de6d39e4997d29f13261c21eeb378f74b3f8a8f)
@@ -8,7 +8,7 @@
  */
 #include "cache.h"
 
-static void check_file(const char *path)
+static void check_file(struct cache *cache, const char *path)
 {
int fd = open(path, O_RDONLY);
struct cache_entry *ce;
@@ -23,10 +23,10 @@
}
 
/* Exists but is not in the cache is not fine */
-   pos = cache_name_pos(path, strlen(path));
+   pos = cache_name_pos(cache, path, strlen(path));
if (pos < 0)
die("preparing to update existing file '%s' not in cache", 
path);
-   ce = get_cache_entry(pos);
+   ce = get_cache_entry(cache, pos);
 
if (fstat(fd, &st) < 0)
die("fstat(%s): %s", path, strerror(errno));
@@ -39,9 +39,9 @@
 int main(int argc, char **argv)
 {
int i;
+   struct cache *cache = read_cache();
 
-   read_cache();
for (i = 1; i < argc ; i++)
-   check_file(argv[i]);
+   check_file(cache, argv[i]);
return 0;
 }
Index: checkout-cache.c
===
--- 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/checkout-cache.c  (mode:100644 
sha1:27b559d5bcc5831eda441bcd1fd88d687f2567b8)
+++ 7e396358c12c0129bcb4945e3e35a4fa76890a0c:1/checkout-cache.c  (mode:100644 
sha1:2e8c61323a72f6052d8c9ef76a4eef05aa5ac0f9)
@@ -120,23 +120,23 @@
return write_entry(ce);
 }
 
-static int checkout_file(const char *name)
+static int checkout_file(struct cache *cache, const char *name)
 {
-   int pos = cache_name_pos(name, strlen(name));
+   int pos = cache_name_pos(cache, name, strlen(name));
if (pos < 0) {
if (!quiet)
fprintf(stderr, "checkout-cache: %s is not in the 
cache\n", name);
return -1;
}
-   return checkout_entry(get_cache_entry(pos));
+   return checkout_entry(get_cache_entry(cache, pos));
 }
 
-static int checkout_all(void)
+static int checkout_all(struct cache *cache)
 {
int i;
 
- 

[PATCH 18/19] rename cache_match_stat to ce_match_stat to match other cache_entry related functions/macros

2005-04-21 Thread Brad Roberts
tree f8dd454f774d42526149193970b612a46f3ddd26
parent 058c25fd81e5949354d96f2aad222ae73a6c1dee
author Brad Roberts <[EMAIL PROTECTED]> 1114088345 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114088345 -0700

[PATCH] rename cache_match_stat to ce_match_stat to match other cache_entry 
related functions/macros

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |3 ++-
 check-files.c|2 +-
 checkout-cache.c |2 +-
 diff-cache.c |2 +-
 read-cache.c |2 +-
 show-diff.c  |2 +-
 update-cache.c   |2 +-
 7 files changed, 8 insertions(+), 7 deletions(-)

Index: cache.h
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/cache.h  (mode:100644 
sha1:a3018f9e12bfdd1a5273b20fcab5062667c6caec)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/cache.h  (mode:100644 
sha1:c64969602d80a0e9d7137b2716fb808c912b075c)
@@ -52,6 +52,8 @@
 #define CE_STAGEMASK (0x3000)
 #define CE_STAGESHIFT 12
 
+extern int ce_match_stat(struct cache_entry *ce, struct stat *st);
+
 #define create_ce_flags(len, stage) htons((len) | ((stage) << CE_STAGESHIFT))
 #define ce_namelen(ce) (CE_NAMEMASK & ntohs((ce)->ce_flags))
 #define ce_size(ce) cache_entry_size(ce_namelen(ce))
@@ -76,7 +78,6 @@
 extern int cache_name_pos(const char *name, int namelen);
 extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
 extern int remove_file_from_cache(char *path);
-extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
 extern int get_num_cache_entries();
 extern struct cache_entry * get_cache_entry(int pos);
 extern void set_cache_entry(struct cache_entry *ce, int pos);
Index: check-files.c
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/check-files.c  (mode:100644 
sha1:919e418b5f0f85220445c876a37bf4cf61d26525)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/check-files.c  (mode:100644 
sha1:0973e81fbbc0f9f98031fb249254bd89d809)
@@ -31,7 +31,7 @@
if (fstat(fd, &st) < 0)
die("fstat(%s): %s", path, strerror(errno));
 
-   changed = cache_match_stat(ce, &st);
+   changed = ce_match_stat(ce, &st);
if (changed)
die("preparing to update file '%s' not uptodate in cache", 
path);
 }
Index: checkout-cache.c
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/checkout-cache.c  (mode:100644 
sha1:bf9cd0572c883219d37f2788ec5f5553a136df2b)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/checkout-cache.c  (mode:100644 
sha1:27b559d5bcc5831eda441bcd1fd88d687f2567b8)
@@ -100,7 +100,7 @@
struct stat st;
 
if (!stat(ce->name, &st)) {
-   unsigned changed = cache_match_stat(ce, &st);
+   unsigned changed = ce_match_stat(ce, &st);
if (!changed)
return 0;
if (!force) {
Index: diff-cache.c
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/diff-cache.c  (mode:100644 
sha1:548211944fc00594bfc06b9ab90f0cb476688285)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/diff-cache.c  (mode:100644 
sha1:5ae6d5de5ed5ad34f72267904ff8eb6288855fc5)
@@ -125,7 +125,7 @@
show_file("-", path1, mode1, sha1, base);
return -1;
}
-   changed = cache_match_stat(ce, &st);
+   changed = ce_match_stat(ce, &st);
close(fd);
if (changed) {
mode2 = st.st_mode;
Index: read-cache.c
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/read-cache.c  (mode:100644 
sha1:31e293a3686622c9ec180d41aa37d85ce49325e8)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/read-cache.c  (mode:100644 
sha1:8837d27ab683bf07d38aee33c62a90f5a7221588)
@@ -44,7 +44,7 @@
cache = NULL;
 }
 
-int cache_match_stat(struct cache_entry *ce, struct stat *st)
+int ce_match_stat(struct cache_entry *ce, struct stat *st)
 {
unsigned int changed = 0;
 
Index: show-diff.c
===
--- 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/show-diff.c  (mode:100644 
sha1:6e04e9182667cbb79afa4c878a31b685fdea3229)
+++ 0a556dc01b8e48f684ce6e0c26f8c00b5e39c4ac:1/show-diff.c  (mode:100644 
sha1:4a0902f50b3120b7791a4d4627a9a4f729afdcf7)
@@ -193,7 +193,7 @@
}
continue;
}
-   changed = cache_match_stat(ce, &st);
+   changed = ce_match_stat(ce, &st);
if (!changed)
continue;
if (!machine_readable)
Index: update-cache.c

[PATCH 17/19] temporarily change add_cache_entry to create an empty cache on demand

2005-04-21 Thread Brad Roberts
tree 6feaeb314fb1bea393250972b109b7d218cf37d7
parent b965055600b8bf4927ea631446cd6cde714aef95
author Brad Roberts <[EMAIL PROTECTED]> 1114087949 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114087949 -0700

[PATCH] temporarily change add_cache_entry to create an empty cache on demand

read-tree.c expects to be able to add entries into an empty cache in the
non-merging mode.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 read-cache.c |   26 ++
 1 files changed, 18 insertions(+), 8 deletions(-)

Index: read-cache.c
===
--- b965055600b8bf4927ea631446cd6cde714aef95:1/read-cache.c  (mode:100644 
sha1:c399f8e497441147afe630ca080558a8c6c79c78)
+++ 058c25fd81e5949354d96f2aad222ae73a6c1dee:1/read-cache.c  (mode:100644 
sha1:31e293a3686622c9ec180d41aa37d85ce49325e8)
@@ -32,6 +32,18 @@
 
 static struct cache * cache = NULL;
 
+struct cache * new_cache()
+{
+   return (struct cache*)calloc(1, sizeof(struct cache));
+}
+
+void free_cache()
+{
+   munmap(cache->map.ptr, cache->map.size);
+   free(cache);
+   cache = NULL;
+}
+
 int cache_match_stat(struct cache_entry *ce, struct stat *st)
 {
unsigned int changed = 0;
@@ -155,6 +167,11 @@
 {
int pos;
 
+   /* temporary, read-tree.c expects the cache to always exist, even
+* without a read_cache being called */
+   if (!cache)
+   cache = new_cache();
+
pos = cache_name_pos(ce->name, htons(ce->ce_flags));
 
/* existing match? Just replace it */
@@ -230,7 +247,7 @@
return (errno == ENOENT) ? 0 : error("open failed");
 
errno = ENOMEM;
-   cache = (struct cache*)malloc(sizeof(struct cache));
+   cache = new_cache();
if (!cache)
return error("unable to allocate cache");
 
@@ -333,10 +350,3 @@
}
return ce_flush(&c, newfd);
 }
-
-void free_cache()
-{
-   munmap(cache->map.ptr, cache->map.size);
-   free(cache);
-   cache = NULL;
-}

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/19] change all call sites that use the return value of read_cache to get the # of cache entries.

2005-04-21 Thread Brad Roberts
tree 6bce19032505c2939bf74eeca5e51aeefa4e1600
parent f07f7073f45a7f81e5b6cf26f5181e14fd051d81
author Brad Roberts <[EMAIL PROTECTED]> 1114086602 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114086602 -0700

[PATCH] change all call sites that use the return value of read_cache to get 
the # of cache entries.

This patch somewhat breaks error handling for those call sites.  I'll fix
that in the next few patches.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 show-diff.c|   13 -
 update-cache.c |3 ++-
 write-tree.c   |4 +++-
 3 files changed, 13 insertions(+), 7 deletions(-)

Index: show-diff.c
===
--- f07f7073f45a7f81e5b6cf26f5181e14fd051d81:1/show-diff.c  (mode:100644 
sha1:e2642b65805b3e52a16c6309b44a92c2a2bd13c3)
+++ b965055600b8bf4927ea631446cd6cde714aef95:1/show-diff.c  (mode:100644 
sha1:6e04e9182667cbb79afa4c878a31b685fdea3229)
@@ -126,10 +126,17 @@
int silent_on_nonexisting_files = 0;
int machine_readable = 0;
int reverse = 0;
-   int entries = read_cache();
+   int entries;
int matched = 0;
int i;
 
+   read_cache();
+   entries = get_num_cache_entries();
+   if (entries < 0) {
+   perror("read_cache");
+   exit(1);
+   }
+
while (1 < argc && argv[1][0] == '-') {
if  (!strcmp(argv[1], "-R"))
reverse = 1;
@@ -147,10 +154,6 @@
/* At this point, if argc == 1, then we are doing everything.
 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
 */
-   if (entries < 0) {
-   perror("read_cache");
-   exit(1);
-   }
prepare_diff_cmd();
for (i = 0; i < entries; i++) {
struct stat st;
Index: update-cache.c
===
--- f07f7073f45a7f81e5b6cf26f5181e14fd051d81:1/update-cache.c  (mode:100644 
sha1:e741f593eb9c56c596fabed7eb6b79dee2d8cba9)
+++ b965055600b8bf4927ea631446cd6cde714aef95:1/update-cache.c  (mode:100644 
sha1:8328975cb726f5e06a413a9f0099bfa2f81d3381)
@@ -299,7 +299,8 @@
atexit(remove_lock_file);
remove_lock = 1;
 
-   entries = read_cache();
+   read_cache();
+   entries = get_num_cache_entries();
if (entries < 0)
die("cache corrupted");
 
Index: write-tree.c
===
--- f07f7073f45a7f81e5b6cf26f5181e14fd051d81:1/write-tree.c  (mode:100644 
sha1:f1b12cdde1bb446a134a121760007150008b251a)
+++ b965055600b8bf4927ea631446cd6cde714aef95:1/write-tree.c  (mode:100644 
sha1:92e707fd4780805da160ce6fa282e75111ea67b9)
@@ -101,9 +101,11 @@
 int main(int argc, char **argv)
 {
int i, unmerged;
-   int entries = read_cache();
+   int entries;
unsigned char sha1[20];
 
+   read_cache();
+   entries = get_num_cache_entries();
if (entries <= 0)
die("write-tree: no cache contents to write");
 

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/19] introduce a cache struct and move the various cache globals into it.

2005-04-21 Thread Brad Roberts
tree c806c7328a6c9297df108ab00ebe1c4014496cb0
parent b7d4fa53d4ee449b4b9b4f3c9dd40d6c99db4bc1
author Brad Roberts <[EMAIL PROTECTED]> 1114086327 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114086327 -0700

[PATCH] introduce a cache struct and move the various cache globals into it.

New elements in the cache struct that previously were discarded:
  - the cache headers
  - the mmap info so we can cleanup later

For this stage, the cache itself is still a global variable.  That will change.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |1 
 read-cache.c |  127 ++-
 2 files changed, 76 insertions(+), 52 deletions(-)

Index: cache.h
===
--- b7d4fa53d4ee449b4b9b4f3c9dd40d6c99db4bc1:1/cache.h  (mode:100644 
sha1:74d6c4d25c564e08eadc04aaef31a711d0645a43)
+++ f07f7073f45a7f81e5b6cf26f5181e14fd051d81:1/cache.h  (mode:100644 
sha1:a3018f9e12bfdd1a5273b20fcab5062667c6caec)
@@ -72,6 +72,7 @@
 /* Initialize and use the cache information */
 extern int read_cache(void);
 extern int write_cache(int newfd);
+extern void free_cache();
 extern int cache_name_pos(const char *name, int namelen);
 extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
 extern int remove_file_from_cache(char *path);
Index: read-cache.c
===
--- b7d4fa53d4ee449b4b9b4f3c9dd40d6c99db4bc1:1/read-cache.c  (mode:100644 
sha1:b16a72dc4e4525a7df060b3a43722217db7869c2)
+++ f07f7073f45a7f81e5b6cf26f5181e14fd051d81:1/read-cache.c  (mode:100644 
sha1:c399f8e497441147afe630ca080558a8c6c79c78)
@@ -17,8 +17,20 @@
unsigned int hdr_entries;
 };
 
-static struct cache_entry **active_cache = NULL;
-static unsigned int active_nr = 0, active_alloc = 0;
+struct mmap_holder {
+   void * ptr;
+   size_t size;
+};
+
+struct cache {
+   struct mmap_holder   map;
+   struct cache_header *header;
+   struct cache_entry **entries;
+   unsigned int num_entries;
+   unsigned int allocated_entries;
+};
+
+static struct cache * cache = NULL;
 
 int cache_match_stat(struct cache_entry *ce, struct stat *st)
 {
@@ -81,10 +93,10 @@
int first, last;
 
first = 0;
-   last = active_nr;
+   last = cache->num_entries;
while (last > first) {
int next = (last + first) >> 1;
-   struct cache_entry *ce = active_cache[next];
+   struct cache_entry *ce = cache->entries[next];
int cmp = cache_name_compare(name, namelen, ce->name, 
htons(ce->ce_flags));
if (!cmp)
return next;
@@ -100,10 +112,10 @@
 /* Remove entry, return true if there are more entries to go.. */
 int remove_cache_entry_at(int pos)
 {
-   active_nr--;
-   if (pos >= active_nr)
+   cache->num_entries--;
+   if (pos >= cache->num_entries)
return 0;
-   memmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos) * 
sizeof(struct cache_entry *));
+   memmove(cache->entries + pos, cache->entries + pos + 1, 
(cache->num_entries - pos) * sizeof(struct cache_entry *));
return 1;
 }
 
@@ -123,20 +135,20 @@
 
 int get_num_cache_entries()
 {
-   return active_nr;
+   return cache->num_entries;
 }
 
 struct cache_entry * get_cache_entry(int pos)
 {
-   return active_cache[pos];
+   return cache->entries[pos];
 }
 
 void set_cache_entry(struct cache_entry *ce, int pos)
 {
-   /* You can NOT just free active_cache[i] here, since it
+   /* You can NOT just free cache->entries[i] here, since it
 * might not be necessarily malloc()ed but can also come
 * from mmap(). */
-   active_cache[pos] = ce;
+   cache->entries[pos] = ce;
 }
 
 int add_cache_entry(struct cache_entry *ce, int ok_to_add)
@@ -147,7 +159,7 @@
 
/* existing match? Just replace it */
if (pos >= 0) {
-   active_cache[pos] = ce;
+   cache->entries[pos] = ce;
return 0;
}
pos = -pos-1;
@@ -156,8 +168,8 @@
 * Inserting a merged entry ("stage 0") into the index
 * will always replace all non-merged entries..
 */
-   if (pos < active_nr && ce_stage(ce) == 0) {
-   while (same_name(active_cache[pos], ce)) {
+   if (pos < cache->num_entries && ce_stage(ce) == 0) {
+   while (same_name(cache->entries[pos], ce)) {
ok_to_add = 1;
if (!remove_cache_entry_at(pos))
break;
@@ -168,16 +180,16 @@
return -1;
 
/* Make sure the array is big enough .. */
-   if (active_nr == active_alloc) {
-   active_alloc = alloc_nr(active_alloc);
- 

[PATCH 14/19] move cache_header out of the public view

2005-04-21 Thread Brad Roberts
tree a2c82ce3512904f82f78d87d86709a471f67ef9f
parent ff3667537379d5b0680e8c4f9a14d82dc9835430
author Brad Roberts <[EMAIL PROTECTED]> 1114083477 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114083477 -0700

[PATCH] move cache_header out of the public view

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |   15 ---
 read-cache.c |   11 +++
 2 files changed, 11 insertions(+), 15 deletions(-)

Index: cache.h
===
--- ff3667537379d5b0680e8c4f9a14d82dc9835430:1/cache.h  (mode:100644 
sha1:b29bb0ca5e7be15c0b423101f5cf381ee68f139e)
+++ b7d4fa53d4ee449b4b9b4f3c9dd40d6c99db4bc1:1/cache.h  (mode:100644 
sha1:74d6c4d25c564e08eadc04aaef31a711d0645a43)
@@ -17,21 +17,6 @@
 #include 
 
 /*
- * Basic data structures for the directory cache
- *
- * NOTE NOTE NOTE! This is all in the native CPU byte format. It's
- * not even trying to be portable. It's trying to be efficient. It's
- * just a cache, after all.
- */
-
-#define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
-struct cache_header {
-   unsigned int hdr_signature;
-   unsigned int hdr_version;
-   unsigned int hdr_entries;
-};
-
-/*
  * The "cache_time" is just the low 32 bits of the
  * time. It doesn't matter if it overflows - we only
  * check it for equality in the 32 bits we save.
Index: read-cache.c
===
--- ff3667537379d5b0680e8c4f9a14d82dc9835430:1/read-cache.c  (mode:100644 
sha1:0e972a80fa19eb77fd547fb579354af784be3ac4)
+++ b7d4fa53d4ee449b4b9b4f3c9dd40d6c99db4bc1:1/read-cache.c  (mode:100644 
sha1:b16a72dc4e4525a7df060b3a43722217db7869c2)
@@ -6,6 +6,17 @@
 #include 
 #include "cache.h"
 
+/*
+ * Basic data structures for the directory cache
+ */
+
+#define CACHE_SIGNATURE 0x44495243 /* "DIRC" */
+struct cache_header {
+   unsigned int hdr_signature;
+   unsigned int hdr_version;
+   unsigned int hdr_entries;
+};
+
 static struct cache_entry **active_cache = NULL;
 static unsigned int active_nr = 0, active_alloc = 0;
 

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 13/19] Remove active_cache, active_nr, and active_alloc from public view

2005-04-21 Thread Brad Roberts
tree 9198385d73b718a2fd016362a9d93ccce1e7423c
parent cc414a188c0e8fefa7bea4f969cc7adfe4265d6f
author Brad Roberts <[EMAIL PROTECTED]> 1114083132 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114083132 -0700

[PATCH] Remove active_cache, active_nr, and active_alloc from public view

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |2 --
 read-cache.c |4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

Index: cache.h
===
--- cc414a188c0e8fefa7bea4f969cc7adfe4265d6f:1/cache.h  (mode:100644 
sha1:74d816c34245e0dde41643188f38cf99ca75e75f)
+++ ff3667537379d5b0680e8c4f9a14d82dc9835430:1/cache.h  (mode:100644 
sha1:b29bb0ca5e7be15c0b423101f5cf381ee68f139e)
@@ -78,8 +78,6 @@
 #define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) 
& ~7)
 
 const char *sha1_file_directory;
-struct cache_entry **active_cache;
-unsigned int active_nr, active_alloc;
 
 #define DB_ENVIRONMENT "SHA1_FILE_DIRECTORY"
 #define DEFAULT_DB_ENVIRONMENT ".git/objects"
Index: read-cache.c
===
--- cc414a188c0e8fefa7bea4f969cc7adfe4265d6f:1/read-cache.c  (mode:100644 
sha1:286f7136bc164f3a2317bb492138d9221efb4025)
+++ ff3667537379d5b0680e8c4f9a14d82dc9835430:1/read-cache.c  (mode:100644 
sha1:0e972a80fa19eb77fd547fb579354af784be3ac4)
@@ -6,8 +6,8 @@
 #include 
 #include "cache.h"
 
-struct cache_entry **active_cache = NULL;
-unsigned int active_nr = 0, active_alloc = 0;
+static struct cache_entry **active_cache = NULL;
+static unsigned int active_nr = 0, active_alloc = 0;
 
 int cache_match_stat(struct cache_entry *ce, struct stat *st)
 {

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/19] fix up diff-cache.c to use new cache api's

2005-04-21 Thread Brad Roberts
tree 44f1ef88a5d0effdf2337f4c72b88b2bdcd9a54b
parent 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1
author Brad Roberts <[EMAIL PROTECTED]> 1114082996 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114082996 -0700

[PATCH] fix up diff-cache.c to use new cache api's

Along the way, rewrite to use a position index rather than pointer math.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 diff-cache.c |   32 +---
 1 files changed, 13 insertions(+), 19 deletions(-)

Index: diff-cache.c
===
--- 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1:1/diff-cache.c  (mode:100644 
sha1:fcbc4900d32f4ca24f67bb8f0fe344c6c5642ac9)
+++ cc414a188c0e8fefa7bea4f969cc7adfe4265d6f:1/diff-cache.c  (mode:100644 
sha1:548211944fc00594bfc06b9ab90f0cb476688285)
@@ -4,7 +4,7 @@
 static int recursive = 0;
 static int line_termination = '\n';
 
-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac, 
int entries, const char *base);
+static int diff_cache(void *tree, unsigned long size, int pos, const char 
*base);
 
 static void update_tree_entry(void **bufp, unsigned long *sizep)
 {
@@ -82,10 +82,10 @@
 }
 
 static int compare_tree_entry(const char *path1, unsigned int mode1, const 
unsigned char *sha1,
- struct cache_entry **ac, int *entries, const char 
*base)
+ int *pos, const char *base)
 {
int baselen = strlen(base);
-   struct cache_entry *ce = *ac;
+   struct cache_entry *ce = get_cache_entry(*pos);
const char *path2 = ce->name + baselen;
unsigned int mode2 = ntohl(ce->ce_mode);
const unsigned char *sha2 = ce->sha1;
@@ -107,7 +107,7 @@
memcpy(newbase + baselen + pathlen1, "/", 2);
if (!tree || strcmp(type, "tree"))
die("unable to read tree object %s", 
sha1_to_hex(sha1));
-   *entries = diff_cache(tree, size, ac, *entries, 
newbase);
+   *pos = diff_cache(tree, size, *pos, newbase);
free(newbase);
free(tree);
return -1;
@@ -158,7 +158,7 @@
return 0;
 }
 
-static int diff_cache(void *tree, unsigned long size, struct cache_entry **ac, 
int entries, const char *base)
+static int diff_cache(void *tree, unsigned long size, int pos, const char 
*base)
 {
int baselen = strlen(base);
 
@@ -167,15 +167,16 @@
unsigned int mode;
const char *path;
const unsigned char *sha1;
-   int left;
 
/*
 * No entries in the cache (with this base)?
 * Output the tree contents.
 */
-   if (!entries || ce_namelen(ce = *ac) < baselen || 
memcmp(ce->name, base, baselen)) {
+   if ((pos == get_num_cache_entries()) ||
+   ce_namelen(ce = get_cache_entry(pos)) < baselen ||
+   memcmp(ce->name, base, baselen)) {
if (!size)
-   return entries;
+   return pos;
sha1 = extract(tree, size, &path, &mode);
show_file("-", path, mode, sha1, base);
update_tree_entry(&tree, &size);
@@ -187,27 +188,20 @@
 */
if (!size) {
show_file("+", ce->name, ntohl(ce->ce_mode), ce->sha1, 
"");
-   ac++;
-   entries--;
+   pos++;
continue;
}
 
sha1 = extract(tree, size, &path, &mode);
-   left = entries;
-   switch (compare_tree_entry(path, mode, sha1, ac, &left, base)) {
+   switch (compare_tree_entry(path, mode, sha1, &pos, base)) {
case -1:
update_tree_entry(&tree, &size);
-   if (left < entries) {
-   ac += (entries - left);
-   entries = left;
-   }
continue;
case 0:
update_tree_entry(&tree, &size);
/* Fallthrough */
case 1:
-   ac++;
-   entries--;
+   pos++;
continue;
}
die("diff-cache: internal error");
@@ -263,5 +257,5 @@
if (strcmp(type, "tree"))
die("bad tree object %s (%s)", sha1_to_hex(tree_sha1), type);
 
-   return diff_cache(tree, size, active_cache, a

[PATCH 11/19] migrate write-tree.c to use the new cache api's

2005-04-21 Thread Brad Roberts
tree 3a2928786f84d81cfb1a5846cdaf9f3d5403cbcf
parent a94803645fb68119be8835d466585c91e664a173
author Brad Roberts <[EMAIL PROTECTED]> 1114077713 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114077713 -0700

[PATCH] migrate write-tree.c to use the new cache api's

Along the way, altered the write_tree recursion to stay based off of a starting
position rather than moving the array pointer for each recurse step.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 write-tree.c |   18 +-
 1 files changed, 9 insertions(+), 9 deletions(-)

Index: write-tree.c
===
--- a94803645fb68119be8835d466585c91e664a173:1/write-tree.c  (mode:100644 
sha1:827809dbddbff6dd8cf842641f6db5ad2f3ae07a)
+++ 8a4556bdf5bc847117c840a8fd7fa42f6efb16e1:1/write-tree.c  (mode:100644 
sha1:f1b12cdde1bb446a134a121760007150008b251a)
@@ -29,7 +29,7 @@
 
 #define ORIG_OFFSET (40)   /* Enough space to add the header of "tree 
\0" */
 
-static int write_tree(struct cache_entry **cachep, int maxentries, const char 
*base, int baselen, unsigned char *returnsha1)
+static int write_tree(int start_pos, const char *base, int baselen, unsigned 
char *returnsha1)
 {
unsigned char subdir_sha1[20];
unsigned long size, offset;
@@ -43,7 +43,7 @@
 
nr = 0;
do {
-   struct cache_entry *ce = cachep[nr];
+   struct cache_entry *ce = get_cache_entry(start_pos + nr);
const char *pathname = ce->name, *filename, *dirname;
int pathlen = ce_namelen(ce), entrylen;
unsigned char *sha1;
@@ -53,16 +53,13 @@
if (baselen >= pathlen || memcmp(base, pathname, baselen))
break;
 
-   sha1 = ce->sha1;
-   mode = ntohl(ce->ce_mode);
-
/* Do we have _further_ subdirectories? */
filename = pathname + baselen;
dirname = strchr(filename, '/');
if (dirname) {
int subdir_written;
 
-   subdir_written = write_tree(cachep + nr, maxentries - 
nr, pathname, dirname-pathname+1, subdir_sha1);
+   subdir_written = write_tree(start_pos + nr, pathname, 
dirname-pathname+1, subdir_sha1);
nr += subdir_written;
 
/* Now we need to write out the directory entry into 
this tree.. */
@@ -72,6 +69,9 @@
/* ..but the directory entry doesn't count towards the 
total count */
nr--;
sha1 = subdir_sha1;
+   } else {
+   sha1 = ce->sha1;
+   mode = ntohl(ce->ce_mode);
}
 
if (check_valid_sha1(sha1) < 0)
@@ -87,7 +87,7 @@
memcpy(buffer + offset, sha1, 20);
offset += 20;
nr++;
-   } while (nr < maxentries);
+   } while ((start_pos + nr) < get_num_cache_entries());
 
i = prepend_integer(buffer, offset - ORIG_OFFSET, ORIG_OFFSET);
i -= 5;
@@ -110,7 +110,7 @@
/* Verify that the tree is merged */
unmerged = 0;
for (i = 0; i < entries; i++) {
-   struct cache_entry *ce = active_cache[i];
+   struct cache_entry *ce = get_cache_entry(i);
if (ntohs(ce->ce_flags) & ~CE_NAMEMASK) {
if (++unmerged > 10) {
fprintf(stderr, "...\n");
@@ -123,7 +123,7 @@
die("write-tree: not able to write tree");
 
/* Ok, write it out */
-   if (write_tree(active_cache, entries, "", 0, sha1) != entries)
+   if (write_tree(0, "", 0, sha1) != entries)
die("write-tree: internal error");
printf("%s\n", sha1_to_hex(sha1));
return 0;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/19] migrate check-files.c to the new cache api's

2005-04-21 Thread Brad Roberts
tree 54aca1a1c5f41995c79fdf6b5f720574d0bfd8ef
parent 50a6596bf7f51ecd598cd02d9c44379a9b92044a
author Brad Roberts <[EMAIL PROTECTED]> 1114077105 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114077105 -0700

[PATCH] migrate check-files.c to the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 check-files.c |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

Index: check-files.c
===
--- 50a6596bf7f51ecd598cd02d9c44379a9b92044a:1/check-files.c  (mode:100644 
sha1:7d16691aa9d51b5b4670d5837b3527ee7c7da79c)
+++ a94803645fb68119be8835d466585c91e664a173:1/check-files.c  (mode:100644 
sha1:919e418b5f0f85220445c876a37bf4cf61d26525)
@@ -26,7 +26,7 @@
pos = cache_name_pos(path, strlen(path));
if (pos < 0)
die("preparing to update existing file '%s' not in cache", 
path);
-   ce = active_cache[pos];
+   ce = get_cache_entry(pos);
 
if (fstat(fd, &st) < 0)
die("fstat(%s): %s", path, strerror(errno));

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/19] migrate read-tree.c to the new cache api's

2005-04-21 Thread Brad Roberts
tree 7a3cab4437a849857cc899017b97eea1787a6ce1
parent 099367f98cc063c33733d15c7a2d9737bea853d9
author Brad Roberts <[EMAIL PROTECTED]> 1114077044 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114077044 -0700

[PATCH] migrate read-tree.c to the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 read-tree.c |   52 +++-
 1 files changed, 31 insertions(+), 21 deletions(-)

Index: read-tree.c
===
--- 099367f98cc063c33733d15c7a2d9737bea853d9:1/read-tree.c  (mode:100644 
sha1:4ad48f5c409ead69407d2b5feab4466cdcb499f8)
+++ 50a6596bf7f51ecd598cd02d9c44379a9b92044a:1/read-tree.c  (mode:100644 
sha1:ad9128f26613a82361475516dd0f2b470f4ce4b3)
@@ -146,26 +146,30 @@
return NULL;
 }
 
-static void trivially_merge_cache(struct cache_entry **src, int nr)
+/* rather than doing the 'right' thing of deleting entries as we merge,
+ * walk dst through the cache, overwriting entries as we go and at the
+ * end truncate the size of the cache */
+static void trivially_merge_cache()
 {
static struct cache_entry null_entry;
-   struct cache_entry **dst = src;
struct cache_entry *old = &null_entry;
+   int src = 0, dst = 0, nr = get_num_cache_entries();
 
-   while (nr) {
+   while (src < nr) {
struct cache_entry *ce, *result;
 
-   ce = src[0];
+   ce = get_cache_entry(src);
 
/* We throw away original cache entries except for the stat 
information */
if (!ce_stage(ce)) {
old = ce;
src++;
-   nr--;
-   active_nr--;
continue;
}
-   if (nr > 2 && (result = merge_entries(ce, src[1], src[2])) != 
NULL) {
+   if ((src < (nr - 2)) &&
+   (result = merge_entries(ce,
+   get_cache_entry(src + 1),
+   get_cache_entry(src + 2))) != NULL) 
{
/*
 * See if we can re-use the old CE directly?
 * That way we get the uptodate stat info.
@@ -175,40 +179,46 @@
ce = result;
ce->ce_flags &= ~htons(CE_STAGEMASK);
src += 2;
-   nr -= 2;
-   active_nr -= 2;
}
-   *dst++ = ce;
+   set_cache_entry(ce, dst);
+   dst++;
src++;
+   }
+   /* this could be replaced by a truncate api */
+   while (nr > dst) {
nr--;
+   remove_cache_entry_at(nr);
}
 }
 
-static void merge_stat_info(struct cache_entry **src, int nr)
+static void merge_stat_info()
 {
static struct cache_entry null_entry;
-   struct cache_entry **dst = src;
struct cache_entry *old = &null_entry;
+   int src = 0, dst = 0, nr = get_num_cache_entries();
 
-   while (nr) {
+   while (src < nr) {
struct cache_entry *ce;
 
-   ce = src[0];
+   ce = get_cache_entry(src);
 
/* We throw away original cache entries except for the stat 
information */
if (!ce_stage(ce)) {
old = ce;
src++;
-   nr--;
-   active_nr--;
continue;
}
if (path_matches(ce, old) && same(ce, old))
*ce = *old;
ce->ce_flags &= ~htons(CE_STAGEMASK);
-   *dst++ = ce;
+   set_cache_entry(ce, dst);
+   dst++;
src++;
+   }
+   /* this could be replaced by a truncate api */
+   while (nr > dst) {
nr--;
+   remove_cache_entry_at(nr);
}
 }
 
@@ -233,8 +243,8 @@
if (stage)
usage("-m needs to come first");
read_cache();
-   for (i = 0; i < active_nr; i++) {
-   if (ce_stage(active_cache[i]))
+   for (i = 0; i < get_num_cache_entries(); i++) {
+   if (ce_stage(get_cache_entry(i)))
usage("you need to resolve your current 
index first");
}
stage = 1;
@@ -252,10 +262,10 @@
if (merge) {
switch (stage) {
case 4: /* Three-way merge */
-   trivially_merge_cache(active_cache, active_nr);
+   trivially_merge_cache();
b

[PATCH 08/19] rename remove_entry_at to remove_cache_entry_at and expose as a public api

2005-04-21 Thread Brad Roberts
tree 68af3fb1d46759f437d15f310a9aea2931708601
parent e2acfff5e544a8c6769a9e665927092b3edd7579
author Brad Roberts <[EMAIL PROTECTED]> 1114075605 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114075605 -0700

[PATCH] rename remove_entry_at to remove_cache_entry_at and expose as a public 
api

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |1 +
 read-cache.c |6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

Index: cache.h
===
--- e2acfff5e544a8c6769a9e665927092b3edd7579:1/cache.h  (mode:100644 
sha1:9ad6e805eafcb213c6bb4b1f8ff4d4e053fa6067)
+++ 099367f98cc063c33733d15c7a2d9737bea853d9:1/cache.h  (mode:100644 
sha1:74d816c34245e0dde41643188f38cf99ca75e75f)
@@ -96,6 +96,7 @@
 extern int get_num_cache_entries();
 extern struct cache_entry * get_cache_entry(int pos);
 extern void set_cache_entry(struct cache_entry *ce, int pos);
+extern int remove_cache_entry_at(int pos);
 
 #define MTIME_CHANGED  0x0001
 #define CTIME_CHANGED  0x0002
Index: read-cache.c
===
--- e2acfff5e544a8c6769a9e665927092b3edd7579:1/read-cache.c  (mode:100644 
sha1:8eaa05957a481b09116c37e43e16c5ef4e219a1e)
+++ 099367f98cc063c33733d15c7a2d9737bea853d9:1/read-cache.c  (mode:100644 
sha1:286f7136bc164f3a2317bb492138d9221efb4025)
@@ -87,7 +87,7 @@
 }
 
 /* Remove entry, return true if there are more entries to go.. */
-static int remove_entry_at(int pos)
+int remove_cache_entry_at(int pos)
 {
active_nr--;
if (pos >= active_nr)
@@ -100,7 +100,7 @@
 {
int pos = cache_name_pos(path, strlen(path));
if (pos >= 0)
-   remove_entry_at(pos);
+   remove_cache_entry_at(pos);
return 0;
 }
 
@@ -148,7 +148,7 @@
if (pos < active_nr && ce_stage(ce) == 0) {
while (same_name(active_cache[pos], ce)) {
ok_to_add = 1;
-   if (!remove_entry_at(pos))
+   if (!remove_cache_entry_at(pos))
break;
}
}

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/19] migrate show-files.c to the new cache api's

2005-04-21 Thread Brad Roberts
tree a3bd48d2beba79d70e97d8647ee35a645e494350
parent f908b2542a9a3ea321633a31cf0e7ca2c8b669d4
author Brad Roberts <[EMAIL PROTECTED]> 1114074486 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114074486 -0700

[PATCH] migrate show-files.c to the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 show-files.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

Index: show-files.c
===
--- f908b2542a9a3ea321633a31cf0e7ca2c8b669d4:1/show-files.c  (mode:100644 
sha1:0b49ca051de413e7182445dd8fb9144125716974)
+++ 32efd81a3292a923ce5b5ae2e39ffefd0b08664d:1/show-files.c  (mode:100644 
sha1:11fbbccef2df50d528105ceb48b15275f2a5693e)
@@ -116,8 +116,8 @@
printf("%s%s%c", tag_other, dir[i], line_terminator);
}
if (show_cached | show_stage) {
-   for (i = 0; i < active_nr; i++) {
-   struct cache_entry *ce = active_cache[i];
+   for (i = 0; i < get_num_cache_entries(); i++) {
+   struct cache_entry *ce = get_cache_entry(i);
if (show_unmerged && !ce_stage(ce))
continue;
if (!show_stage)
@@ -136,8 +136,8 @@
}
}
if (show_deleted) {
-   for (i = 0; i < active_nr; i++) {
-   struct cache_entry *ce = active_cache[i];
+   for (i = 0; i < get_num_cache_entries(); i++) {
+   struct cache_entry *ce = get_cache_entry(i);
struct stat st;
if (!stat(ce->name, &st))
continue;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/19] migrate merge-cache.c over to the new cache api's

2005-04-21 Thread Brad Roberts
tree 8140acee0f9c57bfd87f40d1f99242c772afcdf2
parent 32efd81a3292a923ce5b5ae2e39ffefd0b08664d
author Brad Roberts <[EMAIL PROTECTED]> 1114074631 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114074631 -0700

[PATCH] migrate merge-cache.c over to the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 merge-cache.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

Index: merge-cache.c
===
--- 32efd81a3292a923ce5b5ae2e39ffefd0b08664d:1/merge-cache.c  (mode:100644 
sha1:35a0d588178aa5371399458b1a15519cffd645b8)
+++ e2acfff5e544a8c6769a9e665927092b3edd7579:1/merge-cache.c  (mode:100644 
sha1:c2f96e7652a2aea9417c3790bfe9ab14ffcdb12f)
@@ -30,7 +30,7 @@
 {
int found;

-   if (pos >= active_nr)
+   if (pos >= get_num_cache_entries())
die("merge-cache: %s not in the cache", path);
arguments[0] = pgm;
arguments[1] = "";
@@ -40,7 +40,7 @@
found = 0;
do {
static char hexbuf[4][60];
-   struct cache_entry *ce = active_cache[pos];
+   struct cache_entry *ce = get_cache_entry(pos);
int stage = ce_stage(ce);
 
if (strcmp(ce->name, path))
@@ -48,7 +48,7 @@
found++;
strcpy(hexbuf[stage], sha1_to_hex(ce->sha1));
arguments[stage] = hexbuf[stage];
-   } while (++pos < active_nr);
+   } while (++pos < get_num_cache_entries());
if (!found)
die("merge-cache: %s not in the cache", path);
run_program();
@@ -70,8 +70,8 @@
 static void merge_all(void)
 {
int i;
-   for (i = 0; i < active_nr; i++) {
-   struct cache_entry *ce = active_cache[i];
+   for (i = 0; i < get_num_cache_entries(); i++) {
+   struct cache_entry *ce = get_cache_entry(i);
if (!ce_stage(ce))
continue;
i += merge_entry(i, ce->name)-1;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/19] convert show-diff.c to use new cache hiding api's

2005-04-21 Thread Brad Roberts
tree bbc50100a5cfd22264c2b0731ef8678656a399d8
parent 27fc41dcd4aecafdaf583f3962697a2fa3fb6480
author Brad Roberts <[EMAIL PROTECTED]> 1114073516 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114073516 -0700

[PATCH] convert show-diff.c to use new cache hiding api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 show-diff.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

Index: show-diff.c
===
--- 27fc41dcd4aecafdaf583f3962697a2fa3fb6480:1/show-diff.c  (mode:100644 
sha1:da364e26e28823f951a6be1b686a458575f28ea1)
+++ d70686e08f453199e5451b27fc7d0b36b73a5c7f:1/show-diff.c  (mode:100644 
sha1:e2642b65805b3e52a16c6309b44a92c2a2bd13c3)
@@ -154,7 +154,7 @@
prepare_diff_cmd();
for (i = 0; i < entries; i++) {
struct stat st;
-   struct cache_entry *ce = active_cache[i];
+   struct cache_entry *ce = get_cache_entry(i);
int changed;
unsigned long size;
char type[20];
@@ -172,7 +172,7 @@
printf("%s: Unmerged\n",
   ce->name);
while (i < entries &&
-  !strcmp(ce->name, active_cache[i]->name))
+  !strcmp(ce->name, get_cache_entry(i)->name))
i++;
i--; /* compensate for loop control increments */
continue;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/19] Add new api's to front the active_cache and active_nr cache internals

2005-04-21 Thread Brad Roberts
tree ebbf2c037e68116c4ff934f140ca12cdbe13311d
parent 77de9e0b7a81ddc22526c9415f0273171f631d3f
author Brad Roberts <[EMAIL PROTECTED]> 1114073146 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114073146 -0700

[PATCH] Add new api's to front the active_cache and active_nr cache internals

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h  |3 +++
 read-cache.c |   15 +++
 2 files changed, 18 insertions(+)

Index: cache.h
===
--- 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/cache.h  (mode:100644 
sha1:a101870e4a002a2548d88544a77bedad21668203)
+++ 27fc41dcd4aecafdaf583f3962697a2fa3fb6480:1/cache.h  (mode:100644 
sha1:9ad6e805eafcb213c6bb4b1f8ff4d4e053fa6067)
@@ -93,6 +93,9 @@
 extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
 extern int remove_file_from_cache(char *path);
 extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
+extern int get_num_cache_entries();
+extern struct cache_entry * get_cache_entry(int pos);
+extern void set_cache_entry(struct cache_entry *ce, int pos);
 
 #define MTIME_CHANGED  0x0001
 #define CTIME_CHANGED  0x0002
Index: read-cache.c
===
--- 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/read-cache.c  (mode:100644 
sha1:349ebd1f8a0a95bf462bb1dfd3d9dfb50628829c)
+++ 27fc41dcd4aecafdaf583f3962697a2fa3fb6480:1/read-cache.c  (mode:100644 
sha1:6689df59d5a93e0503d7c80c114efbd16de826f3)
@@ -110,6 +110,21 @@
return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
 }
 
+int get_num_cache_entries()
+{
+   return active_nr;
+}
+
+struct cache_entry * get_cache_entry(int pos)
+{
+   return active_cache[pos];
+}
+
+void set_cache_entry(struct cache_entry *ce, int pos)
+{
+   active_cache[pos] = ce;
+}
+
 int add_cache_entry(struct cache_entry *ce, int ok_to_add)
 {
int pos;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/19] Migrate update-cache.c to use the new cache api's

2005-04-21 Thread Brad Roberts
tree 34f7fc89e28a40387e811057065592ed2f0218a2
parent d70686e08f453199e5451b27fc7d0b36b73a5c7f
author Brad Roberts <[EMAIL PROTECTED]> 1114073784 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114073784 -0700

[PATCH] Migrate update-cache.c to use the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 read-cache.c   |3 +++
 update-cache.c |   13 +
 2 files changed, 8 insertions(+), 8 deletions(-)

Index: read-cache.c
===
--- d70686e08f453199e5451b27fc7d0b36b73a5c7f:1/read-cache.c  (mode:100644 
sha1:6689df59d5a93e0503d7c80c114efbd16de826f3)
+++ 40bf732f5bcb986943070a2ed6c09a16543d81be:1/read-cache.c  (mode:100644 
sha1:8eaa05957a481b09116c37e43e16c5ef4e219a1e)
@@ -122,6 +122,9 @@
 
 void set_cache_entry(struct cache_entry *ce, int pos)
 {
+   /* You can NOT just free active_cache[i] here, since it
+* might not be necessarily malloc()ed but can also come
+* from mmap(). */
active_cache[pos] = ce;
 }
 
Index: update-cache.c
===
--- d70686e08f453199e5451b27fc7d0b36b73a5c7f:1/update-cache.c  (mode:100644 
sha1:585951108c57a64bb774114d289d81fd7fd22768)
+++ 40bf732f5bcb986943070a2ed6c09a16543d81be:1/update-cache.c  (mode:100644 
sha1:e741f593eb9c56c596fabed7eb6b79dee2d8cba9)
@@ -204,13 +204,13 @@
 {
int i;
 
-   for (i = 0; i < active_nr; i++) {
+   for (i = 0; i < get_num_cache_entries(); i++) {
struct cache_entry *ce, *new;
-   ce = active_cache[i];
+   ce = get_cache_entry(i);
if (ce_stage(ce)) {
printf("%s: needs merge\n", ce->name);
-   while ((i < active_nr) &&
-  ! strcmp(active_cache[i]->name, ce->name))
+   while ((i < get_num_cache_entries()) &&
+  ! strcmp(get_cache_entry(i)->name, ce->name))
i++;
i--;
continue;
@@ -221,10 +221,7 @@
printf("%s: needs update\n", ce->name);
continue;
}
-   /* You can NOT just free active_cache[i] here, since it
-* might not be necessarily malloc()ed but can also come
-* from mmap(). */
-   active_cache[i] = new;
+   set_cache_entry(new, i);
}
 }
 

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/19] migrate checkout-cache.c to the new cache api's

2005-04-21 Thread Brad Roberts
tree b95df78e4cc90db8c4c8d0ad870bef74b7fd29e2
parent 40bf732f5bcb986943070a2ed6c09a16543d81be
author Brad Roberts <[EMAIL PROTECTED]> 1114074234 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114074234 -0700

[PATCH] migrate checkout-cache.c to the new cache api's

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 checkout-cache.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Index: checkout-cache.c
===
--- 40bf732f5bcb986943070a2ed6c09a16543d81be:1/checkout-cache.c  (mode:100644 
sha1:8bf86016b5d5fd88a52ce694fc59bb9ecb550d22)
+++ f908b2542a9a3ea321633a31cf0e7ca2c8b669d4:1/checkout-cache.c  (mode:100644 
sha1:bf9cd0572c883219d37f2788ec5f5553a136df2b)
@@ -128,15 +128,15 @@
fprintf(stderr, "checkout-cache: %s is not in the 
cache\n", name);
return -1;
}
-   return checkout_entry(active_cache[pos]);
+   return checkout_entry(get_cache_entry(pos));
 }
 
 static int checkout_all(void)
 {
int i;
 
-   for (i = 0; i < active_nr ; i++) {
-   struct cache_entry *ce = active_cache[i];
+   for (i = 0; i < get_num_cache_entries() ; i++) {
+   struct cache_entry *ce = get_cache_entry(i);
if (ce_stage(ce))
continue;
if (checkout_entry(ce) < 0)

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/19] write_cache api signature change, isolate active_cache and active_nr inside read-cache.c

2005-04-21 Thread Brad Roberts
tree f45fd10b26bf98349b63427805a96bd0551cad74
parent 43fdf65356c50483233cb3d6e391b0849b2a2a50
parent cd1c034369b73da7503da365fa556aab27004814
author Brad Roberts <[EMAIL PROTECTED]> 1114072582 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1114072582 -0700

[PATCH] write_cache api signature change, isolate active_cache and active_nr 
inside read-cache.c


Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>
---

 cache.h|2 +-
 read-cache.c   |8 
 read-tree.c|2 +-
 update-cache.c |2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

Index: cache.h
===
--- cd1c034369b73da7503da365fa556aab27004814:1/cache.h  (mode:100644 
sha1:828d660ab82bb35a1ca632a2ba4620dc483889bd)
+++ 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/cache.h  (mode:100644 
sha1:a101870e4a002a2548d88544a77bedad21668203)
@@ -88,7 +88,7 @@
 
 /* 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 write_cache(int newfd);
 extern int cache_name_pos(const char *name, int namelen);
 extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
 extern int remove_file_from_cache(char *path);
Index: read-cache.c
===
--- cd1c034369b73da7503da365fa556aab27004814:1/read-cache.c  (mode:100644 
sha1:2f6a4aa18d48865db80459a3459ac4384b0b16c8)
+++ 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/read-cache.c  (mode:100644 
sha1:349ebd1f8a0a95bf462bb1dfd3d9dfb50628829c)
@@ -267,7 +267,7 @@
return 0;
 }
 
-int write_cache(int newfd, struct cache_entry **cache, int entries)
+int write_cache(int newfd)
 {
SHA_CTX c;
struct cache_header hdr;
@@ -275,14 +275,14 @@
 
hdr.hdr_signature = htonl(CACHE_SIGNATURE);
hdr.hdr_version = htonl(2);
-   hdr.hdr_entries = htonl(entries);
+   hdr.hdr_entries = htonl(active_nr);
 
SHA1_Init(&c);
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
return -1;
 
-   for (i = 0; i < entries; i++) {
-   struct cache_entry *ce = cache[i];
+   for (i = 0; i < active_nr; i++) {
+   struct cache_entry *ce = active_cache[i];
if (ce_write(&c, newfd, ce, ce_size(ce)) < 0)
return -1;
}
Index: read-tree.c
===
--- cd1c034369b73da7503da365fa556aab27004814:1/read-tree.c  (mode:100644 
sha1:620f3f74eb56366fca8be4d28d7b04875c0fa90c)
+++ 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/read-tree.c  (mode:100644 
sha1:4ad48f5c409ead69407d2b5feab4466cdcb499f8)
@@ -261,7 +261,7 @@
die("just how do you expect me to merge %d trees?", 
stage-1);
}
}
-   if (write_cache(newfd, active_cache, active_nr) ||
+   if (write_cache(newfd) ||
rename(".git/index.lock", ".git/index"))
die("unable to write new index file");
remove_lock = 0;
Index: update-cache.c
===
--- cd1c034369b73da7503da365fa556aab27004814:1/update-cache.c  (mode:100644 
sha1:a09883541c745c76413c62109a80f40df4b7a7fb)
+++ 77de9e0b7a81ddc22526c9415f0273171f631d3f:1/update-cache.c  (mode:100644 
sha1:585951108c57a64bb774114d289d81fd7fd22768)
@@ -341,7 +341,7 @@
if (add_file_to_cache(path))
die("Unable to add %s to database", path);
}
-   if (write_cache(newfd, active_cache, active_nr) ||
+   if (write_cache(newfd) ||
rename(".git/index.lock", ".git/index"))
die("Unable to write new cachefile");
 

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/19] summary of patch set

2005-04-21 Thread Brad Roberts
Tonight I did a bunch of tiny steps towards making the cache management
code behave more like a library.  There are no longer any global variables
in read-cache.c.  Nothing ever uses more than one cache yet, but I can
see how it might simplify some of the merge code.

They're also visible here:  http://gameboy2.puremagic.com:8090/

[PATCH 01/19] write_cache api signature change, isolate active_cache and 
active_nr inside read-cache.c
[PATCH 02/19] Add new api's to front the active_cache and active_nr cache 
internals
[PATCH 03/19] convert show-diff.c to use new cache hiding api's
[PATCH 04/19] Migrate update-cache.c to use the new cache api's
[PATCH 05/19] migrate checkout-cache.c to the new cache api's
[PATCH 06/19] migrate show-files.c to the new cache api's
[PATCH 07/19] migrate merge-cache.c over to the new cache api's
[PATCH 08/19] rename remove_entry_at to remove_cache_entry_at and expose as a 
public api
[PATCH 09/19] migrate read-tree.c to the new cache api's
[PATCH 10/19] migrate check-files.c to the new cache api's
[PATCH 11/19] migrate write-tree.c to use the new cache api's
[PATCH 12/19] fix up diff-cache.c to use new cache api's
[PATCH 13/19] Remove active_cache, active_nr, and active_alloc from public view
[PATCH 14/19] move cache_header out of the public view
[PATCH 15/19] introduce a cache struct and move the various cache globals into 
it.
[PATCH 16/19] change all call sites that use the return value of read_cache to 
get the # of cache entries.
[PATCH 17/19] temporarily change add_cache_entry to create an empty cache on 
demand
[PATCH 18/19] rename cache_match_stat to ce_match_stat to match other 
cache_entry related functions/macros
[PATCH 19/19] the end goal of the last dozen or so commits, there's no longer a 
global cache variable

[PATCH 01-19/19] All of the above combined
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [3/5] Add http-pull

2005-04-20 Thread Brad Roberts
On Sun, 17 Apr 2005, Petr Baudis wrote:

> Date: Sun, 17 Apr 2005 21:59:00 +0200
> From: Petr Baudis <[EMAIL PROTECTED]>
> To: Daniel Barkalow <[EMAIL PROTECTED]>
> Cc: git@vger.kernel.org
> Subject: Re: [3/5] Add http-pull
>
> Dear diary, on Sun, Apr 17, 2005 at 09:24:27PM CEST, I got a letter
> where Daniel Barkalow <[EMAIL PROTECTED]> told me that...
> > On Sun, 17 Apr 2005, Petr Baudis wrote:
> >
> > > Dear diary, on Sun, Apr 17, 2005 at 08:49:11PM CEST, I got a letter
> > > where Daniel Barkalow <[EMAIL PROTECTED]> told me that...
> > > > There's some trickiness for the history of commits thing for stopping at
> > > > the point where you have everything, but also behaving appropriately if
> > > > you try once, fail partway through, and then try again. It's on my queue
> > > > of things to think about.
> > >
> > > Can't you just stop the recursion when you hit a commit you already
> > > have?
> >
> > The problem is that, if you've fetched the final commit already, and then
> > the server dies, and you try again later, you already have the last one,
> > and so you think you've got everything.
>
> Hmm, some kind of journaling? ;-)

How about fetching in the inverse order.  Ie, deepest parents up towards
current.  With that method the repository is always self consistent, even
if not yet current.

Later,
Brad

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch] fork optional branch point normazilation

2005-04-17 Thread Brad Roberts
The patch needed some tweaking, but not in the way you thought. :)

commit a6aa192641e9ea242332fee4916abf5ad2640d75
tree c69878b009ec2f505d75aa7d99e9ee30cd21ab02
parent 60e1274460f50bcecdc3f162b4fced9e5ebf2dfb
author Brad Roberts <[EMAIL PROTECTED]> 1113789519 -0700
committer Brad Roberts <[EMAIL PROTECTED]> 1113789519 -0700

Fix remove_specials for real.  The second half logic needs the original
head of the string.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>

Index: commit-tree.c
===
--- 02cf6917da6297ff4f9172f7af174ba329f01b3d/commit-tree.c  (mode:100644 
sha1:ec53a4565ec0033aaf6df2a48d233ccf4823e8b0)
+++ c69878b009ec2f505d75aa7d99e9ee30cd21ab02/commit-tree.c  (mode:100644 
sha1:f41cda6f9496b9e33cb95305ef1093f846c663ae)
@@ -83,11 +83,11 @@
 static void remove_special(char *p)
 {
char c;
-   char *dst = p;
+   char *dst = p, *src = p;

for (;;) {
-   c = *p;
-   p++;
+   c = *src;
+   src++;
switch(c) {
case '\n': case '<': case '>':
continue;


Later,
Brad

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch] fork optional branch point normazilation

2005-04-17 Thread Brad Roberts
On Sun, 17 Apr 2005, Linus Torvalds wrote:

> On Sun, 17 Apr 2005, Brad Roberts wrote:
> >
> > (ok, author looks better, but committer doesn't obey the AUTHOR_ vars yet)
>
> They should't, but maybe I should add COMMITTER_xxx overrides. I just do
> _not_ want people to think that they should claim to be somebody else:
> it's not a security issue (you could compile your own "commit-tree.c"
> after all), it's more of a "social rule" thing. I prefer seeing bad email
> addresses that at least match the system setup to seeing good email
> addresses that people made up just to make them look clean.
>
> Mind showing what your /etc/passwd file looks like (just your own entry,
> and please just remove your password entry if you don't use shadow
> passwords).
>
> Maybe I should just remove _all_ strange characters when I do the name
> cleanup in "commit". Right now I just remove the ones that matter to
> parsing it unambiguosly: '\n' '<' and '>'.
>
> (The ',' character really is special: some people have
>
>   Torvalds, Linus
>
> and maybe I should not just remove the commas, I should convert it to
> always be "Linus Torvalds". But your gecos entry is just _strange_. Why
> the extra commas, I wonder?)
>
>   Linus
> -

I fully agree with the intent of the field separation, they're two very
different activities.

braddr:x:1000:1000:Brad Roberts,,,:/home/braddr:/bin/bash

All gecos entries on all my debian boxes are of the form:

   fullname, office number, office extension, and home number

This is taken from the chfn man page on debian.  Looking on my nearest
redhat box, the chfn man page is roughly the same.  Debian's man page also
has one snippit that's not in redhat's, suggested delimiter is a ','.  A
bit of searching for other platforms, aix suggests a ';' as a delimiter.
HPUX seems to want a ','.

Later,
Brad

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch] Fix off by one error in show-diff.c:sq_expand

2005-04-17 Thread Brad Roberts
tree b2eb41fec5cb7a3b83b53f1eb59e59785e57cf5d
parent 1c45567134945bccefc1b5fbacc2862cd8f346c4
author Brad Roberts <[EMAIL PROTECTED]> 1113752911 -0700
committer Brad Roberts,,, <[EMAIL PROTECTED]> 1113752911 -0700

Fix off by one error in sq_expand, forgot space for the null.

Signed-off-by: Brad Roberts <[EMAIL PROTECTED]>

 show-diff.c |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

Index: show-diff.c
===
--- f9e06a309f63ac6858d019b51f2172283378d2ef/show-diff.c  (mode:100644 
sha1:d85d79b97a59342390bd34da09049dd58d56900f)
+++ b2eb41fec5cb7a3b83b53f1eb59e59785e57cf5d/show-diff.c  (mode:100644 
sha1:462f88a67cb3a100bbf307e567eebbcf911292ce)
@@ -36,7 +36,7 @@
if (buf_size < cnt) {
free(buf);
buf_size = cnt;
-   buf = malloc(cnt);
+   buf = malloc(cnt+1);
}

cp = buf;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Re: Merge with git-pasky II.

2005-04-17 Thread Brad Roberts
On Sun, 17 Apr 2005, Ingo Molnar wrote:

> Date: Sun, 17 Apr 2005 16:52:32 +0200
> From: Ingo Molnar <[EMAIL PROTECTED]>
> To: Linus Torvalds <[EMAIL PROTECTED]>
> Cc: Petr Baudis <[EMAIL PROTECTED]>, Simon Fowler <[EMAIL PROTECTED]>,
>  David Lang <[EMAIL PROTECTED]>, git@vger.kernel.org
> Subject: Re: Re: Merge with git-pasky II.
>
>
> * Linus Torvalds <[EMAIL PROTECTED]> wrote:
>
> > Almost all attacks on sha1 will depend on _replacing_ a file with a
> > bogus new one. So guys, instead of using sha256 or going overboard,
> > just make sure that when you synchronize, you NEVER import a file you
> > already have.
>
> With tens of thousands (or hundreds of thousands) of objects expected in
> the repository sooner or later, there's quite a selection to pick from.
> Once you apply the patch, instead of the expected new file that you
> reviewed and found safe, the attacker has the other object included in
> the official kernel.
>
> A dangerous object can be anything: e.g. a debugging hack that allows
> arbitrary kernel-space writes. Or a known-insecure module (which since
> then got fixed, but the buggy code still exists in the DB). The module
> is in a single file and is self-installing (e.g. it has __init code to
> register itself as some driver.)

While I agree that a hash collision is bad and certainly worth preventing
during new object creation, for it to actually implant a trojan in a build
successfully it'd have to meet even more criteria than you've layed out.
It'd have to...

  - be shadowing an object that's part of an active tree
  - provide all the public symbols the shadowed object provided so that it
would still build and link successfully

Shadowing an object that's not part of the working tree means something on
another branch or obsoleted some time in the past is still db corruption,
but not nearly as big an issue from a trojan standpoint.

Later,
Brad


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: fork optional branch point normazilation

2005-04-17 Thread Brad Roberts
> >
> > Index: gitfork.sh
> > ===
> > --- 51b1bddbbc05e50d5bbf1f9662e503c2e85d5e96/gitfork.sh  (mode:100755 
> > sha1:e5692ea9bdbc39b028fe1e1205381da632541bab)
> > +++ c291316b28eff4042c80850cd93445345a606835/gitfork.sh  (mode:100755 
> > sha1:386148ae9a99739d06a09742ff4157d0f7e4e223)
> > @@ -37,6 +37,7 @@
> >  [ -e "$destdir" ] && die "$destdir already exists"
> >
> >  [ "$head" ] || head=$(commit-id)
> > +head=$(gitXnormid.sh -c $head)
> >
> >  git lntree "$destdir"
> >  echo $head >.git/heads/$name
>
> commit-id always returns the normalized commit ID.
>
> --
>   Petr "Pasky" Baudis
> Stuff: http://pasky.or.cz/
> C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
>

This feels better to me.  Diffed against my previus commit.  The problem
was that commit-id wasn't called if a branch point was specified nor was
that value checked for validity.

Index: gitfork.sh
===
--- c9ccaa172ccab8e56f2fe621ee24896bfddacf26/gitfork.sh  (mode:100755 
sha1:386148ae9a99739d06a09742ff4157d0f7e4e223)
+++ f9e06a309f63ac6858d019b51f2172283378d2ef/gitfork.sh  (mode:100755 
sha1:dbb508b8431368fc95cc9516eada52f5bf0f8bc1)
@@ -16,7 +16,7 @@

 name=$1
 destdir=$2
-head=$3
+head=$(gitXnormid.sh -c $3)

 die () {
echo gitfork.sh: $@ >&2
@@ -36,9 +36,6 @@

 [ -e "$destdir" ] && die "$destdir already exists"

-[ "$head" ] || head=$(commit-id)
-head=$(gitXnormid.sh -c $head)
-
 git lntree "$destdir"
 echo $head >.git/heads/$name
 ln -s heads/$name "$destdir/.git/HEAD"

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch] fork optional branch point normazilation

2005-04-17 Thread Brad Roberts
(ok, author looks better, but committer doesn't obey the AUTHOR_ vars yet)

This might not be how you intended git fork to behave, but without doing
_something_ to protect the head parameter a bit, this is just asking for a
corrutped .git/HEAD file.

commit 76faec069dfeae59c3ce5faaad10bdcded0cc908
tree c291316b28eff4042c80850cd93445345a606835
parent 1cdbc0a19b8d9b68f1f42735e2f14f1289823a63
author Brad Roberts <[EMAIL PROTECTED]> 1113738584 -0700
committer Brad Roberts,,, <[EMAIL PROTECTED]> 1113738584 -0700

gitfork needs to normalize the optional third parameter before using it.

Index: gitfork.sh
===
--- 51b1bddbbc05e50d5bbf1f9662e503c2e85d5e96/gitfork.sh  (mode:100755 
sha1:e5692ea9bdbc39b028fe1e1205381da632541bab)
+++ c291316b28eff4042c80850cd93445345a606835/gitfork.sh  (mode:100755 
sha1:386148ae9a99739d06a09742ff4157d0f7e4e223)
@@ -37,6 +37,7 @@
 [ -e "$destdir" ] && die "$destdir already exists"

 [ "$head" ] || head=$(commit-id)
+head=$(gitXnormid.sh -c $head)

 git lntree "$destdir"
 echo $head >.git/heads/$name



-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch] fix for memory leak in write-tree.c

2005-04-17 Thread Brad Roberts
I've made my tree rsync'able:

rsync://gameboy2.puremagic.com/git


commit 1cdbc0a19b8d9b68f1f42735e2f14f1289823a63
tree 0e060fed0642337e675368913ec8d4f910a9f019
parent 11ed64c1b141c9ba397a1ca76aef2cd250976007
author Brad Roberts,,, <[EMAIL PROTECTED]> 1113736632 -0700
committer Brad Roberts,,, <[EMAIL PROTECTED]> 1113736632 -0700

Fix a memory leak in write-tree.c, not freeing the directory buffer.

Index: write-tree.c
===
--- 51b1bddbbc05e50d5bbf1f9662e503c2e85d5e96/write-tree.c  (mode:100644 
sha1:34a351b20fb38ea588f34bd9634f101b9dc533cb)
+++ 0e060fed0642337e675368913ec8d4f910a9f019/write-tree.c  (mode:100644 
sha1:fb046aa6ce6b9fce6a523a1e36ff43adab9bdd93)
@@ -93,10 +93,8 @@
i -= 5;
memcpy(buffer+i, "tree ", 5);

-   buffer += i;
-   offset -= i;
-
-   write_sha1_file(buffer, offset, returnsha1);
+   write_sha1_file(buffer + i, offset - i, returnsha1);
+   free(buffer);
return nr;
 }



-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] libgit

2005-04-17 Thread Brad Roberts
> Converted git to libgit. Moved all the main() calls into a single
> multi-call binary - git-main.
> Made extern a bunch of functions that were static. Verified it at least
> still minimally worked.
> Note: this is only a first step towards creating a generic library.
> Figuring out what functions and variables *truly* need to be exported,
> renaming them to a git_ api, making it thread safe
> ... and not least of all, keeping up with everybody working out of the
> base tree... are problems that remain. Also - cleaning up the UI.

Why do all that static and main rearrangement?  It would be a lot simpler
and cleaner to simply rename the main's in place and add the new
dispatcher by itself.

Later,
Brad

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


active_cache leaks

2005-04-17 Thread Brad Roberts
Ok.. so there's been a couple attempts to patch the leak that were all
wrong due to mixed memory management for that array.  Here's a seed for
discussion on how to plug that leak.  Some would argue that it's not
leaking enough to fix, but for those that want to turn git into a library,
the lifetime of the cache could end up not being short any more, so it's
worth discussing how to fix it.

The q&d fix in this patch isn't elegant, but gets the job done.  More
interesting could be to have the entry itself contain a state bit, though
that wastes storage space.

Two basic changes:

1) introduce a set_active_cache() api and change all 'active_cache[i] = ce'
   calls to use it.
2) add a active_cache_malloced array to parallel the active_cache array.

I don't like #2, but see that q&d comment. :)

It's only lightly tested as I'm still trying to wrap my head around how to
actually use git and git-pasky.

I was tempted to add a get_cache_entry api as well, so that nothing
outside of read-cache.c touched active_cache directly, but that can come
next.

Later,
Brad

--- cache.h
+++ cache.h 2005-04-16 23:08:37.0 -0700
@@ -88,6 +88,7 @@
 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 set_cache_entry(struct cache_entry *ce, int pos, int 
malloced_entry);
 extern int add_cache_entry(struct cache_entry *ce, int ok_to_add);
 extern int remove_file_from_cache(char *path);
 extern int cache_match_stat(struct cache_entry *ce, struct stat *st);
--- read-cache.c
+++ read-cache.c2005-04-16 23:32:34.0 -0700
@@ -8,6 +8,7 @@
 
 const char *sha1_file_directory = NULL;
 struct cache_entry **active_cache = NULL;
+static int * active_cache_malloced = NULL;
 unsigned int active_nr = 0, active_alloc = 0;
 
 void usage(const char *err)
@@ -381,6 +382,15 @@
return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
 }
 
+int set_cache_entry(struct cache_entry *ce, int pos, int malloced_entry)
+{
+   if (active_cache_malloced[pos])
+   free(active_cache[pos]);
+   active_cache[pos] = ce;
+   active_cache_malloced[pos] = malloced_entry;
+   return 0;
+}
+
 int add_cache_entry(struct cache_entry *ce, int ok_to_add)
 {
int pos;
@@ -389,7 +399,7 @@
 
/* existing match? Just replace it */
if (pos >= 0) {
-   active_cache[pos] = ce;
+   set_cache_entry(ce, pos, 0);
return 0;
}
pos = -pos-1;
@@ -414,13 +424,16 @@
if (active_nr == active_alloc) {
active_alloc = alloc_nr(active_alloc);
active_cache = realloc(active_cache, active_alloc * 
sizeof(struct cache_entry *));
+   active_cache_malloced = realloc(active_cache, active_alloc * 
sizeof(int));
}
 
/* Add it in.. */
active_nr++;
-   if (active_nr > pos)
+   if (active_nr > pos) {
memmove(active_cache + pos + 1, active_cache + pos, (active_nr 
- pos - 1) * sizeof(ce));
-   active_cache[pos] = ce;
+   memmove(active_cache_malloced + pos + 1, active_cache_malloced 
+ pos, (active_nr - pos - 1) * sizeof(int));
+   }
+   set_cache_entry(ce, pos, 1);
return 0;
 }
 
@@ -482,12 +495,13 @@
active_nr = ntohl(hdr->hdr_entries);
active_alloc = alloc_nr(active_nr);
active_cache = calloc(active_alloc, sizeof(struct cache_entry *));
+   active_cache_malloced = calloc(active_alloc, sizeof(int));
 
offset = sizeof(*hdr);
for (i = 0; i < active_nr; i++) {
struct cache_entry *ce = map + offset;
offset = offset + ce_size(ce);
-   active_cache[i] = ce;
+   set_cache_entry(ce, i, 0);
}
return active_nr;
 
--- update-cache.c
+++ update-cache.c  2005-04-16 23:33:28.0 -0700
@@ -199,11 +199,14 @@
struct cache_entry *ce = active_cache[i];
struct cache_entry *new = refresh_entry(ce);
 
+   if (new == ce)
+   continue;
+
if (!new) {
printf("%s: needs update\n", ce->name);
continue;
}
-   active_cache[i] = new;
+   set_cache_entry(new, i, 1);
}
 }