summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Rene Scharfe <rene.scharfe@lsrfire.ath.cx>2005-05-06 22:55:42 +0200
committerLibravatar Linus Torvalds <torvalds@ppc970.osdl.org>2005-05-06 14:42:59 -0700
commita90a6e6a781129574802c8777f0e083eb255a463 (patch)
treef5178dab754d1d56c58f66445527e0690f62aa26
parentdiff-tree: add "verbose header" mode (diff)
downloadtgif-a90a6e6a781129574802c8777f0e083eb255a463.tar.xz
[PATCH] git-tar-tree: add get_record()
Add get_record() which returns a pointer to the next record in the block.
-rw-r--r--tar-tree.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/tar-tree.c b/tar-tree.c
index 2c64f690e5..06f4ca480e 100644
--- a/tar-tree.c
+++ b/tar-tree.c
@@ -45,6 +45,15 @@ static void write_if_needed(void)
}
}
+/* acquire the next record from the buffer; user must call write_if_needed() */
+static char *get_record(void)
+{
+ char *p = block + offset;
+ memset(p, 0, RECORDSIZE);
+ offset += RECORDSIZE;
+ return p;
+}
+
/*
* The end of tar archives is marked by 1024 nul bytes and after that
* follows the rest of the block (if any).
@@ -178,9 +187,7 @@ static void write_extended_header(const char *headerfilename, int is_dir,
if (size > RECORDSIZE)
die("tar-tree: extended header too big, wtf?");
write_header(NULL, 'x', NULL, NULL, headerfilename, 0100600, size);
- p = block + offset;
- memset(p, 0, RECORDSIZE);
- offset += RECORDSIZE;
+ p = get_record();
append_long(&p, size);
append_string(&p, " path=");
append_path(&p, is_dir, basepath, prefix, path);
@@ -192,9 +199,7 @@ static void write_global_extended_header(const char *sha1)
{
char *p;
write_header(NULL, 'g', NULL, NULL, "pax_global_header", 0, 52);
- p = block + offset;
- memset(p, 0, RECORDSIZE);
- offset += RECORDSIZE;
+ p = get_record();
append_long(&p, 52); /* 2 + 9 + 40 + 1 */
append_string(&p, " comment=");
append_string(&p, sha1_to_hex(sha1));
@@ -223,15 +228,10 @@ static void write_header(const char *sha1, char typeflag, const char *basepath,
write_extended_header(headerfilename, S_ISDIR(mode), basepath,
prefix, path, namelen);
- header = block + offset;
- memset(header, 0, RECORDSIZE);
- offset += RECORDSIZE;
+ header = get_record();
sprintf(header, "%s.data", sha1_hex);
} else {
- header = block + offset;
- memset(header, 0, RECORDSIZE);
- offset += RECORDSIZE;
- p = header;
+ p = header = get_record();
append_path(&p, S_ISDIR(mode), basepath, prefix, path);
}