Mercurial Queues: How to reorder patches efficiently - mercurial

Suppose I have the follow patches in my mercurial queue:
$ hg qser -v
0 A p1
1 A p2
2 A p3-StupidPatch
3 A p4
5 A p6
...
15 A p15
Now suppose that I want to do is reorder the patches so that p3-Stupid patch is the last patch. IE:
$ hg qser -v
0 A p1
1 A p2
2 A p4
3 A p6
...
14 A p15
15 A p3-StupidPatch
I know that I could do it like this:
$ # Pop patches until p2
$ hg qpop p2
$
$ hg qser -v
0 A p1
1 A p2
2 U p3-StupidPatch
3 U p4
5 U p6
...
15 U p15
$
$ # Push patches one by one
$ hg qpush --move p4
$ hg qpush --move p5
$ hg qpush --move p6
$ hg qpush --move p7
$ hg qpush --move p8
$ hg qpush --move p9
$ hg qpush --move p10
$ hg qpush --move p11
$ hg qpush --move p12
$ hg qpush --move p13
$ hg qpush --move p14
$ hg qpush --move p15
$ hg qpush --move p3-StupidPatch
Is there a better way to do this?

You could unapply all the patches and change the order in the file .hg/patches/series. That's where the order is really stored.

You can use hgtk log to reorder patches like this:

Related

Finding logical change log

I'm trying to figure out a way to get an oddly-specific set of logs. This is input into a different program, where I'm parsing the logs and doing stuff with them, but ideally it would be great to do as much as possible with the hg commands to minimize my post-processing.
I want all commits marked with "O" and none of the "X" ones:
A5 O
|
|
|
A4 O X B4 X C2
|\ | |
| \ | |
| \| |
A3 O O B3 |
| | |
| | |
| | |
A2 O O B2 X C1
| | |
| | |
| | |
| O B1 |
| /| |
| / | |
|/ | |
A1 X X B0 X C0
|
|
|
A0 X
Given this chart, where A, B, and C are different branches, our users want a log of changes between A2 and A5. The issue is that they also want to know the rest of the history of any branches merged into A.
hg log -r A2:A5 will return:
A2,3,4,5
B2,3,4
C1,2
First off, I don't want C whatsoever. It isn't connected to anything here.
But what I do want is B1, or more generally all changes in B since it was last merged into A. Also I don't want B4. So if I have hanging tails that connect farther up, I need to find the rest. Annoyingly, they do not want A1.
My current plan is log A2:A5, then I create a tree structure from parsing the results. At the end I look for any hanging tails, and get the log of the common ancestor of that tail and A2, and A2, for just that branch. That's sort of convoluted and crazy.
Any ideas or suggestions to make this easy and reduce the work I have to do to post-process?
An improvement on your current approach will be hg log -r "A5 % parents(A2)". This is equivalent to A5 and all its ancestors, less A1 and any of its ancestors, so it returns:
A2,A3,A4, and A5
B0,B1,B2, and B3
Notably, the following will be excluded:
Any changeset in C
Changesets in B that hasn't been merged into A (e.g. B4)
There is only one undesired changeset in the resulting revset: B0. The criteria for removing that is a little unclear to me (It would probably help to see the ancestors A0, B0 and C0, as they will all stem from a common node at some point). I think a clarification of the stop conditions going backwards on branches that merge into A2::A5 is needed before a revset can be constructed.
However, that revset will probably be quite complicated, and it may be easier to postprocess the above revset instead.
Edit: Some further thoughts
You may be better off doing multiple different revsets:
hg log -r "A2::A5" returns the DAG from A2 to A5 (i.e. A2,A3,A4,A5)
hg log -r "(parents( A2::A5 & merge() ) - ( A2::A5 + parents(A2) ) )" will return any changeset that has been merged into the DAG from A2 to A5 (i.e. B3)
The first one will go directly to your final result set. The second one you can iterate (Imagine there's also a branch D with a D3 that's merged into the branch of interest) and traverse each branch towards the stop criteria, then add the relevant changesets into the final result set.
Iterating the merged branches to stop at the right time may be simpler than trying to prune a larger result set of the incorrectly included changesets

Mercurial - generate patch for both committed and uncommitted changes combined

