=== Applying patches on top of PostgreSQL commit ID 1200dfd60c367e97a5e1f31100d82072eb0178b6 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Thu Aug 6 03:30:33 UTC 2026 On branch cf/6435 nothing to commit, working tree clean === using 'git am' to apply patch ./v6-0001-Address-feedback-on-changed-pg_regress-output.patch === Applying: Address feedback on changed pg_regress output Using index info to reconstruct a base tree... M src/test/regress/pg_regress.c Falling back to patching base and 3-way merge... Auto-merging src/test/regress/pg_regress.c CONFLICT (content): Merge conflict in src/test/regress/pg_regress.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Address feedback on changed pg_regress output When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". === using patch(1) to apply patch ./v6-0001-Address-feedback-on-changed-pg_regress-output.patch === patching file src/test/regress/pg_regress.c Hunk #3 FAILED at 1536. Hunk #4 FAILED at 1549. Hunk #5 succeeded at 1693 (offset 2 lines). Hunk #6 succeeded at 1890 (offset 2 lines). Hunk #7 succeeded at 1972 (offset 2 lines). Hunk #8 succeeded at 2721 (offset 2 lines). 2 out of 8 hunks FAILED -- saving rejects to file src/test/regress/pg_regress.c.rej Unstaged changes after reset: M src/test/regress/pg_regress.c Removing src/test/regress/pg_regress.c.rej === using 'git apply' to apply patch ./v6-0001-Address-feedback-on-changed-pg_regress-output.patch === Applied patch to 'src/test/regress/pg_regress.c' with conflicts. U src/test/regress/pg_regress.c diff --cc src/test/regress/pg_regress.c index 21d00f792d2,a2979ce0fa2..00000000000 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@@ -1534,84 -1534,113 +1534,143 @@@ results_differ(const char *testname, co */ difffile = fopen(difffilename, "a"); ++<<<<<<< ours + if (!difffile) + bail("could not open file \"%s\" for writing: %m", difffilename); + startpos = ftell(difffile); + + /* Write diff header */ + fprintf(difffile, + "diff %s %s %s\n", + pretty_diff_opts, best_expect_file, resultsfile); + fclose(difffile); + + /* Run diff */ + snprintf(cmd, sizeof(cmd), + "diff %s \"%s\" \"%s\" >> \"%s\"", + pretty_diff_opts, best_expect_file, resultsfile, difffilename); + run_diff(cmd, difffilename); + + /* + * Emit the diff output as TAP diagnostics + * + * Reopen the file for reading. We can't keep the file open while diff + * appends to it, because on Windows the file lock prevents diff from + * writing. + */ + difffile = fopen(difffilename, "r"); + if (!difffile) + bail("could not open file \"%s\" for reading: %m", difffilename); + else ++======= + if (difffile) { - /* - * In case of a crash the diff can be huge and all of the subsequent - * tests will fail with essentially useless diffs too. So to avoid - * flooding the output, while still providing useful info in most - * cases we output only the first 80 lines of the *combined* diff. The - * number 80 is chosen so that we output less than 100 lines of - * diagnostics per pg_regress run. Otherwise if meson is run with the - * --quiet flag only the last 100 lines are shown and usually the most - * useful information is actually in the first few lines. - */ - static int nlines = 0; - const int max_diff_lines = 80; - char line[1024]; + /* Write diff header */ + fprintf(difffile, + "diff %s %s %s\n", + pretty_diff_opts, best_expect_file, resultsfile); + fclose(difffile); - fseek(difffile, startpos, SEEK_SET); - while (nlines < max_diff_lines && - fgets(line, sizeof(line), difffile)) - { - size_t len = strlen(line); - bool newline_found = (len > 0 && line[len - 1] == '\n'); + /* Run diff */ + snprintf(cmd, sizeof(cmd), + "diff %s \"%s\" \"%s\" >> \"%s\"", + pretty_diff_opts, best_expect_file, resultsfile, difffilename); + run_diff(cmd, difffilename); + } - if (newline_found) - line[len - 1] = '\0'; + unlink(diff); + return true; + } - diag_detail("%s", line); - if (newline_found) - { - diag_end(); - nlines++; - } - } + /* + * Emit the head of the combined regression.diffs file as TAP diagnostics. + * + * Called once at the end of a run so that diff output appears as a single + * summary block after all per-test status lines, rather than interleaved with + * them. We cap at max_diff_lines lines: in case of a crash the diff can be + * huge and all subsequent tests fail with essentially useless diffs too; + * truncating keeps the output digestible (and avoids the meson --quiet last-100 + * window pushing the actually-useful lines off the screen). + */ + static void + emit_diff_head(void) + { + /* + * Default cap on the size of the diff summary, overridable via the + * PG_REGRESS_DIFF_LINES environment variable. Reliable cross-platform + * terminal-size detection (including from under meson/Perl TAP harnesses + * that hide the controlling tty) is more trouble than it's worth, so we + * just let the caller dial it in when the default doesn't suit them. + */ + const char *env_lines = getenv("PG_REGRESS_DIFF_LINES"); + int max_diff_lines = (env_lines && atoi(env_lines) > 0) ? atoi(env_lines) : 50; - if (in_diag) + /* + * Assumed terminal width when accounting for line wrap. We charge each + * wrapped row against the line budget so a handful of very long diff + * lines doesn't blow past the budget visually. As explained in the + * previous comment, we don't attempt to detect the actual terminal size, + * so instead we just pick 80 as a sensible terminal width. If that + * doesn't match the actual size, the visual line count will be off, but + * generally not by too much. + */ + const int term_width = 80; + FILE *difffile; + int nlines = 0; + char line[1024]; + + /* + * Accumulates the content length of the current physical line across + * fgets() chunks; a single line longer than sizeof(line) is split over + * multiple iterations, so we can't compute its visual width until we see + * the newline that ends it. Start at 2 to account for the "# " TAP diag + * prefix that will be added to each line. + */ + size_t current_line_length = 2; + + difffile = fopen(difffilename, "r"); + if (!difffile) + return; + + while (nlines < max_diff_lines && + fgets(line, sizeof(line), difffile)) ++>>>>>>> theirs + { + size_t len = strlen(line); + bool newline_found = (len > 0 && line[len - 1] == '\n'); + + current_line_length += len; + + if (newline_found) + line[len - 1] = '\0'; + + diag_detail("%s", line); + + if (newline_found) { /* - * If there was no final newline for some reason, we should still - * end the diagnostic. + * Total characters the line paints on screen, including the "# " + * TAP diag prefix. Ceiling-divide by terminal width to get the + * number of visual rows. */ + nlines += current_line_length / term_width + 1; + current_line_length = 2; diag_end(); - nlines++; } + } - if (nlines >= max_diff_lines) - diag("(diff output truncated and silencing output for further failing tests...)"); - - fclose(difffile); + if (in_diag) + { + /* No trailing newline; still close out the diag line. */ + diag_end(); + nlines++; } - unlink(diff); - return true; + if (nlines >= max_diff_lines) + diag("(diff output truncated; see \"%s\" for the full diff, or raise PG_REGRESS_DIFF_LINES to show more)", + difffilename); + + fclose(difffile); } /*