diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-08-21 18:47:53 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-08-21 18:47:53 -0700 |
commit | f00ecbe42b82f3c8e6a170074f2299487026e400 (patch) | |
tree | fca98c6ac1d4cde3d5e60d296b2fcae8caf7fc6b /sha1_file.c | |
parent | 5e092b5bcea48c098af7000f888a2a0f16c9db77 (diff) | |
parent | 4e65b538acc97dd853e19a1692893f5fd47043e6 (diff) | |
download | git-f00ecbe42b82f3c8e6a170074f2299487026e400.tar.gz |
Merge branch 'cc/replace'
* cc/replace:
t6050: check pushing something based on a replaced commit
Documentation: add documentation for "git replace"
Add git-replace to .gitignore
builtin-replace: use "usage_msg_opt" to give better error messages
parse-options: add new function "usage_msg_opt"
builtin-replace: teach "git replace" to actually replace
Add new "git replace" command
environment: add global variable to disable replacement
mktag: call "check_sha1_signature" with the replacement sha1
replace_object: add a test case
object: call "check_sha1_signature" with the replacement sha1
sha1_file: add a "read_sha1_file_repl" function
replace_object: add mechanism to replace objects found in "refs/replace/"
refs: add a "for_each_replace_ref" function
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/sha1_file.c b/sha1_file.c index 1d996a1990..4ea0b18d0a 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2144,13 +2144,26 @@ static void *read_object(const unsigned char *sha1, enum object_type *type, return read_packed_sha1(sha1, type, size); } -void *read_sha1_file(const unsigned char *sha1, enum object_type *type, - unsigned long *size) +void *read_sha1_file_repl(const unsigned char *sha1, + enum object_type *type, + unsigned long *size, + const unsigned char **replacement) { - void *data = read_object(sha1, type, size); + const unsigned char *repl = lookup_replace_object(sha1); + void *data = read_object(repl, type, size); + + /* die if we replaced an object with one that does not exist */ + if (!data && repl != sha1) + die("replacement %s not found for %s", + sha1_to_hex(repl), sha1_to_hex(sha1)); + /* legacy behavior is to die on corrupted objects */ - if (!data && (has_loose_object(sha1) || has_packed_and_bad(sha1))) - die("object %s is corrupted", sha1_to_hex(sha1)); + if (!data && (has_loose_object(repl) || has_packed_and_bad(repl))) + die("object %s is corrupted", sha1_to_hex(repl)); + + if (replacement) + *replacement = repl; + return data; } |