提交 61d7503d 编写于 作者: J Junio C Hamano

Merge branch 'jc/replacing'

* jc/replacing:
  read_sha1_file(): allow selective bypassing of replacement mechanism
  inline lookup_replace_object() calls
  read_sha1_file(): get rid of read_sha1_file_repl() madness
  t6050: make sure we test not just commit replacement
  Declare lookup_replace_object() in cache.h, not in commit.h

Conflicts:
	environment.c
...@@ -23,8 +23,8 @@ static int verify_object(const unsigned char *sha1, const char *expected_type) ...@@ -23,8 +23,8 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
int ret = -1; int ret = -1;
enum object_type type; enum object_type type;
unsigned long size; unsigned long size;
const unsigned char *repl; void *buffer = read_sha1_file(sha1, &type, &size);
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl); const unsigned char *repl = lookup_replace_object(sha1);
if (buffer) { if (buffer) {
if (type == type_from_string(expected_type)) if (type == type_from_string(expected_type))
......
...@@ -756,13 +756,23 @@ char *strip_path_suffix(const char *path, const char *suffix); ...@@ -756,13 +756,23 @@ char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path); int daemon_avoid_alias(const char *path);
int offset_1st_component(const char *path); int offset_1st_component(const char *path);
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */ /* object replacement */
extern int sha1_object_info(const unsigned char *, unsigned long *); #define READ_SHA1_FILE_REPLACE 1
extern void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement); extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size) static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
{ {
return read_sha1_file_repl(sha1, type, size, NULL); return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE);
}
extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
{
if (!read_replace_refs)
return sha1;
return do_lookup_replace_object(sha1);
} }
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern int sha1_object_info(const unsigned char *, unsigned long *);
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1); extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1); extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
......
...@@ -145,8 +145,6 @@ struct commit_graft *read_graft_line(char *buf, int len); ...@@ -145,8 +145,6 @@ struct commit_graft *read_graft_line(char *buf, int len);
int register_commit_graft(struct commit_graft *, int); int register_commit_graft(struct commit_graft *, int);
struct commit_graft *lookup_commit_graft(const unsigned char *sha1); struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
const unsigned char *lookup_replace_object(const unsigned char *sha1);
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup); extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
extern struct commit_list *get_octopus_merge_bases(struct commit_list *in); extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
......
...@@ -42,7 +42,7 @@ const char *editor_program; ...@@ -42,7 +42,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; int read_replace_refs = 1; /* NEEDSWORK: rename to use_replace_refs */
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;
......
...@@ -188,8 +188,8 @@ struct object *parse_object(const unsigned char *sha1) ...@@ -188,8 +188,8 @@ struct object *parse_object(const unsigned char *sha1)
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
int eaten; int eaten;
const unsigned char *repl; const unsigned char *repl = lookup_replace_object(sha1);
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl); void *buffer = read_sha1_file(sha1, &type, &size);
if (buffer) { if (buffer) {
struct object *obj; struct object *obj;
......
...@@ -85,12 +85,14 @@ static void prepare_replace_object(void) ...@@ -85,12 +85,14 @@ 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)
read_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
const unsigned char *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;
const unsigned char *cur = sha1; const unsigned char *cur = sha1;
......
...@@ -2205,23 +2205,21 @@ static void *read_object(const unsigned char *sha1, enum object_type *type, ...@@ -2205,23 +2205,21 @@ static void *read_object(const unsigned char *sha1, enum object_type *type,
* deal with them should arrange to call read_object() and give error * deal with them should arrange to call read_object() and give error
* messages themselves. * messages themselves.
*/ */
void *read_sha1_file_repl(const unsigned char *sha1, void *read_sha1_file_extended(const unsigned char *sha1,
enum object_type *type, enum object_type *type,
unsigned long *size, unsigned long *size,
const unsigned char **replacement) unsigned flag)
{ {
const unsigned char *repl = lookup_replace_object(sha1);
void *data; void *data;
char *path; char *path;
const struct packed_git *p; const struct packed_git *p;
const unsigned char *repl = (flag & READ_SHA1_FILE_REPLACE)
? lookup_replace_object(sha1) : sha1;
errno = 0; errno = 0;
data = read_object(repl, type, size); data = read_object(repl, type, size);
if (data) { if (data)
if (replacement)
*replacement = repl;
return data; return data;
}
if (errno && errno != ENOENT) if (errno && errno != ENOENT)
die_errno("failed to read object %s", sha1_to_hex(sha1)); die_errno("failed to read object %s", sha1_to_hex(sha1));
......
...@@ -236,6 +236,20 @@ test_expect_success 'index-pack and replacements' ' ...@@ -236,6 +236,20 @@ test_expect_success 'index-pack and replacements' '
git index-pack test-*.pack git index-pack test-*.pack
' '
# test_expect_success 'not just commits' '
# echo replaced >file &&
git add file &&
REPLACED=$(git rev-parse :file) &&
mv file file.replaced &&
echo original >file &&
git add file &&
ORIGINAL=$(git rev-parse :file) &&
git update-ref refs/replace/$ORIGINAL $REPLACED &&
mv file file.original &&
git checkout file &&
test_cmp file.replaced file
'
test_done test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册