Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mercurial: test whether a branch contains a changeset

Tags:

mercurial

I wonder whether there is a mercurial command/extension that just tests whether a given changeset is in a branch. The command would be something like:

hg contains [-r branch] changeset_id

and should check whether the given changeset is in the current/given branch, returning just "Yes" or "No".

I know about the "debugancestor" command, but a "Yes/No" answer is way easier to read.

And if there is, is it possible to check for transplanted changesets as well?

EDIT: The scenario is located in a repo where named branches have multiple heads. Lets say a branch is named "dev-X", having more than 1 head and a longer history, too long at least to track it with various graph visualizations. I want to figure out whether a changeset X in branch "dev-X" was merged into another head of "dev-X". Therefore I cannot use branch names but only changeset numbers/hashes to specify a branch.

And to top it all, I'm trying to find out whether changeset X was transplanted there, possibly taking more than 1 transplantation step. I know that the necessary info is stored in mercurial (I've seen it when tampering with the mercurial internals), it's just not accessible via the command line interface.

like image 814
resi Avatar asked Nov 05 '09 15:11

resi


People also ask

What is mercurial changeset?

A changeset (sometimes abbreviated "cset") is an atomic collection of changes to files in a repository. It contains all recorded local modification that lead to a new revision of the repository. A changeset is identified uniquely by a changeset ID. In a single repository, you can identify it using a revision number.

Does Mercurial have branches?

Mercurial supports giving names to branches, by using the branch name property of the changeset (see NamedBranches). If no branch name was set, Mercurial assigns the branch name "default". So the name of the default branch in a repository is "default" (which, for example, is not displayed when doing a hg log).

How to change branch hg?

From the main menu, select Hg | Mercurial | Update to. In the Switch Working Directory dialog that opens, specify the target working directory: To switch to another line of development, choose Branch and select the desired branch from the list.

What does hg push do?

Description. Push changesets from the local repository to the specified destination. This operation is symmetrical to pull: it is identical to a pull in the destination repository from the current one.


2 Answers

How about this:

hg log -r changeset_id -b branchname

That will give some output if changeid_id includes changes on branch branchname, otherwise no output is returned.

You could wrap it in a bash function if you want:

function contains() {
    if [ "$(hg log -r $1 -b $2)" == "" ]
    then
        echo no
    else
        echo yes
    fi
}

which does this:

$ contains 0 default
yes
$ contains 0 other   
no
like image 99
Ry4an Brase Avatar answered Oct 02 '22 16:10

Ry4an Brase


using 1.6 and later with the power of revision sets all you need is

hg log --rev "ancestors(.) and <revNum>"

eg

hg log --rev "ancestors(.) and 1234"

blank means no, output means yes, its in your history. Some of the other solutions posted here wont work if the changeset was created in a named branch, even if it was merged at some point later.

like image 44
Dori Avatar answered Oct 02 '22 17:10

Dori