{"thread":{"id":"21217","subject":"[PATCH] git: add --no-replace-objects option to disable replacing","startedAt":"2009-10-12T20:30:32Z","lastAt":"2009-10-12T23:42:19Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124746","messageId":"20091012203033.8939.43473.chriscool@tuxfamily.org","threadId":"21217","inReplyTo":null,"subject":"[PATCH] git: add --no-replace-objects option to disable replacing","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-10-12T20:30:32Z","receivedAt":"2009-10-12T20:30:32Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Commit dae556b (environment: add global variable to disable replacement)\nadds a variable to enable/disable replacement, and it is enabled by\ndefault for most commands.\n\nSo there is no way to disable it for some commands, which is annoying\nwhen we want to get information about a commit that has been replaced.\n\nFor example:\n\n$ git cat-file -p N\n\nwould output information about the replacement commit if commit N is\nreplaced.\n\nWith the \"--no-replace-objects\" option that this patch adds it is\npossible to get information about the original commit using:\n\n$ git --no-replace-objects cat-file -p N\n\nWhile at it, let's add some documentation about this new option in the\n\"git replace\" man page too.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt |   21 +++++++++++++++++++++\n Documentation/git.txt         |    6 +++++-\n git.c                         |    4 +++-\n t/t6050-replace.sh            |    7 +++++++\n 4 files changed, 36 insertions(+), 2 deletions(-)\n\n\tHere is a patch with some tests and documentation.\n\tThe new option is now called \"--no-replace-objects\" instead of\n\t\"--no-replace\".\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex 915cb77..8adc1ef 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -23,6 +23,26 @@ replacement object.\n Unless `-f` is given, the replace reference must not yet exist in\n `.git/refs/replace/` directory.\n \n+Replace references will be used by default by all git commands except\n+those doing reachability traversal (prune, pack transfer and fsck).\n+\n+It is possible to disable use of replacement refs for any command\n+using the --no-replace-objects option just after \"git\".\n+\n+For example if commit \"foo\" has been replaced by commit \"bar\":\n+\n+------------------------------------------------\n+$ git --no-replace-object cat-file commit foo\n+------------------------------------------------\n+\n+show information about commit \"foo\", while:\n+\n+------------------------------------------------\n+$ git cat-file commit foo\n+------------------------------------------------\n+\n+show information about commit \"bar\".\n+\n OPTIONS\n -------\n -f::\n@@ -54,6 +74,7 @@ SEE ALSO\n --------\n linkgit:git-tag[1]\n linkgit:git-branch[1]\n+linkgit:git[1]\n \n Author\n ------\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex d97aaf5..2f45417 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n-    [-p|--paginate|--no-pager]\n+    [-p|--paginate|--no-pager] [--no-replace-objects]\n     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n     [--help] COMMAND [ARGS]\n \n@@ -237,6 +237,10 @@ help ...`.\n \tenvironment is not set, it is set to the current working\n \tdirectory.\n \n+--no-replace-objects::\n+\tDo not use replacement refs to replace git objects. See\n+\tlinkgit:git-replace[1] for more information.\n+\n \n FURTHER DOCUMENTATION\n ---------------------\ndiff --git a/git.c b/git.c\nindex 9883009..80ebb04 100644\n--- a/git.c\n+++ b/git.c\n@@ -6,7 +6,7 @@\n \n const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\\n\"\n-\t\"           [-p|--paginate|--no-pager]\\n\"\n+\t\"           [-p|--paginate|--no-pager] [--no-replace_objects]\\n\"\n \t\"           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\\n\"\n \t\"           [--help] COMMAND [ARGS]\";\n \n@@ -87,6 +87,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\tuse_pager = 0;\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"--no-replace-objects\")) {\n+\t\t\tread_replace_refs = 0;\n \t\t} else if (!strcmp(cmd, \"--git-dir\")) {\n \t\t\tif (*argc < 2) {\n \t\t\t\tfprintf(stderr, \"No directory given for --git-dir.\\n\" );\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 8b8bd81..d4818b4 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -70,6 +70,13 @@ test_expect_success 'replace the author' '\n      git show $HASH2 | grep \"O Thor\"\n '\n \n+test_expect_success 'test --no-replace-objects option' '\n+     git cat-file commit $HASH2 | grep \"author O Thor\" &&\n+     git --no-replace-objects cat-file commit $HASH2 | grep \"author A U Thor\" &&\n+     git show $HASH2 | grep \"O Thor\" &&\n+     git --no-replace-objects show $HASH2 | grep \"A U Thor\"\n+'\n+\n cat >tag.sig <<EOF\n object $HASH2\n type commit\n-- \n1.6.5.1.gaf97d\n"},{"id":"124780","messageId":"7vmy3w5gdg.fsf@alter.siamese.dyndns.org","threadId":"21217","inReplyTo":"20091012203033.8939.43473.chriscool@tuxfamily.org","subject":"Re: [PATCH] git: add --no-replace-objects option to disable replacing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-12T23:42:19Z","receivedAt":"2009-10-12T23:42:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n\nI understand that the replace mechanism is lazily initialized so it would\nbe Ok to flip this variable as long as it is done before anybody makes the\nfirst call to read_sha1_file().  I am guessing the assignment the patch\nadds is early enough but I didn't audit the code.\n"}]}