@@ -1708,6 +1708,9 @@ class FilteringOptions(object):
1708
1708
To remove all .DS_Store files:
1709
1709
git filter-repo --filename-callback 'return None if os.path.basename(filename) == b".DS_Store" else filename'
1710
1710
1711
+ Note that if BODY resolves to a filename, then the contents of that file
1712
+ will be used as the BODY in the callback function.
1713
+
1711
1714
For more detailed examples and explanations AND caveats, see
1712
1715
https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#CALLBACKS
1713
1716
@@ -1904,32 +1907,32 @@ EXAMPLES
1904
1907
"always use merge --no-ff." ))
1905
1908
1906
1909
callback = parser .add_argument_group (title = _ ("Generic callback code snippets" ))
1907
- callback .add_argument ('--filename-callback' , metavar = "FUNCTION_BODY " ,
1910
+ callback .add_argument ('--filename-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1908
1911
help = _ ("Python code body for processing filenames; see CALLBACKS "
1909
1912
"sections below." ))
1910
- callback .add_argument ('--message-callback' , metavar = "FUNCTION_BODY " ,
1913
+ callback .add_argument ('--message-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1911
1914
help = _ ("Python code body for processing messages (both commit "
1912
1915
"messages and tag messages); see CALLBACKS section below." ))
1913
- callback .add_argument ('--name-callback' , metavar = "FUNCTION_BODY " ,
1916
+ callback .add_argument ('--name-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1914
1917
help = _ ("Python code body for processing names of people; see "
1915
1918
"CALLBACKS section below." ))
1916
- callback .add_argument ('--email-callback' , metavar = "FUNCTION_BODY " ,
1919
+ callback .add_argument ('--email-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1917
1920
help = _ ("Python code body for processing emails addresses; see "
1918
1921
"CALLBACKS section below." ))
1919
- callback .add_argument ('--refname-callback' , metavar = "FUNCTION_BODY " ,
1922
+ callback .add_argument ('--refname-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1920
1923
help = _ ("Python code body for processing refnames; see CALLBACKS "
1921
1924
"section below." ))
1922
1925
1923
- callback .add_argument ('--blob-callback' , metavar = "FUNCTION_BODY " ,
1926
+ callback .add_argument ('--blob-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1924
1927
help = _ ("Python code body for processing blob objects; see "
1925
1928
"CALLBACKS section below." ))
1926
- callback .add_argument ('--commit-callback' , metavar = "FUNCTION_BODY " ,
1929
+ callback .add_argument ('--commit-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1927
1930
help = _ ("Python code body for processing commit objects; see "
1928
1931
"CALLBACKS section below." ))
1929
- callback .add_argument ('--tag-callback' , metavar = "FUNCTION_BODY " ,
1932
+ callback .add_argument ('--tag-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1930
1933
help = _ ("Python code body for processing tag objects; see CALLBACKS "
1931
1934
"section below." ))
1932
- callback .add_argument ('--reset-callback' , metavar = "FUNCTION_BODY " ,
1935
+ callback .add_argument ('--reset-callback' , metavar = "FUNCTION_BODY_OR_FILE " ,
1933
1936
help = _ ("Python code body for processing reset objects; see "
1934
1937
"CALLBACKS section below." ))
1935
1938
@@ -2809,6 +2812,9 @@ class RepoFilter(object):
2809
2812
callback_field = '_{}_callback' .format (type )
2810
2813
code_string = getattr (self ._args , type + '_callback' )
2811
2814
if code_string :
2815
+ if os .path .exists (code_string ):
2816
+ with open (code_string , 'r' , encoding = 'utf-8' ) as f :
2817
+ code_string = f .read ()
2812
2818
if getattr (self , callback_field ):
2813
2819
raise SystemExit (_ ("Error: Cannot pass a %s_callback to RepoFilter "
2814
2820
"AND pass --%s-callback"
0 commit comments