All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/11] Check replacement object type and minor updates
@ 2013-09-03  7:10 Christian Couder
  2013-09-03  7:10 ` [PATCH v4 01/11] replace: forbid replacing an object with one of a different type Christian Couder
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7:10 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

The only changes in this new version are:

	- removed useless redirections in 8/11
	- improved commit message in 11/11 (s/litlle/little/)

I may add examples and more in a new patch series later.

Christian Couder (11):
  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: bypass the type check if -f option is used
  Documentation/replace: tell that -f option bypasses the type check
  t6050-replace: check that -f option bypasses the type check
  replace: allow long option names
  Documentation/replace: list long option names
  t6050-replace: use some long option names

 Documentation/git-replace.txt | 28 +++++++++++++++++++++++++---
 builtin/replace.c             | 16 +++++++++++++---
 t/t6050-replace.sh            | 31 ++++++++++++++++++++++++++++---
 3 files changed, 66 insertions(+), 9 deletions(-)

-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v4 01/11] replace: forbid replacing an object with one of a different type
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 02/11] Documentation/replace: state that objects must be of the same type Christian Couder
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 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..9a94769 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 (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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 02/11] Documentation/replace: state that objects must be of the same type
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
  2013-09-03  7:10 ` [PATCH v4 01/11] replace: forbid replacing an object with one of a different type Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 03/11] t6050-replace: test that objects are " Christian Couder
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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.

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 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index e0b4057..aa66d27 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -20,6 +20,9 @@ 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.
+There is no other restriction on them.
+
 Unless `-f` is given, the 'replace' reference must not yet exist.
 
 Replacement references will be used by default by all Git commands
@@ -69,9 +72,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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 03/11] t6050-replace: test that objects are of the same type
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
  2013-09-03  7:10 ` [PATCH v4 01/11] replace: forbid replacing an object with one of a different type Christian Couder
  2013-09-03  7:10 ` [PATCH v4 02/11] Documentation/replace: state that objects must be of the same type Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-04 20:39   ` Junio C Hamano
  2013-09-03  7:10 ` [PATCH v4 04/11] t6050-replace: add test to clean up all the replace refs Christian Couder
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index decdc33..5c352c4 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 2>err &&
+	grep "mytag. points to a replaced object of type .tag" err &&
+	grep "$HASH1. points to a replacement object of type .commit" err &&
+	test_must_fail git replace HEAD^{tree} HEAD~1 2>err &&
+	grep "HEAD^{tree}. points to a replaced object of type .tree" err &&
+	grep "HEAD~1. points to a replacement object of type .commit" err &&
+	BLOB=$(git rev-parse :file) &&
+	test_must_fail git replace HEAD^ $BLOB 2>err &&
+	grep "HEAD^. points to a replaced object of type .commit" err &&
+	grep "$BLOB. points to a replacement object of type .blob" err
+'
+
 test_done
-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 04/11] t6050-replace: add test to clean up all the replace refs
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (2 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 03/11] t6050-replace: test that objects are " Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 05/11] Documentation/replace: add Creating Replacement Objects section Christian Couder
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 5c352c4..05be228 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -276,4 +276,10 @@ test_expect_success 'replaced and replacement objects must be of the same type'
 	grep "$BLOB. points to a replacement object of type .blob" err
 '
 
+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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 05/11] Documentation/replace: add Creating Replacement Objects section
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (3 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 04/11] t6050-replace: add test to clean up all the replace refs Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 06/11] replace: bypass the type check if -f option is used Christian Couder
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 aa66d27..736b48c 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -64,6 +64,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
@@ -76,6 +89,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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 06/11] replace: bypass the type check if -f option is used
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (4 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 05/11] Documentation/replace: add Creating Replacement Objects section Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-04 20:44   ` Junio C Hamano
  2013-09-03  7:10 ` [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check Christian Couder
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7:10 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

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.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/replace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/replace.c b/builtin/replace.c
index 9a94769..95736d9 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -103,7 +103,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
 
 	obj_type = sha1_object_info(object, NULL);
 	repl_type = sha1_object_info(repl, NULL);
-	if (obj_type != repl_type)
+	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'.",
-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (5 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 06/11] replace: bypass the type check if -f option is used Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-04 20:45   ` Junio C Hamano
  2013-09-04 20:48   ` Junio C Hamano
  2013-09-03  7:10 ` [PATCH v4 08/11] t6050-replace: check " Christian Couder
                   ` (3 subsequent siblings)
  10 siblings, 2 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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>
---
 Documentation/git-replace.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
index 736b48c..a2bd2ee 100644
--- a/Documentation/git-replace.txt
+++ b/Documentation/git-replace.txt
@@ -21,10 +21,12 @@ 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.
-There is no other restriction on them.
+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).
-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 08/11] t6050-replace: check that -f option bypasses the type check
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (6 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 09/11] replace: allow long option names Christian Couder
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 05be228..622b751 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -276,6 +276,12 @@ test_expect_success 'replaced and replacement objects must be of the same type'
 	grep "$BLOB. points to a replacement object of type .blob" err
 '
 
+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_expect_success 'replace ref cleanup' '
 	test -n "$(git replace)" &&
 	git replace -d $(git replace) &&
-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 09/11] replace: allow long option names
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (7 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 08/11] t6050-replace: check " Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-03  7:10 ` [PATCH v4 10/11] Documentation/replace: list " Christian Couder
  2013-09-03  7:10 ` [PATCH v4 11/11] t6050-replace: use some " Christian Couder
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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>
---
 builtin/replace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 10/11] Documentation/replace: list long option names
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (8 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 09/11] replace: allow long option names Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  2013-09-04 20:45   ` Junio C Hamano
  2013-09-03  7:10 ` [PATCH v4 11/11] t6050-replace: use some " Christian Couder
  10 siblings, 1 reply; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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>
---
 Documentation/git-replace.txt | 3 +++
 1 file changed, 3 insertions(+)

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
-- 
1.8.4.rc1.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 11/11] t6050-replace: use some long option names
  2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
                   ` (9 preceding siblings ...)
  2013-09-03  7:10 ` [PATCH v4 10/11] Documentation/replace: list " Christian Couder
@ 2013-09-03  7:10 ` Christian Couder
  10 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-03  7: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 622b751..1fe5c1b 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)"
 '
 
@@ -278,7 +278,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.31.g530f5ce.dirty

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 03/11] t6050-replace: test that objects are of the same type
  2013-09-03  7:10 ` [PATCH v4 03/11] t6050-replace: test that objects are " Christian Couder
@ 2013-09-04 20:39   ` Junio C Hamano
  2013-09-05 19:13     ` Christian Couder
  0 siblings, 1 reply; 20+ messages in thread
From: Junio C Hamano @ 2013-09-04 20:39 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

Christian Couder <chriscool@tuxfamily.org> writes:

> 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..5c352c4 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 2>err &&
> +	grep "mytag. points to a replaced object of type .tag" err &&
> +	grep "$HASH1. points to a replacement object of type .commit" err &&

Hmm, would these messages ever get translated?  I think it is
sufficient to make sure that the proposed replacement fails for
these cases.

> +	test_must_fail git replace HEAD^{tree} HEAD~1 2>err &&
> +	grep "HEAD^{tree}. points to a replaced object of type .tree" err &&
> +	grep "HEAD~1. points to a replacement object of type .commit" err &&
> +	BLOB=$(git rev-parse :file) &&
> +	test_must_fail git replace HEAD^ $BLOB 2>err &&
> +	grep "HEAD^. points to a replaced object of type .commit" err &&
> +	grep "$BLOB. points to a replacement object of type .blob" err
> +'
> +
>  test_done

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 06/11] replace: bypass the type check if -f option is used
  2013-09-03  7:10 ` [PATCH v4 06/11] replace: bypass the type check if -f option is used Christian Couder
@ 2013-09-04 20:44   ` Junio C Hamano
  2013-09-05 12:56     ` Christian Couder
  0 siblings, 1 reply; 20+ messages in thread
From: Junio C Hamano @ 2013-09-04 20:44 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

Christian Couder <chriscool@tuxfamily.org> writes:

> 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.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---

This does not matter in a larger picture, but between 1/11 and this
patch, there is a window where an operation that has been useful in
some workflows becomes unavailable to the user.

For future reference, it would be better to do this as a part of
1/11, to make sure that there always is an escape hatch available to
the users.

>  builtin/replace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/replace.c b/builtin/replace.c
> index 9a94769..95736d9 100644
> --- a/builtin/replace.c
> +++ b/builtin/replace.c
> @@ -103,7 +103,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
>  
>  	obj_type = sha1_object_info(object, NULL);
>  	repl_type = sha1_object_info(repl, NULL);
> -	if (obj_type != repl_type)
> +	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'.",

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check
  2013-09-03  7:10 ` [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check Christian Couder
@ 2013-09-04 20:45   ` Junio C Hamano
  2013-09-04 20:48   ` Junio C Hamano
  1 sibling, 0 replies; 20+ messages in thread
From: Junio C Hamano @ 2013-09-04 20:45 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

Christian Couder <chriscool@tuxfamily.org> writes:

> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  Documentation/git-replace.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
> index 736b48c..a2bd2ee 100644
> --- a/Documentation/git-replace.txt
> +++ b/Documentation/git-replace.txt
> @@ -21,10 +21,12 @@ 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.
> -There is no other restriction on them.
> +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).

And this should be in the same patch as the one that makes the code
change.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 10/11] Documentation/replace: list long option names
  2013-09-03  7:10 ` [PATCH v4 10/11] Documentation/replace: list " Christian Couder
@ 2013-09-04 20:45   ` Junio C Hamano
  2013-09-05 13:03     ` Christian Couder
  0 siblings, 1 reply; 20+ messages in thread
From: Junio C Hamano @ 2013-09-04 20:45 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

Christian Couder <chriscool@tuxfamily.org> writes:

> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  Documentation/git-replace.txt | 3 +++
>  1 file changed, 3 insertions(+)
>
> 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

This should be in the same commit as what adds them.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check
  2013-09-03  7:10 ` [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check Christian Couder
  2013-09-04 20:45   ` Junio C Hamano
@ 2013-09-04 20:48   ` Junio C Hamano
  1 sibling, 0 replies; 20+ messages in thread
From: Junio C Hamano @ 2013-09-04 20:48 UTC (permalink / raw)
  To: Christian Couder
  Cc: git, Philip Oakley, Thomas Rast, Johannes Sixt, Eric Sunshine,
	Jonathan Nieder

Christian Couder <chriscool@tuxfamily.org> writes:

> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  Documentation/git-replace.txt | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt
> index 736b48c..a2bd2ee 100644
> --- a/Documentation/git-replace.txt
> +++ b/Documentation/git-replace.txt
> @@ -21,10 +21,12 @@ 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.
> -There is no other restriction on them.
> +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.
> +

This is outside the scope of this topic, but I wonder if we want to
restrict a replacement operation that causes a cycle in the object
graph (a commit reaches itself after following its parent pointer,
a tree reaches itself after looking into trees within, a tag reaches
itself after following its "object" reference), and if we do want
it, it is feasible to implement it.

>  Replacement references will be used by default by all Git commands
>  except those doing reachability traversal (prune, pack transfer and
>  fsck).

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 06/11] replace: bypass the type check if -f option is used
  2013-09-04 20:44   ` Junio C Hamano
@ 2013-09-05 12:56     ` Christian Couder
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-05 12:56 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Christian Couder, git, Philip Oakley, Thomas Rast, Johannes Sixt,
	Eric Sunshine, Jonathan Nieder

On Wed, Sep 4, 2013 at 10:44 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Christian Couder <chriscool@tuxfamily.org> writes:
>
>> 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.
>>
>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>> ---
>
> This does not matter in a larger picture, but between 1/11 and this
> patch, there is a window where an operation that has been useful in
> some workflows becomes unavailable to the user.
>
> For future reference, it would be better to do this as a part of
> 1/11, to make sure that there always is an escape hatch available to
> the users.

Ok, I will squash patchs 6/11, 7/11 and 8/11 with 1/11, 2/11 and 3/11
respectively.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 10/11] Documentation/replace: list long option names
  2013-09-04 20:45   ` Junio C Hamano
@ 2013-09-05 13:03     ` Christian Couder
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-05 13:03 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Christian Couder, git, Philip Oakley, Thomas Rast, Johannes Sixt,
	Eric Sunshine, Jonathan Nieder

On Wed, Sep 4, 2013 at 10:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Christian Couder <chriscool@tuxfamily.org> writes:
>
>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>> ---
>>  Documentation/git-replace.txt | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> 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
>
> This should be in the same commit as what adds them.

Ok, I will squash 10/11 into 9/11.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 03/11] t6050-replace: test that objects are of the same type
  2013-09-04 20:39   ` Junio C Hamano
@ 2013-09-05 19:13     ` Christian Couder
  0 siblings, 0 replies; 20+ messages in thread
From: Christian Couder @ 2013-09-05 19:13 UTC (permalink / raw)
  To: gitster; +Cc: git, philipoakley, trast, j6t, sunshine, jrnieder

From: Junio C Hamano <gitster@pobox.com>
>
> Christian Couder <chriscool@tuxfamily.org> writes:
>>  
>> +test_expect_success 'replaced and replacement objects must be of the same type' '
>> +	test_must_fail git replace mytag $HASH1 2>err &&
>> +	grep "mytag. points to a replaced object of type .tag" err &&
>> +	grep "$HASH1. points to a replacement object of type .commit" err &&
> 
> Hmm, would these messages ever get translated?  I think it is
> sufficient to make sure that the proposed replacement fails for
> these cases.

Ok, I will get rid of the grep statements.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2013-09-05 19:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03  7:10 [PATCH v4 00/11] Check replacement object type and minor updates Christian Couder
2013-09-03  7:10 ` [PATCH v4 01/11] replace: forbid replacing an object with one of a different type Christian Couder
2013-09-03  7:10 ` [PATCH v4 02/11] Documentation/replace: state that objects must be of the same type Christian Couder
2013-09-03  7:10 ` [PATCH v4 03/11] t6050-replace: test that objects are " Christian Couder
2013-09-04 20:39   ` Junio C Hamano
2013-09-05 19:13     ` Christian Couder
2013-09-03  7:10 ` [PATCH v4 04/11] t6050-replace: add test to clean up all the replace refs Christian Couder
2013-09-03  7:10 ` [PATCH v4 05/11] Documentation/replace: add Creating Replacement Objects section Christian Couder
2013-09-03  7:10 ` [PATCH v4 06/11] replace: bypass the type check if -f option is used Christian Couder
2013-09-04 20:44   ` Junio C Hamano
2013-09-05 12:56     ` Christian Couder
2013-09-03  7:10 ` [PATCH v4 07/11] Documentation/replace: tell that -f option bypasses the type check Christian Couder
2013-09-04 20:45   ` Junio C Hamano
2013-09-04 20:48   ` Junio C Hamano
2013-09-03  7:10 ` [PATCH v4 08/11] t6050-replace: check " Christian Couder
2013-09-03  7:10 ` [PATCH v4 09/11] replace: allow long option names Christian Couder
2013-09-03  7:10 ` [PATCH v4 10/11] Documentation/replace: list " Christian Couder
2013-09-04 20:45   ` Junio C Hamano
2013-09-05 13:03     ` Christian Couder
2013-09-03  7:10 ` [PATCH v4 11/11] t6050-replace: use some " Christian Couder

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.