зеркало из https://github.com/microsoft/git.git
[PATCH] git-tar-tree: add TYPEFLAG_ constants
Add TYPEFLAG_ constants.
This commit is contained in:
Родитель
a90a6e6a78
Коммит
03d791ff11
25
tar-tree.c
25
tar-tree.c
|
@ -4,6 +4,12 @@
|
||||||
#define RECORDSIZE (512)
|
#define RECORDSIZE (512)
|
||||||
#define BLOCKSIZE (RECORDSIZE * 20)
|
#define BLOCKSIZE (RECORDSIZE * 20)
|
||||||
|
|
||||||
|
#define TYPEFLAG_AUTO '\0'
|
||||||
|
#define TYPEFLAG_REG '0'
|
||||||
|
#define TYPEFLAG_DIR '5'
|
||||||
|
#define TYPEFLAG_GLOBAL_HEADER 'g'
|
||||||
|
#define TYPEFLAG_EXT_HEADER 'x'
|
||||||
|
|
||||||
static const char *tar_tree_usage = "tar-tree <key> [basedir]";
|
static const char *tar_tree_usage = "tar-tree <key> [basedir]";
|
||||||
|
|
||||||
static char block[BLOCKSIZE];
|
static char block[BLOCKSIZE];
|
||||||
|
@ -186,7 +192,8 @@ static void write_extended_header(const char *headerfilename, int is_dir,
|
||||||
size++;
|
size++;
|
||||||
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, TYPEFLAG_EXT_HEADER, NULL, NULL, headerfilename,
|
||||||
|
0100600, size);
|
||||||
p = get_record();
|
p = get_record();
|
||||||
append_long(&p, size);
|
append_long(&p, size);
|
||||||
append_string(&p, " path=");
|
append_string(&p, " path=");
|
||||||
|
@ -198,7 +205,8 @@ static void write_extended_header(const char *headerfilename, int is_dir,
|
||||||
static void write_global_extended_header(const char *sha1)
|
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, TYPEFLAG_GLOBAL_HEADER, NULL, NULL,
|
||||||
|
"pax_global_header", 0100600, 52);
|
||||||
p = get_record();
|
p = get_record();
|
||||||
append_long(&p, 52); /* 2 + 9 + 40 + 1 */
|
append_long(&p, 52); /* 2 + 9 + 40 + 1 */
|
||||||
append_string(&p, " comment=");
|
append_string(&p, " comment=");
|
||||||
|
@ -217,6 +225,13 @@ static void write_header(const char *sha1, char typeflag, const char *basepath,
|
||||||
unsigned int checksum = 0;
|
unsigned int checksum = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (typeflag == TYPEFLAG_AUTO) {
|
||||||
|
if (S_ISDIR(mode))
|
||||||
|
typeflag = TYPEFLAG_DIR;
|
||||||
|
else
|
||||||
|
typeflag = TYPEFLAG_REG;
|
||||||
|
}
|
||||||
|
|
||||||
namelen = path_len(S_ISDIR(mode), basepath, prefix, path);
|
namelen = path_len(S_ISDIR(mode), basepath, prefix, path);
|
||||||
if (namelen > 500) {
|
if (namelen > 500) {
|
||||||
die("tar-tree: name too log of object %s\n", sha1_to_hex(sha1));
|
die("tar-tree: name too log of object %s\n", sha1_to_hex(sha1));
|
||||||
|
@ -287,8 +302,8 @@ static void traverse_tree(void *buffer, unsigned long size,
|
||||||
eltbuf = read_sha1_file(sha1, elttype, &eltsize);
|
eltbuf = read_sha1_file(sha1, elttype, &eltsize);
|
||||||
if (!eltbuf)
|
if (!eltbuf)
|
||||||
die("cannot read %s", sha1_to_hex(sha1));
|
die("cannot read %s", sha1_to_hex(sha1));
|
||||||
write_header(sha1, S_ISDIR(mode) ? '5' : '0', basedir,
|
write_header(sha1, TYPEFLAG_AUTO, basedir, prefix, path,
|
||||||
prefix, path, mode, eltsize);
|
mode, eltsize);
|
||||||
if (!strcmp(elttype, "tree")) {
|
if (!strcmp(elttype, "tree")) {
|
||||||
this_prefix.name = path;
|
this_prefix.name = path;
|
||||||
traverse_tree(eltbuf, eltsize, &this_prefix);
|
traverse_tree(eltbuf, eltsize, &this_prefix);
|
||||||
|
@ -362,7 +377,7 @@ int main(int argc, char **argv)
|
||||||
if (!archive_time)
|
if (!archive_time)
|
||||||
archive_time = time(NULL);
|
archive_time = time(NULL);
|
||||||
if (basedir)
|
if (basedir)
|
||||||
write_header("0", '5', NULL, NULL, basedir, 040755, 0);
|
write_header("0", TYPEFLAG_DIR, NULL, NULL, basedir, 040755, 0);
|
||||||
traverse_tree(buffer, size, NULL);
|
traverse_tree(buffer, size, NULL);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
write_trailer();
|
write_trailer();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче