aboutsummaryrefslogtreecommitdiff
path: root/write-tree.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-25 10:19:53 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-25 10:19:53 -0700
commita44c9a5e2e6d4108452f2c64dbd11f74a83745af (patch)
treeaa4796d8d4ae8c6c64bf9bd4b2d657571c67d4e4 /write-tree.c
parente6948b6d88c69a864e9c461911287c5cc5932a3b (diff)
downloadgit-a44c9a5e2e6d4108452f2c64dbd11f74a83745af.tar.gz
git-a44c9a5e2e6d4108452f2c64dbd11f74a83745af.tar.xz
Simplify "write_sha1_file()" interfaces
The write function now adds the header to the file by itself, so there is no reason to duplicate it among all the users any more.
Diffstat (limited to 'write-tree.c')
-rw-r--r--write-tree.c22
1 files changed, 3 insertions, 19 deletions
diff --git a/write-tree.c b/write-tree.c
index 827809dbd..bb7ceedb8 100644
--- a/write-tree.c
+++ b/write-tree.c
@@ -17,29 +17,17 @@ static int check_valid_sha1(unsigned char *sha1)
return ret;
}
-static int prepend_integer(char *buffer, unsigned val, int i)
-{
- buffer[--i] = '\0';
- do {
- buffer[--i] = '0' + (val % 10);
- val /= 10;
- } while (val);
- return i;
-}
-
-#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)
{
unsigned char subdir_sha1[20];
unsigned long size, offset;
char *buffer;
- int i, nr;
+ int nr;
/* Guess at some random initial size */
size = 8192;
buffer = malloc(size);
- offset = ORIG_OFFSET;
+ offset = 0;
nr = 0;
do {
@@ -89,11 +77,7 @@ static int write_tree(struct cache_entry **cachep, int maxentries, const char *b
nr++;
} while (nr < maxentries);
- i = prepend_integer(buffer, offset - ORIG_OFFSET, ORIG_OFFSET);
- i -= 5;
- memcpy(buffer+i, "tree ", 5);
-
- write_sha1_file(buffer + i, offset - i, returnsha1);
+ write_sha1_file(buffer, offset, "tree", returnsha1);
free(buffer);
return nr;
}