Skip to content

Commit bcd7ab4

Browse files
committed
fixup! filter-repo: add a --file-info-callback
Add another testcase for code coverage, and tweak the documentation a bit more.
1 parent 733d137 commit bcd7ab4

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

Documentation/git-filter-repo.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,12 +1289,15 @@ deletions have no file contents to operate on). The file info
12891289
callback takes four parameters (filename, mode, blob_id, and value),
12901290
and expects three to be returned (filename, mode, blob_id). The
12911291
filename is handled similar to the filename callback; it can be used
1292-
to rename the file, or if set to None, to drop that change from the
1293-
commit. The mode is a simple bytestring (or None to signal you want
1294-
the file in question deleted; mode being None trumps filename being
1295-
None), and the blob_id is most useful in conjunction with the value
1296-
parameter. The value parameter is an instance of a class that has the
1297-
following functions
1292+
to rename the file. The mode is a simple bytestring (b"100644" for
1293+
regular non-executable files, b"100755" for executable files/scripts,
1294+
b"120000" for symlinks, and b"160000" for submodules). For special
1295+
cases, there are two special return values for mode and filename -- a
1296+
mode of None signals that you want the file deleted by the commit
1297+
processing this change, and a filename of None signals that you want
1298+
this change dropped from the commit processing it. The blob_id is
1299+
most useful in conjunction with the value parameter. The value
1300+
parameter is an instance of a class that has the following functions
12981301
value.get_contents_by_identifier(blob_id) -> contents (bytestring)
12991302
value.get_size_by_identifier(blob_id) -> size_of_blob (int)
13001303
value.insert_file_with_contents(contents) -> blob_id

git-filter-repo

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,12 +1846,12 @@ class FilteringOptions(object):
18461846
value.apply_replace_text(contents) -> new_contents (bytestring)
18471847
and can read/write the following data member from the value instance:
18481848
value.data (dict)
1849-
The filename return value is interpreted the same as for
1850-
--filename-callback (with a value of None signalling the commit
1851-
modification in this commit should be dropped), and mode is one of
1852-
b'100644', b'100755', b'120000', or b'160000' (or None to signal that the
1853-
file in question should be deleted by the commit processing this file
1854-
change).
1849+
1850+
The filename can be used for renaming the file similar to
1851+
--filename-callback, and mode is one of b'100644', b'100755',
1852+
b'120000', or b'160000'. There are two special case: if filename is
1853+
returned as None, the change will be dropped, and if mode is None, the
1854+
file will be deleted by the commit processing this change.
18551855
18561856
For more detailed examples and explanations AND caveats, see
18571857
https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#CALLBACKS
@@ -3875,6 +3875,7 @@ class RepoFilter(object):
38753875
change.blob_id,
38763876
self._file_info_value)
38773877
if mode is None:
3878+
assert(filename is not None)
38783879
new_change = FileChange(b'D', filename)
38793880
elif filename is None:
38803881
continue # Drop the FileChange from this commit

t/t9392-filter-repo-python-callback.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,43 @@ test_expect_success '--file-info-callback messing with history' '
295295
)
296296
'
297297

298+
test_expect_success '--file-info-callback and deletes and drops' '
299+
setup file_info_deletes_drops &&
300+
(
301+
cd file_info_deletes_drops &&
302+
303+
git rm file.doc &&
304+
git commit -m "Nuke doc file" &&
305+
306+
git filter-repo --force --file-info-callback "
307+
size = value.get_size_by_identifier(blob_id)
308+
(newname, newmode) = (filename, mode)
309+
if filename == b\"world\" and size == 12:
310+
newname = None
311+
if filename == b\"advice\" and size == 77:
312+
newmode = None
313+
return (newname, newmode, blob_id)
314+
"
315+
316+
cat <<-EOF >expect &&
317+
foobar.c
318+
secret
319+
world
320+
EOF
321+
322+
echo 1 >expect &&
323+
git rev-list --count HEAD -- world >actual &&
324+
test_cmp expect actual &&
325+
326+
echo 2 >expect &&
327+
git rev-list --count HEAD -- advice >actual &&
328+
test_cmp expect actual &&
329+
330+
echo hello >expect &&
331+
test_cmp expect world
332+
)
333+
'
334+
298335
test_lazy_prereq UNIX2DOS '
299336
unix2dos -h
300337
test $? -ne 127

0 commit comments

Comments
 (0)