From d7ca2decd135edf473ace135911d5addf90c0fb1 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 6 Jul 2024 22:03:23 -0700 Subject: [PATCH] Test revert to 65c5863b6bd0 (Merge branch vp/support-git-2.43, 2024-06-15) --- .github/dependabot.yml | 7 ---- Documentation/git-filter-repo.txt | 8 ++-- Makefile | 13 +++--- contrib/filter-repo-demos/clean-ignore | 19 ++++----- contrib/filter-repo-demos/lint-history | 8 +--- git-filter-repo | 31 +++----------- pyproject.toml | 45 -------------------- release/setup.cfg | 32 +++++++++++++++ release/setup.py | 21 ++++++++++ t/run_coverage | 2 +- t/t9390-filter-repo.sh | 53 ------------------------ t/t9390/date-order | 57 -------------------------- t/t9391-filter-repo-lib-usage.sh | 53 ------------------------ t/t9391/emoji-repo | 29 ------------- 14 files changed, 82 insertions(+), 296 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 pyproject.toml create mode 100644 release/setup.cfg create mode 100644 release/setup.py delete mode 100644 t/t9390/date-order delete mode 100644 t/t9391/emoji-repo diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 57995a43..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -version: 2 -updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "monthly" \ No newline at end of file diff --git a/Documentation/git-filter-repo.txt b/Documentation/git-filter-repo.txt index bb00203f..576489b6 100644 --- a/Documentation/git-filter-repo.txt +++ b/Documentation/git-filter-repo.txt @@ -572,9 +572,11 @@ history rewrite are roughly as follows: hosting provider about how to remove any server-side references to the old commits (example: https://docs.gitlab.com/ee/user/project/repository/reducing_the_repo_size_using_git.html[GitLab's - excellent docs on reducing repository size], or - https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository#fully-removing-the-data-from-github[the - first and second steps under "Fully removing the data from GitHub"]). + excellent docs on reducing repository size], or just the warning + box that references "GitHub support" from + https://docs.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository[GitHub's + otherwise dangerously out-of-date docs on removing sensitive + data]). 6. (Optional) Some additional considerations diff --git a/Makefile b/Makefile index d50f3bbc..470bfde1 100644 --- a/Makefile +++ b/Makefile @@ -130,14 +130,15 @@ github_release: update_docs pypi_release: # Has an implicit dependency on github_release because... # Upload to PyPI, automatically picking tag created by github_release - python3 -m venv venv - venv/bin/pip install --upgrade pip - venv/bin/pip install build twine - venv/bin/pyproject-build + cd release && python3 -m venv venv + cd release && venv/bin/pip3 install --upgrade setuptools pip + cd release && venv/bin/pip3 install twine wheel + cd release && venv/bin/python3 setup.py sdist bdist_wheel # Note: hope you remember password for pypi, but username is 'newren' - venv/bin/twine upload dist/* + cd release && venv/bin/twine upload dist/* # Remove temporary file(s) - rm -rf dist/ venv/ git_filter_repo.egg-info/ + cd release && rm -f README.md git-filter-repo git_filter_repo.py + cd release && rm -rf .eggs/ build/ venv/ git_filter_repo.egg-info/ # NOTE TO FUTURE SELF: If you accidentally push a bad release, you can remove # all but the git-filter-repo-$VERSION.tar.xz asset with diff --git a/contrib/filter-repo-demos/clean-ignore b/contrib/filter-repo-demos/clean-ignore index a8427e8c..06823eed 100755 --- a/contrib/filter-repo-demos/clean-ignore +++ b/contrib/filter-repo-demos/clean-ignore @@ -29,7 +29,7 @@ class CheckIgnores: self.ignored = set() self.okay = set() - cmd = 'git check-ignore --stdin --verbose --non-matching --no-index -z' + cmd = 'git check-ignore --stdin --verbose --non-matching --no-index' self.check_ignore_process = subprocess.Popen(cmd.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE) @@ -46,20 +46,17 @@ class CheckIgnores: elif name in self.okay: continue else: - self.check_ignore_process.stdin.write(name+b'\0') + self.check_ignore_process.stdin.write(name+b'\n') self.check_ignore_process.stdin.flush() - result = os.read(self.check_ignore_process.stdout.fileno(), 65535).rstrip(b'\0') - (source, linenum, pattern, pathname) = result.split(b"\0") + result = self.check_ignore_process.stdout.readline().rstrip(b'\n') + (rest, pathname) = result.split(b"\t") if name != pathname: raise SystemExit("Error: Passed {} but got {}".format(name, pathname)) - if not source and not linenum and not pattern: + if rest == b'::': self.okay.add(name) else: - if pattern[0:1] == b"!": - self.okay.add(name) - else: - self.ignored.add(name) - ignored.add(name) + self.ignored.add(name) + ignored.add(name) return ignored @@ -72,7 +69,7 @@ class CheckIgnores: def main(): checker = CheckIgnores() - args = fr.FilteringOptions.parse_args(sys.argv[1:], error_on_empty = False) + args = fr.FilteringOptions.parse_args(sys.argv[1:]) filter = fr.RepoFilter(args, commit_callback=checker.skip_ignores) filter.run() diff --git a/contrib/filter-repo-demos/lint-history b/contrib/filter-repo-demos/lint-history index 22061962..61967b73 100755 --- a/contrib/filter-repo-demos/lint-history +++ b/contrib/filter-repo-demos/lint-history @@ -31,7 +31,7 @@ near the top of git-filter-repo. # about filenames, then this program could be replaced by a "one-liner"; e.g. # git filter-repo --force --blob-callback ' # if not b"\0" in blob.data[0:8192]: -# filename = ".git/info/tmpfile" +# filename = '.git/info/tmpfile' # with open(filename, "wb") as f: # f.write(blob.data) # subprocess.check_call(["lint_program", "--some", "arg", filename]) @@ -104,8 +104,6 @@ parser.add_argument('command', nargs=argparse.REMAINDER, lint_args = parser.parse_args() if not lint_args.command: raise SystemExit("Error: Need to specify a lint command") -if len(lint_args.command) > 1 and lint_args.command[0] == '--': - lint_args.command.pop(0) tmpdir = None blobs_handled = {} @@ -164,7 +162,7 @@ if lint_args.relevant: lint_args.filenames_important = True input_args = [] if lint_args.refs: - input_args = ["--refs",] + lint_args.refs + input_args = ["--args",] + lint_args.refs args = fr.FilteringOptions.parse_args(input_args, error_on_empty = False) args.force = True if lint_args.filenames_important: @@ -177,7 +175,5 @@ if lint_args.filenames_important: cat_file_process.stdin.close() cat_file_process.wait() else: - if not os.path.exists('.git/info'): - os.makedirs('.git/info') filter = fr.RepoFilter(args, blob_callback=lint_non_binary_blobs) filter.run() diff --git a/git-filter-repo b/git-filter-repo index 3dfe5569..ed61b405 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -51,13 +51,6 @@ __all__ = ["Blob", "Reset", "FileChange", "Commit", "Tag", "Progress", "string_to_date", "date_to_string", "record_id_rename", "GitUtils", "FilteringOptions", "RepoFilter"] -# The globals to make visible to callbacks. They will see all our imports for -# free, as well as our public API. -public_globals = ["__builtins__", "argparse", "collections", "fnmatch", - "gettext", "io", "os", "platform", "re", "shutil", - "subprocess", "sys", "time", "textwrap", "tzinfo", - "timedelta", "datetime"] + __all__ - deleted_hash = b'0'*40 write_marks = True date_format_permissive = True @@ -1818,7 +1811,6 @@ EXAMPLES "paths; you also need a filter to select them.")) helpers = parser.add_argument_group(title=_("Path shortcuts")) - helpers.add_argument('--paths', help=argparse.SUPPRESS, metavar='IGNORE') helpers.add_argument('--paths-from-file', metavar='FILENAME', type=os.fsencode, action=FilteringOptions.FileWithPathsFilter, dest='path_changes', @@ -1972,10 +1964,6 @@ EXAMPLES location.add_argument('--target', type=os.fsencode, help=_("Git repository to overwrite with filtered history")) - order = parser.add_argument_group(title=_("Ordering of commits")) - order.add_argument('--date-order', action='store_true', - help=_("Processes commits in commit timestamp order.")) - misc = parser.add_argument_group(title=_("Miscellaneous options")) misc.add_argument('--help', '-h', action='store_true', help=_("Show this help message and exit.")) @@ -2209,8 +2197,6 @@ EXAMPLES if args.help: parser.print_help() raise SystemExit() - if args.paths: - raise SystemExit("Error: Option `--paths` unrecognized; did you mean --path or --paths-from-file?") if args.version: GitUtils.print_my_version() raise SystemExit() @@ -2851,11 +2837,9 @@ class RepoFilter(object): def _handle_arg_callbacks(self): def make_callback(argname, str): - callback_globals = {g: globals()[g] for g in public_globals} - callback_locals = {} exec('def callback({}, _do_not_use_this_var = None):\n'.format(argname)+ - ' '+'\n '.join(str.splitlines()), callback_globals, callback_locals) - return callback_locals['callback'] + ' '+'\n '.join(str.splitlines()), globals()) + return callback #namespace['callback'] def handle(type): callback_field = '_{}_callback'.format(type) code_string = getattr(self._args, type+'_callback') @@ -3416,6 +3400,10 @@ class RepoFilter(object): commit.file_changes = [v for k,v in sorted(new_file_changes.items())] def _tweak_commit(self, commit, aux_info): + # Change the commit message according to callback + if not self._args.preserve_commit_hashes: + commit.message = self._hash_re.sub(self._translate_commit_hash, + commit.message) if self._args.replace_message: for literal, replacement in self._args.replace_message['literals']: commit.message = commit.message.replace(literal, replacement) @@ -3424,11 +3412,6 @@ class RepoFilter(object): if self._message_callback: commit.message = self._message_callback(commit.message) - # Change the commit message according to callback - if not self._args.preserve_commit_hashes: - commit.message = self._hash_re.sub(self._translate_commit_hash, - commit.message) - # Change the author & committer according to mailmap rules args = self._args if args.mailmap: @@ -3678,8 +3661,6 @@ class RepoFilter(object): if self._args.preserve_commit_encoding is not None: # pragma: no cover reencode = 'no' if self._args.preserve_commit_encoding else 'yes' extra_flags.append('--reencode='+reencode) - if self._args.date_order: - extra_flags.append('--date-order') location = ['-C', self._args.source] if self._args.source else [] fep_cmd = ['git'] + location + ['fast-export', '--show-original-ids', '--signed-tags=strip', '--tag-of-filtered-object=rewrite', diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index e6cee7a5..00000000 --- a/pyproject.toml +++ /dev/null @@ -1,45 +0,0 @@ -[project] -name = "git-filter-repo" -description = "Quickly rewrite git repository history" -authors = [ - {name = "Elijah Newren", email = "newren@gmail.com"} -] -readme = "README.md" -classifiers = [ - "Development Status :: 4 - Beta", - "Operating System :: OS Independent", - "Programming Language :: Python", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", -] -license.text = "MIT" -requires-python = ">= 3.5" -dynamic = ["version"] - -[project.urls] -Homepage = "https://github.com/newren/git-filter-repo" -Issues = "https://github.com/newren/git-filter-repo/issues/" -Source = "https://github.com/newren/git-filter-repo" - -[project.scripts] -git-filter-repo = "git_filter_repo:main" - -[build-system] -requires = ["setuptools>=61", "setuptools_scm>=8.0", "wheel"] -build-backend = "setuptools.build_meta" - -[tool.setuptools] -py-modules = ["git_filter_repo"] - -[tool.setuptools_scm] -# This section intentionally left blank diff --git a/release/setup.cfg b/release/setup.cfg new file mode 100644 index 00000000..078f3ff5 --- /dev/null +++ b/release/setup.cfg @@ -0,0 +1,32 @@ +[metadata] +name = git-filter-repo +url = https://github.com/newren/git-filter-repo +project_urls = + Source = https://github.com/newren/git-filter-repo + Issues = https://github.com/newren/git-filter-repo/issues/ +description = Quickly rewrite git repository history +long_description = file: README.md +long_description_content_type = text/markdown +classifiers = + Development Status :: 4 - Beta + Operating System :: OS Independent + Programming Language :: Python + License :: OSI Approved :: MIT License + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy +platforms = any +license = MIT + +[options] +scripts = git-filter-repo +py_modules = git_filter_repo +python_requires = >= 3.5 +setup_requires = setuptools_scm + +[bdist_wheel] +universal = 1 diff --git a/release/setup.py b/release/setup.py new file mode 100644 index 00000000..0e36611a --- /dev/null +++ b/release/setup.py @@ -0,0 +1,21 @@ +from setuptools import setup +import os + + +def link_parent(src, target=None): + if target is None: + target = src + try: + os.symlink(os.path.join("..", src), target) + except FileExistsError: + pass + + +for f in ['git-filter-repo', 'README.md']: + link_parent(f) + +link_parent('git-filter-repo', 'git_filter_repo.py') + + +setup(use_scm_version=dict(root="..", relative_to=__file__), + entry_points={'console_scripts': ['git-filter-repo = git_filter_repo:main']}) diff --git a/t/run_coverage b/t/run_coverage index be5e8a89..5517459b 100755 --- a/t/run_coverage +++ b/t/run_coverage @@ -26,7 +26,7 @@ exitcode=$? set -e cd $tmpdir -coverage3 combine -q +coverage3 combine coverage3 html -d $orig_dir/report coverage3 report -m cd $orig_dir diff --git a/t/t9390-filter-repo.sh b/t/t9390-filter-repo.sh index 85f155a6..f96ee004 100755 --- a/t/t9390-filter-repo.sh +++ b/t/t9390-filter-repo.sh @@ -187,19 +187,6 @@ test_expect_success '--paths-from-file' ' ) ' -test_expect_success '--paths does not mean --paths-from-file' ' - setup_path_rename && - ( - git clone file://"$(pwd)"/path_rename paths_misuse && - cd paths_misuse && - - test_must_fail git filter-repo --paths values/large 2>../err && - - grep "Error: Option.*--paths.*unrecognized; did you" ../err && - rm ../err - ) -' - create_path_filtering_and_renaming() { test -d path_filtering_and_renaming && return @@ -1474,46 +1461,6 @@ test_expect_success '--target' ' test_cmp target/expect target/actual ' -test_expect_success '--date-order' ' - test_create_repo date_order && - ( - cd date_order && - git fast-import --quiet <$DATA/date-order && - # First, verify that without date-order, C is before B - cat <<-EOF >expect-normal && - Initial - A - C - B - D - merge - EOF - git filter-repo --force --message-callback " - with open(\"messages.txt\", \"ab\") as f: - f.write(message) - return message - " && - test_cmp expect-normal messages.txt && - - # Next, verify that with date-order, C and B are reversed - rm messages.txt && - cat <<-EOF >expect && - Initial - A - B - C - D - merge - EOF - git filter-repo --date-order --force --message-callback " - with open(\"messages.txt\", \"ab\") as f: - f.write(message) - return message - " && - test_cmp expect messages.txt - ) -' - test_expect_success '--refs' ' setup_analyze_me && git init refs && diff --git a/t/t9390/date-order b/t/t9390/date-order deleted file mode 100644 index 8a83f221..00000000 --- a/t/t9390/date-order +++ /dev/null @@ -1,57 +0,0 @@ -feature done -blob -mark :1 -data 8 -initial - -reset refs/heads/master -commit refs/heads/master -mark :2 -author Little O. Me 1535228562 -0700 -committer Little O. Me 1535228562 -0700 -data 8 -Initial -M 100644 :1 filename - -commit refs/heads/master -mark :3 -author Little Me 1535229601 -0700 -committer Little Me 1535229601 -0700 -data 2 -A -from :2 - -commit refs/heads/master -mark :4 -author Little Me 1535229602 -0700 -committer Little Me 1535229602 -0700 -data 2 -B -from :2 - -commit refs/heads/master -mark :5 -author Little Me 1535229603 -0700 -committer Little Me 1535229603 -0700 -data 2 -C -from :3 - -commit refs/heads/master -mark :6 -author Little Me 1535229604 -0700 -committer Little Me 1535229604 -0700 -data 2 -D -from :4 - -commit refs/heads/master -mark :7 -author Little Me 1535229605 -0700 -committer Little Me 1535229605 -0700 -data 6 -merge -from :5 -merge :6 - -done diff --git a/t/t9391-filter-repo-lib-usage.sh b/t/t9391-filter-repo-lib-usage.sh index 192eacff..25bc9869 100755 --- a/t/t9391-filter-repo-lib-usage.sh +++ b/t/t9391-filter-repo-lib-usage.sh @@ -16,8 +16,6 @@ esac export PYTHONDONTWRITEBYTECODE=1 export CONTRIB_DIR=$TEST_DIRECTORY/../contrib/filter-repo-demos -DATA="$TEST_DIRECTORY/t9391" - setup() { git init $1 && @@ -205,55 +203,4 @@ test_expect_success 'lint-history' ' ) ' -test_expect_success 'lint-history --refs' ' - test_create_repo lint-history-only-some-refs && - ( - cd lint-history-only-some-refs && - test_commit a somefile bad && - test_commit b notherfile baaad && - test_commit c whatever baaaaaad && - git checkout -b mybranch HEAD~1 && - test_commit d somefile baaaaaaaad && - test_commit e whatever "baaaaaaaaaad to the bone" && - - cat <<-EOF >linter.sh && - #!/bin/bash - cat \$1 | tr -d a >tmp - mv tmp \$1 - EOF - chmod u+x linter.sh && - - PATH=$PATH:. $CONTRIB_DIR/lint-history --refs master..mybranch -- linter.sh && - - echo bd >expect && - echo bd to the bone >long-expect && - - # Verify master is untouched - git checkout master && - ! test_cmp somefile expect && - ! test_cmp notherfile expect && - ! test_cmp whatever expect && - - # Verify that files touched on the branch are tweaked - git checkout mybranch && - test_cmp somefile expect && - ! test_cmp notherfile expect && - test_cmp whatever long-expect - - ) -' - -test_expect_success 'clean-ignore with emoji in filenames' ' - test_create_repo clean-ignore && - ( - cd clean-ignore && - git fast-import --quiet <$DATA/emoji-repo && - git reset --hard && - $CONTRIB_DIR/clean-ignore --force && - printf ".gitignore\nfilename\n" >expect && - git ls-files >actual && - test_cmp expect actual - ) -' - test_done diff --git a/t/t9391/emoji-repo b/t/t9391/emoji-repo deleted file mode 100644 index b7d1aa84..00000000 --- a/t/t9391/emoji-repo +++ /dev/null @@ -1,29 +0,0 @@ -feature done -blob -mark :1 -data 8 -initial - -blob -mark :2 -data 5 -lock - -blob -mark :3 -data 11 -*.bak -🔒 - -reset refs/heads/master -commit refs/heads/master -mark :4 -author Little O. Me 1535228562 -0700 -committer Little O. Me 1535228562 -0700 -data 10 -My commit -M 100644 :1 filename -M 100644 :2 🔒 -M 100644 :3 .gitignore - -done