Skip to content

Instantly share code, notes, and snippets.

@hmeine
Last active March 11, 2021 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmeine/4a671ea1a083c7130cf52d6a3284db0e to your computer and use it in GitHub Desktop.
Save hmeine/4a671ea1a083c7130cf52d6a3284db0e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse, subprocess, sys, re
def resolve_glob_filename(filename):
resolve_glob_filename = subprocess.check_output(
'git log -n1 --name-only --format=oneline --'.split() + [filename], text = True).split('\n')
commit = resolve_glob_filename[0].split()[0]
full_path = resolve_glob_filename[1]
return commit, full_path
re_svn_id = re.compile(r'git-svn-id: (.*)@([0-9]+) ([0-9a-f-]+)$')
def parse_svn_info(log_message):
ma = re_svn_id.search(log_message)
return ma.groups()
def get_svn_info(commit):
return parse_svn_info(
subprocess.check_output('git cat-file -p'.split() + [commit], text = True))
parser = argparse.ArgumentParser(description = 'display combined history from git log and svn log')
parser.add_argument('filename')
args = parser.parse_args()
commit, full_path = resolve_glob_filename(args.filename)
base_url, rev, repo_id = get_svn_info(commit)
rev = int(rev)
svn_log_command = ['svn', 'log', '-v', f'{base_url}/{full_path}@{rev}']
print(' '.join(svn_log_command))
subprocess.check_call(svn_log_command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment