Skip to content

Commit

Permalink
Merge branch 'ua/t3404-cleanup' into jch
Browse files Browse the repository at this point in the history
Test update.

* ua/t3404-cleanup:
  parse: replace atoi() with strtoul_ui() and strtol_i()
  t3404: replace test with test_line_count()
  t3404: avoid losing exit status with focus on `git show` and `git cat-file`
  • Loading branch information
ttaylorr committed Oct 18, 2024
2 parents 84f5925 + 40cd9d8 commit f8cc52b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 39 deletions.
14 changes: 9 additions & 5 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,17 +1308,21 @@ int cmd_main(int argc, const char **argv)
continue;
}
if (skip_prefix(arg, "--timeout=", &v)) {
timeout = atoi(v);
if (strtoul_ui(v, 10, &timeout) < 0) {
die("'%s': not a valid integer for --timeout", v);
}
continue;
}
if (skip_prefix(arg, "--init-timeout=", &v)) {
init_timeout = atoi(v);
if (strtoul_ui(v, 10, &init_timeout) < 0) {
die("'%s': not a valid integer for --init-timeout", v);
}
continue;
}
if (skip_prefix(arg, "--max-connections=", &v)) {
max_connections = atoi(v);
if (max_connections < 0)
max_connections = 0; /* unlimited */
if (strtol_i(v, 10, &max_connections) != 0 || max_connections < 0) {
max_connections = 0; /* unlimited */
}
continue;
}
if (!strcmp(arg, "--strict-paths")) {
Expand Down
13 changes: 8 additions & 5 deletions imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
return RESP_BAD;
}
if (!strcmp("UIDVALIDITY", arg)) {
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) != 0) {
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
return RESP_BAD;
}
} else if (!strcmp("UIDNEXT", arg)) {
if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) {
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) != 0) {
fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
return RESP_BAD;
}
Expand All @@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
for (; isspace((unsigned char)*p); p++);
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
if (!(arg = next_arg(&s)) || (strtol_i(arg, 10, &ctx->uidvalidity) != 0) ||
!(arg = next_arg(&s)) || (strtol_i(arg, 10, (int *)cb->ctx) != 0)) {
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
return RESP_BAD;
}
Expand Down Expand Up @@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
if (!tcmd)
return DRV_OK;
} else {
tag = atoi(arg);
if (strtol_i(arg, 10, &tag) != 0) {
fprintf(stderr, "IMAP error: malformed tag %s\n", arg);
return RESP_BAD;
}
for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
if (cmdp->tag == tag)
goto gottag;
Expand Down
6 changes: 2 additions & 4 deletions merge-ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
git_check_attr(istate, path, check);
ll_driver_name = check->items[0].value;
if (check->items[1].value) {
marker_size = atoi(check->items[1].value);
if (marker_size <= 0)
if (strtol_i(check->items[1].value, 10, &marker_size) != 0 || marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
}
driver = find_ll_merge_driver(ll_driver_name);
Expand All @@ -454,8 +453,7 @@ int ll_merge_marker_size(struct index_state *istate, const char *path)
check = attr_check_initl("conflict-marker-size", NULL);
git_check_attr(istate, path, check);
if (check->items[0].value) {
marker_size = atoi(check->items[0].value);
if (marker_size <= 0)
if (strtol_i(check->items[0].value, 10, &marker_size) != 0 || marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
}
return marker_size;
Expand Down
75 changes: 50 additions & 25 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ test_expect_success 'stop on conflicting pick' '
test_cmp expect2 file1 &&
test "$(git diff --name-status |
sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
grep -v "^#" <.git/rebase-merge/done >actual &&
test_line_count = 4 actual &&
test 0 = $(grep -c "^[^#]" <.git/rebase-merge/git-rebase-todo)
'

test_expect_success 'show conflicted patch' '
Expand Down Expand Up @@ -319,7 +320,8 @@ test_expect_success 'retain authorship' '
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
git tag twerp &&
git rebase -i --onto primary HEAD^ &&
git show HEAD | grep "^Author: Twerp Snog"
git show HEAD >actual &&
grep "^Author: Twerp Snog" actual
'

test_expect_success 'retain authorship w/ conflicts' '
Expand Down Expand Up @@ -360,7 +362,8 @@ test_expect_success 'squash' '
'

test_expect_success 'retain authorship when squashing' '
git show HEAD | grep "^Author: Twerp Snog"
git show HEAD >actual &&
grep "^Author: Twerp Snog" actual
'

test_expect_success '--continue tries to commit' '
Expand All @@ -374,7 +377,8 @@ test_expect_success '--continue tries to commit' '
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
) &&
test_cmp_rev HEAD^ new-branch1 &&
git show HEAD | grep chouette
git show HEAD >actual &&
grep chouette actual
'

test_expect_success 'verbose flag is heeded, even after --continue' '
Expand All @@ -397,7 +401,9 @@ test_expect_success 'multi-squash only fires up editor once' '
git rebase -i $base
) &&
test $base = $(git rev-parse HEAD^) &&
test 1 = $(git show | grep ONCE | wc -l)
git show >output &&
grep ONCE output >actual &&
test_line_count = 1 actual
'

test_expect_success 'multi-fixup does not fire up editor' '
Expand All @@ -410,7 +416,8 @@ test_expect_success 'multi-fixup does not fire up editor' '
git rebase -i $base
) &&
test $base = $(git rev-parse HEAD^) &&
test 0 = $(git show | grep NEVER | wc -l) &&
git show >output &&
! grep NEVER output &&
git checkout @{-1} &&
git branch -D multi-fixup
'
Expand All @@ -428,7 +435,9 @@ test_expect_success 'commit message used after conflict' '
git rebase --continue
) &&
test $base = $(git rev-parse HEAD^) &&
test 1 = $(git show | grep ONCE | wc -l) &&
git show >output &&
grep ONCE output >actual &&
test_line_count = 1 actual &&
git checkout @{-1} &&
git branch -D conflict-fixup
'
Expand All @@ -446,7 +455,9 @@ test_expect_success 'commit message retained after conflict' '
git rebase --continue
) &&
test $base = $(git rev-parse HEAD^) &&
test 2 = $(git show | grep TWICE | wc -l) &&
git show >output &&
grep TWICE output >actual &&
test_line_count = 2 actual &&
git checkout @{-1} &&
git branch -D conflict-squash
'
Expand All @@ -470,10 +481,10 @@ test_expect_success 'squash and fixup generate correct log messages' '
) &&
git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
test_cmp expect-squash-fixup actual-squash-fixup &&
git cat-file commit HEAD@{2} |
grep "^# This is a combination of 3 commits\." &&
git cat-file commit HEAD@{3} |
grep "^# This is a combination of 2 commits\." &&
git cat-file commit HEAD@{2} >actual &&
grep "^# This is a combination of 3 commits\." actual &&
git cat-file commit HEAD@{3} >actual &&
grep "^# This is a combination of 2 commits\." actual &&
git checkout @{-1} &&
git branch -D squash-fixup
'
Expand All @@ -489,7 +500,9 @@ test_expect_success 'squash ignores comments' '
git rebase -i $base
) &&
test $base = $(git rev-parse HEAD^) &&
test 1 = $(git show | grep ONCE | wc -l) &&
git show >output &&
grep ONCE output >actual &&
test_line_count = 1 actual &&
git checkout @{-1} &&
git branch -D skip-comments
'
Expand All @@ -505,7 +518,9 @@ test_expect_success 'squash ignores blank lines' '
git rebase -i $base
) &&
test $base = $(git rev-parse HEAD^) &&
test 1 = $(git show | grep ONCE | wc -l) &&
git show >output &&
grep ONCE output >actual &&
test_line_count = 1 actual &&
git checkout @{-1} &&
git branch -D skip-blank-lines
'
Expand Down Expand Up @@ -572,7 +587,8 @@ test_expect_success '--continue tries to commit, even for "edit"' '
FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
) &&
test edited = $(git show HEAD:file7) &&
git show HEAD | grep chouette &&
git show HEAD >actual &&
grep chouette actual &&
test $parent = $(git rev-parse HEAD^)
'

