Trying to determine how quickly a user would be warned of corruption in the object database with git-1.7.4.1, I pulled a one-bit switcheroo:
$ git init repo Initialized empty Git repository in /tmp/repo/.git/ $ cd repo $ echo 'very important info' >critical $ git add critical $ git commit -m critical [master (root-commit) c4d6d90] critical 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 critical $ git ls-tree HEAD 100644 blob 82d423c32c4bb2c52938088e0234db041bf4eaaf critical $ git show 82d423c32c4bb2c52938088e0234db041bf4eaaf very important info $ echo 'Very important info' | git hash-object --stdin -w 81a3797afe76d339db25c0f9c705a6caa47279c2 $ mv .git/objects/81/a3797afe76d339db25c0f9c705a6caa47279c2 \ .git/objects/82/d423c32c4bb2c52938088e0234db041bf4eaaf
Of course, git-fsck
notices
$ git fsck error: sha1 mismatch 82d423c32c4bb2c52938088e0234db041bf4eaaf error: 82d423c32c4bb2c52938088e0234db041bf4eaaf: object corrupt or missing missing blob 82d423c32c4bb2c52938088e0234db041bf4eaaf
but git-log
is happy with the change
$ git log -p commit c4d6d90467af9ffa94772795d5c5d191228933c1 Author: Greg Bacon <gbacon@dbresearch.net> Date: Thu Apr 7 12:20:53 2011 -0500 critical diff --git a/critical b/critical new file mode 100644 index 0000000..82d423c --- /dev/null +++ b/critical @@ -0,0 +1 @@ +Very important info
as is git-checkout
.
$ rm critical $ git checkout . $ cat critical Very important info
A specific invocation of git-show
reveals the corruption
$ git show 82d423c32c4bb2c52938088e0234db041bf4eaaf error: sha1 mismatch 82d423c32c4bb2c52938088e0234db041bf4eaaf fatal: bad object 82d423c32c4bb2c52938088e0234db041bf4eaaf
but not a broader one.
$ git show commit c4d6d90467af9ffa94772795d5c5d191228933c1 Author: Greg Bacon <gbacon@dbresearch.net> Date: Thu Apr 7 12:20:53 2011 -0500 critical diff --git a/critical b/critical new file mode 100644 index 0000000..82d423c --- /dev/null +++ b/critical @@ -0,0 +1 @@ +Very important info
Even git-clone
doesn't notice!
$ cd .. $ git clone repo clone Cloning into clone... done. $ cat clone/critical Very important info
What is the full list of specific git command modes (e.g., git show $sha1
should be present but not git show
or git show HEAD
) that perform integrity checks?
Here's how I would go about finding this out, although I'm not going to go through each source file to work out the conditions under which the check is performed. :)
Clone git's source code:
git clone git://git.kernel.org/pub/scm/git/git.git
Check out the version you care about:
cd git
git checkout v1.7.1
Look for that error message:
git grep 'sha1 mismatch'
That leads you to object.c
and the parse_object
function. Now look for that function:
git grep parse_object
... and go through the 38 files checking the conditions under which that function will be called.
In response to Mark Longair's answer, I fired up cscope and found:
(note how cscope has a curses interface and integrates nicely into Vim in case your interest was piqued)
Functions calling this function: parse_object
File Function Line
0 bundle.c verify_bundle 110 struct object *o = parse_object(e->sha1);
1 bundle.c create_bundle 242 struct object *object = parse_object(sha1);
2 bundle.c create_bundle 247 struct object *object = parse_object(sha1);
3 bundle.c create_bundle 323 obj = parse_object(sha1);
4 commit.c lookup_commit_reference_gently 30 struct object *obj = deref_tag(parse_object(sha1), NULL, 0);
5 http-backend.c show_text_ref 372 struct object *o = parse_object(sha1);
6 http-push.c one_remote_object 742 obj = parse_object(sha1);
7 http-push.c add_remote_info_ref 1530 o = parse_object(ref->old_sha1);
8 log-tree.c add_ref_decoration 93 struct object *obj = parse_object(sha1);
9 merge-recursive.c get_ref 1664 object = deref_tag(parse_object(sha1), name, strlen(name));
a pack-refs.c handle_one_ref 43 struct object *o = parse_object(sha1);
b pretty.c format_commit_one 835 parse_object(commit->object.sha1);
c reachable.c add_one_reflog_ent 122 object = parse_object(osha1);
d reachable.c add_one_reflog_ent 125 object = parse_object(nsha1);
e reachable.c add_one_ref 133 struct object *object = parse_object(sha1);
f reflog-walk.c fake_reflog_parent 234 commit_info->commit = (struct commit *)parse_object(reflog->osha1);
g refs.c peel_ref 647 o = parse_object(base);
h refs.c write_ref_sha1 1452 o = parse_object(sha1);
i remote.c ref_newer 1482 o = deref_tag(parse_object(old_sha1), NULL, 0);
j remote.c ref_newer 1487 o = deref_tag(parse_object(new_sha1), NULL, 0);
k revision.c add_head_to_pending 166 obj = parse_object(sha1);
l revision.c get_reference 176 object = parse_object(sha1);
m revision.c handle_commit 196 object = parse_object(tag->tagged->sha1);
n revision.c handle_one_reflog_commit 855 struct object *o = parse_object(sha1);
o server-info.c add_info_ref 12 struct object *o = parse_object(sha1);
p sha1_name.c peel_to_type 508 o = parse_object(sha1);
q sha1_name.c peel_to_type 511 if (!o || (!o->parsed && !parse_object(o->sha1)))
r sha1_name.c peel_onion 573 o = parse_object(outer);
s sha1_name.c peel_onion 578 if (!o || (!o->parsed && !parse_object(o->sha1)))
t sha1_name.c handle_one_ref 698 struct object *object = parse_object(sha1);
u sha1_name.c get_sha1_oneline 740 if (!parse_object(commit->object.sha1))
v tag.c deref_tag 16 o = parse_object(((struct tag *)o)->tagged->sha1);
w tree.c parse_tree_indirect 271 struct object *obj = parse_object(sha1);
x tree.c parse_tree_indirect 284 parse_object(obj->sha1);
y upload-pack.c got_sha1 342 o = parse_object(sha1);
z upload-pack.c reachable 382 parse_object(commit->object.sha1);
A upload-pack.c receive_needs 526 object = parse_object(sha1);
B upload-pack.c send_ref 644 struct object *o = parse_object(sha1);
C upload-pack.c mark_our_ref 670 struct object *o = parse_object(sha1);
D walker.c loop 182 parse_object(obj->sha1);
来源:https://stackoverflow.com/questions/5585388/which-git-commands-perform-integrity-checks