Skip to content

Commit

Permalink
Merge branch 'jc/replacing'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed May 20, 2011
2 parents 2d22086 + 5bf29b9 commit 61d7503
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
4 changes: 2 additions & 2 deletions builtin/mktag.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
int ret = -1;
enum object_type type;
unsigned long size;
const unsigned char *repl;
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
void *buffer = read_sha1_file(sha1, &type, &size);
const unsigned char *repl = lookup_replace_object(sha1);

if (buffer) {
if (type == type_from_string(expected_type))
Expand Down
18 changes: 14 additions & 4 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,23 @@ char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path);
int offset_1st_component(const char *path);

/* 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 void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement);
/* object replacement */
#define READ_SHA1_FILE_REPLACE 1
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)
{
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 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 *);
Expand Down
2 changes: 0 additions & 2 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ struct commit_graft *read_graft_line(char *buf, int len);
int register_commit_graft(struct commit_graft *, int);
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_many(struct commit *one, int n, struct commit **twos, int cleanup);
extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
Expand Down
2 changes: 1 addition & 1 deletion environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const char *editor_program;
const char *askpass_program;
const char *excludes_file;
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 safe_crlf safe_crlf = SAFE_CRLF_WARN;
unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
Expand Down
4 changes: 2 additions & 2 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ struct object *parse_object(const unsigned char *sha1)
unsigned long size;
enum object_type type;
int eaten;
const unsigned char *repl;
void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
const unsigned char *repl = lookup_replace_object(sha1);
void *buffer = read_sha1_file(sha1, &type, &size);

if (buffer) {
struct object *obj;
Expand Down
4 changes: 3 additions & 1 deletion replace_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ static void prepare_replace_object(void)

for_each_replace_ref(register_replace_ref, NULL);
replace_object_prepared = 1;
if (!replace_object_nr)
read_replace_refs = 0;
}

/* We allow "recursive" replacement. Only within reason, though */
#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;
const unsigned char *cur = sha1;
Expand Down
16 changes: 7 additions & 9 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
* messages themselves.
*/
void *read_sha1_file_repl(const unsigned char *sha1,
enum object_type *type,
unsigned long *size,
const unsigned char **replacement)
void *read_sha1_file_extended(const unsigned char *sha1,
enum object_type *type,
unsigned long *size,
unsigned flag)
{
const unsigned char *repl = lookup_replace_object(sha1);
void *data;
char *path;
const struct packed_git *p;
const unsigned char *repl = (flag & READ_SHA1_FILE_REPLACE)
? lookup_replace_object(sha1) : sha1;

errno = 0;
data = read_object(repl, type, size);
if (data) {
if (replacement)
*replacement = repl;
if (data)
return data;
}

if (errno && errno != ENOENT)
die_errno("failed to read object %s", sha1_to_hex(sha1));
Expand Down
18 changes: 16 additions & 2 deletions t/t6050-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ test_expect_success 'index-pack and replacements' '
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

0 comments on commit 61d7503

Please sign in to comment.