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
<size>\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