2019-04-01 23:35:49 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-11-05 15:31:06 +01:00
|
|
|
|
2019-03-05 20:00:11 +01:00
|
|
|
"""
|
|
|
|
Please see the
|
|
|
|
***** API BACKWARD COMPATIBILITY CAVEAT *****
|
|
|
|
near the top of git-filter-repo.
|
|
|
|
"""
|
|
|
|
|
2019-02-10 03:24:37 +01:00
|
|
|
import git_filter_repo as fr
|
2019-05-16 04:46:05 +02:00
|
|
|
from git_filter_repo import Blob, Reset, FileChange, Commit, Tag, FixedTimeZone
|
2019-02-10 03:24:37 +01:00
|
|
|
from git_filter_repo import Progress, Checkpoint
|
2018-11-05 15:31:06 +01:00
|
|
|
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
2019-02-10 03:24:37 +01:00
|
|
|
args = fr.FilteringOptions.default_options()
|
|
|
|
out = fr.RepoFilter(args)
|
2018-11-05 15:31:06 +01:00
|
|
|
out.importer_only()
|
|
|
|
|
|
|
|
output = out._output
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
world = Blob(b"Hello")
|
2018-11-05 15:31:06 +01:00
|
|
|
world.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
bar = Blob(b"foo\n")
|
2018-11-05 15:31:06 +01:00
|
|
|
bar.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
master = Reset(b"refs/heads/master")
|
2018-11-05 15:31:06 +01:00
|
|
|
master.dump(output)
|
|
|
|
|
2019-05-16 04:46:05 +02:00
|
|
|
changes = [FileChange(b'M', b'world', world.id, mode=b"100644"),
|
|
|
|
FileChange(b'M', b'bar', bar.id, mode=b"100644")]
|
2018-11-05 15:31:06 +01:00
|
|
|
when = datetime(year=2005, month=4, day=7,
|
|
|
|
hour=15, minute=16, second=10,
|
2019-04-28 00:18:59 +02:00
|
|
|
tzinfo=FixedTimeZone(b"-0700"))
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2019-04-28 00:18:59 +02:00
|
|
|
commit1 = Commit(b"refs/heads/master",
|
|
|
|
b"A U Thor", b"au@thor.email", when_string,
|
|
|
|
b"Com M. Iter", b"comm@iter.email", when_string,
|
|
|
|
b"My first commit! Wooot!\n\nLonger description",
|
2018-11-05 15:31:06 +01:00
|
|
|
changes,
|
2019-04-26 15:28:16 +02:00
|
|
|
parents = [])
|
2018-11-05 15:31:06 +01:00
|
|
|
commit1.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
world = Blob(b"Hello\nHi")
|
2018-11-05 15:31:06 +01:00
|
|
|
world.dump(output)
|
2019-04-28 00:18:59 +02:00
|
|
|
world_link = Blob(b"world")
|
2018-11-05 15:31:06 +01:00
|
|
|
world_link.dump(output)
|
|
|
|
|
2019-05-16 04:46:05 +02:00
|
|
|
changes = [FileChange(b'M', b'world', world.id, mode=b"100644"),
|
|
|
|
FileChange(b'M', b'planet', world_link.id, mode=b"120000")]
|
2018-11-05 15:31:06 +01:00
|
|
|
when += timedelta(days=3, hours=4, minutes=6)
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2019-04-28 00:18:59 +02:00
|
|
|
commit2 = Commit(b"refs/heads/master",
|
|
|
|
b"A U Thor", b"au@thor.email", when_string,
|
|
|
|
b"Com M. Iter", b"comm@iter.email", when_string,
|
|
|
|
b"Make a symlink to world called planet, modify world",
|
2018-11-05 15:31:06 +01:00
|
|
|
changes,
|
2019-04-26 15:28:16 +02:00
|
|
|
parents = [commit1.id])
|
2018-11-05 15:31:06 +01:00
|
|
|
commit2.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
script = Blob(b"#!/bin/sh\n\necho Hello")
|
2018-11-05 15:31:06 +01:00
|
|
|
script.dump(output)
|
2019-05-16 04:46:05 +02:00
|
|
|
changes = [FileChange(b'M', b'runme', script.id, mode=b"100755"),
|
|
|
|
FileChange(b'D', b'bar')]
|
2019-04-28 00:18:59 +02:00
|
|
|
when_string = b"1234567890 -0700"
|
|
|
|
commit3 = Commit(b"refs/heads/master",
|
|
|
|
b"A U Thor", b"au@thor.email", when_string,
|
|
|
|
b"Com M. Iter", b"comm@iter.email", when_string,
|
|
|
|
b"Add runme script, remove bar",
|
2018-11-05 15:31:06 +01:00
|
|
|
changes,
|
2019-04-26 15:28:16 +02:00
|
|
|
parents = [commit2.id])
|
2018-11-05 15:31:06 +01:00
|
|
|
commit3.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
progress = Progress(b"Done with the master branch now...")
|
2018-11-05 15:31:06 +01:00
|
|
|
progress.dump(output)
|
|
|
|
checkpoint = Checkpoint()
|
|
|
|
checkpoint.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
devel = Reset(b"refs/heads/devel", commit1.id)
|
2018-11-05 15:31:06 +01:00
|
|
|
devel.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
world = Blob(b"Hello\nGoodbye")
|
2018-11-05 15:31:06 +01:00
|
|
|
world.dump(output)
|
|
|
|
|
2019-05-16 04:46:05 +02:00
|
|
|
changes = [FileChange(b'M', b'world', world.id, mode=b"100644")]
|
2019-04-28 00:18:59 +02:00
|
|
|
when = datetime(2006, 8, 17, tzinfo=FixedTimeZone(b"+0200"))
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2019-04-28 00:18:59 +02:00
|
|
|
commit4 = Commit(b"refs/heads/devel",
|
|
|
|
b"A U Thor", b"au@thor.email", when_string,
|
|
|
|
b"Com M. Iter", b"comm@iter.email", when_string,
|
|
|
|
b"Modify world",
|
2018-11-05 15:31:06 +01:00
|
|
|
changes,
|
2019-04-26 15:28:16 +02:00
|
|
|
parents = [commit1.id])
|
2018-11-05 15:31:06 +01:00
|
|
|
commit4.dump(output)
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
world = Blob(b"Hello\nHi\nGoodbye")
|
2018-11-05 15:31:06 +01:00
|
|
|
world.dump(output)
|
2019-02-10 03:24:37 +01:00
|
|
|
when = fr.string_to_date(commit3.author_date) + timedelta(days=47)
|
|
|
|
when_string = fr.date_to_string(when)
|
2018-11-05 15:31:06 +01:00
|
|
|
# git fast-import requires file changes to be listed in terms of differences
|
|
|
|
# to the first parent. Thus, despite the fact that runme and planet have
|
|
|
|
# not changed and bar was not modified in the devel side, we have to list them
|
|
|
|
# all anyway.
|
2019-05-16 04:46:05 +02:00
|
|
|
changes = [FileChange(b'M', b'world', world.id, mode=b"100644"),
|
|
|
|
FileChange(b'D', b'bar'),
|
|
|
|
FileChange(b'M', b'runme', script.id, mode=b"100755"),
|
|
|
|
FileChange(b'M', b'planet', world_link.id, mode=b"120000")]
|
2019-04-28 00:18:59 +02:00
|
|
|
|
|
|
|
commit5 = Commit(b"refs/heads/devel",
|
|
|
|
b"A U Thor", b"au@thor.email", when_string,
|
|
|
|
b"Com M. Iter", b"comm@iter.email", when_string,
|
|
|
|
b"Merge branch 'master'\n",
|
2018-11-05 15:31:06 +01:00
|
|
|
changes,
|
2019-04-26 15:28:16 +02:00
|
|
|
parents = [commit4.id, commit3.id])
|
2018-11-05 15:31:06 +01:00
|
|
|
commit5.dump(output)
|
|
|
|
|
|
|
|
|
2019-04-28 00:18:59 +02:00
|
|
|
mytag = Tag(b"refs/tags/v1.0", commit5.id,
|
|
|
|
b"His R. Highness", b"royalty@my.kingdom", when_string,
|
|
|
|
b"I bequeath to my peons this royal software")
|
2018-11-05 15:31:06 +01:00
|
|
|
mytag.dump(output)
|
|
|
|
out.finish()
|