{"thread":{"id":"34862","subject":"[PATCH v5 0/7] Check replacement object type and minor updates","startedAt":"2013-09-06T05:10:52Z","lastAt":"2013-09-06T21:34:18Z","messageCount":10,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":5,"patchTotal":7},"messages":[{"id":"226909","messageId":"20130906050702.6657.25651.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":null,"subject":"[PATCH v5 0/7] Check replacement object type and minor updates","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:52Z","receivedAt":"2013-09-06T05:10:52Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Many patchs have been squashed together as Junio suggested.\nAnd in patch 3/7 now no grep is done on the error message.\n\nChristian Couder (7):\n  replace: forbid replacing an object with one of a different type\n  Documentation/replace: state that objects must be of the same type\n  t6050-replace: test that objects are of the same type\n  t6050-replace: add test to clean up all the replace refs\n  Documentation/replace: add Creating Replacement Objects section\n  replace: allow long option names\n  t6050-replace: use some long option names\n\n Documentation/git-replace.txt | 28 +++++++++++++++++++++++++---\n builtin/replace.c             | 16 +++++++++++++---\n t/t6050-replace.sh            | 25 ++++++++++++++++++++++---\n 3 files changed, 60 insertions(+), 9 deletions(-)\n\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226913","messageId":"20130906051100.6657.41248.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 1/7] replace: forbid replacing an object with one of a different type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:53Z","receivedAt":"2013-09-06T05:10:53Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Users replacing an object with one of a different type were not\nprevented to do so, even if it was obvious, and stated in the doc,\nthat bad things would result from doing that.\n\nTo avoid mistakes, it is better to just forbid that though.\n\nIf -f option, which means '--force', is used, we can allow an object\nto be replaced with one of a different type, as the user should know\nwhat (s)he is doing.\n\nIf one object is replaced with one of a different type, the only way\nto keep the history valid is to also replace all the other objects\nthat point to the replaced object. That's because:\n\n* Annotated tags contain the type of the tagged object.\n\n* The tree/parent lines in commits must be a tree and commits, resp.\n\n* The object types referred to by trees are specified in the 'mode'\n  field:\n    100644 and 100755    blob\n    160000               commit\n    040000               tree\n  (these are the only valid modes)\n\n* Blobs don't point at anything.\n\nThe doc will be updated in a later patch.\n\nAcked-by: Philip Oakley <philipoakley@iee.org>\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/replace.c | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 59d3115..95736d9 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -85,6 +85,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n \t\t\t  int force)\n {\n \tunsigned char object[20], prev[20], repl[20];\n+\tenum object_type obj_type, repl_type;\n \tchar ref[PATH_MAX];\n \tstruct ref_lock *lock;\n \n@@ -100,6 +101,15 @@ static int replace_object(const char *object_ref, const char *replace_ref,\n \tif (check_refname_format(ref, 0))\n \t\tdie(\"'%s' is not a valid ref name.\", ref);\n \n+\tobj_type = sha1_object_info(object, NULL);\n+\trepl_type = sha1_object_info(repl, NULL);\n+\tif (!force && obj_type != repl_type)\n+\t\tdie(\"Objects must be of the same type.\\n\"\n+\t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n+\t\t    \"while '%s' points to a replacement object of type '%s'.\",\n+\t\t    object_ref, typename(obj_type),\n+\t\t    replace_ref, typename(repl_type));\n+\n \tif (read_ref(ref, prev))\n \t\thashclr(prev);\n \telse if (!force)\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226912","messageId":"20130906051100.6657.88471.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 2/7] Documentation/replace: state that objects must be of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:54Z","receivedAt":"2013-09-06T05:10:54Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"A previous patch ensures that both the replaced and the replacement\nobjects passed to git replace must be of the same type, except if\n-f option is used.\n\nWhile at it state that there is no other restriction on both objects.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 9 ++++++---\n 1 file changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex e0b4057..d198006 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -20,8 +20,13 @@ The name of the 'replace' reference is the SHA-1 of the object that is\n replaced. The content of the 'replace' reference is the SHA-1 of the\n replacement object.\n \n+The replaced object and the replacement object must be of the same type.\n+This restriction can be bypassed using `-f`.\n+\n Unless `-f` is given, the 'replace' reference must not yet exist.\n \n+There is no other restriction on the replaced and replacement objects.\n+\n Replacement references will be used by default by all Git commands\n except those doing reachability traversal (prune, pack transfer and\n fsck).\n@@ -69,9 +74,7 @@ go back to a replaced commit will move the branch to the replacement\n commit instead of the replaced commit.\n \n There may be other problems when using 'git rev-list' related to\n-pending objects. And of course things may break if an object of one\n-type is replaced by an object of another type (for example a blob\n-replaced by a commit).\n+pending objects.\n \n SEE ALSO\n --------\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226914","messageId":"20130906051100.6657.75496.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 3/7] t6050-replace: test that objects are of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:55Z","receivedAt":"2013-09-06T05:10:55Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"and that the -f option bypasses the type check\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex decdc33..09bad98 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -263,4 +263,17 @@ test_expect_success 'not just commits' '\n \ttest_cmp file.replaced file\n '\n \n+test_expect_success 'replaced and replacement objects must be of the same type' '\n+\ttest_must_fail git replace mytag $HASH1 &&\n+\ttest_must_fail git replace HEAD^{tree} HEAD~1 &&\n+\tBLOB=$(git rev-parse :file) &&\n+\ttest_must_fail git replace HEAD^ $BLOB\n+'\n+\n+test_expect_success '-f option bypasses the type check' '\n+\tgit replace -f mytag $HASH1 &&\n+\tgit replace -f HEAD^{tree} HEAD~1 &&\n+\tgit replace -f HEAD^ $BLOB\n+'\n+\n test_done\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226910","messageId":"20130906051100.6657.48216.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 4/7] t6050-replace: add test to clean up all the replace refs","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:56Z","receivedAt":"2013-09-06T05:10:56Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 09bad98..09a2b49 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -276,4 +276,10 @@ test_expect_success '-f option bypasses the type check' '\n \tgit replace -f HEAD^ $BLOB\n '\n \n+test_expect_success 'replace ref cleanup' '\n+\ttest -n \"$(git replace)\" &&\n+\tgit replace -d $(git replace) &&\n+\ttest -z \"$(git replace)\"\n+'\n+\n test_done\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226916","messageId":"20130906051100.6657.16629.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 5/7] Documentation/replace: add Creating Replacement Objects section","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:57Z","receivedAt":"2013-09-06T05:10:57Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"There were no hints in the documentation about how to create\nreplacement objects.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex d198006..a2bd2ee 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -66,6 +66,19 @@ OPTIONS\n \tTyping \"git replace\" without arguments, also lists all replace\n \trefs.\n \n+CREATING REPLACEMENT OBJECTS\n+----------------------------\n+\n+linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and\n+linkgit:git-rebase[1], among other git commands, can be used to create\n+replacement objects from existing objects.\n+\n+If you want to replace many blobs, trees or commits that are part of a\n+string of commits, you may just want to create a replacement string of\n+commits and then only replace the commit at the tip of the target\n+string of commits with the commit at the tip of the replacement string\n+of commits.\n+\n BUGS\n ----\n Comparing blobs or trees that have been replaced with those that\n@@ -78,6 +91,9 @@ pending objects.\n \n SEE ALSO\n --------\n+linkgit:git-hash-object[1]\n+linkgit:git-filter-branch[1]\n+linkgit:git-rebase[1]\n linkgit:git-tag[1]\n linkgit:git-branch[1]\n linkgit:git[1]\n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226915","messageId":"20130906051100.6657.18553.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 6/7] replace: allow long option names","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:58Z","receivedAt":"2013-09-06T05:10:58Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"It is now standard practice in Git to have both short and long option\nnames. So let's give a long option name to the git replace options too.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-replace.txt | 3 +++\n builtin/replace.c             | 6 +++---\n 2 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex a2bd2ee..414000e 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -54,13 +54,16 @@ achieve the same effect as the `--no-replace-objects` option.\n OPTIONS\n -------\n -f::\n+--force::\n \tIf an existing replace ref for the same object exists, it will\n \tbe overwritten (instead of failing).\n \n -d::\n+--delete::\n \tDelete existing replace refs for the given objects.\n \n -l <pattern>::\n+--list <pattern>::\n \tList replace refs for objects that match the given pattern (or\n \tall if no pattern is given).\n \tTyping \"git replace\" without arguments, also lists all replace\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 95736d9..d4d1b75 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -128,9 +128,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix)\n {\n \tint list = 0, delete = 0, force = 0;\n \tstruct option options[] = {\n-\t\tOPT_BOOLEAN('l', NULL, &list, N_(\"list replace refs\")),\n-\t\tOPT_BOOLEAN('d', NULL, &delete, N_(\"delete replace refs\")),\n-\t\tOPT_BOOLEAN('f', NULL, &force, N_(\"replace the ref if it exists\")),\n+\t\tOPT_BOOLEAN('l', \"list\", &list, N_(\"list replace refs\")),\n+\t\tOPT_BOOLEAN('d', \"delete\", &delete, N_(\"delete replace refs\")),\n+\t\tOPT_BOOLEAN('f', \"force\", &force, N_(\"replace the ref if it exists\")),\n \t\tOPT_END()\n \t};\n \n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226911","messageId":"20130906051100.6657.36477.chriscool@tuxfamily.org","threadId":"34862","inReplyTo":"20130906050702.6657.25651.chriscool@tuxfamily.org","subject":"[PATCH v5 7/7] t6050-replace: use some long option names","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-09-06T05:10:59Z","receivedAt":"2013-09-06T05:10:59Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"So that they are tested a little bit too.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n t/t6050-replace.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 09a2b49..7d47984 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -122,9 +122,9 @@ test_expect_success '\"git replace\" listing and deleting' '\n      test \"$HASH2\" = \"$(git replace -l)\" &&\n      test \"$HASH2\" = \"$(git replace)\" &&\n      aa=${HASH2%??????????????????????????????????????} &&\n-     test \"$HASH2\" = \"$(git replace -l \"$aa*\")\" &&\n+     test \"$HASH2\" = \"$(git replace --list \"$aa*\")\" &&\n      test_must_fail git replace -d $R &&\n-     test_must_fail git replace -d &&\n+     test_must_fail git replace --delete &&\n      test_must_fail git replace -l -d $HASH2 &&\n      git replace -d $HASH2 &&\n      git show $HASH2 | grep \"A U Thor\" &&\n@@ -147,7 +147,7 @@ test_expect_success '\"git replace\" resolves sha1' '\n      git show $HASH2 | grep \"O Thor\" &&\n      test_must_fail git replace $HASH2 $R &&\n      git replace -f $HASH2 $R &&\n-     test_must_fail git replace -f &&\n+     test_must_fail git replace --force &&\n      test \"$HASH2\" = \"$(git replace)\"\n '\n \n@@ -272,7 +272,7 @@ test_expect_success 'replaced and replacement objects must be of the same type'\n \n test_expect_success '-f option bypasses the type check' '\n \tgit replace -f mytag $HASH1 &&\n-\tgit replace -f HEAD^{tree} HEAD~1 &&\n+\tgit replace --force HEAD^{tree} HEAD~1 &&\n \tgit replace -f HEAD^ $BLOB\n '\n \n-- \n1.8.4.rc1.28.ge2684af\n"},{"id":"226985","messageId":"xmqqmwnpwv6m.fsf@gitster.dls.corp.google.com","threadId":"34862","inReplyTo":"20130906051100.6657.41248.chriscool@tuxfamily.org","subject":"Re: [PATCH v5 1/7] replace: forbid replacing an object with one of a different type","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-06T20:29:21Z","receivedAt":"2013-09-06T20:29:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> +\tobj_type = sha1_object_info(object, NULL);\n> +\trepl_type = sha1_object_info(repl, NULL);\n\nThat we can do this is somewhat curious.  If an object is replaced\nwith a different one, would it mean that this code snippet is\ntotally bogus?\n\n        type1 = sha1_object_info(sha1, &size1);\n        area = xmalloc(size1);\n        orig = read_sha1_file(sha1, &type0, &size0);\n\tmemcpy(area, orig, size1);\n\tfree(orig);\n\n> +\tif (!force && obj_type != repl_type)\n> +\t\tdie(\"Objects must be of the same type.\\n\"\n> +\t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n> +\t\t    \"while '%s' points to a replacement object of type '%s'.\",\n> +\t\t    object_ref, typename(obj_type),\n> +\t\t    replace_ref, typename(repl_type));\n> +\n>  \tif (read_ref(ref, prev))\n>  \t\thashclr(prev);\n>  \telse if (!force)\n"},{"id":"226988","messageId":"xmqqioydws6d.fsf@gitster.dls.corp.google.com","threadId":"34862","inReplyTo":"xmqqmwnpwv6m.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v5 1/7] replace: forbid replacing an object with one of a different type","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-09-06T21:34:18Z","receivedAt":"2013-09-06T21:34:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Christian Couder <chriscool@tuxfamily.org> writes:\n>\n>> +\tobj_type = sha1_object_info(object, NULL);\n>> +\trepl_type = sha1_object_info(repl, NULL);\n>\n> That we can do this is somewhat curious....\n\nNote that this was a comment on the sha1_object_info() API, which,\nunlike read_sha1_file() API, does not seem to interact with the\n\"replace\" mechanism.  I _think_ that needs to be rethought by\nchecking each call site, but for the purpose of this series, I think\nthis is the best we can do in this patch.\n\nWill queue the whole series.\n\nThanks.\n"}]}