What to do when a patch for Mercurial import fails? - version-control

I exported a bunch of changesets from my local working repo after doing a pull from the server repository. To make sure the patches work, I cloned a fresh repo from the server and I tried to apply the changeset. Unfortunately, the import fails with this:
applying G:\OSS\premake-dev\premake-dev_rev493.patch
unable to find 'src/host/scripts.c' for patching
3 out of 3 hunks FAILED -- saving rejects to file src/host/scripts.c.rej
patching file src/base/api.lua
patching file src/host/scripts.c
patching file src/tools/bcc.lua
file tests/test_bcc.lua already exists
1 out of 1 hunks FAILED -- saving rejects to file tests/test_bcc.lua.rej
patching file tests/premake4.lua
patching file tests/test_bcc.lua
abort: patch failed to apply
[command interrupted]
I know the reason for the failure, it's due to a removed source file that no longer exist in the latest changeset. But I'm not sure how to fix up my patch so that it will apply cleanly with the current server repository.
I'm fairly new to Mercurial so some of the terms used I'm not going to be familiar with. Also note that I don't have write access to the Hg server repository. So in order to get my changeset in, I have to export it as a patch and submit that to the maintainers.

I must confess to not having used patches a lot, so this might not be the right workflow, but what I would try, if I was in that situation was to apply the patch to the changeset it was originally based on.
In other words, it sounds like you have the following case:
+-- you're here
|
v
1---2---3---4---5---6
\
\
X <-- patch was built to change 2 to X
What I would do, provided I know the changeset the patch was originally based on, would be to update back to that changeset, apply the patch, this would add another head, then merge this into the tip of your repository.
After those actions, the repository should look like this:
+-- you're here
|
v
1---2---3---4---5---6---8
\ /
\ /
7-------------/
^
|
+-- this is the changeset you committed after applying the patch
Now, for a different way.
Is using a patch the only way? One common way when using Mercurial is that you set up your own repository, a fork, containing originally a full clone of the central repository, but you have commit access.
Thus you can commit your new changesets into your own clone.
If the central repository have new changesets added after you clone, at some point you pull from it into your clone, and merge.
Then when you're satisfied, you issue a pull request to the maintainers of the central repository, telling them that "Hey, I have some changes for you, you can pull them from my clone here: http://...".
This way, it is really easy for those maintainers to get everything in, since you've done all the hard work for them.
This would mean that you have the two repositories like this:
central: 1--2
clone: 1--2
You add your work:
central: 1--2
clone: 1--2--3
They add some changesets:
central: 1--2--3--4--5--6
clone: 1--2--3
Then you pull:
central: 1--2--3--4--5--6
clone: 1--2--4--5--6--7
\
\
3 <-- this is your changeset
Then you merge:
central: 1--2--3--4--5--6
clone: 1--2--4--5--6--7--8
\ /
\ /
3--------/
If the maintainers now pull from you, they get the exact same history into their repository.
There's also some support for rebasing, which would mean that you didn't have to pull and merge, but the maintainers would issue a "pull with rebase" command, in effect relocating your changeset from its current position into a new position in their repository, this would look like this:
central: 1--2--3--4--5--6---7
^
clone: 1--2--3 | relocated here
| |
+------------+
This would only work if there are no merge conflicts. The method where you pull and merge is the best for them, since you do all the hard work, they only have to verify that the code is what they want.
For more information on forking, check out Tekpub's video on CodePlex and Mercurial, here: Tekpub: 7 - Mercurial With CodePlex, seek to around 21:15 for the forking part to start.
Note that a "fork" is basically just a clone, the way forking works in CodePlex is that it automates setting up a clone on your own account, and sending the original maintainers the pull request, but if you create your own account on Bitbucket or CodePlex or whatever, publish your clone there, and just send the maintainers an email with your repository URL, that's all there is to it.

In my case, my failing hg import was related to line endings. The solution was putting this in my ~/.hgrc file:
[patch]
eol = auto

Related

Mercurial: "no match found" when performing merge, "no node!" if I try to strip

