Skip to content

Commit cefeef1

Browse files
committed
filter-repo: use new --date-format=raw-permissive fast-import option
fast-import gained a new raw-permissive date format explictly for allowing people to import repositories as-is. Make use of the flag, and stop rewriting the bogus timezone found in rails.git. If users do not like these bogus times, they can of course write a filter to fix them (or even make them bogus in a different way). For example: git filter-repo ... --commit-callback ' if commit.author_date.endswith(b"+051800"): commit.author_date.replace(b"+051800", b"+0261") ' Signed-off-by: Elijah Newren <[email protected]>
1 parent debe520 commit cefeef1

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

Documentation/git-filter-repo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ sequence that more accurately reflects what filter-repo runs is:
11731173
1. Verify we're in a fresh clone
11741174
2. `git fetch -u . refs/remotes/origin/*:refs/heads/*`
11751175
3. `git remote rm origin`
1176-
4. `git fast-export --show-original-ids --reference-excluded-parents --fake-missing-tagger --signed-tags=strip --tag-of-filtered-object=rewrite --use-done-feature --no-data --reencode=yes --mark-tags --all | filter | git -c core.ignorecase=false fast-import --force --quiet`
1176+
4. `git fast-export --show-original-ids --reference-excluded-parents --fake-missing-tagger --signed-tags=strip --tag-of-filtered-object=rewrite --use-done-feature --no-data --reencode=yes --mark-tags --all | filter | git -c core.ignorecase=false fast-import --date-format=raw-permissive --force --quiet`
11771177
5. `git update-ref --no-deref --stdin`, fed with a list of refs to nuke, and a list of replace refs to delete, create, or update.
11781178
6. `git reset --hard`
11791179
7. `git reflog expire --expire=now --all`

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ history rewriting tools](contrib/filter-repo-demos).
3939
filter-repo requires:
4040

4141
* git >= 2.22.0 at a minimum; [some features](#upstream-improvements)
42-
require git >= 2.24.0
42+
require git >= 2.24.0 or later
4343
* python3 >= 3.5
4444

4545
# How do I install it?
@@ -259,7 +259,8 @@ One can kind of hack this together with something like:
259259
| perl -pe 's%^(M [0-9]+ [0-9a-f]+ )(.*)$%\1my-module/\2%' \
260260
| perl -pe 's%^(D )(.*)$%\1my-module/\2%' \
261261
| perl -pe s%refs/tags/%refs/tags/my-module-% \
262-
| git -c core.ignorecase=false fast-import --force --quiet
262+
| git -c core.ignorecase=false fast-import --date-format=raw-permissive \
263+
--force --quiet
263264
git for-each-ref --format="delete %(refname)" refs/tags/ \
264265
| grep -v refs/tags/my-module- \
265266
| git update-ref --stdin
@@ -429,6 +430,9 @@ has also driven numerous improvements to fast-export and fast-import
429430
(and occasionally other commands) in core git, based on things
430431
filter-repo needs to do its work:
431432

433+
* git-2.28.0 (not yet released)
434+
* [fast-import: add new --date-format=raw-permissive format](
435+
https://git.kernel.org/pub/scm/git/git.git/commit/?id=d42a2fb72f)
432436
* git-2.24.0
433437
* [fast-export: handle nested tags](
434438
https://git.kernel.org/pub/scm/git/git.git/commit/?id=941790d7de)

git-filter-repo

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ __all__ = ["Blob", "Reset", "FileChange", "Commit", "Tag", "Progress",
5353

5454
deleted_hash = b'0'*40
5555
write_marks = True
56+
date_format_permissive = True
5657

5758
def gettext_poison(msg):
5859
if "GIT_TEST_GETTEXT_POISON" in os.environ: # pragma: no cover
@@ -1075,15 +1076,6 @@ class FastExportParser(object):
10751076
user_regex = self._user_regexes[usertype]
10761077
(name, email, when) = user_regex.match(self._currentline).groups()
10771078

1078-
# TimeZone idiocy; IST is any of four timezones, so someone translated
1079-
# it to something that was totally invalid...and it got recorded that
1080-
# way. Others have suggested just using an invalid timezone that
1081-
# fast-import will not choke on. Let's do that. Note that +051800
1082-
# seems to be the only weird timezone found in the wild, by me or some
1083-
# other posts google returned on the subject...
1084-
if when.endswith(b'+051800'):
1085-
when = when[0:-7]+b'+0261'
1086-
10871079
self._advance_currentline()
10881080
return (name, email, when)
10891081

@@ -2050,6 +2042,9 @@ EXAMPLES
20502042
p = subproc.Popen('git fast-export -h'.split(),
20512043
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
20522044
output = p.stdout.read()
2045+
if b'--anonymize-map' not in output: # pragma: no cover
2046+
global date_format_permissive
2047+
date_format_permissive = False
20532048
if b'--mark-tags' not in output: # pragma: no cover
20542049
global write_marks
20552050
write_marks = False
@@ -3633,6 +3628,8 @@ class RepoFilter(object):
36333628
location = ['-C', self._args.target] if self._args.target else []
36343629
fip_cmd = ['git'] + location + ['-c', 'core.ignorecase=false',
36353630
'fast-import', '--force', '--quiet']
3631+
if date_format_permissive:
3632+
fip_cmd.append('--date-format=raw-permissive')
36363633
if self._args.state_branch:
36373634
target_marks_file = self._load_marks_file(b'target-marks')
36383635
fip_cmd.extend([b'--export-marks='+target_marks_file,

t/t9390/unusual-filtered

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ hello
66
reset refs/heads/develop
77
commit refs/heads/develop
88
mark :2
9-
author Srinivasa Ramanujan <[email protected]> 1535228562 +0261
10-
committer Srinivasa Ramanujan <[email protected]> 1535228562 +0261
9+
author Srinivasa Ramanujan <[email protected]> 1535228562 +051800
10+
committer Srinivasa Ramanujan <[email protected]> 1535228562 +051800
1111
data 8
1212
Initial
1313
M 100644 :1 greeting

t/t9390/unusual-mailmap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ hello
66
reset refs/heads/develop
77
commit refs/heads/develop
88
mark :2
9-
author Srinivasa Ramanujan <[email protected]> 1535228562 +0261
10-
committer Srinivasa Ramanujan <[email protected]> 1535228562 +0261
9+
author Srinivasa Ramanujan <[email protected]> 1535228562 +051800
10+
committer Srinivasa Ramanujan <[email protected]> 1535228562 +051800
1111
data 8
1212
Initial
1313
M 100644 :1 greeting

0 commit comments

Comments
 (0)