Mercurial: How can I change default tag message template? - version-control

I would like to use some prefix labels in commit messages to quickly identify the kind of commit when viewing the revision log, and for ability to quickly filter down the log.
Some of the prefixes I intend to use are (TAG:, MERGE:, TEST:, STABLE:, TRUE-UP:, FIX():, FEATURE():, & possibly others).
Additionally, for tags I would like to change the default message to be a little more descriptive, like so:
TAG: Added tag v3.4 for e90d0caa766 created on 2022-09-22 01:05:00
Applied fix for foobar.
For tagging, Mercurial seems to not open the editor so I can examine the tag message, so my attempts to debug this have been tedious.
I've tried adding the following to my repo hgrc config file:
[committemplate]
changeset.tag = "TAG: Added tag {tag} for {node|short} created on {date|isodate}\n{desc}"
I've also played around with the [hooks] section and pretag hook.
Additionally, I've tried on the command line with various formatting adjustments:
hg tag -r . -m 'TAG: Added tag {tag} for {node|short} created on {date|isodate}\n{desc}' test4
For the command line attempt above none of this populates the template fields in the message, and for the other attempts in the hgrc config file, this has not altered the commit message not once or even errored.
What am I missing here?

[committemplate] work, if it was added to hgrc (tried at repo-level, not globally), but somehow not in expected form (see below)
Just note: if you'll use "Added tag" wording, you, maybe want to limit area of modified message to only adding tags (hg tag can remove tags also, BTW) with changeset.tag.add
My test-case
Hg 6.2.2
No redefined committemplate in global config
Dumb oneliner for changeset.tag and later for changeset.tag.add
Tagging pure in CLI (due to total fails in THG)
Some logs
Plain hg tag -r 0 0.1 + hg tag --remove 0.1 used with changeset.tag redefined (default messages used by hg)
changeset: 2:006c40256d9b
user: lazybadger
date: Thu Sep 22 17:05:15 2022 +0500
summary: Removed tag 0.1
changeset: 1:1927f74a0ec0
user: lazybadger
date: Thu Sep 22 17:02:46 2022 +0500
summary: Added tag 0.1 for changeset 8385f66bee57
Tagging with -e additional option (BEWARE: tag inserted in editor by hand, {tag} nor {tags} are not expanded in changeset.tag.* text)
changeset: 7:5aee36e13e4d
tag: lazybadger
date: Thu Sep 22 17:13:43 2022 +0500
summary: TAGGING: Tag 0.3 added
...
changeset: 3:9a4b0a117fb1
user: lazybadger
date: Thu Sep 22 17:06:23 2022 +0500
summary: TAG: Tag 0.1 touched

Related

SVN Keywords File doesn't update after switch revision

Hi I am using svn in Eclipse.
My problem is that the File with the keywords doesn't update when I switch the revision. Example I am on the trunk, my file show me that
// File name: $HeadURL: svn://svnsrv.blabla.de/TestProjekt/trunk/TestProjekt/SVNInfo.txt $
// Revision: $Revision: 30 $
// Last modified: $Date: 2019-06-04 09:04:08 +0200 (Di, 04 Jun 2019) $
// Last modified by: $Author: scn $
and when i create now a tag und switch to him, it shows me the same file but if i look in TortoiseSVN the file is updated.
Is there an option in Eclipse to activate this? Is my way the right?
My file SVNInfo.txt is in the project directory.
// File name: $HeadURL$
// Revision: $Revision$
// Last modified: $Date$
// Last modified by: $Author$
Then I set svn:keywords with Set Property... on the Projekt and then set keywords.
At last i commit the Project.

How do you find the changesets between two tags in mercurial?