Expand Down Expand Up @@ -757,19 +773,23 @@ test_expect_success 'reword' '
set_fake_editor &&
FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
git rebase -i A &&
git show HEAD | grep "E changed" &&
git show HEAD >actual &&
grep "E changed" actual &&
test $(git rev-parse primary) != $(git rev-parse HEAD) &&
test_cmp_rev primary^ HEAD^ &&
FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
git rebase -i A &&
git show HEAD^ | grep "D changed" &&
git show HEAD^ >actual &&
grep "D changed" actual &&
FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
git rebase -i A &&
git show HEAD~3 | grep "B changed" &&
git show HEAD~3 >actual &&
grep "B changed" actual &&
FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
git rebase -i A
) &&
git show HEAD~2 | grep "C changed"
git show HEAD~2 >actual &&
grep "C changed" actual
'

test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' '
Expand Down Expand Up @@ -1003,8 +1023,10 @@ test_expect_success 'rebase -i --root retain root commit author and message' '
set_fake_editor &&
FAKE_LINES="2" git rebase -i --root
) &&
git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
git cat-file commit HEAD | grep -q "^different author$"
git cat-file commit HEAD >output &&
grep -q "^author Twerp Snog" output &&
git cat-file commit HEAD >actual &&
grep -q "^different author$" actual
'

test_expect_success 'rebase -i --root temporary sentinel commit' '
Expand All @@ -1013,7 +1035,8 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
set_fake_editor &&
test_must_fail env FAKE_LINES="2" git rebase -i --root
) &&
git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
git cat-file commit HEAD >actual &&
grep "^tree $EMPTY_TREE" actual &&
git rebase --abort
'

Expand All @@ -1036,7 +1059,8 @@ test_expect_success 'rebase -i --root reword original root commit' '
FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
git rebase -i --root
) &&
git show HEAD^ | grep "A changed" &&
git show HEAD^ >actual &&
grep "A changed" actual &&
test -z "$(git show -s --format=%p HEAD^)"
'

Expand All @@ -1048,7 +1072,8 @@ test_expect_success 'rebase -i --root reword new root commit' '
FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
git rebase -i --root
) &&
git show HEAD^ | grep "C changed" &&
git show HEAD^ >actual &&
grep "C changed" actual &&
test -z "$(git show -s --format=%p HEAD^)"
'

Expand Down

0 comments on commit f8cc52b

Please sign in to comment.