From: Junio C Hamano Date: Tue, 28 Mar 2017 20:52:25 +0000 (-0700) Subject: Merge branch 'jk/pack-name-cleanups' into maint X-Git-Tag: v2.12.3~12 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ba5e05ffeff03c4835d0618ab34acb97ef753d0c?hp=-c Merge branch 'jk/pack-name-cleanups' into maint Code clean-up. * jk/pack-name-cleanups: index-pack: make pointer-alias fallbacks safer replace snprintf with odb_pack_name() odb_pack_keep(): stop generating keepfile name sha1_file.c: make pack-name helper globally accessible move odb_* declarations out of git-compat-util.h --- ba5e05ffeff03c4835d0618ab34acb97ef753d0c diff --combined cache.h index b3cf851b59,0c177b7acd..900796c155 --- a/cache.h +++ b/cache.h @@@ -1045,6 -1045,9 +1045,6 @@@ static inline int is_empty_tree_oid(con return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN); } - -int git_mkstemp(char *path, size_t n, const char *template); - /* set default permissions by passing mode arguments to open(2) */ int git_mkstemps_mode(char *pattern, int suffix_len, int mode); int git_mkstemp_mode(char *pattern, int mode); @@@ -1106,7 -1109,7 +1106,7 @@@ char *strbuf_realpath(struct strbuf *re int die_on_error); const char *real_path(const char *path); const char *real_path_if_valid(const char *path); -char *real_pathdup(const char *path); +char *real_pathdup(const char *path, int die_on_error); const char *absolute_path(const char *path); char *absolute_pathdup(const char *path); const char *remove_leading_path(const char *in, const char *prefix); @@@ -1316,37 -1319,7 +1316,37 @@@ extern char *oid_to_hex_r(char *out, co extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */ -extern int interpret_branch_name(const char *str, int len, struct strbuf *); +/* + * This reads short-hand syntax that not only evaluates to a commit + * object name, but also can act as if the end user spelled the name + * of the branch from the command line. + * + * - "@{-N}" finds the name of the Nth previous branch we were on, and + * places the name of the branch in the given buf and returns the + * number of characters parsed if successful. + * + * - "@{upstream}" finds the name of the other ref that + * is configured to merge with (missing defaults + * to the current branch), and places the name of the branch in the + * given buf and returns the number of characters parsed if + * successful. + * + * If the input is not of the accepted format, it returns a negative + * number to signal an error. + * + * If the input was ok but there are not N branch switches in the + * reflog, it returns 0. + * + * If "allowed" is non-zero, it is a treated as a bitfield of allowable + * expansions: local branches ("refs/heads/"), remote branches + * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is + * allowed, even ones to refs outside of those namespaces. + */ +#define INTERPRET_BRANCH_LOCAL (1<<0) +#define INTERPRET_BRANCH_REMOTE (1<<1) +#define INTERPRET_BRANCH_HEAD (1<<2) +extern int interpret_branch_name(const char *str, int len, struct strbuf *, + unsigned allowed); extern int get_oid_mb(const char *str, struct object_id *oid); extern int validate_headref(const char *ref); @@@ -1590,6 -1563,27 +1590,27 @@@ extern struct packed_git *find_sha1_pac extern void pack_report(void); + /* + * Create a temporary file rooted in the object database directory. + */ + extern int odb_mkstemp(char *template, size_t limit, const char *pattern); + + /* + * Generate the filename to be used for a pack file with checksum "sha1" and + * extension "ext". The result is written into the strbuf "buf", overwriting + * any existing contents. A pointer to buf->buf is returned as a convenience. + * + * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx" + */ + extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); + + /* + * Create a pack .keep file named "name" (which should generally be the output + * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on + * error. + */ + extern int odb_pack_keep(const char *name); + /* * mmap the index file for the specified packfile (if it is not * already mmapped). Return 0 on success. @@@ -1846,11 -1840,8 +1867,11 @@@ extern int git_config_include(const cha * * (i.e., what gets handed to a config_fn_t). The caller provides the section; * we return -1 if it does not match, 0 otherwise. The subsection and key - * out-parameters are filled by the function (and subsection is NULL if it is + * out-parameters are filled by the function (and *subsection is NULL if it is * missing). + * + * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if + * there is no subsection at all. */ extern int parse_config_key(const char *var, const char *section, diff --combined environment.c index 42dc3106d2,4cd20d7067..2fdba76222 --- a/environment.c +++ b/environment.c @@@ -259,7 -259,7 +259,7 @@@ void set_git_work_tree(const char *new_ return; } git_work_tree_initialized = 1; - work_tree = real_pathdup(new_work_tree); + work_tree = real_pathdup(new_work_tree, 1); } const char *get_git_work_tree(void) @@@ -296,18 -296,16 +296,16 @@@ int odb_mkstemp(char *template, size_t return xmkstemp_mode(template, mode); } - int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1) + int odb_pack_keep(const char *name) { int fd; - snprintf(name, namesz, "%s/pack/pack-%s.keep", - get_object_directory(), sha1_to_hex(sha1)); fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); if (0 <= fd) return fd; /* slow path */ - safe_create_leading_directories(name); + safe_create_leading_directories_const(name); return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } diff --combined git-compat-util.h index e626851fe9,412703b4ff..8a4a3f85e7 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -639,6 -639,11 +639,6 @@@ extern int gitsetenv(const char *, cons extern char *gitmkdtemp(char *); #endif -#ifdef NO_MKSTEMPS -#define mkstemps gitmkstemps -extern int gitmkstemps(char *, int); -#endif - #ifdef NO_UNSETENV #define unsetenv gitunsetenv extern void gitunsetenv(const char *); @@@ -798,8 -803,6 +798,6 @@@ extern FILE *xfopen(const char *path, c extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); extern int xmkstemp_mode(char *template, int mode); - extern int odb_mkstemp(char *template, size_t limit, const char *pattern); - extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1); extern char *xgetcwd(void); extern FILE *fopen_for_writing(const char *path); diff --combined sha1_file.c index 8ce80d4481,df98c7f0dc..d77b915db6 --- a/sha1_file.c +++ b/sha1_file.c @@@ -203,31 -203,26 +203,26 @@@ static const char *alt_sha1_path(struc return buf->buf; } - /* - * Return the name of the pack or index file with the specified sha1 - * in its filename. *base and *name are scratch space that must be - * provided by the caller. which should be "pack" or "idx". - */ - static char *sha1_get_pack_name(const unsigned char *sha1, - struct strbuf *buf, - const char *which) + char *odb_pack_name(struct strbuf *buf, + const unsigned char *sha1, + const char *ext) { strbuf_reset(buf); strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(), - sha1_to_hex(sha1), which); + sha1_to_hex(sha1), ext); return buf->buf; } char *sha1_pack_name(const unsigned char *sha1) { static struct strbuf buf = STRBUF_INIT; - return sha1_get_pack_name(sha1, &buf, "pack"); + return odb_pack_name(&buf, sha1, "pack"); } char *sha1_pack_index_name(const unsigned char *sha1) { static struct strbuf buf = STRBUF_INIT; - return sha1_get_pack_name(sha1, &buf, "idx"); + return odb_pack_name(&buf, sha1, "idx"); } struct alternate_object_database *alt_odb_list; @@@ -2532,7 -2527,6 +2527,7 @@@ void *unpack_entry(struct packed_git *p while (delta_stack_nr) { void *delta_data; void *base = data; + void *external_base = NULL; unsigned long delta_size, base_size = size; int i; @@@ -2559,7 -2553,6 +2554,7 @@@ p->pack_name); mark_bad_packed_object(p, base_sha1); base = read_object(base_sha1, &type, &base_size); + external_base = base; } } @@@ -2578,7 -2571,6 +2573,7 @@@ "at offset %"PRIuMAX" from %s", (uintmax_t)curpos, p->pack_name); data = NULL; + free(external_base); continue; } @@@ -2598,7 -2590,6 +2593,7 @@@ error("failed to apply delta"); free(delta_data); + free(external_base); } *final_type = type;