Skip to main content

GitMap: Map git commits to new commits, preserving history.

Project description

gitmap

Map git commits to new commits, preserving history.

Usage

  1. Install dependencies, pip install -r requirements.txt. (python2 is currently unsupported.)
  2. Inherit the class gitmap.GitMap, and override blob_map and commit_map. The blob_map function maps a source path to a destination path, etc. The commit_map function maps a commit message to a new message, etc.
  3. Call run(src_repo_path, dst_repo_path). All heads will be mapped.
  4. Set remove_empty_commits to True if you want to remove empty commits. (A non-empty commit may be mapped to an empty commit, depending on your map function.)
  5. Moreover, you can add blobs to each commit by overriding commit_add, and print progress by override progress. The commit_add returns a list of blobs, each of which is in the same scheme as blob_map. progress is called after each commit is mapped.

Example

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('Tailing Yuan', 'yuantailing@gmail.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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitmap-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

gitmap-0.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file gitmap-0.0.1.tar.gz.

File metadata

  • Download URL: gitmap-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for gitmap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 11e6037cce03ac102f1c1dfa5acd515fb7457f9ed28ecf661d16d9c620df9cae
MD5 a0b91763b62aecd6e5b00d0dbe22658f
BLAKE2b-256 8cec7f7831bce19a7698d063a2afb9d8d37d0c68aa6062777924463d99b7218b

See more details on using hashes here.

File details

Details for the file gitmap-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: gitmap-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for gitmap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa278be73ff600e69742a33bf1d1e143fee02c884a413a3d34b4b3f6c2479ad2
MD5 eb64e8676704d5890e457f511123f921
BLAKE2b-256 e52bb45593a2db929bacaa42757a5343c5fa4de6c72c8b9bd762b4d5f0b0a424

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page