{"thread":{"id":"34764","subject":"[PATCH 0/5] Check replacement object type and minor updates","startedAt":"2013-08-25T13:06:03Z","lastAt":"2013-08-26T07:19:37Z","messageCount":11,"participants":["Christian Couder","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"225860","messageId":"20130825125940.4681.70226.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":null,"subject":"[PATCH 0/5] Check replacement object type and minor updates","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:03Z","receivedAt":"2013-08-25T13:06:03Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Here is a reroll of the patch forbiding replacing an bject with one\nof a different type (1/5).\nIt is followed by a documentation update (2/5) and a test (3/5).\nI also added for good mesure another test (4/5) I came up with while\ndeveloping the previous test, and another doc update related to what\nwe discussed about creating replacement objects (5/5).\n\nChristian Couder (5):\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\n Documentation/git-replace.txt | 23 ++++++++++++++++++++---\n builtin/replace.c             | 10 ++++++++++\n t/t6050-replace.sh            | 19 +++++++++++++++++++\n 3 files changed, 49 insertions(+), 3 deletions(-)\n\n-- \n1.8.4.rc1.24.g13dc82a\n"},{"id":"225864","messageId":"20130825130609.4681.25786.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"20130825125940.4681.70226.chriscool@tuxfamily.org","subject":"[PATCH 1/5] replace: forbid replacing an object with one of a different type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:04Z","receivedAt":"2013-08-25T13:06:04Z","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\nThere is no case where one object can be replaced with one of a\ndifferent type while keeping the history valid, 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..bc6c245 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 (obj_type != repl_type)\n+\t\tdie(\"Objects must be of the same type.\\n\"\n+\t\t    \"Object ref '%s' is of type '%s'\\n\"\n+\t\t    \"while replace ref '%s' is 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.24.g13dc82a\n"},{"id":"225862","messageId":"20130825130609.4681.83578.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"20130825125940.4681.70226.chriscool@tuxfamily.org","subject":"[PATCH 2/5] Documentation/replace: state that objects must be of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:05Z","receivedAt":"2013-08-25T13:06:05Z","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.\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 | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt\nindex e0b4057..aa66d27 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -20,6 +20,9 @@ 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+There is no other restriction on them.\n+\n Unless `-f` is given, the 'replace' reference must not yet exist.\n \n Replacement references will be used by default by all Git commands\n@@ -69,9 +72,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.24.g13dc82a\n"},{"id":"225861","messageId":"20130825130609.4681.58306.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"20130825125940.4681.70226.chriscool@tuxfamily.org","subject":"[PATCH 3/5] t6050-replace: test that objects are of the same type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:06Z","receivedAt":"2013-08-25T13:06:06Z","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 | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex decdc33..8f631ac 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 2>err &&\n+\tgrep \"Object ref '\\''mytag'\\'' is of type '\\''tag'\\''\" err &&\n+\tgrep \"replace ref '\\''$HASH1'\\'' is of type '\\''commit'\\''\" err &&\n+\ttest_must_fail git replace HEAD^{tree} HEAD~1 2>err &&\n+\tgrep \"Object ref '\\''HEAD^{tree}'\\'' is of type '\\''tree'\\''\" err &&\n+\tgrep \"replace ref '\\''HEAD~1'\\'' is of type '\\''commit'\\''\" err &&\n+\tBLOB=$(git rev-parse :file) &&\n+\ttest_must_fail git replace HEAD^ $BLOB 2>err &&\n+\tgrep \"Object ref '\\''HEAD^'\\'' is of type '\\''commit'\\''\" err &&\n+\tgrep \"replace ref '\\''$BLOB'\\'' is of type '\\''blob'\\''\" err\n+'\n+\n test_done\n-- \n1.8.4.rc1.24.g13dc82a\n"},{"id":"225863","messageId":"20130825130609.4681.43592.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"20130825125940.4681.70226.chriscool@tuxfamily.org","subject":"[PATCH 4/5] t6050-replace: add test to clean up all the replace refs","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:07Z","receivedAt":"2013-08-25T13:06:07Z","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 8f631ac..4807689 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -276,4 +276,10 @@ test_expect_success 'replaced and replacement objects must be of the same type'\n \tgrep \"replace ref '\\''$BLOB'\\'' is of type '\\''blob'\\''\" err\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.24.g13dc82a\n"},{"id":"225865","messageId":"20130825130609.4681.95932.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"20130825125940.4681.70226.chriscool@tuxfamily.org","subject":"[PATCH 5/5] Documentation/replace: add Creating Replacement Objects section","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T13:06:08Z","receivedAt":"2013-08-25T13:06:08Z","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 aa66d27..736b48c 100644\n--- a/Documentation/git-replace.txt\n+++ b/Documentation/git-replace.txt\n@@ -64,6 +64,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@@ -76,6 +89,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.24.g13dc82a\n"},{"id":"225869","messageId":"521A4E83.9000400@kdbg.org","threadId":"34764","inReplyTo":"20130825130609.4681.25786.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/5] replace: forbid replacing an object with one of a different type","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-08-25T18:35:47Z","receivedAt":"2013-08-25T18:35:47Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 25.08.2013 15:06, schrieb Christian Couder:\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 (obj_type != repl_type)\n> +\t\tdie(\"Objects must be of the same type.\\n\"\n> +\t\t    \"Object ref '%s' is of type '%s'\\n\"\n\nIs it really an \"Object ref\", not just an \"Object\"?\n\n> +\t\t    \"while replace ref '%s' is of type '%s'.\",\n\nAnd here:\n\n\t\t\"while replacement object '%s' is of type '%s'.\",\n\nBTW, I appreciate your choice of where in the sentence the line breaks are.\n\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\n-- Hannes\n"},{"id":"225870","messageId":"20130825.214417.1308749312477487067.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"521A4E83.9000400@kdbg.org","subject":"Re: [PATCH 1/5] replace: forbid replacing an object with one of a different type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-25T19:44:17Z","receivedAt":"2013-08-25T19:44:17Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: Johannes Sixt <j6t@kdbg.org>\n\n> Am 25.08.2013 15:06, schrieb Christian Couder:\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 (obj_type != repl_type)\n>> +\t\tdie(\"Objects must be of the same type.\\n\"\n>> +\t\t    \"Object ref '%s' is of type '%s'\\n\"\n> \n> Is it really an \"Object ref\", not just an \"Object\"?\n\nWell, it is what is passed to the command line. It is then converted into an\nhex sha1 using get_sha1() and then sha1_to_hex().\n\nWhat about:\n\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\n> BTW, I appreciate your choice of where in the sentence the line breaks are.\n\nThanks,\nChristian.\n"},{"id":"225872","messageId":"521A63B3.6040004@kdbg.org","threadId":"34764","inReplyTo":"20130825130609.4681.58306.chriscool@tuxfamily.org","subject":"Re: [PATCH 3/5] t6050-replace: test that objects are of the same type","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-08-25T20:06:11Z","receivedAt":"2013-08-25T20:06:11Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 25.08.2013 15:06, schrieb Christian Couder:\n> +test_expect_success 'replaced and replacement objects must be of the same type' '\n> +\ttest_must_fail git replace mytag $HASH1 2>err &&\n> +\tgrep \"Object ref '\\''mytag'\\'' is of type '\\''tag'\\''\" err &&\n\nUh, this hurts in the eye! Please write this as\n\n\tgrep \"Object ref .mytag. is of type .tag\" err &&\n\n-- Hannes\n"},{"id":"225874","messageId":"521A6684.7090103@kdbg.org","threadId":"34764","inReplyTo":"20130825.214417.1308749312477487067.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/5] replace: forbid replacing an object with one of a different type","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-08-25T20:18:12Z","receivedAt":"2013-08-25T20:18:12Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 25.08.2013 21:44, schrieb Christian Couder:\n> What about:\n> \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\nMuch better!\n\n-- Hannes\n"},{"id":"225888","messageId":"20130826.091937.1157849584660055093.chriscool@tuxfamily.org","threadId":"34764","inReplyTo":"521A6684.7090103@kdbg.org","subject":"Re: [PATCH 1/5] replace: forbid replacing an object with one of a different type","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2013-08-26T07:19:37Z","receivedAt":"2013-08-26T07:19:37Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: Johannes Sixt <j6t@kdbg.org>\n\n> Am 25.08.2013 21:44, schrieb Christian Couder:\n>> What about:\n>> \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> \n> Much better!\n\nOk, I will reroll with this change and the change you suggest in the test.\n\nThanks,\nChristian.\n"}]}