Merge branch 'mh/replace-refs-variable-rename'
* mh/replace-refs-variable-rename: Document some functions defined in object.c Add docstrings for lookup_replace_object() and do_lookup_replace_object() rename read_replace_refs to check_replace_refs
This commit is contained in:
@ -630,7 +630,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
|||||||
struct alternate_object_database *alt;
|
struct alternate_object_database *alt;
|
||||||
|
|
||||||
errors_found = 0;
|
errors_found = 0;
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
||||||
|
|
||||||
|
@ -1502,7 +1502,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
|
|||||||
if (argc == 2 && !strcmp(argv[1], "-h"))
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
||||||
usage(index_pack_usage);
|
usage(index_pack_usage);
|
||||||
|
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
reset_pack_idx_option(&opts);
|
reset_pack_idx_option(&opts);
|
||||||
git_config(git_index_pack_config, &opts);
|
git_config(git_index_pack_config, &opts);
|
||||||
|
@ -2612,7 +2612,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_END(),
|
OPT_END(),
|
||||||
};
|
};
|
||||||
|
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
reset_pack_idx_option(&pack_idx_opts);
|
reset_pack_idx_option(&pack_idx_opts);
|
||||||
git_config(git_pack_config, NULL);
|
git_config(git_pack_config, NULL);
|
||||||
|
@ -150,7 +150,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
expire = ULONG_MAX;
|
expire = ULONG_MAX;
|
||||||
save_commit_buffer = 0;
|
save_commit_buffer = 0;
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
init_revisions(&revs, prefix);
|
init_revisions(&revs, prefix);
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
|
||||||
|
@ -178,7 +178,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
int i;
|
int i;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
|
||||||
|
27
cache.h
27
cache.h
@ -581,7 +581,17 @@ extern size_t packed_git_limit;
|
|||||||
extern size_t delta_base_cache_limit;
|
extern size_t delta_base_cache_limit;
|
||||||
extern unsigned long big_file_threshold;
|
extern unsigned long big_file_threshold;
|
||||||
extern unsigned long pack_size_limit_cfg;
|
extern unsigned long pack_size_limit_cfg;
|
||||||
extern int read_replace_refs;
|
|
||||||
|
/*
|
||||||
|
* Do replace refs need to be checked this run? This variable is
|
||||||
|
* initialized to true unless --no-replace-object is used or
|
||||||
|
* $GIT_NO_REPLACE_OBJECTS is set, but is set to false by some
|
||||||
|
* commands that do not want replace references to be active. As an
|
||||||
|
* optimization it is also set to false if replace references have
|
||||||
|
* been sought but there were none.
|
||||||
|
*/
|
||||||
|
extern int check_replace_refs;
|
||||||
|
|
||||||
extern int fsync_object_files;
|
extern int fsync_object_files;
|
||||||
extern int core_preload_index;
|
extern int core_preload_index;
|
||||||
extern int core_apply_sparse_checkout;
|
extern int core_apply_sparse_checkout;
|
||||||
@ -808,13 +818,26 @@ static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *
|
|||||||
{
|
{
|
||||||
return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
|
return read_sha1_file_extended(sha1, type, size, LOOKUP_REPLACE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This internal function is only declared here for the benefit of
|
||||||
|
* lookup_replace_object(). Please do not call it directly.
|
||||||
|
*/
|
||||||
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
|
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If object sha1 should be replaced, return the replacement object's
|
||||||
|
* name (replaced recursively, if necessary). The return value is
|
||||||
|
* either sha1 or a pointer to a permanently-allocated value. When
|
||||||
|
* object replacement is suppressed, always return sha1.
|
||||||
|
*/
|
||||||
static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
|
static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
if (!read_replace_refs)
|
if (!check_replace_refs)
|
||||||
return sha1;
|
return sha1;
|
||||||
return do_lookup_replace_object(sha1);
|
return do_lookup_replace_object(sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag)
|
static inline const unsigned char *lookup_replace_object_extended(const unsigned char *sha1, unsigned flag)
|
||||||
{
|
{
|
||||||
if (!(flag & LOOKUP_REPLACE_OBJECT))
|
if (!(flag & LOOKUP_REPLACE_OBJECT))
|
||||||
|
@ -45,7 +45,7 @@ const char *editor_program;
|
|||||||
const char *askpass_program;
|
const char *askpass_program;
|
||||||
const char *excludes_file;
|
const char *excludes_file;
|
||||||
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
|
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
|
||||||
int read_replace_refs = 1; /* NEEDSWORK: rename to use_replace_refs */
|
int check_replace_refs = 1;
|
||||||
enum eol core_eol = EOL_UNSET;
|
enum eol core_eol = EOL_UNSET;
|
||||||
enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
|
enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
|
||||||
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
|
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
|
||||||
@ -147,7 +147,7 @@ static void setup_git_env(void)
|
|||||||
if (!git_graft_file)
|
if (!git_graft_file)
|
||||||
git_graft_file = git_pathdup("info/grafts");
|
git_graft_file = git_pathdup("info/grafts");
|
||||||
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
|
if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
|
namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
|
||||||
namespace_len = strlen(namespace);
|
namespace_len = strlen(namespace);
|
||||||
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
|
shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
|
||||||
|
2
git.c
2
git.c
@ -78,7 +78,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
|
|||||||
if (envchanged)
|
if (envchanged)
|
||||||
*envchanged = 1;
|
*envchanged = 1;
|
||||||
} else if (!strcmp(cmd, "--no-replace-objects")) {
|
} else if (!strcmp(cmd, "--no-replace-objects")) {
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
|
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
|
||||||
if (envchanged)
|
if (envchanged)
|
||||||
*envchanged = 1;
|
*envchanged = 1;
|
||||||
|
@ -100,7 +100,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
|
|||||||
|
|
||||||
if (starts_with(refname, "refs/replace/")) {
|
if (starts_with(refname, "refs/replace/")) {
|
||||||
unsigned char original_sha1[20];
|
unsigned char original_sha1[20];
|
||||||
if (!read_replace_refs)
|
if (!check_replace_refs)
|
||||||
return 0;
|
return 0;
|
||||||
if (get_sha1_hex(refname + 13, original_sha1)) {
|
if (get_sha1_hex(refname + 13, original_sha1)) {
|
||||||
warning("invalid replace ref %s", refname);
|
warning("invalid replace ref %s", refname);
|
||||||
|
29
object.c
29
object.c
@ -43,14 +43,32 @@ int type_from_string(const char *str)
|
|||||||
die("invalid object type \"%s\"", str);
|
die("invalid object type \"%s\"", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a numerical hash value between 0 and n-1 for the object with
|
||||||
|
* the specified sha1. n must be a power of 2. Please note that the
|
||||||
|
* return value is *not* consistent across computer architectures.
|
||||||
|
*/
|
||||||
static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
|
static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
|
||||||
{
|
{
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since the sha1 is essentially random, we just take the
|
||||||
|
* required number of bits directly from the first
|
||||||
|
* sizeof(unsigned int) bytes of sha1. First we have to copy
|
||||||
|
* the bytes into a properly aligned integer. If we cared
|
||||||
|
* about getting consistent results across architectures, we
|
||||||
|
* would have to call ntohl() here, too.
|
||||||
|
*/
|
||||||
memcpy(&hash, sha1, sizeof(unsigned int));
|
memcpy(&hash, sha1, sizeof(unsigned int));
|
||||||
/* Assumes power-of-2 hash sizes in grow_object_hash */
|
|
||||||
return hash & (n - 1);
|
return hash & (n - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Insert obj into the hash table hash, which has length size (which
|
||||||
|
* must be a power of 2). On collisions, simply overflow to the next
|
||||||
|
* empty bucket.
|
||||||
|
*/
|
||||||
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
|
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
|
||||||
{
|
{
|
||||||
unsigned int j = hash_obj(obj->sha1, size);
|
unsigned int j = hash_obj(obj->sha1, size);
|
||||||
@ -63,6 +81,10 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
|
|||||||
hash[j] = obj;
|
hash[j] = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look up the record for the given sha1 in the hash map stored in
|
||||||
|
* obj_hash. Return NULL if it was not found.
|
||||||
|
*/
|
||||||
struct object *lookup_object(const unsigned char *sha1)
|
struct object *lookup_object(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
unsigned int i, first;
|
unsigned int i, first;
|
||||||
@ -92,6 +114,11 @@ struct object *lookup_object(const unsigned char *sha1)
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Increase the size of the hash map stored in obj_hash to the next
|
||||||
|
* power of 2 (but at least 32). Copy the existing values to the new
|
||||||
|
* hash map.
|
||||||
|
*/
|
||||||
static void grow_object_hash(void)
|
static void grow_object_hash(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
7
object.h
7
object.h
@ -42,7 +42,14 @@ struct object {
|
|||||||
extern const char *typename(unsigned int type);
|
extern const char *typename(unsigned int type);
|
||||||
extern int type_from_string(const char *str);
|
extern int type_from_string(const char *str);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the current number of buckets in the object hashmap.
|
||||||
|
*/
|
||||||
extern unsigned int get_max_object_index(void);
|
extern unsigned int get_max_object_index(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the object from the specified bucket in the object hashmap.
|
||||||
|
*/
|
||||||
extern struct object *get_indexed_object(unsigned int);
|
extern struct object *get_indexed_object(unsigned int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -91,12 +91,19 @@ static void prepare_replace_object(void)
|
|||||||
for_each_replace_ref(register_replace_ref, NULL);
|
for_each_replace_ref(register_replace_ref, NULL);
|
||||||
replace_object_prepared = 1;
|
replace_object_prepared = 1;
|
||||||
if (!replace_object_nr)
|
if (!replace_object_nr)
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We allow "recursive" replacement. Only within reason, though */
|
/* We allow "recursive" replacement. Only within reason, though */
|
||||||
#define MAXREPLACEDEPTH 5
|
#define MAXREPLACEDEPTH 5
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a replacement for object sha1 has been set up, return the
|
||||||
|
* replacement object's name (replaced recursively, if necessary).
|
||||||
|
* The return value is either sha1 or a pointer to a
|
||||||
|
* permanently-allocated value. This function always respects replace
|
||||||
|
* references, regardless of the value of check_replace_refs.
|
||||||
|
*/
|
||||||
const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
|
const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
int pos, depth = MAXREPLACEDEPTH;
|
int pos, depth = MAXREPLACEDEPTH;
|
||||||
|
@ -796,7 +796,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
packet_trace_identity("upload-pack");
|
packet_trace_identity("upload-pack");
|
||||||
git_extract_argv0_path(argv[0]);
|
git_extract_argv0_path(argv[0]);
|
||||||
read_replace_refs = 0;
|
check_replace_refs = 0;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
char *arg = argv[i];
|
char *arg = argv[i];
|
||||||
|
Reference in New Issue
Block a user