Re: Fixing Commit And Author
- From
- Darrin Thompson <darrint@progeny.com>
- Date
- Nov 4, 2005, 21:35 UTC
- Message-ID
- <1131140121.24792.9.camel@localhost.localdomain>
- In-Reply-To
- <Pine.LNX.4.64.0511040924400.27915@g5.osdl.org>
On Fri, 2005-11-04 at 09:30 -0800, Linus Torvalds wrote:
Show 6 quoted lines
> The rules currently do _not_ include changing the author/committer info, > but it does know how to parse the really old-style dates, for example, > which are on those same lines, so adding some code there to also re-write > the author/committer name and email wouldn't be impossible. > > The code isn't necessarily all that easy to understand,
I can follow it mostly. If the commits were being read and built from scratch with strbuf's I'd be willing to give it a try. :-)
I was able to hack together a really stupid python script that worked fine (I think) for my less demanding case.
import sys import os
name = "Darrin Thompson" mail = "email@address" os.environ['GIT_AUTHOR_NAME'] = name os.environ['GIT_AUTHOR_EMAIL'] = mail os.environ['GIT_COMMITTER_NAME'] = name os.environ['GIT_COMMITTER_EMAIL'] = mail
commits = os.popen('git-rev-list HEAD | tac')def parse_commit(commit):
tree = '///'
parents = []
lines = os.popen('git-cat-file commit %s' % commit)
for line in lines:
if not line.strip():
break
key, value = line.strip().split(None, 1)
if key == 'tree':
tree = value
elif key == 'parent':
parents.append(value)
elif key == 'author' or key == 'committer':
parts = value.split()
seconds, tz = parts[-2:]
date = ' '.join([seconds, tz]) message = ''.join(lines)
return tree, parents, message, datetag_map = {}
tags = os.popen('git-rev-parse --symbolic --all | grep ^refs/tags/')
for line in tags:
filename = line.strip()
tag_name = filename.split('/')[-1]
tag_commit = os.popen('git-rev-parse %s' % tag_name).read().strip()
tag_list = tag_map.setdefault(tag_commit, [])
tag_list.append(tag_name)commit_map = {}
for line in commits:
commit = line.strip()
tree, bio_parents, message, date = parse_commit(commit)
real_parents = [ commit_map[p] for p in bio_parents ]
parents_args = ' '.join([ '-p %s' % p for p in real_parents ])
os.environ['GIT_COMMITTER_DATE'] = date
os.environ['GIT_AUTHOR_DATE'] = date
write_handle, read_handle \
= os.popen2('git-commit-tree %s %s' % (tree, parents_args), 'w')
write_handle.write(message)
write_handle.close()
new_commit = read_handle.read().strip()
commit_map[commit] = new_commit
for tag_name in tag_map.get(commit, []):
os.system('git-tag -f %s %s' % (tag_name, new_commit))
read_handle.close()print new_commit
-- Darrin