Skip to contentSkip to conversation

backfill: error out when HEAD cannot be parsed

PATCH Superseded Trieu Huynh 3 participants 4 messages Mar 29 – Mar 30

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backfill: error out when HEAD cannot be parsed

handle_revision_arg() returns non-zero on failure, but do_backfill() ignored the return value. On an empty repo with no commits, HEAD is unborn and handle_revision_arg() fails, but backfill silently continues with an empty revision walk and exits zero, looks like success but did nothing.

Check the return value and propagate the error, consistent with how builtin/pack-objects.c handles handle_revision_arg() failures.

Add a test to verify that backfill on an empty repository fails with a clear error message.

---
 builtin/backfill.c  | 3 ++-
 t/t5620-backfill.sh | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
builtin/backfill.c +2 -1
index 27a301f9b2..4b2db94173 100644
@@ -96,7 +96,8 @@ static int do_backfill(struct backfill_context *ctx)
 	}
 
 	repo_init_revisions(ctx->repo, &revs, "");
-	handle_revision_arg("HEAD", &revs, 0, 0);
+	if (handle_revision_arg("HEAD", &revs, 0, 0))
+		return error(_("unable to parse HEAD revision"));
 
 	info.blobs = 1;
 	info.tags = info.commits = info.trees = 0;
t/t5620-backfill.sh +6 -0
index ff67e8ecea..91b5115732 100755
@@ -101,6 +101,12 @@ test_expect_success 'backfill no flag on non-TTY is silent' '
 	test_grep ! "Downloading batches" err
 '
 
+test_expect_success 'backfill on empty repo fails gracefully' '
+	git init empty-repo &&
+	test_must_fail git -C empty-repo backfill 2>err &&
+	grep "unable to parse HEAD" err
+'
+
 test_expect_success 'backfill --sparse without sparse-checkout fails' '
 	git init not-sparse &&
 	test_must_fail git -C not-sparse backfill --sparse 2>err &&
Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines · Trieu Huynh

handle_revision_arg() returns non-zero on failure, but do_backfill() ignored the return value. On an empty repo with no commits, HEAD is

Nit: s/ignored/ignores

We use present tense in the commit message. See the 'present-tense' section in 'Documentation/SubmittingPatches' for more info.

Quoted 3 lines

unborn and handle_revision_arg() fails, but backfill silently continues with an empty revision walk and exits zero, looks like success but did nothing.

Perhaps: we want to say 'and silently exists with a zero return code.' to be more explicit.

Quoted 3 lines

Check the return value and propagate the error, consistent with how builtin/pack-objects.c handles handle_revision_arg() failures.

Nice.

Quoted 14 lines

Add a test to verify that backfill on an empty repository fails with a clear error message.

---
 builtin/backfill.c  | 3 ++-
 t/t5620-backfill.sh | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
builtin/backfill.c +0 -0
index 27a301f9b2..4b2db94173 100644

builtin/backfill.c static int do_backfill(struct backfill_context *ctx) · line 101

Quoted 7 lines
builtin/backfill.c +2 -1
@@ -96,7 +96,8 @@ static int do_backfill(struct backfill_context *ctx)
 	}
 
 	repo_init_revisions(ctx->repo, &revs, "");
-	handle_revision_arg("HEAD", &revs, 0, 0);
+	if (handle_revision_arg("HEAD", &revs, 0, 0))
+		return error(_("unable to parse HEAD revision"));
 

Makes sense.

Quoted 7 lines
builtin/backfill.c +0 -0
 	info.blobs = 1;
 	info.tags = info.commits = info.trees = 0;
t/t5620-backfill.sh +0 -0
index ff67e8ecea..91b5115732 100755

t/t5620-backfill.sh test_expect_success 'backfill no flag on non-TTY is silent' ' · line 109

Quoted 9 lines
t/t5620-backfill.sh +6 -0
@@ -101,6 +101,12 @@ test_expect_success 'backfill no flag on non-TTY is silent' '
 	test_grep ! "Downloading batches" err
 '
 
+test_expect_success 'backfill on empty repo fails gracefully' '
+	git init empty-repo &&
+	test_must_fail git -C empty-repo backfill 2>err &&
+	grep "unable to parse HEAD" err
+'
+

Looks good. Thanks

Quoted 5 lines
t/t5620-backfill.sh +0 -1
 test_expect_success 'backfill --sparse without sparse-checkout fails' '
 	git init not-sparse &&
 	test_must_fail git -C not-sparse backfill --sparse 2>err &&
--

2.43.0

#2 lore raw
In reply to Trieu Huynh
Quoted 6 lines · Trieu Huynh

handle_revision_arg() returns non-zero on failure, but do_backfill() ignored the return value. On an empty repo with no commits, HEAD is unborn and handle_revision_arg() fails, but backfill silently continues with an empty revision walk and exits zero, looks like success but did nothing.

Quoted 6 lines

Check the return value and propagate the error, consistent with how builtin/pack-objects.c handles handle_revision_arg() failures.

Add a test to verify that backfill on an empty repository fails with a clear error message.

Aside from the minor flaws Karthik mentioned, I think this commit message is spot on.

