Map git commits to new commits, preserving history.
- Install dependencies,
pip install -r requirements.txt. (python2 is currently unsupported.) - Inherit class
gitmap.GitMap, and overrideblob_mapandcommit_map. Theblob_mapfunction maps a source path to a destination path, etc. Blobs mapped toNonewill be deleted from all commits. Thecommit_mapfunction maps a commit message to a new message, etc. - Call
run(src_repo_path, dst_repo_path). All heads will be mapped. - Set
remove_empty_commitstoTrueif you want to remove empty commits. (A non-empty commit may be mapped to an empty commit, depending on your map function.) - Moreover, you can add blobs to each commit by overriding
commit_add, and print progress by overrideprogress. Thecommit_addreturns a list of blobs, each of which is in the same scheme asblob_map.progressis called after each commit is mapped.
See example.py.
class MyGitMap(gitmap.GitMap):
def blob_map(self, data_stream, mode, path):
# keep README and LICENSE
if path in ['README.md', 'LICENSE.txt']:
return data_stream.read(), mode, path
# flatten python dir
if path.startswith('python/'):
return data_stream.read(), mode, path[len('python/'):]
# delete other files
else:
return None
def commit_add(self, old_commit):
# add .gitignore
return [
(b'__pycache__\njittor.egg-info\n', 0o100644, '.gitignore'),
]
def commit_map(self, old_commit, message, author, authored_date, author_tz_offset, committer, committed_date, committer_tz_offset):
# keep author, update committer
committer = git.Actor('The committer', 'committer@example.com')
committed_date = time.time()
return message, author, authored_date, author_tz_offset, committer, committed_date, committer_tz_offset
def progress(self, old_commit, new_commit):
# logging
print('committed', old_commit, '=>', new_commit)
remove_empty_commits = True
MyGitMap().run('../jittor', '../jittor-python-only')