8

I have some old commit messages in a Mercurial repository that should be changed (to adjust for some new tools). I already understand that this hacking has to be done on the master repository and all local repositories would have to be re-cloned, because checksums of all subsequent changesets will also change.

I've tried following the recipes in "How to edit incorrect commit messages in Mercurial?", but with MQ extension I got stuck on error message

X:\project>hg qimport -r 2:tip
abort: revision 2 is the root of more than one branch

and with Histedit quite similarly

X:\project>hg histedit 2
abort: cannot edit history that would orphan nodes

The problem seems to be that there have been branches created after the changeset.

I can see how it would become messy if I'd want to change the contents of patch, but perhaps there's a workaround that I've missed for editing the commit message?

Community
  • 1
  • 1
Imre
  • 221
  • 3
  • 14
  • Are you *really* sure you need to do this? I'm pretty curious what sort of tooling change is forcing you to undertake this. – John Zwinck Nov 17 '11 at 02:46
  • 1
    AFAIK, you can't use MQ or HistEdit to edit a commit message after branching and I'm not aware of an other tool able to do that. @Sergey if you read the question carefully you will see that the link you provided is of no help at all, the OP already tried the solution proposed their ;) – krtek Nov 17 '11 at 02:57
  • @krtek I do read it carefully. particularly error message. so if repository already cloned between users it is problem for all users. – Sergei Nikulov Nov 17 '11 at 04:08
  • 1
    @JohnZwinck task management for a couple of projects was migrated to a new system, which picks up relationships with commits by the commit message. Currently, the messages have references only to old system, meaningless for the new one. – Imre Nov 17 '11 at 07:46
  • Sounds like it is time to write some compatibility logic into the new system. – John Zwinck Nov 18 '11 at 14:59

3 Answers3

4

I would use a hacked version of the convert extension to do this. The extension can do hg → hg conversions which lets you alter author and branch names. There is not support for changing commit messages yet, but you can hack it.

Specifically, you should change the getcommit method from:

def getcommit(self, rev):
    ctx = self.changectx(rev)
    parents = [p.hex() for p in self.parents(ctx)]
    if self.saverev:
        crev = rev
    else:
        crev = None
    return commit(author=ctx.user(), date=util.datestr(ctx.date()),
                  desc=ctx.description(), rev=crev, parents=parents,
                  branch=ctx.branch(), extra=ctx.extra(),
                  sortkey=ctx.rev())

which is responsible for reading the old commits. Change the

desc=ctx.description()

to

desc=adjust(ctx.description())

and then implement the adjust function at the top of the file:

def adjust(text):
    return text.upper()
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Martin Geisler
  • 69,865
  • 23
  • 162
  • 224
2

If these are accidental/duplicate branches due to using --amend and push --force then strip them first and try 'histedit' again then wipe the central repo on bitbucket; try the following which worked for me:

Inspect the repository log and look for branches, you can use the GraphlogExtension which you will have to enable first:

# hg log -G | more
...
o  changeset:   43:c2fcca731aa5
|  parent:      41:59669b9dfa4a
|  user:        Daniel Sokolowski (https://webdesign.danols.com)
|  date:        Tue Aug 27 20:14:38 2013 -0400
|  summary:     Progress snapshot: major content text and model instance  ..
...
| o  changeset:   42:c50724a6f1c6 
|/   user:        Daniel Sokolowski (https://webdesign.danols.com)
|    date:        Tue Aug 27 20:14:38 2013 -0400
|    summary:     Progress snapshot: major content text and model instance ...
|
o  changeset:   41:59669b9dfa4a
|  user:        Daniel Sokolowski (https://webdesign.danols.com)
...

Enable the MqExtension and strip all branches.

# hg strip --no-backup 42:c50724a6f1c6
# hg strip --no-backup 45:3420dja12jsa
...

If needed change the commit to 'draft' (see Phases) and re-run 'histedit' and all should be good now.

# hg histedit 14:599dfa4a669b
abort: cannot edit immutable changeset: b7cfa2f28bde
# hg phase -f -d 14:599dfa4a669b
# hg hsitedit 14:599dfa4a669ba
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Daniel Sokolowski
  • 10,545
  • 3
  • 61
  • 49
0

I needed something similar so I filed a feature request.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Gili
  • 76,473
  • 85
  • 341
  • 624