I have a mercurial dropbox hosted in a Dropbox folder on which I push from another repo that I keep in my office PC. In this way I can work on my project from the office and perform hotfixes from home.
Something bad happened while synchronizing, therefore a file wasn't correctly put in sync somewhere. I have a revision (n. 678) which I can't merge with actual head.
If I try to merge I get this message
abort:
data/hotelsclick/src/main/res/values/string-array.xml.i#5f2b6faa86a1:
no match found!
if I try to delete that useless revision with hg strip 678 I get
abort:
data/hotelsclick/src/main/res/values/string-array.xml.i#5f2b6faa86a1:
no node!
and if I perform a hg verify this is the result
checking files [...]/src/main/res/values/string-array.xml#678: 5f2b6faa86a1 in manifests not found
libs/date-interval-picker/.git/index#678: a83e1b77d446 in manifests
not found 8009 files, 681 changesets, 14161 total revisions 2
integrity errors encountered! (first damaged changeset appears to be
678)
what if I try to push?
searching for changes
abort: push creates new remote head 16c4912af9a5!
(merge or see "hg help push" for details about pushing new heads)
So I cannot merge, cannot delete that revision, cannot push. I'm pretty stuck and I don't know why. Can anybody please help? I don't care about the content of revision 678, if I could I'd delete it happily.
First of all, I strongly recommend against using a file synchronization service (whether Dropbox or Google Drive or something else) for use with version control systems. These services do not respect the atomicity of repository operations; even version control systems with single file repositories (such as Fossil) are not 100% safe and even if only a single user is using the service.
Second, you have a partially corrupted repository that you need to repair. In the ideal case, you have a clean backup somewhere, even if it's not perfectly up-to-date and can replay the missing revisions selectively (e.g. with hg export and hg import).
Barring that, the next step would be to see if you can do a partial clone. For example, you can try:
hg clone -r 680 /path/to/repo /path/to/clean_repo
This should normally skip revision 678, if only that data is defective. However, the way that delta compression works, revisions that occur in order after 678 may also have been corrupted. In this case, I would try it with -r 677 instead of -r 680 and see if hg export works for copying revisions 679 and 680.
If that does not work and the corruption goes deeper, I would then try the convert extension:
hg --config extensions.convert= convert --config convert.hg.ignoreerrors=True /path/to/repo /path/to/clean_repo
Note that such a conversion will likely change the hash values of individual repository entries and means that you will have to update the repository contents everywhere.

How do I prevent Mercurial patches from being pulled?

So far I haven't been able to find a clear answer, though it's possible that the answer is "change your workflow".
I've just started playing around with Mercurial's patch queue and I can see some serious power in it. It seems pretty awesome. In my tests, I've discovered that if you have a patch queue in repo1, and you pull from repo2, you can do some bad things. For example:
Create repos 1, and clone it.
Enable the queue on repo1
Make some commits and some patches on repo1
Pull changes to repo2
On repo1 un-apply(pop?) all your patches
Pull changes to repo2
Now you'll see two different branches - which makes sense from a certain viewpoint. However, since my patches aren't a part of repo1's history (at least until they're applied), it seems like there should be a way to tell mercurial that my patches are off-limits, and only provide what's in the "official history".
Is there a way to do this?
Mercurial phases may be the answer to this.
Starting with Mercurial v2.1, you can configure mq changesets to automatically be marked secret. secret changesets are ignored by incoming/pull and outgoing/push commands.
To enable this behavior, you need to add the following to your config:
[mq]
secret = True
Once enabled, it behaves as follows:
$ hg qpush --all
applying my-patch
now at: my-patch
$ hg phase -r .
16873: secret
$hg outgoing
comparing with https://www.mercurial-scm.org/repo/hg
searching for changes
no changes found (ignored 1 secret changesets)

Mercurial workflow for updating with uncommitted changes?

So i've made the switch from CVS to mercurial for my website.
The biggest issue I am having is that if i'm working on some files that I don't want to commit, I just save them.. I then have other files I want to push to the server, however if someone else has made changes to the repository, and I pull them down.. It asks me to merge or rebase.. either of these options will cause me to lose my local changes that I have not committed.
I've read that I should clone the repository for each project on my local host and merge it into the live when it's ready to do so. This not only seems tedious, but also takes a long time as it's a large repository.
Are there better solutions to this?
I would have hoped that Mercurial would see that I haven't committed my changes (even though I have changed the file from what's on the server) so it'd just overlook the file.
Any input on this would be greatly appreciated. Thank you!
Also, i'm using the hg eclipse plugin to work on my files and push/pull from the server.
hg shelve is your friend here I think.
which comes from the shelve extention (maybe - see below)
from the overview:
The shelve extension provides the
shelve command to lets you choose
which parts of the changes in a
working directory you'd like to set
aside temporarily, at the granularity
of patch hunks. You can later restore
the shelved patch hunks using the
unshelve command.
The shelve extension has been adapted
from Mercurial's RecordExtension.
or maybe its the attic extension
This module deals with a set of
patches in the folder .hg/attic. At
any time you can shelve your current
working copy changes there or unshelve
a patch from the folder.
it seems to have the same syntax as the shelve extension, so I'm not certain which one I've used
I second #Sam's answer. However, if you prefer to use standard Mercurial, a simple workflow is to
save your working dir changes in a temporary file,
sync your working dir with a specific revision, then
push, pull, merge .. whatever you want to do and which requires a clean working copy, and
get back your changes from the temporary file into the working dir.
For instance:
$ hg diff > snapshot.patch # save your uncommited changes
$ hg up -C # get a clean working copy
$ hg pull # do things ..
$ hg merge # .. you need a clean ..
$ hg commit -m "merge" # .. working copy for
$ hg import snapshot.patch # get back your uncommited work
First, are you working from the commandline, or using something like Tortoise?
If you're working from the commandline, and you've done a pull, mercurial will not ask you to do anything, as it merely updates your local repository.
If you then do an hg update and have local changes, it should do what you're used to from CVS. It will update to the tip of the current branch, and attempt to merge your outstanding changes in. There are some caveats to that, so refer to the official docs at http://www.selenic.com/mercurial/hg.1.html#update.
Also, for temporarily storing changes, I would recommend MQ over shelve. Shelve only provides one storage area, whereas MQ provides as many as you need. MQ takes some getting used to, but worth the investment.

