0

I've recently started to work on an open source project which uses Mercurial. I'm a new user to Mercurial, so I read the HG book and started working. My goal was to write code and always pull and merge changes from the upstream so I can stay up-to-date. The area that I am working on is also under heavy development by others so I do want to merge my changes after a long period of time. I cloned a repo. So, my workflow is like this:

  1. I created a bookmark mybook

  2. hg up mybook

  3. Write code

3.1 hg commit -m 'new functions'

  1. hg up default

  2. hg pull

  3. hg update

  4. hg up mybook

  5. hg merge default

  6. Go to step 3.

In my mind this is the simplest workflow that allows me to stay up-to-date. I also have only one HEAD because I always merge.

Since I am not a contributor yet, I am not allowed to push changes to remote repo.

Recently I wanted to show my work to a project lead and he said send me a patch. And this is where I am stuck. hg out shows 10 changesets. First of which appeard already a month ago. They're numbers are 3341, 3342, 3345, 3346, 3349, 3356, 3360, 3365, 3366, 3368. The changeset numer 3368 is the tip.

I've recently read the chapter about the MQ extension. And this extensions seems to be what I need. But the problem is that I wrote code without using the MQ extension.

So, how can I make use of the MQ extension on already created changesets so that I can make a patch to send to the project lead so that he can apply it and see my changes?

I've just issued hg qinit. What's next? Issueing hg qimport -r 3341 gives

abort: revision 3341 has unmanaged children

Reading the book and googling further does not help me. I need an advice.

PS I've tried not using hg and MQ at all: simple diff -urN old/ new/ but I want understand how to do it with the MQ.

Thank you.

Grigory
  • 992
  • 2
  • 18
  • 34
  • Don't use MQ for this task. Export changesets as set of patches with `hg export -r REVSET` – Lazy Badger Apr 27 '16 at 16:46
  • And, BTW, you can have less number of frictions in your workflow in 4-6 area – Lazy Badger Apr 27 '16 at 16:51
  • I think @LazyBadger means that you can `pull` and `merge` from `default` without updating away from your branch (if you don't mind doing so without reviewing the new version). – alexis Apr 29 '16 at 10:21

1 Answers1

2

Yeah, don't use MQ. It's a parallel system, meant for keeping things out of the history, and more important you don't need it.

You were asked for "a patch", not a complete history of your work, so I would recommend sending it in the form of a single before-after diff. hg export will give you a series of diffs, for all the work you've done, including the merges. I find it's far easier to read and review a single diff (before applying it). But instead of plain diff, use hg diff which knows to only look at tracked files, and has a number of other nice features (including the --git option, which provides richer metadata). This should do it:

hg up mybook
hg diff --git -r default > mywork.patch

Before sending it off, do an hg up default and apply the patch to check that it works without conflicts. And mention to the recipient which version of default you are patching against.

Edit: As you can read in the comments, @LazyBadger is a fan of the step-by-step patch generated by export. I prefer the single-step patch since my history is usually TMI: Nobody cares about all the times I added a forgotten file, or noticed a bug too late and fixed in in the next commit, etc. Take your pick.

alexis
  • 48,685
  • 16
  • 101
  • 161
  • Don't mix `hg export` and `hg archive`, dude - export save **patch-file** – Lazy Badger Apr 29 '16 at 16:08
  • Sorry if that sounded misleading. `hg export` will generate a patch, containing separate diffs for each file _and for each changeset_ in the included range of revisions. So it includes multiple diffs for each file affected. `hg diff` will just compare the beginning and final state, and produce a single spanning patch. – alexis Apr 29 '16 at 19:50
  • My interest is not in whether the output of `export` can properly be called a patch, but in whether it's useful to a project lead wanting to review a potential contribution. – alexis Apr 29 '16 at 19:54
  • Well, you are right in mentioning differences, but anyway - lead *will not* verify patch by eye (sure) - it will be applied to some (mercurial) sandbox and export's diffs are somehow **healthier** in *this* case – Lazy Badger Apr 30 '16 at 14:28
  • Ok, I edited my answer to make it clear that opinions differ on this. – alexis May 02 '16 at 12:32