hg revision specifier for Nth entry in the obslog? (evolve extension) - mercurial

I'm using Mercurial with the evolve extension. Is there a revision specifier that means "the Nth first parent in the obslog for revision X"?
After I rebase a commit I would like to be able to quickly get the diff between the pre-rebased version of the commit and the post-rebased version. (Something similar to Git's #{1} revision specifier.)

You can reference the first parent in obslog (called precursor) by using the following revset: hg log -r "precursors(.)" --hidden. The problem is that you can have multiple precursors for a single revision.
If you are sure you have a linear obsolescence history, you can access the Nth parent by calling precursors several times: hg log -r "precursors(precursors(.))".

Related

Is it possible to pipe output of 'hg log' command to secondary command?

I'm trying to write a small script for my team that automatically updates the feature branche to a case and then creates a branch for review. I've got the commands down manually but I'm having trouble making it a bit more hands off.
For now, I want to use this templated command:
hg log --rev <changeset> --template "{branch}\n"
Which returns the branch name of a changset. Then I would like to remove a portion of the name and prepend a string. For example, a branch would be named case-1234-FeatureDescription and I would want to be creating a branch named review-1234-FeatureDescription
Ideally, I would like to pipe the output of this command to the branch command
hg branch <result-of-previous-command>
Is it possible to do this?
You suggest to create a branch by a name which you just extraced from the logs of the very same repo. That doesn't exactly look like it can succeed as it already exists.
Additionally, it likely is probably not a good idea to create a named branch for each review process as branch names are persistent. You might consider to use bookmarks for that purpose as they can be deleted without trace from the repo after review is completed.
I'd suggest to use - without piping - something like
hg bookmark -r CHANGESET $(hg log --rev CHANGESET -T"{branch}")-review

Detect creating of branches or bookmarks in HG

Is it possible to detect if a commit creates a new bookmark or branch via hooks in .hgrc?
I've tried to see if I can find out using hg log, but it just shows on what branch/bookmark the commit has been created: http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
There don't seem to be hooks for it: http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html
It would make sense I suppose that there isn't a hook for it, because it is also not possible to make a commit which is 'just' the creation of the branch indicating branches/bookmarks only exists when added to a specific commit.
I figured I could check hg branches and hg bookmarks before and after each commit and determine which are removed and added, but is there a cleaner way for detecting branch/bookmark adds/removes?
The pushkey and prepushkey hooks can detect the addition, deletion, and moves of bookmarks.
In hgrc:
[hooks]
prepushkey=echo %HG_NAMESPACE% %HG_KEY% %HG_OLD% %HG_NEW%\n >> out.txt
HG_NAMESPACE will contain "bookmark" and HG_KEY will contain the name of the bookmark.
HG_OLD will contain the hash of the commit the bookmark was before the operation. It won't be set if the bookmark is being created.
HG_NEW will contain the hash of the commit the bookmark will be after the operation. It won't be set if the bookmark is being deleted.
Bookmarks
Bookmarks-handling does not require commit
Bookmark can be created|modified for any changeset in history, not only for current
Bookmark(s) can appear as result of data-exchange (pull|push), not local user's actions
Only part of all possible cases can be covered by hook
Branches
Changing branch always reflected in commit
Branch in changeset may differ from parent's branch not only as result of hg branch (see "merge branches" and "mergesets") - and I haven't nice and easy and ready to use solution for this case
Common notes
You can use standard precommit hook (executed before commit and can enable|disable commit) for testing different conditions in commit or or pretxncommit
Mercurial template-engine has keywords for branch and bookmark for using in hg log -T
In pretxncommit hook commit already exist, but not finalized - it means you can manipulate with commit's data using -r tip and tip's parent in any Mercurial command
Dirty skeleton for hook's body
hg log -T "{KEYWORD}\n" -r "tip + tip^" | ....
where KEYWORD may be branch or bookmarks. Result of log is two-strings output, which can be identical of different (not sure for bookmark, TBT!!), which you have to compare (as you want and can)
PS: Idea inspired by EnsureCommitPolicy Wiki and Mercurial pre commit hook topic here

How to list only my outgoing changes in Mercurial?

I'd like to get a list of the files I've modified and committed before I push.
I can generally do this OK with hg outgoing.
But if I pull in some additional changes, after I've committed mine, then those new changes are also listed, and they are even listed under my name. I did do a commit of the merge, but nothing really merged, I just pulled in an unrelated changeset. If I'm pulling in a lot of changes from other users, my changes get lost in all of these changes.
Is there a way to list just my changes ?
You can always use log with revset's function and some template keywords in order to get such filelist
hg help revsets suggests usage of outgoing():
"outgoing([path])"
Changesets not found in the specified destination repository, or the
default push location.
--template "{files}\n" give you space-separated list of files in each changeset in range and newline-separation of sets from different changesets. --template "{files % '{file}\n'}" do the trivk "file per line"
You can pipe output of log to sort in order to get sorted, without duplicates, list of files
Final draft hg log -r 'outgoing()' --template "{files % '{file}\n'}" | sort -u
You can use
hg outgoing --no-merge
to filter out the merge changesets (-M is the short version see hg help outgoing).
If you are pushing to the same repo from which you pulled the changesets authored by others, you should only see the changesets you created.

How to extract a list of changed files between two mercurial revisions

I need to extract a list of changed files from Mercurial from the last "revision" tag to the current working version instead of the head. The process is part of a batch script, so the current revision bit needs to be automated.
I know that I can get the current revision using:
hg id -n
or
hg parent --template "{rev}\n"
I also know that I can get a list of changed files from a tagged version ("from") like this:
hg st --rev from > file_list.txt
I also know that I can get a list of changed files from a tagged version ("from") to another tagged version ("to") like this:
hg st --rev from --rev to > file_list.txt
However, is there a tag or a way that one can specify the "to" version to be the current working version automatically? I need to be able to exclude the "tip" or "default" files.
This process happens in a DOS batch file, if that helps, and the results are all output to text files.
Sorry - I got confused about which files actually had changed... The answer is as simple as:
hg st --rev from > file_list.txt
That will list all files that have changed from the named revision to the current working version and NOT the head revision (tip or default).

hg command to see the changeset prior to an hg fetch

What mercurial command can you use to see the changeset prior to changeset xyz?
If you do hg log -r :xyz you see all the changesets prior to (and including) xyz - listed in ascending order. But I'd like to easily see just the prior changeset.
Update: Really what I'm after is this: If I do an hg fetch, what command can I use to see the changeset PRIOR to the the changesets that were pulled in by the fetch?
hg log -r :xyz where xyz is the first changeset pulled in by the fetch works but it returns the entire list of prior changesets where I just want the most recent.
You can't do it. Once you've pulled (and fetch is just pull + either update or merge) there is no record of what you had before the pull and what you just got from the pull.
You should do hg incoming before you pull to see what you will get.
Also, stop using fetch. The acts of pulling and updating and merging are completely separate and doing them in a single commands provides inadequate error reporting and just confuses things. The command is disabled by default and there's talk of removing it entirely. Merging is coding, and it shouldn't be hidden.
Expanding to Show cases you can't cover
If before fetching your history is this:
[A]-[B]-[C]
and you (against all advice) fetch and get [D] you now have:
[A]-[B]-[C]-[D]
And you can see exactly what's new with:
hg diff -r tip-1
or with:
hg diff -r "parent(tip)"
But if starting again with A,B,C you fetch and get D,E yielding this:
[A]-[B]-[C]-[D]-[E]
there is no command you can run to see "what changed" without having previously written [C] down on a post it note.
If, on the other hand your repo started out looking like this:
[A]-[B]
\
-[C]
and after fetching you have this:
[A]-[B]-[D]
\
-[C]-[E]
there's no single command that will tell you "what changed". Similarly, if before pulling your repo looked like this:
[A]-[B]-[C]
and after fetching you got this:
[A]-[B]-[C]-[E]-[F]
\ /
-[D]-------/
where [F] is the new ill-advised auto-merge changeset fetch created then the command:
hg diff -r C
will tell you what's new, but there's no way to look up 'C' without having previously written it down.
I assume xyz is a changeset in hash form. Try:
hg log -r :xyz-1
That should work to list just the changeset prior to 1
I'm not sure what is meant by prior. Your question could mean you might just want the parents of the changeset. These you would get easily with
hg parent -r xyz
This does not need fancy new versions of mercurial.
hg parents [-r REV] [FILE]
show the parents of the working directory or revision
Print the working directory's parent revisions. If a revision is given via
-r/--rev, the parent of that revision will be printed. If a file argument
is given, the revision in which the file was last changed (before the
working directory revision or the argument to --rev if given) is printed.
options:
-r --rev show parents of the specified revision
--style display using template map file
--template display with template
--mq operate on patch repository
With the parentrevspec[1] extension installed, you can use the git-like syntax below. Depending on your shell, the quotes may not be necessary.
hg log -r 'xyz^'
https://www.mercurial-scm.org/wiki/ParentrevspecExtension