How should I work on a CVS hosted project to both (1) fix bugs and (2) maintain my own private fork with additional features

The question
An open source program uses CVS for version control. I would like to make a number of bug-fixes and submit patch bombs to the developers with commit access. I would also like to maintain my own semi-private fork that mainly tracks the main code-base but that includes my own features (these features, right now, should not be incorporated into the main code-base.)
I prefer to use mercurial for my own version control needs, but I am open to other version control systems if necessary.
I'd like to:
Be able to easily create patch-bombs against the current CVS source with my own bug-fixes
Keep track of history on my own features
Have fixes and improvements from the main tree easily incorporated in my new-feature fork
Easily apply my own bug-fixes to my new-feature fork
Be able to work and track change history without an Internet connection.
What suggestions do you have for doing this?
My current idea
My own best guess is below, to give you a better idea of what I am thinking about.
I will have 3 mercurial repositories.
The first two repos are managed as specified at (https://wiki.mozilla.org/Using_Mercurial_locally_with_CVS). One just mirrors the latest changes from the CVS upstream. I do "cvs update" then "hg commit" in this repo. The second repo holds my bug-fixes as patches using the mq extension and I pull from the the first repo and re-base my patches every so often. When my patches are incorporated into the main tree, I remove the patches from the patch queue/make them permanent commits.
The third repo is my local fork. It will start out as a clone of the first repo. Then each time I do an update of the first repo, I'll pull from it into repo 3. My own features will be directly present as commits in this repo. When I fix a bug, I'll export a patch from repo 2 and apply it to the appropriate pull from repo 1.
I have used Git to manage changes on top of a CVS repository in a similar way. My solution in Git uses local branches instead of multiple repositories, but it sounds essentially similar to your proposed idea.
I found that this arrangement works best if you commit all the CVS metadata (in the CVS/) subdirectories) to your mirrored repository. This means that the CVS metadata gets replicated in the other repositories, but it doesn't cause any harm (and lets you run commands like cvs diff if you need to).

Mercurial: info on modified files

Before pulling from the central repositiry, I usually use the 'hg incoming' command to see what I will be pulling. However, this only gives me a list of changesets with some comments, and not a list of the actual files that have been modified.
1) In such a situation, how can I get a list of modified files (including some basic info about the chane, like Removed, Moved, etc)?
2) Similarly, when I do an 'hg status', I get the differences between my local working copy and what is currently on the repository. However, a more useful feature would be to get the differences between what is incoming and my local working copy. How can I get this?
Thanks!
1/ Most options are presented in "how to see files in repository before running 'update'":
hg incoming --stat
Notes:
For remote repository, using --bundle avoids downloading the changesets twice if the incoming is followed by a pull.
--stat: output diffstat-style summary of changes.
(ie: Statistics of changes with the following format: "modified files: +added/-removed lines")
2/ See RDiff extension (and the SO question "Using Mercurial, is there an easy way to diff my working copy with the tip file in the default remote repository")
If you don't have a recent enough version for --stat, you can get a similar overview using status:
cd repo
// grab the newest changes into a bundle
hg incoming --bundle morechanges.bun
// get an id for the current tip
hg tip
changeset: x:abcdef
...
// see what's changed by overlaying the bundle on the repo
hg -R morechanges.bun status --rev abcdef:tip
//info you're looking for
// everything's good; add the bundle to the repo
hg pull morechanges.bun
rm morechanges.bun