git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Darrin Thompson <darrint@progeny.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: Re: Fixing Commit And Author
Date: Fri, 04 Nov 2005 16:35:21 -0500	[thread overview]
Message-ID: <1131140121.24792.9.camel@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0511040924400.27915@g5.osdl.org>

On Fri, 2005-11-04 at 09:30 -0800, Linus Torvalds wrote:
> 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, date


tag_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

      reply	other threads:[~2005-11-04 21:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04 16:38 Fixing Commit And Author Darrin Thompson
2005-11-04 17:30 ` Linus Torvalds
2005-11-04 21:35   ` Darrin Thompson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1131140121.24792.9.camel@localhost.localdomain \
    --to=darrint@progeny.com \
    --cc=git@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).