File: file_filter.py

package info (click to toggle)
git-filter-repo 2.47.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,280 kB
  • sloc: sh: 4,887; python: 4,856; makefile: 114
file content (30 lines) | stat: -rwxr-xr-x 796 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3

"""
Please see the
  ***** API BACKWARD COMPATIBILITY CAVEAT *****
near the top of git-filter-repo.
"""

import sys
import git_filter_repo as fr

def drop_file_by_contents(blob, metadata):
  bad_file_contents = b'The launch code is 1-2-3-4.'
  if blob.data == bad_file_contents:
    blob.skip()

def drop_files_by_name(commit, metadata):
  new_file_changes = []
  for change in commit.file_changes:
    if not change.filename.endswith(b'.doc'):
      new_file_changes.append(change)
  commit.file_changes = new_file_changes

sys.argv.append('--force')
args = fr.FilteringOptions.parse_args(sys.argv[1:])

filter = fr.RepoFilter(args,
                       blob_callback   = drop_file_by_contents,
                       commit_callback = drop_files_by_name)
filter.run()