If I have two tags named 2.0 and 2.1, how do I find the changeset messages between the two? I'm trying to find to a way to use HG make release notes and list the different messages associated with the commits.
Example Changeset:
changeset: 263:5a4b3c2d1e
user: User Name <user.name#gmail.com>
date: Tue Nov 27 14:22:54 2018 -0500
summary: Added tag 2.0.1 for changeset 9876fghij
Desired Output:
Added tag 2.1 for changeset 67890pqrst
Change Info...
Added tag 2.0.1 for changeset 9876fghij
Change Info...
Added tag 2.0 for changeset klmno12345
Preface
"Any challenge has a simple, easy-to-understand wrong decision". And Boris's answer is a nicest illustration for this rule: "::" topo-range will produce good results only in case of pure single-branch development (which is, in common, The Bad Idea (tm) anyway)
Face
Good solution must correctly handle complex DAGs and answer on question "New changesets included in NEW, missing in OLD (regardless of the nature of occurrence)"
For me it's "only()" functions in revsets with both parameters
"only(set, [set])"
Changesets that are ancestors of the first set that are not ancestors
of any other head in the repo. If a second set is specified, the
result is ancestors of the first set that are not ancestors of the
second set (i.e. ::set1 - ::set2).
hg log -r "only(2.1,2.0)"
maybe for better presentation powered by predefined style "changelog"
hg log -r "only(2.1,2.0)" -s changelog
or custom style|template
You'll want to use a revset to select all changesets between two tags, for example: 2.0::2.1 will likely do the trick. You can validate the selected changesets by running: hg log -G -r '2.0::2.1'. (See hg help revset for more information about revsets).
Once you have the right selected changesets, you can now apply a template to retrieve only the needed information. For example if you only want the first line of changeset description, you can do hg log -r '2.0::2.1' -T '{desc}\n' for the whole description or hg log -r '2.0::2.1' -T '{desc|firstline}\n' only for the first line of each changeset description.
If you want to add even more information, hg help template is your friend.

How to view a single Mercurial commit from the command line?

I would like to view from the commandline what was changed in given Mercurial commit similar to what one would see from hg status or from the TortoiseHg tool. The closest I can seem to get is hg log --stat but that prints extra symbols (i.e. pluses and minuses) and I cannot specify at which specific revision I want to look.
I need this because I have developers who have check-in comments like "." or ",". >:-(
It turns out that hg status has a --change argument where you can pass the revision number (e.g. 109), relative revision (ie -1 is last commit, -2 is second-last, etc), or the hash of the revision to it and it will print out the changes (i.e. additions, removals, and modification) that revision had.
--change isolates that revision and shows just from that revision, but replacing --change with --rev shows the cumulative effect since that revision to the current state.
hg log -v -r <changeset>
changeset: 563:af4d66e2bc6e
tag: tip
user: David M. Carr <****>
date: Fri Oct 26 22:46:02 2012 -0400
files: hggit/gitrepo.py tests/test-pull.t
description:
pull: don't pull tags as bookmarks
or, using templates, something like
hg log -r tip --template "{node|short} - files: {files}\n"
with output
af4d66e2bc6e - files: hggit/gitrepo.py tests/test-pull.t

How to edit Mercurial commit message after branching?

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?
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()
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
I needed something similar so I filed a feature request.

How to get the closest revision to the given one that contains other changes than .hgtags only?

I have a revision hash key. I would like to get the closest revision that contains anything, but the .hgtags.
For instance, consider the following fragment of a Mercurial history:
D:\CI\NC\8.0>hg log -l3 -b 8.0 -v
changeset: 1768:633cf1f61665
branch: 8.0
tag: tip
user: ci
date: Wed Nov 16 21:06:20 2011 +0200
files: .hgtags
description:
Replaced tag 'good.NC.16' with 'rejected.NC.16' for changeset 9451e8f187b1
changeset: 1767:6cad328c622c
branch: 8.0
parent: 1765:9451e8f187b1
user: ci
date: Wed Nov 16 21:04:26 2011 +0200
files: .hgtags
description:
Added tag 'good.NC.16' for changeset 9451e8f187b1
changeset: 1765:9451e8f187b1
branch: 8.0
tag: rejected.NC.16
user: gilad
date: Tue Nov 15 18:26:09 2011 +0200
files: .hgignore
description:
update
In this case, if the given revision is 633cf1f61665, then I am looking for the revision 9451e8f187b1, because it is the closest one, which contains not just .hgtags, but something else.
How, given 633cf1f61665, can I locate 9451e8f187b1 using as few hg.exe invocations as possible?
EDIT
I have fixed the output, it should have displayed revisions from the same branch.
EDIT2
I will try to explain myself. Let us define two notions:
A dull changeset - the one created by the hg tag action.
An interesting changeset - any non dull changeset.
So, my question can be rephrased like so:
Given an arbitrary revision (dull or interesting) I need to find the closest
interesting revision belonging to the same named branch using as few hg invocations
as possible.
For instance, given 633cf1f61665 or 6cad328c622c or 9451e8f187b1 the required revision is 9451e8f187b1.
Try with
$ hg log -r "max(::REV and not file(.hgtags))"
and see if that does what you want. See hg help revsets for more information about the query language.
You can make a revset alias for this if you use it often:
[revsetalias]
interesting($1) = max(::$1 and not file(.hgtags))
and then use hg log -r "interesting(123)" in the future.