понедельник, 11 декабря 2017 г.

Fixing the 'repository has at least one unnamed head' error when converting a Mercurial repository to Git

I was following the "Migrating to Git" instructions and run into an issue while converting our Mercurial repository. The fast-export script displayed the message: "Error: repository has at least one unnamed head: hg r3419".

My first move was to check the revision 3419. The revision was a 'close branch' commit on a named branch. Nothing special and that was confusing.

It took me a while to realize: the error means there is a branch with more than one head. Now it seems pretty obvious :)

The following command produced me a list of branches along with the number of heads:

hg heads -c | grep branch: | uniq -c | sort

It turned out, there was an old, closed branch with two heads. Each head was closed with a separate commit. The solution was to merge these heads and close the branch once again.

I hope this post might help in case someone else runs into this issue.

среда, 19 декабря 2012 г.

Mercurial: an incident with "hg pull --rebase"

Our team uses Mercurial. Some time ago we started using rebase instead of merges to have clean linear timeline. The rebase approach seemed to be straightforward and almost automatic. But recently we run into an issue: a code from the development branch leaked into the stable branch, the branch that is indended for bugfixes only.

Below is a reconstruction of the incident. While it might appear to be a lot of text, it is actually just a couple of commits, so please don't be scared and read on.

Consider a team of two developers - Leo and Penny - working on a product. The product's repository has two branches: 'default' and 'stable'. New features are being developed on the 'default' branch. Bugs are fixed on the 'stable' branch. From time to time the 'stable' branch is merged back into the 'default'.


hg init repo
cd repo
@echo > product.cs
hg add
hg commit -u leo -m "initial version"
hg branch stable
hg commit -u leo -m "creating 'stable' branch"





1. Leo fixes a bug and pushes his changes:

hg clone repo repo-leo
cd repo-leo
hg up stable
@echo > bugfix-01.cs
hg add
hg commit -u leo -m "fixed: bug-01"
hg push

2. Penny fixes a bug and merges the 'stable' into the 'default':

hg clone repo repo-penny
cd repo-penny
hg up stable
@echo > bugfix-02.cs
hg add
hg commit -u penny -m "fixed: bug-02"
hg up default
hg merge stable
hg commit -u penny -m "merged bugfixes into the default branch"


3. Penny writes a new feature:

hg up default
@echo > new-feature.cs
hg add
hg commit -u penny -m "new cool feature"


Penny's repository: bug fixed, feature implemented.

4. Now Penny wants to push her changes:

hg push
pushing to C:\Temp\repo
searching for changes
abort: push creates new remote head 4fa702a0c723 on branch 'stable'!
(you should pull and merge or use push -f to force)

But the server aborts the push. Penny understands that someone has already pushed changes, so she does a regular routine: pull --rebase

hg up stable
hg pull --rebase

Damage is done!

Penny's repository before rebase

Penny's repository after rebase. A code from the development branch is now on the stable branch.
Look at the screenshots illustrating Penny's repository before and after rebase. Notice the "new cool feature" changeset that should be on the development branch. Now it is on the branch 'stable' and that should have never happen...

(to be continued)








среда, 12 января 2011 г.

WPF - create DataTemplate from FrameworkElement

Yet another code snippet for future reference.
I'm not quite sure if it works in all cases, but it does work for Canvas.


        DataTemplate GetElementAsTemplate(FrameworkElement element) {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(
                "{0}",
                XamlWriter.Save(element));

            using(MemoryStream stream = new MemoryStream()) {
                using(StreamWriter writer = new StreamWriter(stream)) {
                    writer.Write(builder.ToString());
                    writer.Flush();

                    stream.Position = 0;
                    DataTemplate template = (DataTemplate)XamlReader.Load(stream);
                    return template;
                }
            }
        }

воскресенье, 14 ноября 2010 г.

Client HTTP Stack: HttpWebRequest and non-ASCII characters in HTTP response headers

Client HTTP Stack in Silverlight seems to bee too strict sometimes. I have an OOB application that uses HttpWebRequest object to get data from external web service.

Unfortunately, HTTP response from the service includes header that contains non-ASCII characters. And it turns out to be a problem. See code snippet below:

void GetResponseCallback(IAsyncResult ar) {
    HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
    WebResponse response = request.EndGetResponse(ar);
    // code continues …
}

EndGetResponse() call results in System.ArgumentException: Specified value has invalid Control characters. Parameter name: value.

I’m not sure whether it is a bug or designed behaviour. But it’s a pity that invalid header prevents application from obtaining response at all. In fact I don’t even need that header, so my workaround was to switch to browser http handling so that I can move on.

And just for the record: the same code works fine in WPF application.

среда, 10 ноября 2010 г.

Silverlight OOB applications and HTTP handling

With Silverlight, you can specify whether the browser or the client provides HTTP handling for your Silverlight-based applications. By default, HTTP handling is performed by the browser and you must opt-in to client HTTP handling.

Surprisingly, despite of what your intuition might suggest, Silverlight out of browser applications use browser HTTP handling by default. At least for WCF service calls :)

Igor on .NET

Random thoughts, ideas and questions on .NET development

Постоянные читатели