From 4520ef02abe1c2a124b979d6da0c911c8aa85f87 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Sun, 4 Aug 2024 22:38:23 +0900 Subject: [PATCH 1/2] Ignore initial spaces in locating a line for anchor --- .ci/create-changes-html.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.ci/create-changes-html.sh b/.ci/create-changes-html.sh index 2cca91d81c8..6b5c431c7de 100755 --- a/.ci/create-changes-html.sh +++ b/.ci/create-changes-html.sh @@ -83,12 +83,18 @@ for block in diff_blocks: hunk_lines = [] search_result = re.search(r'@@ -(\d+),(\d+) \+(\d+),(\d+)', line) if search_result: - line_number = int(search_result.group(3)) + line_number = int(search_result.group(3)) - 1 span = int(search_result.group(4)) - for i in chain(range(line_number, line_number + span), range(line_number - 1, -1, -1)): - if content[i].startswith('<') and not content[i].startswith('' + content[i] + content[i] = ln[:idx] + f'' + ln[idx:] hunks.append(f'

hunk #{count}

') break hunk_lines.append(line) From 0a60a0e11ee000ececb1d5e97480c1a784369c12 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Mon, 5 Aug 2024 00:16:19 +0900 Subject: [PATCH 2/2] Fix merge conflicts #38467 --- .ci/create-changes-html.sh | 21 +++++++++++---------- .github/workflows/doc-build.yml | 7 ++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.ci/create-changes-html.sh b/.ci/create-changes-html.sh index 6b5c431c7de..ee21416cb65 100755 --- a/.ci/create-changes-html.sh +++ b/.ci/create-changes-html.sh @@ -1,12 +1,11 @@ #!/bin/sh -if [ $# != 2 ]; then - echo >&2 "usage: $0 BASE_DOC_COMMIT DOC_REPO" +if [ $# != 1 ]; then + echo >&2 "usage: $0 DIFF_TEXT" echo >&2 "creates CHANGES.html in the current directory" - echo >&2 "for the diffs of DOC_REPO against BASE_DOC_COMMIT" + echo >&2 "for the diffs in the file DIFF_TEXT" exit 1 fi -BASE_DOC_COMMIT="$1" -DOC_REPOSITORY="$2" +DIFF_TEXT="$1" # Create CHANGES.html echo '' > CHANGES.html @@ -52,11 +51,10 @@ diffParagraphs.forEach(paragraph => { EOF echo '' >> CHANGES.html echo '' >> CHANGES.html -(cd $DOC_REPOSITORY && git diff $BASE_DOC_COMMIT -- "*.html") > diff.txt python3 - << EOF import os, re, html from itertools import chain -with open('diff.txt', 'r') as f: +with open('$DIFF_TEXT', 'r') as f: diff_text = f.read() diff_blocks = re.split(r'^(?=diff --git)', diff_text, flags=re.MULTILINE) out_blocks = [] @@ -85,8 +83,11 @@ for block in diff_blocks: if search_result: line_number = int(search_result.group(3)) - 1 span = int(search_result.group(4)) - for i in chain(range(line_number, line_number + span), range(line_number, -1, -1)): - ln = content[i] + for i in chain(range(line_number, line_number + span), range(line_number - 1, -1, -1)): + try: + ln = content[i] + except IndexError: + continue for idx, char in enumerate(ln): if not char.isspace(): break @@ -113,4 +114,4 @@ EOF cat diff.html >> CHANGES.html echo '' >> CHANGES.html echo '' >> CHANGES.html -rm diff.txt diff.html +rm diff.html diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index c5ff832b591..59fbc51944f 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -204,9 +204,10 @@ jobs: -e 's;#L[0-9]*";";' \ && git commit -a -m 'wipe-out') # Since HEAD is at commit 'wipe-out', HEAD~1 is commit 'new' (new doc), HEAD~2 is commit 'old' (old doc) - .ci/create-changes-html.sh $(cd doc && git rev-parse HEAD~2) doc - # Restore the new doc with changes made in create-changes-html.sh but dropping changes by "wipe out" - (cd doc && git stash -q && git checkout -q -f HEAD~1 && git stash pop -q) + (cd doc && git diff $(git rev-parse HEAD~2) -- "*.html") > diff.txt + # Restore the new doc dropping changes by "wipe out" + (cd doc && git checkout -q -f HEAD~1) + .ci/create-changes-html.sh diff.txt # Sometimes rm -rf .git errors out because of some diehard hidden files # So we simply move it out of the doc directory (cd doc && mv .git ../git && mv .gitattributes ../gitattributes)