Quoted 11 lines
---
  builtin/backfill.c  | 3 ++-
  t/t5620-backfill.sh | 6 ++++++
  2 files changed, 8 insertions(+), 1 deletion(-)
builtin/backfill.c +0 -0
index 27a301f9b2..4b2db94173 100644

builtin/backfill.c static int do_backfill(struct backfill_context *ctx) · line 101

Quoted 7 lines
builtin/backfill.c +2 -1
@@ -96,7 +96,8 @@ static int do_backfill(struct backfill_context *ctx)
  	}
 
  	repo_init_revisions(ctx->repo, &revs, "");
-	handle_revision_arg("HEAD", &revs, 0, 0);
+	if (handle_revision_arg("HEAD", &revs, 0, 0))
+		return error(_("unable to parse HEAD revision"));
 

Looks good to me.

Quoted 7 lines
builtin/backfill.c +0 -0
  	info.blobs = 1;
  	info.tags = info.commits = info.trees = 0;
t/t5620-backfill.sh +0 -0
index ff67e8ecea..91b5115732 100755

t/t5620-backfill.sh test_expect_success 'backfill no flag on non-TTY is silent' ' · line 107

Quoted 7 lines
t/t5620-backfill.sh +4 -0
@@ -101,6 +101,12 @@ test_expect_success 'backfill no flag on non-TTY is silent' '
  	test_grep ! "Downloading batches" err
  '
 
+test_expect_success 'backfill on empty repo fails gracefully' '
+	git init empty-repo &&
+	test_must_fail git -C empty-repo backfill 2>err &&
+	grep "unable to parse HEAD" err

Remember your last patch? Wouldn't it be better to use 'test_grep' here? It's easy to see that the original code uses 'test_grep' (a few lines above):

> test_grep ! "Downloading batches" err

Wouldn't it be better to maintain consistency? ;)

t/t5620-backfill.sh test_expect_success 'backfill no flag on non-TTY is silent' ' · line 112

Quoted 5 lines
t/t5620-backfill.sh +2 -0
+'
+
  test_expect_success 'backfill --sparse without sparse-checkout fails' '
  	git init not-sparse &&
  	test_must_fail git -C not-sparse backfill --sparse 2>err &&

Regards,

Yuchen

#3 lore raw
Quoted 54 lines · Tian Yuchen
Quoted 6 lines · Trieu Huynh

handle_revision_arg() returns non-zero on failure, but do_backfill() ignored the return value. On an empty repo with no commits, HEAD is unborn and handle_revision_arg() fails, but backfill silently continues with an empty revision walk and exits zero, looks like success but did nothing.

Quoted 6 lines

Check the return value and propagate the error, consistent with how builtin/pack-objects.c handles handle_revision_arg() failures.

Add a test to verify that backfill on an empty repository fails with a clear error message.

Aside from the minor flaws Karthik mentioned, I think this commit message is spot on.

Quoted 11 lines
---
  builtin/backfill.c  | 3 ++-
  t/t5620-backfill.sh | 6 ++++++
  2 files changed, 8 insertions(+), 1 deletion(-)
builtin/backfill.c +0 -0
index 27a301f9b2..4b2db94173 100644

builtin/backfill.c static int do_backfill(struct backfill_context *ctx) · line 99

Quoted 5 lines
builtin/backfill.c +2 -1
@@ -96,7 +96,8 @@ static int do_backfill(struct backfill_context *ctx)
  	}
  	repo_init_revisions(ctx->repo, &revs, "");
-	handle_revision_arg("HEAD", &revs, 0, 0);
+	if (handle_revision_arg("HEAD", &revs, 0, 0))
+		return error(_("unable to parse HEAD revision"));

Looks good to me.

t/t5620-backfill.sh test_expect_success 'backfill no flag on non-TTY is silent' ' · line 106

Quoted 13 lines
builtin/backfill.c +0 -0
  	info.blobs = 1;
  	info.tags = info.commits = info.trees = 0;
t/t5620-backfill.sh +4 -0
index ff67e8ecea..91b5115732 100755
@@ -101,6 +101,12 @@ test_expect_success 'backfill no flag on non-TTY is silent' '
  	test_grep ! "Downloading batches" err
  '
+test_expect_success 'backfill on empty repo fails gracefully' '
+	git init empty-repo &&
+	test_must_fail git -C empty-repo backfill 2>err &&
+	grep "unable to parse HEAD" err

Remember your last patch? Wouldn't it be better to use 'test_grep' here? It's easy to see that the original code uses 'test_grep' (a few lines above):

Quoted 3 lines

> test_grep ! "Downloading batches" err

Wouldn't it be better to maintain consistency? ;)

thanks for the spot.

Quoted 11 lines

t/t5620-backfill.sh test_expect_success 'backfill no flag on non-TTY is silent' ' · line 112

Quoted 6 lines
t/t5620-backfill.sh +2 -0
+'
+
  test_expect_success 'backfill --sparse without sparse-checkout fails' '
  	git init not-sparse &&
  	test_must_fail git -C not-sparse backfill --sparse 2>err &&

Regards,

Yuchen

acked, will submit v2, shortly.