* [PATCH v5 0/7] Check replacement object type and minor updates
@ 2013-09-06 5:10 Christian Couder
2013-09-06 5:10 ` [PATCH v5 1/7] replace: forbid replacing an object with one of a different type Christian Couder
` (6 more replies)
0 siblings, 7 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
Many patchs have been squashed together as Junio suggested.
And in patch 3/7 now no grep is done on the error message.
Christian Couder (7):
replace: forbid replacing an object with one of a different type
Documentation/replace: state that objects must be of the same type
t6050-replace: test that objects are of the same type
t6050-replace: add test to clean up all the replace refs
Documentation/replace: add Creating Replacement Objects section
replace: allow long option names
t6050-replace: use some long option names
Documentation/git-replace.txt | 28 +++++++++++++++++++++++++---
builtin/replace.c | 16 +++++++++++++---
t/t6050-replace.sh | 25 ++++++++++++++++++++++---
3 files changed, 60 insertions(+), 9 deletions(-)
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 1/7] replace: forbid replacing an object with one of a different type
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 20:29 ` Junio C Hamano
2013-09-06 5:10 ` [PATCH v5 2/7] Documentation/replace: state that objects must be of the same type Christian Couder
` (5 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
Users replacing an object with one of a different type were not
prevented to do so, even if it was obvious, and stated in the doc,
that bad things would result from doing that.
To avoid mistakes, it is better to just forbid that though.
If -f option, which means '--force', is used, we can allow an object
to be replaced with one of a different type, as the user should know
what (s)he is doing.
If one object is replaced with one of a different type, the only way
to keep the history valid is to also replace all the other objects
that point to the replaced object. That's because:
* Annotated tags contain the type of the tagged object.
* The tree/parent lines in commits must be a tree and commits, resp.
* The object types referred to by trees are specified in the 'mode'
field:
100644 and 100755 blob
160000 commit
040000 tree
(these are the only valid modes)
* Blobs don't point at anything.
The doc will be updated in a later patch.
Acked-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin/replace.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/builtin/replace.c b/builtin/replace.c
index 59d3115..95736d9 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -85,6 +85,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
int force)
{
unsigned char object[20], prev[20], repl[20];
+ enum object_type obj_type, repl_type;
char ref[PATH_MAX];
struct ref_lock *lock;
@@ -100,6 +101,15 @@ static int replace_object(const char *object_ref, const char *replace_ref,
if (check_refname_format(ref, 0))
die("'%s' is not a valid ref name.", ref);
+ obj_type = sha1_object_info(object, NULL);
+ repl_type = sha1_object_info(repl, NULL);
+ if (!force && obj_type != repl_type)
+ die("Objects must be of the same type.\n"
+ "'%s' points to a replaced object of type '%s'\n"
+ "while '%s' points to a replacement object of type '%s'.",
+ object_ref, typename(obj_type),
+ replace_ref, typename(repl_type));
+
if (read_ref(ref, prev))
hashclr(prev);
else if (!force)
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 2/7] Documentation/replace: state that objects must be of the same type
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
2013-09-06 5:10 ` [PATCH v5 1/7] replace: forbid replacing an object with one of a different type Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 5:10 ` [PATCH v5 3/7] t6050-replace: test that objects are " Christian Couder
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
A previous patch ensures that both the replaced and the replacement
objects passed to git replace must be of the same type, except if
-f option is used.
While at it state that there is no other restriction on both objects.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/git-replace.txt | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index e0b4057..d198006 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -20,8 +20,13 @@ The name of the 'replace' reference is the SHA-1 of the object that is
replaced. The content of the 'replace' reference is the SHA-1 of the
replacement object.
+The replaced object and the replacement object must be of the same type.
+This restriction can be bypassed using `-f`.
+
Unless `-f` is given, the 'replace' reference must not yet exist.
+There is no other restriction on the replaced and replacement objects.
+
Replacement references will be used by default by all Git commands
except those doing reachability traversal (prune, pack transfer and
fsck).
@@ -69,9 +74,7 @@ go back to a replaced commit will move the branch to the replacement
commit instead of the replaced commit.
There may be other problems when using 'git rev-list' related to
-pending objects. And of course things may break if an object of one
-type is replaced by an object of another type (for example a blob
-replaced by a commit).
+pending objects.
SEE ALSO
--------
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 3/7] t6050-replace: test that objects are of the same type
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
2013-09-06 5:10 ` [PATCH v5 1/7] replace: forbid replacing an object with one of a different type Christian Couder
2013-09-06 5:10 ` [PATCH v5 2/7] Documentation/replace: state that objects must be of the same type Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 5:10 ` [PATCH v5 4/7] t6050-replace: add test to clean up all the replace refs Christian Couder
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
and that the -f option bypasses the type check
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t6050-replace.sh | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index decdc33..09bad98 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -263,4 +263,17 @@ test_expect_success 'not just commits' '
test_cmp file.replaced file
'
+test_expect_success 'replaced and replacement objects must be of the same type' '
+ test_must_fail git replace mytag $HASH1 &&
+ test_must_fail git replace HEAD^{tree} HEAD~1 &&
+ BLOB=$(git rev-parse :file) &&
+ test_must_fail git replace HEAD^ $BLOB
+'
+
+test_expect_success '-f option bypasses the type check' '
+ git replace -f mytag $HASH1 &&
+ git replace -f HEAD^{tree} HEAD~1 &&
+ git replace -f HEAD^ $BLOB
+'
+
test_done
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 4/7] t6050-replace: add test to clean up all the replace refs
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
` (2 preceding siblings ...)
2013-09-06 5:10 ` [PATCH v5 3/7] t6050-replace: test that objects are " Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 5:10 ` [PATCH v5 5/7] Documentation/replace: add Creating Replacement Objects section Christian Couder
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t6050-replace.sh | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 09bad98..09a2b49 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -276,4 +276,10 @@ test_expect_success '-f option bypasses the type check' '
git replace -f HEAD^ $BLOB
'
+test_expect_success 'replace ref cleanup' '
+ test -n "$(git replace)" &&
+ git replace -d $(git replace) &&
+ test -z "$(git replace)"
+'
+
test_done
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 5/7] Documentation/replace: add Creating Replacement Objects section
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
` (3 preceding siblings ...)
2013-09-06 5:10 ` [PATCH v5 4/7] t6050-replace: add test to clean up all the replace refs Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 5:10 ` [PATCH v5 6/7] replace: allow long option names Christian Couder
2013-09-06 5:10 ` [PATCH v5 7/7] t6050-replace: use some " Christian Couder
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
There were no hints in the documentation about how to create
replacement objects.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/git-replace.txt | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index d198006..a2bd2ee 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -66,6 +66,19 @@ OPTIONS
Typing "git replace" without arguments, also lists all replace
refs.
+CREATING REPLACEMENT OBJECTS
+----------------------------
+
+linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and
+linkgit:git-rebase[1], among other git commands, can be used to create
+replacement objects from existing objects.
+
+If you want to replace many blobs, trees or commits that are part of a
+string of commits, you may just want to create a replacement string of
+commits and then only replace the commit at the tip of the target
+string of commits with the commit at the tip of the replacement string
+of commits.
+
BUGS
----
Comparing blobs or trees that have been replaced with those that
@@ -78,6 +91,9 @@ pending objects.
SEE ALSO
--------
+linkgit:git-hash-object[1]
+linkgit:git-filter-branch[1]
+linkgit:git-rebase[1]
linkgit:git-tag[1]
linkgit:git-branch[1]
linkgit:git[1]
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 6/7] replace: allow long option names
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
` (4 preceding siblings ...)
2013-09-06 5:10 ` [PATCH v5 5/7] Documentation/replace: add Creating Replacement Objects section Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
2013-09-06 5:10 ` [PATCH v5 7/7] t6050-replace: use some " Christian Couder
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
It is now standard practice in Git to have both short and long option
names. So let's give a long option name to the git replace options too.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
Documentation/git-replace.txt | 3 +++
builtin/replace.c | 6 +++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index a2bd2ee..414000e 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -54,13 +54,16 @@ achieve the same effect as the `--no-replace-objects` option.
OPTIONS
-------
-f::
+--force::
If an existing replace ref for the same object exists, it will
be overwritten (instead of failing).
-d::
+--delete::
Delete existing replace refs for the given objects.
-l <pattern>::
+--list <pattern>::
List replace refs for objects that match the given pattern (or
all if no pattern is given).
Typing "git replace" without arguments, also lists all replace
diff --git a/builtin/replace.c b/builtin/replace.c
index 95736d9..d4d1b75 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -128,9 +128,9 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
{
int list = 0, delete = 0, force = 0;
struct option options[] = {
- OPT_BOOLEAN('l', NULL, &list, N_("list replace refs")),
- OPT_BOOLEAN('d', NULL, &delete, N_("delete replace refs")),
- OPT_BOOLEAN('f', NULL, &force, N_("replace the ref if it exists")),
+ OPT_BOOLEAN('l', "list", &list, N_("list replace refs")),
+ OPT_BOOLEAN('d', "delete", &delete, N_("delete replace refs")),
+ OPT_BOOLEAN('f', "force", &force, N_("replace the ref if it exists")),
OPT_END()
};
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 7/7] t6050-replace: use some long option names
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
` (5 preceding siblings ...)
2013-09-06 5:10 ` [PATCH v5 6/7] replace: allow long option names Christian Couder
@ 2013-09-06 5:10 ` Christian Couder
6 siblings, 0 replies; 10+ messages in thread
From: Christian Couder @ 2013-09-06 5:10 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
So that they are tested a little bit too.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
t/t6050-replace.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 09a2b49..7d47984 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -122,9 +122,9 @@ test_expect_success '"git replace" listing and deleting' '
test "$HASH2" = "$(git replace -l)" &&
test "$HASH2" = "$(git replace)" &&
aa=${HASH2%??????????????????????????????????????} &&
- test "$HASH2" = "$(git replace -l "$aa*")" &&
+ test "$HASH2" = "$(git replace --list "$aa*")" &&
test_must_fail git replace -d $R &&
- test_must_fail git replace -d &&
+ test_must_fail git replace --delete &&
test_must_fail git replace -l -d $HASH2 &&
git replace -d $HASH2 &&
git show $HASH2 | grep "A U Thor" &&
@@ -147,7 +147,7 @@ test_expect_success '"git replace" resolves sha1' '
git show $HASH2 | grep "O Thor" &&
test_must_fail git replace $HASH2 $R &&
git replace -f $HASH2 $R &&
- test_must_fail git replace -f &&
+ test_must_fail git replace --force &&
test "$HASH2" = "$(git replace)"
'
@@ -272,7 +272,7 @@ test_expect_success 'replaced and replacement objects must be of the same type'
test_expect_success '-f option bypasses the type check' '
git replace -f mytag $HASH1 &&
- git replace -f HEAD^{tree} HEAD~1 &&
+ git replace --force HEAD^{tree} HEAD~1 &&
git replace -f HEAD^ $BLOB
'
--
1.8.4.rc1.28.ge2684af
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v5 1/7] replace: forbid replacing an object with one of a different type
2013-09-06 5:10 ` [PATCH v5 1/7] replace: forbid replacing an object with one of a different type Christian Couder
@ 2013-09-06 20:29 ` Junio C Hamano
2013-09-06 21:34 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2013-09-06 20:29 UTC (permalink / raw)
To: Christian Couder
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
Christian Couder <chriscool@tuxfamily.org> writes:
> + obj_type = sha1_object_info(object, NULL);
> + repl_type = sha1_object_info(repl, NULL);
That we can do this is somewhat curious. If an object is replaced
with a different one, would it mean that this code snippet is
totally bogus?
type1 = sha1_object_info(sha1, &size1);
area = xmalloc(size1);
orig = read_sha1_file(sha1, &type0, &size0);
memcpy(area, orig, size1);
free(orig);
> + if (!force && obj_type != repl_type)
> + die("Objects must be of the same type.\n"
> + "'%s' points to a replaced object of type '%s'\n"
> + "while '%s' points to a replacement object of type '%s'.",
> + object_ref, typename(obj_type),
> + replace_ref, typename(repl_type));
> +
> if (read_ref(ref, prev))
> hashclr(prev);
> else if (!force)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 1/7] replace: forbid replacing an object with one of a different type
2013-09-06 20:29 ` Junio C Hamano
@ 2013-09-06 21:34 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2013-09-06 21:34 UTC (permalink / raw)
To: Christian Couder
Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
Jonathan Nieder
Junio C Hamano <gitster@pobox.com> writes:
> Christian Couder <chriscool@tuxfamily.org> writes:
>
>> + obj_type = sha1_object_info(object, NULL);
>> + repl_type = sha1_object_info(repl, NULL);
>
> That we can do this is somewhat curious....
Note that this was a comment on the sha1_object_info() API, which,
unlike read_sha1_file() API, does not seem to interact with the
"replace" mechanism. I _think_ that needs to be rethought by
checking each call site, but for the purpose of this series, I think
this is the best we can do in this patch.
Will queue the whole series.
Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-09-06 21:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06 5:10 [PATCH v5 0/7] Check replacement object type and minor updates Christian Couder
2013-09-06 5:10 ` [PATCH v5 1/7] replace: forbid replacing an object with one of a different type Christian Couder
2013-09-06 20:29 ` Junio C Hamano
2013-09-06 21:34 ` Junio C Hamano
2013-09-06 5:10 ` [PATCH v5 2/7] Documentation/replace: state that objects must be of the same type Christian Couder
2013-09-06 5:10 ` [PATCH v5 3/7] t6050-replace: test that objects are " Christian Couder
2013-09-06 5:10 ` [PATCH v5 4/7] t6050-replace: add test to clean up all the replace refs Christian Couder
2013-09-06 5:10 ` [PATCH v5 5/7] Documentation/replace: add Creating Replacement Objects section Christian Couder
2013-09-06 5:10 ` [PATCH v5 6/7] replace: allow long option names Christian Couder
2013-09-06 5:10 ` [PATCH v5 7/7] t6050-replace: use some " Christian Couder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).