2018-11-05 15:31:06 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-02-10 03:24:37 +01:00
|
|
|
import git_filter_repo as fr
|
|
|
|
from git_filter_repo import Blob, Reset, FileChanges, Commit, Tag, FixedTimeZone
|
|
|
|
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
|
|
|
|
|
|
|
|
world = Blob("Hello")
|
|
|
|
world.dump(output)
|
|
|
|
|
|
|
|
bar = Blob("foo\n")
|
|
|
|
bar.dump(output)
|
|
|
|
|
|
|
|
master = Reset("refs/heads/master")
|
|
|
|
master.dump(output)
|
|
|
|
|
|
|
|
changes = [FileChanges('M', 'world', world.id, mode="100644"),
|
|
|
|
FileChanges('M', 'bar', bar.id, mode="100644")]
|
|
|
|
when = datetime(year=2005, month=4, day=7,
|
|
|
|
hour=15, minute=16, second=10,
|
|
|
|
tzinfo=FixedTimeZone("-0700"))
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2018-11-05 15:31:06 +01:00
|
|
|
commit1 = Commit("refs/heads/master",
|
2019-02-05 03:30:50 +01:00
|
|
|
"A U Thor", "au@thor.email", when_string,
|
|
|
|
"Com M. Iter", "comm@iter.email", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"My first commit! Wooot!\n\nLonger description",
|
|
|
|
changes,
|
|
|
|
from_commit = None,
|
|
|
|
merge_commits = [])
|
|
|
|
commit1.dump(output)
|
|
|
|
|
|
|
|
world = Blob("Hello\nHi")
|
|
|
|
world.dump(output)
|
|
|
|
world_link = Blob("world")
|
|
|
|
world_link.dump(output)
|
|
|
|
|
|
|
|
changes = [FileChanges('M', 'world', world.id, mode="100644"),
|
|
|
|
FileChanges('M', 'planet', world_link.id, mode="120000")]
|
|
|
|
when += timedelta(days=3, hours=4, minutes=6)
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2018-11-05 15:31:06 +01:00
|
|
|
commit2 = Commit("refs/heads/master",
|
2019-02-05 03:30:50 +01:00
|
|
|
"A U Thor", "au@thor.email", when_string,
|
|
|
|
"Com M. Iter", "comm@iter.email", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"Make a symlink to world called planet, modify world",
|
|
|
|
changes,
|
|
|
|
from_commit = commit1.id,
|
|
|
|
merge_commits = [])
|
|
|
|
commit2.dump(output)
|
|
|
|
|
|
|
|
script = Blob("#!/bin/sh\n\necho Hello")
|
|
|
|
script.dump(output)
|
|
|
|
changes = [FileChanges('M', 'runme', script.id, mode="100755"),
|
|
|
|
FileChanges('D', 'bar')]
|
2019-02-05 03:30:50 +01:00
|
|
|
when_string = "1234567890 -0700"
|
2018-11-05 15:31:06 +01:00
|
|
|
commit3 = Commit("refs/heads/master",
|
2019-02-05 03:30:50 +01:00
|
|
|
"A U Thor", "au@thor.email", when_string,
|
|
|
|
"Com M. Iter", "comm@iter.email", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"Add runme script, remove bar",
|
|
|
|
changes,
|
|
|
|
from_commit = commit2.id,
|
|
|
|
merge_commits = [])
|
|
|
|
commit3.dump(output)
|
|
|
|
|
|
|
|
progress = Progress("Done with the master branch now...")
|
|
|
|
progress.dump(output)
|
|
|
|
checkpoint = Checkpoint()
|
|
|
|
checkpoint.dump(output)
|
|
|
|
|
|
|
|
devel = Reset("refs/heads/devel", commit1.id)
|
|
|
|
devel.dump(output)
|
|
|
|
|
|
|
|
world = Blob("Hello\nGoodbye")
|
|
|
|
world.dump(output)
|
|
|
|
|
|
|
|
changes = [FileChanges('M', 'world', world.id, mode="100644")]
|
|
|
|
when = datetime(2006, 8, 17, tzinfo=FixedTimeZone("+0200"))
|
2019-02-10 03:24:37 +01:00
|
|
|
when_string = fr.date_to_string(when)
|
2018-11-05 15:31:06 +01:00
|
|
|
commit4 = Commit("refs/heads/devel",
|
2019-02-05 03:30:50 +01:00
|
|
|
"A U Thor", "au@thor.email", when_string,
|
|
|
|
"Com M. Iter", "comm@iter.email", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"Modify world",
|
|
|
|
changes,
|
|
|
|
from_commit = commit1.id,
|
|
|
|
merge_commits = [])
|
|
|
|
commit4.dump(output)
|
|
|
|
|
|
|
|
world = Blob("Hello\nHi\nGoodbye")
|
|
|
|
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.
|
|
|
|
changes = [FileChanges('M', 'world', world.id, mode="100644"),
|
|
|
|
FileChanges('D', 'bar'),
|
|
|
|
FileChanges('M', 'runme', script.id, mode="100755"),
|
|
|
|
FileChanges('M', 'planet', world_link.id, mode="120000")]
|
|
|
|
|
|
|
|
commit5 = Commit("refs/heads/devel",
|
2019-02-05 03:30:50 +01:00
|
|
|
"A U Thor", "au@thor.email", when_string,
|
|
|
|
"Com M. Iter", "comm@iter.email", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"Merge branch 'master'\n",
|
|
|
|
changes,
|
|
|
|
from_commit = commit4.id,
|
|
|
|
merge_commits = [commit3.id])
|
|
|
|
commit5.dump(output)
|
|
|
|
|
|
|
|
|
|
|
|
mytag = Tag("refs/tags/v1.0", commit5.id,
|
2019-02-05 03:30:50 +01:00
|
|
|
"His R. Highness", "royalty@my.kingdom", when_string,
|
2018-11-05 15:31:06 +01:00
|
|
|
"I bequeath to my peons this royal software")
|
|
|
|
mytag.dump(output)
|
|
|
|
out.finish()
|