mirror of
https://github.com/git/git.git
synced 2024-11-05 08:47:56 +01:00
Merge branch 'pe/cleanup' into next
* pe/cleanup: Replace xmalloc+memset(0) with xcalloc. Use blob_, commit_, tag_, and tree_type throughout.
This commit is contained in:
commit
00cbdec981
30 changed files with 120 additions and 106 deletions
14
apply.c
14
apply.c
|
@ -9,6 +9,7 @@
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
#include "blob.h"
|
||||||
|
|
||||||
// --check turns on checking that the working tree matches the
|
// --check turns on checking that the working tree matches the
|
||||||
// files that are being modified, but doesn't apply the patch
|
// files that are being modified, but doesn't apply the patch
|
||||||
|
@ -924,8 +925,7 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
|
||||||
struct fragment *fragment;
|
struct fragment *fragment;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
fragment = xmalloc(sizeof(*fragment));
|
fragment = xcalloc(1, sizeof(*fragment));
|
||||||
memset(fragment, 0, sizeof(*fragment));
|
|
||||||
len = parse_fragment(line, size, patch, fragment);
|
len = parse_fragment(line, size, patch, fragment);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
die("corrupt patch at line %d", linenr);
|
die("corrupt patch at line %d", linenr);
|
||||||
|
@ -1296,7 +1296,7 @@ static int apply_fragments(struct buffer_desc *desc, struct patch *patch)
|
||||||
* applies to.
|
* applies to.
|
||||||
*/
|
*/
|
||||||
write_sha1_file_prepare(desc->buffer, desc->size,
|
write_sha1_file_prepare(desc->buffer, desc->size,
|
||||||
"blob", sha1, hdr, &hdrlen);
|
blob_type, sha1, hdr, &hdrlen);
|
||||||
if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix))
|
if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix))
|
||||||
return error("the patch applies to '%s' (%s), "
|
return error("the patch applies to '%s' (%s), "
|
||||||
"which does not match the "
|
"which does not match the "
|
||||||
|
@ -1651,15 +1651,14 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
|
||||||
if (!write_index)
|
if (!write_index)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ce = xmalloc(ce_size);
|
ce = xcalloc(1, ce_size);
|
||||||
memset(ce, 0, ce_size);
|
|
||||||
memcpy(ce->name, path, namelen);
|
memcpy(ce->name, path, namelen);
|
||||||
ce->ce_mode = create_ce_mode(mode);
|
ce->ce_mode = create_ce_mode(mode);
|
||||||
ce->ce_flags = htons(namelen);
|
ce->ce_flags = htons(namelen);
|
||||||
if (lstat(path, &st) < 0)
|
if (lstat(path, &st) < 0)
|
||||||
die("unable to stat newly created file %s", path);
|
die("unable to stat newly created file %s", path);
|
||||||
fill_stat_cache_info(ce, &st);
|
fill_stat_cache_info(ce, &st);
|
||||||
if (write_sha1_file(buf, size, "blob", ce->sha1) < 0)
|
if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)
|
||||||
die("unable to create backing store for newly created file %s", path);
|
die("unable to create backing store for newly created file %s", path);
|
||||||
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
|
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
|
||||||
die("unable to add cache entry for %s", path);
|
die("unable to add cache entry for %s", path);
|
||||||
|
@ -1808,8 +1807,7 @@ static int apply_patch(int fd, const char *filename)
|
||||||
struct patch *patch;
|
struct patch *patch;
|
||||||
int nr;
|
int nr;
|
||||||
|
|
||||||
patch = xmalloc(sizeof(*patch));
|
patch = xcalloc(1, sizeof(*patch));
|
||||||
memset(patch, 0, sizeof(*patch));
|
|
||||||
nr = parse_chunk(buffer + offset, size, patch);
|
nr = parse_chunk(buffer + offset, size, patch);
|
||||||
if (nr < 0)
|
if (nr < 0)
|
||||||
break;
|
break;
|
||||||
|
|
2
blame.c
2
blame.c
|
@ -229,7 +229,7 @@ static void get_blob(struct commit *commit)
|
||||||
|
|
||||||
info->buf = read_sha1_file(info->sha1, type, &info->size);
|
info->buf = read_sha1_file(info->sha1, type, &info->size);
|
||||||
|
|
||||||
assert(!strcmp(type, "blob"));
|
assert(!strcmp(type, blob_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For debugging only */
|
/* For debugging only */
|
||||||
|
|
3
blob.c
3
blob.c
|
@ -8,8 +8,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
struct blob *ret = xmalloc(sizeof(struct blob));
|
struct blob *ret = xcalloc(1, sizeof(struct blob));
|
||||||
memset(ret, 0, sizeof(struct blob));
|
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
ret->object.type = blob_type;
|
ret->object.type = blob_type;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "exec_cmd.h"
|
#include "exec_cmd.h"
|
||||||
|
#include "tag.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
static void flush_buffer(const char *buf, unsigned long size)
|
static void flush_buffer(const char *buf, unsigned long size)
|
||||||
{
|
{
|
||||||
|
@ -136,13 +138,13 @@ int main(int argc, char **argv)
|
||||||
die("Not a valid object name %s", argv[2]);
|
die("Not a valid object name %s", argv[2]);
|
||||||
|
|
||||||
/* custom pretty-print here */
|
/* custom pretty-print here */
|
||||||
if (!strcmp(type, "tree"))
|
if (!strcmp(type, tree_type))
|
||||||
return execl_git_cmd("ls-tree", argv[2], NULL);
|
return execl_git_cmd("ls-tree", argv[2], NULL);
|
||||||
|
|
||||||
buf = read_sha1_file(sha1, type, &size);
|
buf = read_sha1_file(sha1, type, &size);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
die("Cannot read object %s", argv[2]);
|
die("Cannot read object %s", argv[2]);
|
||||||
if (!strcmp(type, "tag"))
|
if (!strcmp(type, tag_type))
|
||||||
return pprint_tag(sha1, buf, size);
|
return pprint_tag(sha1, buf, size);
|
||||||
|
|
||||||
/* otherwise just spit out the data */
|
/* otherwise just spit out the data */
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
|
#include "blob.h"
|
||||||
#include "diff.h"
|
#include "diff.h"
|
||||||
#include "diffcore.h"
|
#include "diffcore.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
@ -104,7 +105,7 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size)
|
||||||
return xcalloc(1, 1);
|
return xcalloc(1, 1);
|
||||||
}
|
}
|
||||||
blob = read_sha1_file(sha1, type, size);
|
blob = read_sha1_file(sha1, type, size);
|
||||||
if (strcmp(type, "blob"))
|
if (strcmp(type, blob_type))
|
||||||
die("object '%s' is not a blob!", sha1_to_hex(sha1));
|
die("object '%s' is not a blob!", sha1_to_hex(sha1));
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
* Copyright (C) Linus Torvalds, 2005
|
* Copyright (C) Linus Torvalds, 2005
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
#define BLOCKING (1ul << 14)
|
#define BLOCKING (1ul << 14)
|
||||||
|
|
||||||
|
@ -93,13 +95,13 @@ int main(int argc, char **argv)
|
||||||
if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)
|
if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)
|
||||||
usage(commit_tree_usage);
|
usage(commit_tree_usage);
|
||||||
|
|
||||||
check_valid(tree_sha1, "tree");
|
check_valid(tree_sha1, tree_type);
|
||||||
for (i = 2; i < argc; i += 2) {
|
for (i = 2; i < argc; i += 2) {
|
||||||
char *a, *b;
|
char *a, *b;
|
||||||
a = argv[i]; b = argv[i+1];
|
a = argv[i]; b = argv[i+1];
|
||||||
if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
|
if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
|
||||||
usage(commit_tree_usage);
|
usage(commit_tree_usage);
|
||||||
check_valid(parent_sha1[parents], "commit");
|
check_valid(parent_sha1[parents], commit_type);
|
||||||
if (new_parent(parents))
|
if (new_parent(parents))
|
||||||
parents++;
|
parents++;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +127,7 @@ int main(int argc, char **argv)
|
||||||
while (fgets(comment, sizeof(comment), stdin) != NULL)
|
while (fgets(comment, sizeof(comment), stdin) != NULL)
|
||||||
add_buffer(&buffer, &size, "%s", comment);
|
add_buffer(&buffer, &size, "%s", comment);
|
||||||
|
|
||||||
if (!write_sha1_file(buffer, size, "commit", commit_sha1)) {
|
if (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {
|
||||||
printf("%s\n", sha1_to_hex(commit_sha1));
|
printf("%s\n", sha1_to_hex(commit_sha1));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
3
commit.c
3
commit.c
|
@ -73,8 +73,7 @@ struct commit *lookup_commit(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
struct commit *ret = xmalloc(sizeof(struct commit));
|
struct commit *ret = xcalloc(1, sizeof(struct commit));
|
||||||
memset(ret, 0, sizeof(struct commit));
|
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
ret->object.type = commit_type;
|
ret->object.type = commit_type;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
|
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "blob.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
struct entry {
|
struct entry {
|
||||||
unsigned char old_sha1[20];
|
unsigned char old_sha1[20];
|
||||||
|
@ -18,8 +21,7 @@ static struct entry * convert_entry(unsigned char *sha1);
|
||||||
|
|
||||||
static struct entry *insert_new(unsigned char *sha1, int pos)
|
static struct entry *insert_new(unsigned char *sha1, int pos)
|
||||||
{
|
{
|
||||||
struct entry *new = xmalloc(sizeof(struct entry));
|
struct entry *new = xcalloc(1, sizeof(struct entry));
|
||||||
memset(new, 0, sizeof(*new));
|
|
||||||
memcpy(new->old_sha1, sha1, 20);
|
memcpy(new->old_sha1, sha1, 20);
|
||||||
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
|
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
|
||||||
convert[pos] = new;
|
convert[pos] = new;
|
||||||
|
@ -122,7 +124,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
|
||||||
buffer += len;
|
buffer += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_sha1_file(new, newlen, "tree", result_sha1);
|
write_sha1_file(new, newlen, tree_type, result_sha1);
|
||||||
free(new);
|
free(new);
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +264,7 @@ static void convert_date(void *buffer, unsigned long size, unsigned char *result
|
||||||
memcpy(new + newlen, buffer, size);
|
memcpy(new + newlen, buffer, size);
|
||||||
newlen += size;
|
newlen += size;
|
||||||
|
|
||||||
write_sha1_file(new, newlen, "commit", result_sha1);
|
write_sha1_file(new, newlen, commit_type, result_sha1);
|
||||||
free(new);
|
free(new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,11 +300,11 @@ static struct entry * convert_entry(unsigned char *sha1)
|
||||||
buffer = xmalloc(size);
|
buffer = xmalloc(size);
|
||||||
memcpy(buffer, data, size);
|
memcpy(buffer, data, size);
|
||||||
|
|
||||||
if (!strcmp(type, "blob")) {
|
if (!strcmp(type, blob_type)) {
|
||||||
write_sha1_file(buffer, size, "blob", entry->new_sha1);
|
write_sha1_file(buffer, size, blob_type, entry->new_sha1);
|
||||||
} else if (!strcmp(type, "tree"))
|
} else if (!strcmp(type, tree_type))
|
||||||
convert_tree(buffer, size, entry->new_sha1);
|
convert_tree(buffer, size, entry->new_sha1);
|
||||||
else if (!strcmp(type, "commit"))
|
else if (!strcmp(type, commit_type))
|
||||||
convert_commit(buffer, size, entry->new_sha1);
|
convert_commit(buffer, size, entry->new_sha1);
|
||||||
else
|
else
|
||||||
die("unknown object type '%s' in %s", type, sha1_to_hex(sha1));
|
die("unknown object type '%s' in %s", type, sha1_to_hex(sha1));
|
||||||
|
|
|
@ -52,7 +52,7 @@ static int diff_root_tree(const unsigned char *new, const char *base)
|
||||||
void *tree;
|
void *tree;
|
||||||
struct tree_desc empty, real;
|
struct tree_desc empty, real;
|
||||||
|
|
||||||
tree = read_object_with_reference(new, "tree", &real.size, NULL);
|
tree = read_object_with_reference(new, tree_type, &real.size, NULL);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
die("unable to read root tree (%s)", sha1_to_hex(new));
|
die("unable to read root tree (%s)", sha1_to_hex(new));
|
||||||
real.buf = tree;
|
real.buf = tree;
|
||||||
|
|
3
entry.c
3
entry.c
|
@ -1,6 +1,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "blob.h"
|
||||||
|
|
||||||
static void create_directories(const char *path, struct checkout *state)
|
static void create_directories(const char *path, struct checkout *state)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +73,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
|
||||||
char type[20];
|
char type[20];
|
||||||
|
|
||||||
new = read_sha1_file(ce->sha1, type, &size);
|
new = read_sha1_file(ce->sha1, type, &size);
|
||||||
if (!new || strcmp(type, "blob")) {
|
if (!new || strcmp(type, blob_type)) {
|
||||||
if (new)
|
if (new)
|
||||||
free(new);
|
free(new);
|
||||||
return error("git-checkout-index: unable to read sha1 file of %s (%s)",
|
return error("git-checkout-index: unable to read sha1 file of %s (%s)",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* Copyright (C) Junio C Hamano, 2005
|
* Copyright (C) Junio C Hamano, 2005
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "blob.h"
|
||||||
|
|
||||||
static void hash_object(const char *path, const char *type, int write_object)
|
static void hash_object(const char *path, const char *type, int write_object)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +36,7 @@ static const char hash_object_usage[] =
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *type = "blob";
|
const char *type = blob_type;
|
||||||
int write_object = 0;
|
int write_object = 0;
|
||||||
const char *prefix = NULL;
|
const char *prefix = NULL;
|
||||||
int prefix_length = -1;
|
int prefix_length = -1;
|
||||||
|
|
|
@ -1008,8 +1008,7 @@ static int fetch_indices(void)
|
||||||
struct active_request_slot *slot;
|
struct active_request_slot *slot;
|
||||||
struct slot_results results;
|
struct slot_results results;
|
||||||
|
|
||||||
data = xmalloc(4096);
|
data = xcalloc(1, 4096);
|
||||||
memset(data, 0, 4096);
|
|
||||||
buffer.size = 4096;
|
buffer.size = 4096;
|
||||||
buffer.posn = 0;
|
buffer.posn = 0;
|
||||||
buffer.buffer = data;
|
buffer.buffer = data;
|
||||||
|
@ -2042,8 +2041,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
|
||||||
char *if_header;
|
char *if_header;
|
||||||
struct curl_slist *dav_headers = NULL;
|
struct curl_slist *dav_headers = NULL;
|
||||||
|
|
||||||
buffer.buffer = xmalloc(4096);
|
buffer.buffer = xcalloc(1, 4096);
|
||||||
memset(buffer.buffer, 0, 4096);
|
|
||||||
buffer.size = 4096;
|
buffer.size = 4096;
|
||||||
buffer.posn = 0;
|
buffer.posn = 0;
|
||||||
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
|
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
|
||||||
|
|
12
index-pack.c
12
index-pack.c
|
@ -2,6 +2,10 @@
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include "csum-file.h"
|
#include "csum-file.h"
|
||||||
|
#include "blob.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tag.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
static const char index_pack_usage[] =
|
static const char index_pack_usage[] =
|
||||||
"git-index-pack [-o index-file] pack-file";
|
"git-index-pack [-o index-file] pack-file";
|
||||||
|
@ -224,10 +228,10 @@ static void sha1_object(const void *data, unsigned long size,
|
||||||
const char *type_str;
|
const char *type_str;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OBJ_COMMIT: type_str = "commit"; break;
|
case OBJ_COMMIT: type_str = commit_type; break;
|
||||||
case OBJ_TREE: type_str = "tree"; break;
|
case OBJ_TREE: type_str = tree_type; break;
|
||||||
case OBJ_BLOB: type_str = "blob"; break;
|
case OBJ_BLOB: type_str = blob_type; break;
|
||||||
case OBJ_TAG: type_str = "tag"; break;
|
case OBJ_TAG: type_str = tag_type; break;
|
||||||
default:
|
default:
|
||||||
die("bad type %d", type);
|
die("bad type %d", type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen,
|
||||||
const char *pathname, unsigned mode, int stage)
|
const char *pathname, unsigned mode, int stage)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
const char *type = "blob";
|
const char *type = blob_type;
|
||||||
|
|
||||||
if (S_ISDIR(mode)) {
|
if (S_ISDIR(mode)) {
|
||||||
if (show_recursive(base, baselen, pathname)) {
|
if (show_recursive(base, baselen, pathname)) {
|
||||||
|
@ -64,7 +64,7 @@ static int show_tree(unsigned char *sha1, const char *base, int baselen,
|
||||||
if (!(ls_options & LS_SHOW_TREES))
|
if (!(ls_options & LS_SHOW_TREES))
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
type = "tree";
|
type = tree_type;
|
||||||
}
|
}
|
||||||
else if (ls_options & LS_TREE_ONLY)
|
else if (ls_options & LS_TREE_ONLY)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
3
mktag.c
3
mktag.c
|
@ -1,4 +1,5 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "tag.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A signature file has a very simple fixed format: three lines
|
* A signature file has a very simple fixed format: three lines
|
||||||
|
@ -126,7 +127,7 @@ int main(int argc, char **argv)
|
||||||
if (verify_tag(buffer, size) < 0)
|
if (verify_tag(buffer, size) < 0)
|
||||||
die("invalid tag signature file");
|
die("invalid tag signature file");
|
||||||
|
|
||||||
if (write_sha1_file(buffer, size, "tag", result_sha1) < 0)
|
if (write_sha1_file(buffer, size, tag_type, result_sha1) < 0)
|
||||||
die("unable to write tag file");
|
die("unable to write tag file");
|
||||||
printf("%s\n", sha1_to_hex(result_sha1));
|
printf("%s\n", sha1_to_hex(result_sha1));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
3
mktree.c
3
mktree.c
|
@ -6,6 +6,7 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
static struct treeent {
|
static struct treeent {
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
|
@ -67,7 +68,7 @@ static void write_tree(unsigned char *sha1)
|
||||||
memcpy(buffer + offset, ent->sha1, 20);
|
memcpy(buffer + offset, ent->sha1, 20);
|
||||||
offset += 20;
|
offset += 20;
|
||||||
}
|
}
|
||||||
write_sha1_file(buffer, offset, "tree", sha1);
|
write_sha1_file(buffer, offset, tree_type, sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char mktree_usage[] = "mktree [-z]";
|
static const char mktree_usage[] = "mktree [-z]";
|
||||||
|
|
14
object.c
14
object.c
|
@ -85,8 +85,7 @@ struct object_refs *alloc_object_refs(unsigned count)
|
||||||
struct object_refs *refs;
|
struct object_refs *refs;
|
||||||
size_t size = sizeof(*refs) + count*sizeof(struct object *);
|
size_t size = sizeof(*refs) + count*sizeof(struct object *);
|
||||||
|
|
||||||
refs = xmalloc(size);
|
refs = xcalloc(1, size);
|
||||||
memset(refs, 0, size);
|
|
||||||
refs->count = count;
|
refs->count = count;
|
||||||
return refs;
|
return refs;
|
||||||
}
|
}
|
||||||
|
@ -178,8 +177,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
union any_object *ret = xmalloc(sizeof(*ret));
|
union any_object *ret = xcalloc(1, sizeof(*ret));
|
||||||
memset(ret, 0, sizeof(*ret));
|
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
ret->object.type = NULL;
|
ret->object.type = NULL;
|
||||||
return &ret->object;
|
return &ret->object;
|
||||||
|
@ -196,15 +194,15 @@ struct object *parse_object(const unsigned char *sha1)
|
||||||
struct object *obj;
|
struct object *obj;
|
||||||
if (check_sha1_signature(sha1, buffer, size, type) < 0)
|
if (check_sha1_signature(sha1, buffer, size, type) < 0)
|
||||||
printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
|
printf("sha1 mismatch %s\n", sha1_to_hex(sha1));
|
||||||
if (!strcmp(type, "blob")) {
|
if (!strcmp(type, blob_type)) {
|
||||||
struct blob *blob = lookup_blob(sha1);
|
struct blob *blob = lookup_blob(sha1);
|
||||||
parse_blob_buffer(blob, buffer, size);
|
parse_blob_buffer(blob, buffer, size);
|
||||||
obj = &blob->object;
|
obj = &blob->object;
|
||||||
} else if (!strcmp(type, "tree")) {
|
} else if (!strcmp(type, tree_type)) {
|
||||||
struct tree *tree = lookup_tree(sha1);
|
struct tree *tree = lookup_tree(sha1);
|
||||||
parse_tree_buffer(tree, buffer, size);
|
parse_tree_buffer(tree, buffer, size);
|
||||||
obj = &tree->object;
|
obj = &tree->object;
|
||||||
} else if (!strcmp(type, "commit")) {
|
} else if (!strcmp(type, commit_type)) {
|
||||||
struct commit *commit = lookup_commit(sha1);
|
struct commit *commit = lookup_commit(sha1);
|
||||||
parse_commit_buffer(commit, buffer, size);
|
parse_commit_buffer(commit, buffer, size);
|
||||||
if (!commit->buffer) {
|
if (!commit->buffer) {
|
||||||
|
@ -212,7 +210,7 @@ struct object *parse_object(const unsigned char *sha1)
|
||||||
buffer = NULL;
|
buffer = NULL;
|
||||||
}
|
}
|
||||||
obj = &commit->object;
|
obj = &commit->object;
|
||||||
} else if (!strcmp(type, "tag")) {
|
} else if (!strcmp(type, tag_type)) {
|
||||||
struct tag *tag = lookup_tag(sha1);
|
struct tag *tag = lookup_tag(sha1);
|
||||||
parse_tag_buffer(tag, buffer, size);
|
parse_tag_buffer(tag, buffer, size);
|
||||||
obj = &tag->object;
|
obj = &tag->object;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "blob.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tag.h"
|
||||||
|
#include "tree.h"
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
#include "csum-file.h"
|
#include "csum-file.h"
|
||||||
|
@ -603,7 +607,7 @@ static void add_pbase_tree(struct tree_desc *tree, struct name_path *up)
|
||||||
if (!add_object_entry(sha1, hash, 1))
|
if (!add_object_entry(sha1, hash, 1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!strcmp(type, "tree")) {
|
if (!strcmp(type, tree_type)) {
|
||||||
struct tree_desc sub;
|
struct tree_desc sub;
|
||||||
void *elem;
|
void *elem;
|
||||||
struct name_path me;
|
struct name_path me;
|
||||||
|
@ -626,7 +630,7 @@ static void add_preferred_base(unsigned char *sha1)
|
||||||
struct tree_desc tree;
|
struct tree_desc tree;
|
||||||
void *elem;
|
void *elem;
|
||||||
|
|
||||||
elem = read_object_with_reference(sha1, "tree", &tree.size, NULL);
|
elem = read_object_with_reference(sha1, tree_type, &tree.size, NULL);
|
||||||
tree.buf = elem;
|
tree.buf = elem;
|
||||||
if (!tree.buf)
|
if (!tree.buf)
|
||||||
return;
|
return;
|
||||||
|
@ -684,13 +688,13 @@ static void check_object(struct object_entry *entry)
|
||||||
die("unable to get type of object %s",
|
die("unable to get type of object %s",
|
||||||
sha1_to_hex(entry->sha1));
|
sha1_to_hex(entry->sha1));
|
||||||
|
|
||||||
if (!strcmp(type, "commit")) {
|
if (!strcmp(type, commit_type)) {
|
||||||
entry->type = OBJ_COMMIT;
|
entry->type = OBJ_COMMIT;
|
||||||
} else if (!strcmp(type, "tree")) {
|
} else if (!strcmp(type, tree_type)) {
|
||||||
entry->type = OBJ_TREE;
|
entry->type = OBJ_TREE;
|
||||||
} else if (!strcmp(type, "blob")) {
|
} else if (!strcmp(type, blob_type)) {
|
||||||
entry->type = OBJ_BLOB;
|
entry->type = OBJ_BLOB;
|
||||||
} else if (!strcmp(type, "tag")) {
|
} else if (!strcmp(type, tag_type)) {
|
||||||
entry->type = OBJ_TAG;
|
entry->type = OBJ_TAG;
|
||||||
} else
|
} else
|
||||||
die("unable to pack object %s of type %s",
|
die("unable to pack object %s of type %s",
|
||||||
|
|
|
@ -133,11 +133,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
|
||||||
pathlen = strlen(first);
|
pathlen = strlen(first);
|
||||||
ce_size = cache_entry_size(baselen + pathlen);
|
ce_size = cache_entry_size(baselen + pathlen);
|
||||||
|
|
||||||
src = xmalloc(sizeof(struct cache_entry *) * src_size);
|
src = xcalloc(src_size, sizeof(struct cache_entry *));
|
||||||
memset(src, 0, sizeof(struct cache_entry *) * src_size);
|
|
||||||
|
|
||||||
subposns = xmalloc(sizeof(struct tree_list_entry *) * len);
|
subposns = xcalloc(len, sizeof(struct tree_list_entry *));
|
||||||
memset(subposns, 0, sizeof(struct tree_list_entry *) * len);
|
|
||||||
|
|
||||||
if (cache_name && !strcmp(cache_name, first)) {
|
if (cache_name && !strcmp(cache_name, first)) {
|
||||||
any_files = 1;
|
any_files = 1;
|
||||||
|
@ -177,8 +175,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
|
||||||
else
|
else
|
||||||
ce_stage = 2;
|
ce_stage = 2;
|
||||||
|
|
||||||
ce = xmalloc(ce_size);
|
ce = xcalloc(1, ce_size);
|
||||||
memset(ce, 0, ce_size);
|
|
||||||
ce->ce_mode = create_ce_mode(posns[i]->mode);
|
ce->ce_mode = create_ce_mode(posns[i]->mode);
|
||||||
ce->ce_flags = create_ce_flags(baselen + pathlen,
|
ce->ce_flags = create_ce_flags(baselen + pathlen,
|
||||||
ce_stage);
|
ce_stage);
|
||||||
|
|
|
@ -260,7 +260,7 @@ int rev_same_tree_as_empty(struct tree *t1)
|
||||||
if (!t1)
|
if (!t1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
tree = read_object_with_reference(t1->object.sha1, "tree", &real.size, NULL);
|
tree = read_object_with_reference(t1->object.sha1, tree_type, &real.size, NULL);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
return 0;
|
return 0;
|
||||||
real.buf = tree;
|
real.buf = tree;
|
||||||
|
|
40
sha1_file.c
40
sha1_file.c
|
@ -9,6 +9,10 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
#include "blob.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tag.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
#ifndef O_NOATIME
|
#ifndef O_NOATIME
|
||||||
#if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
|
#if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
|
||||||
|
@ -894,16 +898,16 @@ void packed_object_info_detail(struct pack_entry *e,
|
||||||
}
|
}
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case OBJ_COMMIT:
|
case OBJ_COMMIT:
|
||||||
strcpy(type, "commit");
|
strcpy(type, commit_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
strcpy(type, "tree");
|
strcpy(type, tree_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
strcpy(type, "blob");
|
strcpy(type, blob_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TAG:
|
case OBJ_TAG:
|
||||||
strcpy(type, "tag");
|
strcpy(type, tag_type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("corrupted pack file %s containing object of kind %d",
|
die("corrupted pack file %s containing object of kind %d",
|
||||||
|
@ -934,16 +938,16 @@ static int packed_object_info(struct pack_entry *entry,
|
||||||
unuse_packed_git(p);
|
unuse_packed_git(p);
|
||||||
return retval;
|
return retval;
|
||||||
case OBJ_COMMIT:
|
case OBJ_COMMIT:
|
||||||
strcpy(type, "commit");
|
strcpy(type, commit_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
strcpy(type, "tree");
|
strcpy(type, tree_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
strcpy(type, "blob");
|
strcpy(type, blob_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TAG:
|
case OBJ_TAG:
|
||||||
strcpy(type, "tag");
|
strcpy(type, tag_type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("corrupted pack file %s containing object of kind %d",
|
die("corrupted pack file %s containing object of kind %d",
|
||||||
|
@ -1071,16 +1075,16 @@ void *unpack_entry_gently(struct pack_entry *entry,
|
||||||
retval = unpack_delta_entry(pack, size, left, type, sizep, p);
|
retval = unpack_delta_entry(pack, size, left, type, sizep, p);
|
||||||
return retval;
|
return retval;
|
||||||
case OBJ_COMMIT:
|
case OBJ_COMMIT:
|
||||||
strcpy(type, "commit");
|
strcpy(type, commit_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
strcpy(type, "tree");
|
strcpy(type, tree_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
strcpy(type, "blob");
|
strcpy(type, blob_type);
|
||||||
break;
|
break;
|
||||||
case OBJ_TAG:
|
case OBJ_TAG:
|
||||||
strcpy(type, "tag");
|
strcpy(type, tag_type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1241,9 +1245,9 @@ void *read_object_with_reference(const unsigned char *sha1,
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
/* Handle references */
|
/* Handle references */
|
||||||
else if (!strcmp(type, "commit"))
|
else if (!strcmp(type, commit_type))
|
||||||
ref_type = "tree ";
|
ref_type = "tree ";
|
||||||
else if (!strcmp(type, "tag"))
|
else if (!strcmp(type, tag_type))
|
||||||
ref_type = "object ";
|
ref_type = "object ";
|
||||||
else {
|
else {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -1625,7 +1629,7 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!type)
|
if (!type)
|
||||||
type = "blob";
|
type = blob_type;
|
||||||
if (write_object)
|
if (write_object)
|
||||||
ret = write_sha1_file(buf, off, type, sha1);
|
ret = write_sha1_file(buf, off, type, sha1);
|
||||||
else {
|
else {
|
||||||
|
@ -1652,7 +1656,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, con
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!type)
|
if (!type)
|
||||||
type = "blob";
|
type = blob_type;
|
||||||
if (write_object)
|
if (write_object)
|
||||||
ret = write_sha1_file(buf, size, type, sha1);
|
ret = write_sha1_file(buf, size, type, sha1);
|
||||||
else {
|
else {
|
||||||
|
@ -1690,9 +1694,9 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
|
||||||
if (!write_object) {
|
if (!write_object) {
|
||||||
unsigned char hdr[50];
|
unsigned char hdr[50];
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
write_sha1_file_prepare(target, st->st_size, "blob",
|
write_sha1_file_prepare(target, st->st_size, blob_type,
|
||||||
sha1, hdr, &hdrlen);
|
sha1, hdr, &hdrlen);
|
||||||
} else if (write_sha1_file(target, st->st_size, "blob", sha1))
|
} else if (write_sha1_file(target, st->st_size, blob_type, sha1))
|
||||||
return error("%s: failed to insert into database",
|
return error("%s: failed to insert into database",
|
||||||
path);
|
path);
|
||||||
free(target);
|
free(target);
|
||||||
|
|
3
tag.c
3
tag.c
|
@ -19,8 +19,7 @@ struct tag *lookup_tag(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
struct tag *ret = xmalloc(sizeof(struct tag));
|
struct tag *ret = xcalloc(1, sizeof(struct tag));
|
||||||
memset(ret, 0, sizeof(struct tag));
|
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
ret->object.type = tag_type;
|
ret->object.type = tag_type;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -335,7 +335,7 @@ int main(int argc, char **argv)
|
||||||
} else
|
} else
|
||||||
archive_time = time(NULL);
|
archive_time = time(NULL);
|
||||||
|
|
||||||
tree.buf = read_object_with_reference(sha1, "tree", &tree.size,
|
tree.buf = read_object_with_reference(sha1, tree_type, &tree.size,
|
||||||
tree_sha1);
|
tree_sha1);
|
||||||
if (!tree.buf)
|
if (!tree.buf)
|
||||||
die("not a reference to a tag, commit or tree object: %s",
|
die("not a reference to a tag, commit or tree object: %s",
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "diff.h"
|
#include "diff.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
// What paths are we interested in?
|
// What paths are we interested in?
|
||||||
static int nr_paths = 0;
|
static int nr_paths = 0;
|
||||||
|
@ -148,7 +149,7 @@ static int show_entry(struct diff_options *opt, const char *prefix, struct tree_
|
||||||
void *tree;
|
void *tree;
|
||||||
|
|
||||||
tree = read_sha1_file(sha1, type, &inner.size);
|
tree = read_sha1_file(sha1, type, &inner.size);
|
||||||
if (!tree || strcmp(type, "tree"))
|
if (!tree || strcmp(type, tree_type))
|
||||||
die("corrupt tree sha %s", sha1_to_hex(sha1));
|
die("corrupt tree sha %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
inner.buf = tree;
|
inner.buf = tree;
|
||||||
|
@ -206,10 +207,10 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
|
||||||
struct tree_desc t1, t2;
|
struct tree_desc t1, t2;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
tree1 = read_object_with_reference(old, "tree", &t1.size, NULL);
|
tree1 = read_object_with_reference(old, tree_type, &t1.size, NULL);
|
||||||
if (!tree1)
|
if (!tree1)
|
||||||
die("unable to read source tree (%s)", sha1_to_hex(old));
|
die("unable to read source tree (%s)", sha1_to_hex(old));
|
||||||
tree2 = read_object_with_reference(new, "tree", &t2.size, NULL);
|
tree2 = read_object_with_reference(new, tree_type, &t2.size, NULL);
|
||||||
if (!tree2)
|
if (!tree2)
|
||||||
die("unable to read destination tree (%s)", sha1_to_hex(new));
|
die("unable to read destination tree (%s)", sha1_to_hex(new));
|
||||||
t1.buf = tree1;
|
t1.buf = tree1;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "tree-walk.h"
|
#include "tree-walk.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
|
void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +8,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
|
||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
|
|
||||||
if (sha1) {
|
if (sha1) {
|
||||||
buf = read_object_with_reference(sha1, "tree", &size, NULL);
|
buf = read_object_with_reference(sha1, tree_type, &size, NULL);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
die("unable to read tree %s", sha1_to_hex(sha1));
|
die("unable to read tree %s", sha1_to_hex(sha1));
|
||||||
}
|
}
|
||||||
|
|
7
tree.c
7
tree.c
|
@ -18,9 +18,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
|
||||||
|
|
||||||
len = strlen(pathname);
|
len = strlen(pathname);
|
||||||
size = cache_entry_size(baselen + len);
|
size = cache_entry_size(baselen + len);
|
||||||
ce = xmalloc(size);
|
ce = xcalloc(1, size);
|
||||||
|
|
||||||
memset(ce, 0, size);
|
|
||||||
|
|
||||||
ce->ce_mode = create_ce_mode(mode);
|
ce->ce_mode = create_ce_mode(mode);
|
||||||
ce->ce_flags = create_ce_flags(baselen + len, stage);
|
ce->ce_flags = create_ce_flags(baselen + len, stage);
|
||||||
|
@ -130,8 +128,7 @@ struct tree *lookup_tree(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
struct tree *ret = xmalloc(sizeof(struct tree));
|
struct tree *ret = xcalloc(1, sizeof(struct tree));
|
||||||
memset(ret, 0, sizeof(struct tree));
|
|
||||||
created_object(sha1, &ret->object);
|
created_object(sha1, &ret->object);
|
||||||
ret->object.type = tree_type;
|
ret->object.type = tree_type;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "blob.h"
|
||||||
|
|
||||||
static char *create_temp_file(unsigned char *sha1)
|
static char *create_temp_file(unsigned char *sha1)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ static char *create_temp_file(unsigned char *sha1)
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
buf = read_sha1_file(sha1, type, &size);
|
buf = read_sha1_file(sha1, type, &size);
|
||||||
if (!buf || strcmp(type, "blob"))
|
if (!buf || strcmp(type, blob_type))
|
||||||
die("unable to read blob object %s", sha1_to_hex(sha1));
|
die("unable to read blob object %s", sha1_to_hex(sha1));
|
||||||
|
|
||||||
strcpy(path, ".merge_file_XXXXXX");
|
strcpy(path, ".merge_file_XXXXXX");
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "delta.h"
|
#include "delta.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
#include "blob.h"
|
||||||
|
#include "commit.h"
|
||||||
|
#include "tag.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
@ -148,10 +152,10 @@ static int unpack_non_delta_entry(enum object_type kind, unsigned long size)
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case OBJ_COMMIT: type = "commit"; break;
|
case OBJ_COMMIT: type = commit_type; break;
|
||||||
case OBJ_TREE: type = "tree"; break;
|
case OBJ_TREE: type = tree_type; break;
|
||||||
case OBJ_BLOB: type = "blob"; break;
|
case OBJ_BLOB: type = blob_type; break;
|
||||||
case OBJ_TAG: type = "tag"; break;
|
case OBJ_TAG: type = tag_type; break;
|
||||||
default: die("bad type %d", kind);
|
default: die("bad type %d", kind);
|
||||||
}
|
}
|
||||||
if (!dry_run)
|
if (!dry_run)
|
||||||
|
|
|
@ -114,8 +114,7 @@ static int add_file_to_cache(const char *path)
|
||||||
|
|
||||||
namelen = strlen(path);
|
namelen = strlen(path);
|
||||||
size = cache_entry_size(namelen);
|
size = cache_entry_size(namelen);
|
||||||
ce = xmalloc(size);
|
ce = xcalloc(1, size);
|
||||||
memset(ce, 0, size);
|
|
||||||
memcpy(ce->name, path, namelen);
|
memcpy(ce->name, path, namelen);
|
||||||
ce->ce_flags = htons(namelen);
|
ce->ce_flags = htons(namelen);
|
||||||
fill_stat_cache_info(ce, &st);
|
fill_stat_cache_info(ce, &st);
|
||||||
|
@ -312,8 +311,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
|
||||||
|
|
||||||
len = strlen(path);
|
len = strlen(path);
|
||||||
size = cache_entry_size(len);
|
size = cache_entry_size(len);
|
||||||
ce = xmalloc(size);
|
ce = xcalloc(1, size);
|
||||||
memset(ce, 0, size);
|
|
||||||
|
|
||||||
memcpy(ce->sha1, sha1, 20);
|
memcpy(ce->sha1, sha1, 20);
|
||||||
memcpy(ce->name, path, len);
|
memcpy(ce->name, path, len);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* Copyright (C) Linus Torvalds, 2005
|
* Copyright (C) Linus Torvalds, 2005
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
static int missing_ok = 0;
|
static int missing_ok = 0;
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ static int write_tree(struct cache_entry **cachep, int maxentries, const char *b
|
||||||
nr++;
|
nr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_sha1_file(buffer, offset, "tree", returnsha1);
|
write_sha1_file(buffer, offset, tree_type, returnsha1);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue