git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/4] Preliminary fixes for reftable support
@ 2020-06-30 12:05 Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-06-30 12:05 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys

These are assorted small fixes split out from the reftable topic.

Han-Wen Nienhuys (4):
  lib-t6000.sh: write tag using git-update-ref
  t3432: use git-reflog to inspect the reflog for HEAD
  checkout: add '\n' to reflog message
  Treat BISECT_HEAD as a pseudo ref

 builtin/bisect--helper.c       | 3 +--
 builtin/checkout.c             | 5 +++--
 git-bisect.sh                  | 4 ++--
 t/lib-t6000.sh                 | 5 ++---
 t/t3432-rebase-fast-forward.sh | 7 ++++---
 5 files changed, 12 insertions(+), 12 deletions(-)


base-commit: f402ea68166bd77f09b176c96005ac7f8886e14b
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/669
-- 
gitgitgadget

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

* [PATCH 1/4] lib-t6000.sh: write tag using git-update-ref
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
@ 2020-06-30 12:05 ` Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-06-30 12:05 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 t/lib-t6000.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/t/lib-t6000.sh b/t/lib-t6000.sh
index b0ed4767e3..fba6778ca3 100644
--- a/t/lib-t6000.sh
+++ b/t/lib-t6000.sh
@@ -1,7 +1,5 @@
 : included from 6002 and others
 
-mkdir -p .git/refs/tags
-
 >sed.script
 
 # Answer the sha1 has associated with the tag. The tag must exist under refs/tags
@@ -26,7 +24,8 @@ save_tag () {
 	_tag=$1
 	test -n "$_tag" || error "usage: save_tag tag commit-args ..."
 	shift 1
-	"$@" >".git/refs/tags/$_tag"
+
+	git update-ref "refs/tags/$_tag" $("$@")
 
 	echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
 	cat sed.script >>sed.script.tmp
-- 
gitgitgadget


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

* [PATCH 2/4] t3432: use git-reflog to inspect the reflog for HEAD
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
@ 2020-06-30 12:05 ` Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 3/4] checkout: add '\n' to reflog message Han-Wen Nienhuys via GitGitGadget
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-06-30 12:05 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 t/t3432-rebase-fast-forward.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 6f0452c0ea..22afeb8ccd 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -60,15 +60,16 @@ test_rebase_same_head_ () {
 		fi &&
 		oldhead=\$(git rev-parse HEAD) &&
 		test_when_finished 'git reset --hard \$oldhead' &&
-		cp .git/logs/HEAD expect &&
+		git reflog HEAD > expect &&
 		git rebase$flag $* >stdout &&
+		git reflog HEAD > actual &&
 		if test $what = work
 		then
 			old=\$(wc -l <expect) &&
-			test_line_count '-gt' \$old .git/logs/HEAD
+			test_line_count '-gt' \$old actual
 		elif test $what = noop
 		then
-			test_cmp expect .git/logs/HEAD
+			test_cmp expect actual
 		fi &&
 		newhead=\$(git rev-parse HEAD) &&
 		if test $cmp = same
-- 
gitgitgadget


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

* [PATCH 3/4] checkout: add '\n' to reflog message
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
@ 2020-06-30 12:05 ` Han-Wen Nienhuys via GitGitGadget
  2020-06-30 12:05 ` [PATCH 4/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-06-30 12:05 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

This makes check consistent with the rest of the git code, which tends to use a
trailing '\n' when writing reflog messages.  (The storage layer adds a '\n'
when it is missing.)

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 builtin/checkout.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index af849c644f..bb11fcc4e9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -884,8 +884,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 
 	reflog_msg = getenv("GIT_REFLOG_ACTION");
 	if (!reflog_msg)
-		strbuf_addf(&msg, "checkout: moving from %s to %s",
-			old_desc ? old_desc : "(invalid)", new_branch_info->name);
+		strbuf_addf(&msg, "checkout: moving from %s to %s\n",
+			    old_desc ? old_desc : "(invalid)",
+			    new_branch_info->name);
 	else
 		strbuf_insertstr(&msg, 0, reflog_msg);
 
-- 
gitgitgadget


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

* [PATCH 4/4] Treat BISECT_HEAD as a pseudo ref
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
                   ` (2 preceding siblings ...)
  2020-06-30 12:05 ` [PATCH 3/4] checkout: add '\n' to reflog message Han-Wen Nienhuys via GitGitGadget
@ 2020-06-30 12:05 ` Han-Wen Nienhuys via GitGitGadget
  2020-07-07  4:40 ` [PATCH 0/4] Preliminary fixes for reftable support Junio C Hamano
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
  5 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-06-30 12:05 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Both the git-bisect.sh as bisect--helper inspected the file system directly.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 builtin/bisect--helper.c | 3 +--
 git-bisect.sh            | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index ec4996282e..73f9324ad7 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
 static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
 static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
 static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
-static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
 static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
 static GIT_PATH_FUNC(git_path_head_name, "head-name")
 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
@@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)
 		strbuf_addstr(&branch, commit);
 	}
 
-	if (!file_exists(git_path_bisect_head())) {
+	if (!ref_exists("BISECT_HEAD")) {
 		struct argv_array argv = ARGV_ARRAY_INIT;
 
 		argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
diff --git a/git-bisect.sh b/git-bisect.sh
index 08a6ed57dd..f03fbb18f0 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -41,7 +41,7 @@ TERM_GOOD=good
 
 bisect_head()
 {
-	if test -f "$GIT_DIR/BISECT_HEAD"
+	if git rev-parse --verify -q BISECT_HEAD > /dev/null
 	then
 		echo BISECT_HEAD
 	else
@@ -153,7 +153,7 @@ bisect_next() {
 	git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
 
 	# Perform all bisection computation, display and checkout
-	git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
+	git bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)
 	res=$?
 
 	# Check if we should exit because bisection is finished
-- 
gitgitgadget

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

* Re: [PATCH 0/4] Preliminary fixes for reftable support
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
                   ` (3 preceding siblings ...)
  2020-06-30 12:05 ` [PATCH 4/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
@ 2020-07-07  4:40 ` Junio C Hamano
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
  5 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2020-07-07  4:40 UTC (permalink / raw)
  To: Han-Wen Nienhuys via GitGitGadget; +Cc: git, Han-Wen Nienhuys

"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> These are assorted small fixes split out from the reftable topic.
>
> Han-Wen Nienhuys (4):
>   lib-t6000.sh: write tag using git-update-ref
>   t3432: use git-reflog to inspect the reflog for HEAD
>   checkout: add '\n' to reflog message
>   Treat BISECT_HEAD as a pseudo ref
>
>  builtin/bisect--helper.c       | 3 +--
>  builtin/checkout.c             | 5 +++--
>  git-bisect.sh                  | 4 ++--
>  t/lib-t6000.sh                 | 5 ++---
>  t/t3432-rebase-fast-forward.sh | 7 ++++---
>  5 files changed, 12 insertions(+), 12 deletions(-)

Thanks for splitting these out, and sorry for not being able to get
to them earlier.

Will queue.


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

* [PATCH v2 0/4] Preliminary fixes for reftable support
  2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
                   ` (4 preceding siblings ...)
  2020-07-07  4:40 ` [PATCH 0/4] Preliminary fixes for reftable support Junio C Hamano
@ 2020-07-10 17:19 ` Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
                     ` (4 more replies)
  5 siblings, 5 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-07-10 17:19 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys

These are assorted small fixes split out from the reftable topic.

Han-Wen Nienhuys (3):
  lib-t6000.sh: write tag using git-update-ref
  t3432: use git-reflog to inspect the reflog for HEAD
  Treat BISECT_HEAD as a pseudo ref

Junio C Hamano (1):
  Cleanse reflog messages in the refs.c layer

 builtin/bisect--helper.c       |  3 +-
 git-bisect.sh                  |  4 +--
 refs.c                         | 50 ++++++++++++++++++++++++++++------
 refs/files-backend.c           |  2 +-
 refs/refs-internal.h           |  6 ----
 t/lib-t6000.sh                 |  5 ++--
 t/t3432-rebase-fast-forward.sh |  7 +++--
 7 files changed, 51 insertions(+), 26 deletions(-)


base-commit: bd42bbe1a46c0fe486fc33e82969275e27e4dc19
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/669

Range-diff vs v1:

 1:  b7b2ad8e79 = 1:  0f244ed6cb lib-t6000.sh: write tag using git-update-ref
 2:  f238d1d7f8 ! 2:  123d246edf t3432: use git-reflog to inspect the reflog for HEAD
     @@ t/t3432-rebase-fast-forward.sh: test_rebase_same_head_ () {
       		oldhead=\$(git rev-parse HEAD) &&
       		test_when_finished 'git reset --hard \$oldhead' &&
      -		cp .git/logs/HEAD expect &&
     -+		git reflog HEAD > expect &&
     ++		git reflog HEAD >expect &&
       		git rebase$flag $* >stdout &&
     -+		git reflog HEAD > actual &&
     ++		git reflog HEAD >actual &&
       		if test $what = work
       		then
       			old=\$(wc -l <expect) &&
 3:  8a62cc2668 < -:  ---------- checkout: add '\n' to reflog message
 4:  2b7eb58c15 = 3:  d4007c2a5b Treat BISECT_HEAD as a pseudo ref
 -:  ---------- > 4:  6ca5b99c8d Cleanse reflog messages in the refs.c layer

-- 
gitgitgadget

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

* [PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
@ 2020-07-10 17:19   ` Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-07-10 17:19 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 t/lib-t6000.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/t/lib-t6000.sh b/t/lib-t6000.sh
index b0ed4767e3..fba6778ca3 100644
--- a/t/lib-t6000.sh
+++ b/t/lib-t6000.sh
@@ -1,7 +1,5 @@
 : included from 6002 and others
 
-mkdir -p .git/refs/tags
-
 >sed.script
 
 # Answer the sha1 has associated with the tag. The tag must exist under refs/tags
@@ -26,7 +24,8 @@ save_tag () {
 	_tag=$1
 	test -n "$_tag" || error "usage: save_tag tag commit-args ..."
 	shift 1
-	"$@" >".git/refs/tags/$_tag"
+
+	git update-ref "refs/tags/$_tag" $("$@")
 
 	echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
 	cat sed.script >>sed.script.tmp
-- 
gitgitgadget


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

* [PATCH v2 2/4] t3432: use git-reflog to inspect the reflog for HEAD
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
@ 2020-07-10 17:19   ` Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 3/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-07-10 17:19 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 t/t3432-rebase-fast-forward.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
index 6f0452c0ea..a29eda87e9 100755
--- a/t/t3432-rebase-fast-forward.sh
+++ b/t/t3432-rebase-fast-forward.sh
@@ -60,15 +60,16 @@ test_rebase_same_head_ () {
 		fi &&
 		oldhead=\$(git rev-parse HEAD) &&
 		test_when_finished 'git reset --hard \$oldhead' &&
-		cp .git/logs/HEAD expect &&
+		git reflog HEAD >expect &&
 		git rebase$flag $* >stdout &&
+		git reflog HEAD >actual &&
 		if test $what = work
 		then
 			old=\$(wc -l <expect) &&
-			test_line_count '-gt' \$old .git/logs/HEAD
+			test_line_count '-gt' \$old actual
 		elif test $what = noop
 		then
-			test_cmp expect .git/logs/HEAD
+			test_cmp expect actual
 		fi &&
 		newhead=\$(git rev-parse HEAD) &&
 		if test $cmp = same
-- 
gitgitgadget


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

* [PATCH v2 3/4] Treat BISECT_HEAD as a pseudo ref
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
@ 2020-07-10 17:19   ` Han-Wen Nienhuys via GitGitGadget
  2020-07-10 17:19   ` [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer Junio C Hamano via GitGitGadget
  2020-07-10 20:57   ` [PATCH v2 0/4] Preliminary fixes for reftable support Junio C Hamano
  4 siblings, 0 replies; 13+ messages in thread
From: Han-Wen Nienhuys via GitGitGadget @ 2020-07-10 17:19 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Han-Wen Nienhuys

From: Han-Wen Nienhuys <hanwen@google.com>

Both the git-bisect.sh as bisect--helper inspected the file system directly.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 builtin/bisect--helper.c | 3 +--
 git-bisect.sh            | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index ec4996282e..73f9324ad7 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
 static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
 static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
 static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
-static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
 static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
 static GIT_PATH_FUNC(git_path_head_name, "head-name")
 static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
@@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)
 		strbuf_addstr(&branch, commit);
 	}
 
-	if (!file_exists(git_path_bisect_head())) {
+	if (!ref_exists("BISECT_HEAD")) {
 		struct argv_array argv = ARGV_ARRAY_INIT;
 
 		argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
diff --git a/git-bisect.sh b/git-bisect.sh
index 08a6ed57dd..f03fbb18f0 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -41,7 +41,7 @@ TERM_GOOD=good
 
 bisect_head()
 {
-	if test -f "$GIT_DIR/BISECT_HEAD"
+	if git rev-parse --verify -q BISECT_HEAD > /dev/null
 	then
 		echo BISECT_HEAD
 	else
@@ -153,7 +153,7 @@ bisect_next() {
 	git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
 
 	# Perform all bisection computation, display and checkout
-	git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
+	git bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)
 	res=$?
 
 	# Check if we should exit because bisection is finished
-- 
gitgitgadget


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

* [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
                     ` (2 preceding siblings ...)
  2020-07-10 17:19   ` [PATCH v2 3/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
@ 2020-07-10 17:19   ` Junio C Hamano via GitGitGadget
  2020-07-10 21:06     ` Junio C Hamano
  2020-07-10 20:57   ` [PATCH v2 0/4] Preliminary fixes for reftable support Junio C Hamano
  4 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano via GitGitGadget @ 2020-07-10 17:19 UTC (permalink / raw)
  To: git; +Cc: Han-Wen Nienhuys, Junio C Hamano

From: Junio C Hamano <gitster@pobox.com>

Regarding reflog messages:

 - We expect that a reflog message consists of a single line.  The
   file format used by the files backend may add a LF after the
   message as a delimiter, and output by commands like "git log -g"
   may complete such an incomplete line by adding a LF at the end,
   but philosophically, the terminating LF is not a part of the
   message.

 - We however allow callers of refs API to supply a random sequence
   of NUL terminated bytes.  We cleanse caller-supplied message by
   squashing a run of whitespaces into a SP, and by trimming trailing
   whitespace, before storing the message.  This is how we tolerate,
   instead of erring out, a message with LF in it (be it at the end,
   in the middle, or both).

Currently, the cleansing of the reflog message is done by the files
backend, before the log is written out.  This is sufficient with the
current code, as that is the only backend that writes reflogs.  But
new backends can be added that write reflogs, and we'd want the
resulting log message we would read out of "log -g" the same no
matter what backend is used.

An added benefit is that the "cleansing" function could be updated
later, independent from individual backends, to e.g. allow
multi-line log messages if we wanted to, and when that happens, it
would help a lot to ensure we covered all bases if the cleansing
function (which would be updated) is called from the generic layer.

Side note: I am not interested in supporting multi-line
reflog messages right at the moment (nobody is asking for
it), but I envision that instead of the "squash a run of
whitespaces into a SP and rtrim" cleansing, we can
%urlencode problematic bytes in the message *AND* append a
SP at the end, when a new version of Git that supports
multi-line and/or verbatim reflog messages writes a reflog
record.  The reading side can detect the presense of SP at
the end (which should have been rtrimmed out if it were
written by existing versions of Git) as a signal that
decoding %urlencode recovers the original reflog message.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 refs.c               | 50 ++++++++++++++++++++++++++++++++++++--------
 refs/files-backend.c |  2 +-
 refs/refs-internal.h |  6 ------
 3 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/refs.c b/refs.c
index 639cba93b4..89814c7be4 100644
--- a/refs.c
+++ b/refs.c
@@ -902,7 +902,7 @@ int delete_ref(const char *msg, const char *refname,
 			       old_oid, flags);
 }
 
-void copy_reflog_msg(struct strbuf *sb, const char *msg)
+static void copy_reflog_msg(struct strbuf *sb, const char *msg)
 {
 	char c;
 	int wasspace = 1;
@@ -919,6 +919,15 @@ void copy_reflog_msg(struct strbuf *sb, const char *msg)
 	strbuf_rtrim(sb);
 }
 
+static char *normalize_reflog_message(const char *msg)
+{
+	struct strbuf sb = STRBUF_INIT;
+
+	if (msg && *msg)
+		copy_reflog_msg(&sb, msg);
+	return strbuf_detach(&sb, NULL);
+}
+
 int should_autocreate_reflog(const char *refname)
 {
 	switch (log_all_ref_updates) {
@@ -1124,7 +1133,7 @@ struct ref_update *ref_transaction_add_update(
 		oidcpy(&update->new_oid, new_oid);
 	if (flags & REF_HAVE_OLD)
 		oidcpy(&update->old_oid, old_oid);
-	update->msg = xstrdup_or_null(msg);
+	update->msg = normalize_reflog_message(msg);
 	return update;
 }
 
@@ -1983,9 +1992,14 @@ int refs_create_symref(struct ref_store *refs,
 		       const char *refs_heads_master,
 		       const char *logmsg)
 {
-	return refs->be->create_symref(refs, ref_target,
-				       refs_heads_master,
-				       logmsg);
+	char *msg;
+	int retval;
+
+	msg = normalize_reflog_message(logmsg);
+	retval = refs->be->create_symref(refs, ref_target, refs_heads_master,
+					 msg);
+	free(msg);
+	return retval;
 }
 
 int create_symref(const char *ref_target, const char *refs_heads_master,
@@ -2370,10 +2384,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
 	return refs->be->initial_transaction_commit(refs, transaction, err);
 }
 
-int refs_delete_refs(struct ref_store *refs, const char *msg,
+int refs_delete_refs(struct ref_store *refs, const char *logmsg,
 		     struct string_list *refnames, unsigned int flags)
 {
-	return refs->be->delete_refs(refs, msg, refnames, flags);
+	char *msg;
+	int retval;
+
+	msg = normalize_reflog_message(logmsg);
+	retval = refs->be->delete_refs(refs, msg, refnames, flags);
+	free(msg);
+	return retval;
 }
 
 int delete_refs(const char *msg, struct string_list *refnames,
@@ -2385,7 +2405,13 @@ int delete_refs(const char *msg, struct string_list *refnames,
 int refs_rename_ref(struct ref_store *refs, const char *oldref,
 		    const char *newref, const char *logmsg)
 {
-	return refs->be->rename_ref(refs, oldref, newref, logmsg);
+	char *msg;
+	int retval;
+
+	msg = normalize_reflog_message(logmsg);
+	retval = refs->be->rename_ref(refs, oldref, newref, msg);
+	free(msg);
+	return retval;
 }
 
 int rename_ref(const char *oldref, const char *newref, const char *logmsg)
@@ -2396,7 +2422,13 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
 		    const char *newref, const char *logmsg)
 {
-	return refs->be->copy_ref(refs, oldref, newref, logmsg);
+	char *msg;
+	int retval;
+
+	msg = normalize_reflog_message(logmsg);
+	retval = refs->be->copy_ref(refs, oldref, newref, msg);
+	free(msg);
+	return retval;
 }
 
 int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 6516c7bc8c..e0aba23eb2 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1629,7 +1629,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
 
 	strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
 	if (msg && *msg)
-		copy_reflog_msg(&sb, msg);
+		strbuf_addstr(&sb, msg);
 	strbuf_addch(&sb, '\n');
 	if (write_in_full(fd, sb.buf, sb.len) < 0)
 		ret = -1;
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 4271362d26..357359a0be 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -96,12 +96,6 @@ enum peel_status {
  */
 enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
 
-/*
- * Copy the reflog message msg to sb while cleaning up the whitespaces.
- * Especially, convert LF to space, because reflog file is one line per entry.
- */
-void copy_reflog_msg(struct strbuf *sb, const char *msg);
-
 /**
  * Information needed for a single ref update. Set new_oid to the new
  * value or to null_oid to delete the ref. To check the old value
-- 
gitgitgadget

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

* Re: [PATCH v2 0/4] Preliminary fixes for reftable support
  2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
                     ` (3 preceding siblings ...)
  2020-07-10 17:19   ` [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer Junio C Hamano via GitGitGadget
@ 2020-07-10 20:57   ` Junio C Hamano
  4 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2020-07-10 20:57 UTC (permalink / raw)
  To: Han-Wen Nienhuys via GitGitGadget; +Cc: git, Han-Wen Nienhuys

"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> These are assorted small fixes split out from the reftable topic.

Will replace.  I'll retitle the 3/4 and 4/4 to

    bisect: treat BISECT_HEAD as a pseudo ref
    reflgo: cleanse messages in the refs.c layer

while queuing.

Thanks.

> Han-Wen Nienhuys (3):
>   lib-t6000.sh: write tag using git-update-ref
>   t3432: use git-reflog to inspect the reflog for HEAD
>   Treat BISECT_HEAD as a pseudo ref
>
> Junio C Hamano (1):
>   Cleanse reflog messages in the refs.c layer
>
>  builtin/bisect--helper.c       |  3 +-
>  git-bisect.sh                  |  4 +--
>  refs.c                         | 50 ++++++++++++++++++++++++++++------
>  refs/files-backend.c           |  2 +-
>  refs/refs-internal.h           |  6 ----
>  t/lib-t6000.sh                 |  5 ++--
>  t/t3432-rebase-fast-forward.sh |  7 +++--
>  7 files changed, 51 insertions(+), 26 deletions(-)
>
>
> base-commit: bd42bbe1a46c0fe486fc33e82969275e27e4dc19
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-669%2Fhanwen%2Fpreliminaries-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-669/hanwen/preliminaries-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/669
>
> Range-diff vs v1:
>
>  1:  b7b2ad8e79 = 1:  0f244ed6cb lib-t6000.sh: write tag using git-update-ref
>  2:  f238d1d7f8 ! 2:  123d246edf t3432: use git-reflog to inspect the reflog for HEAD
>      @@ t/t3432-rebase-fast-forward.sh: test_rebase_same_head_ () {
>        		oldhead=\$(git rev-parse HEAD) &&
>        		test_when_finished 'git reset --hard \$oldhead' &&
>       -		cp .git/logs/HEAD expect &&
>      -+		git reflog HEAD > expect &&
>      ++		git reflog HEAD >expect &&
>        		git rebase$flag $* >stdout &&
>      -+		git reflog HEAD > actual &&
>      ++		git reflog HEAD >actual &&
>        		if test $what = work
>        		then
>        			old=\$(wc -l <expect) &&
>  3:  8a62cc2668 < -:  ---------- checkout: add '\n' to reflog message
>  4:  2b7eb58c15 = 3:  d4007c2a5b Treat BISECT_HEAD as a pseudo ref
>  -:  ---------- > 4:  6ca5b99c8d Cleanse reflog messages in the refs.c layer

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

* Re: [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer
  2020-07-10 17:19   ` [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer Junio C Hamano via GitGitGadget
@ 2020-07-10 21:06     ` Junio C Hamano
  0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2020-07-10 21:06 UTC (permalink / raw)
  To: Junio C Hamano via GitGitGadget; +Cc: git, Han-Wen Nienhuys

"Junio C Hamano via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Currently, the cleansing of the reflog message is done by the files
> backend, before the log is written out.  This is sufficient with the
> current code, as that is the only backend that writes reflogs.  But
> new backends can be added that write reflogs, and we'd want the
> resulting log message we would read out of "log -g" the same no
> matter what backend is used.

I _think_ there is no correctness impact, but this slightly changes
the semantics.  We used to take whatever random string from the
caller and at the lowest layer of the files backend, i.e.

>  	strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
>  	if (msg && *msg)
> -		copy_reflog_msg(&sb, msg);
> +		strbuf_addstr(&sb, msg);

cleansed and added the message to strbuf.

With the updated code, normalize_reflog_message() is defined like so

> +static char *normalize_reflog_message(const char *msg)
> +{
> +	struct strbuf sb = STRBUF_INIT;
> +
> +	if (msg && *msg)
> +		copy_reflog_msg(&sb, msg);
> +	return strbuf_detach(&sb, NULL);
> +}

to always return a non-NULL but an empty string, even if the caller
gave us a NULL pointer.  We always pass a non-NULL string around,
and the updated low-level code avoids calling strbuf_addstr()
because msg is not NULL, but *msg is '\0'.

We _might_ be able to optimize by tweaking the normalizer a bit
further, perhaps like so:

    static char *normalize_reflog_message(const char *msg)
    {
            struct strbuf sb = STRBUF_INIT;

            if (msg && *msg)
                    copy_reflog_msg(&sb, msg);
            if (sb.len) {
                    return strbuf_detach(&sb, NULL);
            } else {
                    strbuf_release(&sb);
                    return NULL;
            }
    }

to avoid allocating 1 byte '\0' on the heap by strbuf_detach() when
sb here ends up being truly empty.

But it would be a premature optimization to worry about such a thing
at this point, I think.

Thanks.

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

end of thread, other threads:[~2020-07-10 21:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 12:05 [PATCH 0/4] Preliminary fixes for reftable support Han-Wen Nienhuys via GitGitGadget
2020-06-30 12:05 ` [PATCH 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
2020-06-30 12:05 ` [PATCH 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
2020-06-30 12:05 ` [PATCH 3/4] checkout: add '\n' to reflog message Han-Wen Nienhuys via GitGitGadget
2020-06-30 12:05 ` [PATCH 4/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
2020-07-07  4:40 ` [PATCH 0/4] Preliminary fixes for reftable support Junio C Hamano
2020-07-10 17:19 ` [PATCH v2 " Han-Wen Nienhuys via GitGitGadget
2020-07-10 17:19   ` [PATCH v2 1/4] lib-t6000.sh: write tag using git-update-ref Han-Wen Nienhuys via GitGitGadget
2020-07-10 17:19   ` [PATCH v2 2/4] t3432: use git-reflog to inspect the reflog for HEAD Han-Wen Nienhuys via GitGitGadget
2020-07-10 17:19   ` [PATCH v2 3/4] Treat BISECT_HEAD as a pseudo ref Han-Wen Nienhuys via GitGitGadget
2020-07-10 17:19   ` [PATCH v2 4/4] Cleanse reflog messages in the refs.c layer Junio C Hamano via GitGitGadget
2020-07-10 21:06     ` Junio C Hamano
2020-07-10 20:57   ` [PATCH v2 0/4] Preliminary fixes for reftable support Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).