[PATCH] git-tar-tree: add get_record()
Add get_record() which returns a pointer to the next record in the block.
This commit is contained in:

committed by
Linus Torvalds

parent
cee99d2257
commit
a90a6e6a78
26
tar-tree.c
26
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
|
* The end of tar archives is marked by 1024 nul bytes and after that
|
||||||
* follows the rest of the block (if any).
|
* 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)
|
if (size > RECORDSIZE)
|
||||||
die("tar-tree: extended header too big, wtf?");
|
die("tar-tree: extended header too big, wtf?");
|
||||||
write_header(NULL, 'x', NULL, NULL, headerfilename, 0100600, size);
|
write_header(NULL, 'x', NULL, NULL, headerfilename, 0100600, size);
|
||||||
p = block + offset;
|
p = get_record();
|
||||||
memset(p, 0, RECORDSIZE);
|
|
||||||
offset += RECORDSIZE;
|
|
||||||
append_long(&p, size);
|
append_long(&p, size);
|
||||||
append_string(&p, " path=");
|
append_string(&p, " path=");
|
||||||
append_path(&p, is_dir, basepath, prefix, path);
|
append_path(&p, is_dir, basepath, prefix, path);
|
||||||
@ -192,9 +199,7 @@ static void write_global_extended_header(const char *sha1)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
write_header(NULL, 'g', NULL, NULL, "pax_global_header", 0, 52);
|
write_header(NULL, 'g', NULL, NULL, "pax_global_header", 0, 52);
|
||||||
p = block + offset;
|
p = get_record();
|
||||||
memset(p, 0, RECORDSIZE);
|
|
||||||
offset += RECORDSIZE;
|
|
||||||
append_long(&p, 52); /* 2 + 9 + 40 + 1 */
|
append_long(&p, 52); /* 2 + 9 + 40 + 1 */
|
||||||
append_string(&p, " comment=");
|
append_string(&p, " comment=");
|
||||||
append_string(&p, sha1_to_hex(sha1));
|
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,
|
write_extended_header(headerfilename, S_ISDIR(mode), basepath,
|
||||||
prefix, path, namelen);
|
prefix, path, namelen);
|
||||||
|
|
||||||
header = block + offset;
|
header = get_record();
|
||||||
memset(header, 0, RECORDSIZE);
|
|
||||||
offset += RECORDSIZE;
|
|
||||||
sprintf(header, "%s.data", sha1_hex);
|
sprintf(header, "%s.data", sha1_hex);
|
||||||
} else {
|
} else {
|
||||||
header = block + offset;
|
p = header = get_record();
|
||||||
memset(header, 0, RECORDSIZE);
|
|
||||||
offset += RECORDSIZE;
|
|
||||||
p = header;
|
|
||||||
append_path(&p, S_ISDIR(mode), basepath, prefix, path);
|
append_path(&p, S_ISDIR(mode), basepath, prefix, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user