Sometimes in development it is useful for me to see a diff for both committed changes and uncommitted changes combined.
eg, as though they were either both uncommitted and I used hg diff,
or both uncommitted and I used hg diff -c REV.
Is there a way to do that? I have tried variants of diff, export and log.
For this toy-repo in such state
>hg st
M a.txt
>hg log --style compact
1[tip] 4d554db9595b 2016-08-05 23:56 +0500 lazybadger
Change 1
0 8bc9bcf8b736 2016-08-05 23:55 +0500 lazybadger
Initial state
combined diff for 4d554db9595b
>hg diff -c 1
diff -r 8bc9bcf8b736 -r 4d554db9595b a.txt
--- a/a.txt Fri Aug 05 23:55:46 2016 +0500
+++ b/a.txt Fri Aug 05 23:56:19 2016 +0500
## -1,1 +1,2 ##
Line 1
+Line 2
and workdir
>hg diff
diff -r 4d554db9595b a.txt
--- a/a.txt Fri Aug 05 23:56:19 2016 +0500
+++ b/a.txt Fri Aug 05 23:57:59 2016 +0500
## -1,2 +1,3 ##
Line 1
Line 2
+Line 3
will be, obviously
>hg diff -r "parents(1)"
diff -r 8bc9bcf8b736 a.txt
--- a/a.txt Fri Aug 05 23:55:46 2016 +0500
+++ b/a.txt Sat Aug 06 00:06:20 2016 +0500
## -1,1 +1,3 ##
Line 1
+Line 2
+Line 3
PS: Just some fast-reading of hg help diff, nothing more harder... use brain, at last!

Joining 2 csv files in OS X

I want to join 2 csv files, e.g.
A,B
1,2
and
C,D
1,3
to
A,B,C,D
1,2,1,3
I had tried it out with
cat *.csv >merged.csv
But it doesnt reach the goal, that I want.
Can anyone helps me
cat stands for concatenate, it prints the 1st file and then the content of 2nd file after it not next to it. So using cat you cant achieve your output:
$ cat *.csv
A,B
1,2
C,D
1,3
$
You can use the paste command which paste's lines from 2 files side by side i.e line 1 from file 1 is pasted before line 1 from file 2.
$ cat file1.csv
A,B
1,2
$ cat file2.csv
C,D
1,3
$ paste -d ',' file1.csv file2.csv > newfile.csv
$ cat newfile.csv
A,B,C,D
1,2,1,3
$
-d , means delimiter must be comma.

How to delete a head?

I have pushed some files by mistake and it shows different heads in main repository. How can I delete that head?
You can enable the "mq" extension by editing your .hgrc file.
Make sure the following lines are present:
[extensions]
mq =
Afterwards you can "strip" a specific revision which deletes it so that you have only one head:
hg strip ...
I don't think that you actually want to delete the heads. If you do that, you will lose the work that was done in those branches.
You probably want to merge the heads back into one branch.
Say that you have a tree like this:
o 4 : Head 1
|
o 3 : Another commit
|
| o 2 : Head 2
| |
|/
o 1 : A commit
|
o 0 : Initial commit
To get rid of the additional head without losing the work contained within it you would merge the two heads (revisions 2 and 4 in this example) like this:
hg update 4
hg merge 2
hg commit -m "Merge"
That will create another commit which has all the changes in revisions 2, 3 and 4 in a single head like this:
o 5: Merge
|\
o | 4 : Head 1
| |
o | 3 : Another commit
| |
| o 2 : Head 2
| |
|/
o 1 : A commit
|
o 0 : Initial commit
This is standard procedure when multiple developers work on the same repository.

How to get mercurial commit sequence number in a branch

I want to retrieve commit order number, counting ONLY commits of specific branch (master).
As a branch "master" is the same on each machine/repo, then this will allow me to:
1. Have the same number regardless of the repository
2. Use this number in a version string.
So, is there any way to accomplish this?
hg log -b master --template "." | wc -m for example
Output current amount of changesets in branch
Your idea wont work, even though you limit yourself to a single named branch. As mentioned by Ry4an, the problem is that the order of changesets on that branch is determined by the order of hg push and hg pull. So you can easily end up with a situation where you have:
# branch: master, changeset: 5:f5b6808f2f04, summary: merge
|\
| o branch: master, changeset: 4:2b7bdcc98a88, summary: mmm
| |
o | branch: master, changeset: 3:6b60342a01a6, summary: mm
|/
o branch: master, changeset: 2:f39fa3fa1aaf, summary: m
|
o branch: master, changeset: 1:4dd5e8ae6481, summary: create master
|
o branch: default, changeset: 0:68b4eb1ca123, summary: a
in one repository, but
# branch: master, changeset: 5:f5b6808f2f04, summary: merge
|\
| o branch: master, changeset: 4:6b60342a01a6, summary: mm
| |
o | branch: master, changeset: 3:2b7bdcc98a88, summary: mmm
|/
o branch: master, changeset: 2:f39fa3fa1aaf, summary: m
|
o branch: master, changeset: 1:4dd5e8ae6481, summary: create master
|
o branch: default, changeset: 0:68b4eb1ca123, summary: a
in another. Note how the mm and mmm changesets are swapped in the two repositories.
It is only if the branch has the same heads in both repositories that you can talk about the "branch being the same" in each repository. If that is the case, then, as suggested by Lazy, a simple
hg log -b master --template "." | wc -m
will give the same count in both repositories.