--- commit.c | 30 +++++++++++++----------------- local-fetch.c | 34 ++++++++++++++++------------------ 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/commit.c b/commit.c index bee066f..58f1718 100644 --- a/commit.c +++ b/commit.c @@ -6,6 +6,7 @@ #include "interpolate.h" #include "diff.h" #include "revision.h" +#include "str.h" int save_commit_buffer = 1; @@ -821,7 +822,7 @@ static long format_commit_message(const struct commit *commit, ILEFT_RIGHT, }; struct commit_list *p; - char parents[1024]; + stringbuf(parents, 1024); int i; enum { HEADER, SUBJECT, BODY } state; @@ -853,22 +854,17 @@ static long format_commit_message(const struct commit *commit, ? "<" : ">"); - parents[1] = 0; - for (i = 0, p = commit->parents; - p && i < sizeof(parents) - 1; - p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", - sha1_to_hex(p->item->object.sha1)); - interp_set_entry(table, IPARENTS, parents + 1); - - parents[1] = 0; - for (i = 0, p = commit->parents; - p && i < sizeof(parents) - 1; - p = p->next) - i += snprintf(parents + i, sizeof(parents) - i - 1, " %s", - find_unique_abbrev(p->item->object.sha1, - DEFAULT_ABBREV)); - interp_set_entry(table, IPARENTS_ABBREV, parents + 1); + str_c(parents)[1] = 0; + for (p = commit->parents; p; p = p->next) + str_printfa(parents, " %s", sha1_to_hex(p->item->object.sha1)); + interp_set_entry(table, IPARENTS, str_c(parents) + 1); + + str_c(parents)[1] = 0; + for (p = commit->parents; p; p = p->next) + str_printfa(parents, " %s", + find_unique_abbrev(p->item->object.sha1, + DEFAULT_ABBREV)); + interp_set_entry(table, IPARENTS_ABBREV, str_c(parents) + 1); for (i = 0, state = HEADER; msg[i] && state < BODY; i++) { int eol; diff --git a/local-fetch.c b/local-fetch.c index 4b650ef..6d0599f 100644 --- a/local-fetch.c +++ b/local-fetch.c @@ -4,6 +4,7 @@ #include "cache.h" #include "commit.h" #include "fetch.h" +#include "str.h" static int use_link; static int use_symlink; @@ -21,12 +22,11 @@ static struct packed_git *packs; static void setup_index(unsigned char *sha1) { struct packed_git *new_pack; - char filename[PATH_MAX]; - strcpy(filename, path); - strcat(filename, "/objects/pack/pack-"); - strcat(filename, sha1_to_hex(sha1)); - strcat(filename, ".idx"); - new_pack = parse_pack_index_file(sha1, filename); + stringbuf(filename, PATH_MAX); + + str_printfa(filename, "%s/objects/pack/pack-%s.idx", + path, sha1_to_hex(sha1)); + new_pack = parse_pack_index_file(sha1, str_c(filename)); new_pack->next = packs; packs = new_pack; } @@ -35,10 +35,11 @@ static int setup_indices(void) { DIR *dir; struct dirent *de; - char filename[PATH_MAX]; + stringbuf(filename, PATH_MAX); unsigned char sha1[20]; - sprintf(filename, "%s/objects/pack/", path); - dir = opendir(filename); + + str_printfa(filename, "%s/objects/pack/", path); + dir = opendir(str_c(filename)); if (!dir) return -1; while ((de = readdir(dir)) != NULL) { @@ -137,20 +138,17 @@ static int fetch_pack(const unsigned char *sha1) static int fetch_file(const unsigned char *sha1) { static int object_name_start = -1; - static char filename[PATH_MAX]; + static stringbuf(filename, PATH_MAX); char *hex = sha1_to_hex(sha1); char *dest_filename = sha1_file_name(sha1); if (object_name_start < 0) { - strcpy(filename, path); /* e.g. git.git */ - strcat(filename, "/objects/"); - object_name_start = strlen(filename); + str_printfa(filename, "%s/objects/", path); /* e.g. git.git */ + object_name_start = str_len(filename); } - filename[object_name_start+0] = hex[0]; - filename[object_name_start+1] = hex[1]; - filename[object_name_start+2] = '/'; - strcpy(filename + object_name_start + 3, hex + 2); - return copy_file(filename, dest_filename, hex, 0); + str_truncate(filename, object_name_start); + str_printfa(filename, "%c%c/%s", hex[0], hex[1], hex + 2); + return copy_file(str_c(filename), dest_filename, hex, 0); } int fetch(unsigned char *sha1) -- 1.5.1.4
Attachment:
signature.asc
Description: This is a digitally signed message part