@matheusbsbs / matheus-bagliano / commits / b0fa7ab51b
Fork 0

git: add --no-replace-objects option to disable replacing

Commit dae556b (environment: add global variable to disable replacement) adds a variable to enable/disable replacement, and it is enabled by default for most commands. So there is no way to disable it for some commands, which is annoying when we want to get information about a commit that has been replaced. For example: $ git cat-file -p N would output information about the replacement commit if commit N is replaced. With the "--no-replace-objects" option that this patch adds it is possible to get information about the original commit using: $ git --no-replace-objects cat-file -p N While at it, let's add some documentation about this new option in the "git replace" man page too. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Oct 12, 2009 at 22:30 UTC b0fa7ab51b29d34579d8f6bb4443dfbcb8278c7a
4 files changed +36 -2
Documentation/git-replace.txt
+21
@@ -23,6 +23,26 @@ replacement object.
23 Unless `-f` is given, the replace reference must not yet exist in
24 `.git/refs/replace/` directory.
25
26 +Replace references will be used by default by all git commands except
27 +those doing reachability traversal (prune, pack transfer and fsck).
28 +
29 +It is possible to disable use of replacement refs for any command
30 +using the --no-replace-objects option just after "git".
31 +
32 +For example if commit "foo" has been replaced by commit "bar":
33 +
34 +------------------------------------------------
35 +$ git --no-replace-object cat-file commit foo
36 +------------------------------------------------
37 +
38 +show information about commit "foo", while:
39 +
40 +------------------------------------------------
41 +$ git cat-file commit foo
42 +------------------------------------------------
43 +
44 +show information about commit "bar".
45 +
46 OPTIONS
47 -------
48 -f::
@@ -54,6 +74,7 @@ SEE ALSO
74 --------
75 linkgit:git-tag[1]
76 linkgit:git-branch[1]
77 +linkgit:git[1]
78
79 Author
80 ------
Documentation/git.txt
+5 -1
@@ -10,7 +10,7 @@ SYNOPSIS
10 --------
11 [verse]
12 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
13 - [-p|--paginate|--no-pager]
13 + [-p|--paginate|--no-pager] [--no-replace-objects]
14 [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
15 [--help] COMMAND [ARGS]
16
@@ -237,6 +237,10 @@ help ...`.
237 environment is not set, it is set to the current working
238 directory.
239
240 +--no-replace-objects::
241 + Do not use replacement refs to replace git objects. See
242 + linkgit:git-replace[1] for more information.
243 +
244
245 FURTHER DOCUMENTATION
246 ---------------------
git.c
+3 -1
@@ -6,7 +6,7 @@
6
7 const char git_usage_string[] =
8 "git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
9 - " [-p|--paginate|--no-pager]\n"
9 + " [-p|--paginate|--no-pager] [--no-replace-objects]\n"
10 " [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n"
11 " [--help] COMMAND [ARGS]";
12
@@ -87,6 +87,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
87 use_pager = 0;
88 if (envchanged)
89 *envchanged = 1;
90 + } else if (!strcmp(cmd, "--no-replace-objects")) {
91 + read_replace_refs = 0;
92 } else if (!strcmp(cmd, "--git-dir")) {
93 if (*argc < 2) {
94 fprintf(stderr, "No directory given for --git-dir.\n" );
t/t6050-replace.sh
+7
@@ -70,6 +70,13 @@ test_expect_success 'replace the author' '
70 git show $HASH2 | grep "O Thor"
71 '
72
73 +test_expect_success 'test --no-replace-objects option' '
74 + git cat-file commit $HASH2 | grep "author O Thor" &&
75 + git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
76 + git show $HASH2 | grep "O Thor" &&
77 + git --no-replace-objects show $HASH2 | grep "A U Thor"
78 +'
79 +
80 cat >tag.sig <<EOF
81 object $HASH2
82 type commit