Skip to content

Commit 38e70b6

Browse files
committed
filter-repo: ignore comment lines in --paths-from-file
Allow lines starting with '#' to be treated as a comment and be ignored. Update the documentation to note that both blank lines and comment lines are ignored, and mention how filenames starting with '#' can be matched (namely, the same way that filenames startwith with 'regex:', 'glob:', or 'literal:' can be -- by prefixing the filename with 'literal:'). Signed-off-by: Elijah Newren <[email protected]>
1 parent 771404d commit 38e70b6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Documentation/git-filter-repo.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ Path shortcuts
129129
Specify several path filtering and renaming directives, one
130130
per line. Lines with `==>` in them specify path renames, and
131131
lines can begin with `literal:` (the default), `glob:`, or
132-
`regex:` to specify different matching styles
132+
`regex:` to specify different matching styles. Blank lines
133+
and lines starting with a `#` are ignored (if you have a
134+
filename that you want to filter on that starts with
135+
`literal:`, `#`, `glob:`, or `regex:`, then prefix the line
136+
with 'literal:').
133137

134138
--subdirectory-filter <directory>::
135139
Only look at history that touches the given subdirectory and
@@ -676,12 +680,22 @@ expressions to filter on, you can stick them in a file and use
676680
contents of
677681

678682
--------------------------------------------------
683+
# Blank lines and comment lines are ignored.
684+
# Examples similar to --path:
679685
README.md
680686
guides/
681687
tools/releases
688+
689+
# An example that is like --path-glob:
682690
glob:*.py
691+
692+
# An example that is like --path-regex:
683693
regex:^.*/.*/[0-9]{4}-[0-9]{2}-[0-9]{2}.txt$
694+
695+
# An example of renaming a path
684696
tools/==>scripts/
697+
698+
# An example of using a regex to rename a path
685699
regex:(.*)/([^/]*)/([^/]*)\.text$==>\2/\1/\3.txt
686700
--------------------------------------------------
687701

git-filter-repo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,8 @@ EXAMPLES
18071807
help=_("Specify several path filtering and renaming directives, one "
18081808
"per line. Lines with '==>' in them specify path renames, "
18091809
"and lines can begin with 'literal:' (the default), 'glob:', "
1810-
"or 'regex:' to specify different matching styles"))
1810+
"or 'regex:' to specify different matching styles. Blank "
1811+
"lines and lines starting with a '#' are ignored."))
18111812
helpers.add_argument('--subdirectory-filter', metavar='DIRECTORY',
18121813
action=FilteringOptions.HelperFilter, type=os.fsencode,
18131814
help=_("Only look at history that touches the given subdirectory "
@@ -2123,6 +2124,9 @@ EXAMPLES
21232124
# Skip blank lines
21242125
if not line:
21252126
continue
2127+
# Skip comment lines
2128+
if line.startswith(b'#'):
2129+
continue
21262130

21272131
# Determine the replacement
21282132
match_type, repl = 'literal', None

t/t9390-filter-repo.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ test_expect_success '--paths-from-file' '
165165
values/huge==>values/gargantuan
166166
glob:*rge
167167
168+
# Comments and blank lines are ignored
168169
regex:.*med.*
169170
regex:^([^/]*)/(.*)ge$==>\2/\1/ge
170171
EOF

0 commit comments

Comments
 (0)