<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Bluish Coder: git</title>
 <link href="http://bluishcoder.co.nz/tag/git/atom.xml" rel="self"/>
 <link href="http://bluishcoder.co.nz/"/>
 <updated>2011-12-16T21:17:53+13:00</updated>
 <id>http://bluishcoder.co.nz/</id>
 <author>
   <name>Chris Double</name>
   <email>chris.double@double.co.nz</email>
 </author>

 
 <entry>
   <title>Performing Compatible Updates of Mozilla Central Git Forks</title>
   <link href="http://bluishcoder.co.nz/2011/10/28/performing-compatible-updates-of-mozilla-central-git-forks.html"/>
   <updated>2011-10-28T16:00:00+13:00</updated>
   <id>http://bluishcoder.co.nz/2011/10/28/performing-compatible-updates-of-mozilla-central-git-forks</id>
   <content type="html">&lt;p&gt;Earlier this year I posted about &lt;a href='/2011/02/10/git-conversion-of-mozilla-central.html'&gt;how I created my git mirror&lt;/a&gt; of the mozilla-central mercurial repository. I&amp;#8217;ve been keeping a &lt;a href='https://github.com/doublec/mozilla-central'&gt;fork on github&lt;/a&gt; updated regularly since then that a number of people have started using.&lt;/p&gt;

&lt;p&gt;Users of my mirror have wanted to be able to keep up to date with the mercurial mozilla-central repository themselves, or add updates from other branches of the Mozilla source. It takes a large amount of time to start a conversion from scratch but it&amp;#8217;s possible to start from the existing git mirror, perform the incremental updates from mercurial yourself, and still stay compatible with the incremental updates I push to my github mirror.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://hg-git.github.com/'&gt;hg-git&lt;/a&gt; uses a &lt;code&gt;git-mapfile&lt;/code&gt; in the &lt;code&gt;.hg&lt;/code&gt; directory of the mercurial clone to keep track of the mapping between mercurial and git commits. By using the same &lt;code&gt;git-mapfile&lt;/code&gt; that I use for my mirror you can start your own incremental update from the latest data in the &lt;code&gt;git-mapfile&lt;/code&gt; instead of from the beginning. I keep an up-to-date &lt;code&gt;git-mapfile&lt;/code&gt; in &lt;a href='http://www.bluishcoder.co.nz/git-mapfile.bz2'&gt;git-mapfile.bz2&lt;/a&gt;. It&amp;#8217;s compressed with &lt;code&gt;bzip2&lt;/code&gt; as the uncompressed version is quite large.&lt;/p&gt;

&lt;p&gt;The steps to start your own update process are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone the &lt;a href='https://hg.mozilla.org/mozilla-central'&gt;mercurial mozilla-central repository&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Clone my &lt;a href='https://github.com/doublec/mozilla-central'&gt;git mirror&lt;/a&gt; as a bare repository in &lt;code&gt;.hg/git&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Place the &lt;code&gt;git-mapfile&lt;/code&gt; in &lt;code&gt;.hg&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Do an &lt;code&gt;hg bookmark -f -r default master&lt;/code&gt; to mark the commit to convert to&lt;/li&gt;

&lt;li&gt;Perform &lt;code&gt;hg gexport&lt;/code&gt; to update &lt;code&gt;.hg/git&lt;/code&gt; with recent mercurial commits&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;.hg/git&lt;/code&gt; directory should now be up-to-date with respect to the mercurial repository. And the additional git commits will have the same SHA id as any commits I push into my mirror when I perform my own update.&lt;/p&gt;

&lt;p&gt;The steps to do an incremental update are the normal:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull from the mercurial mozilla-central repository&lt;/li&gt;

&lt;li&gt;Run &lt;code&gt;hg bookmark -f -r default master&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Run &lt;code&gt;hg gexport&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;Push or pull to/from &lt;code&gt;.hg/git&lt;/code&gt; as needed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As a working example, the following shell commands on a Linux system should set up your own repository ready for incremental updating:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ hg clone https://hg.mozilla.org/mozilla-central
$ cd mozilla-central/.hg
$ git clone --bare git://github.com/doublec/mozilla-central.git git
$ wget http://www.bluishcoder.co.nz/git-mapfile.bz2
$ bunzip2 git-mapfile.bz2
$ cd ..
$ hg bookmark -f -r default master
$ hg gexport
$ cd .hg/git
$ git push --all ~/some/other/repo.git&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Incremental updates just repeat the last few commands above:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ hg pull -u
$ hg bookmark -f -r default master
$ hg gexport
$ cd .hg/git
$ git push --all ~/some/other/repo.git&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that I use &lt;code&gt;hg gexport&lt;/code&gt; and push from the &lt;code&gt;.hg/git&lt;/code&gt; repository using the &lt;code&gt;git&lt;/code&gt; command instead of doing an &lt;code&gt;hg push&lt;/code&gt; and relying on &lt;code&gt;hg-git&lt;/code&gt; to do the conversion and push. In my &lt;a href='http://www.bluishcoder.co.nz/2011/02/10/git-conversion-of-mozilla-central.html'&gt;original article&lt;/a&gt; I did the latter. The &lt;code&gt;hg-git push&lt;/code&gt; method uses slower python based routines to do the push which can take a long time and large amounts of memory on big repositories like mozilla-central. By splitting this up into &lt;code&gt;gexport&lt;/code&gt; and using the native &lt;code&gt;git&lt;/code&gt; command I save a lot of time and memory.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>My Git Workflow for Mozilla Development</title>
   <link href="http://bluishcoder.co.nz/2011/04/16/my-git-workflow-for-mozilla-development.html"/>
   <updated>2011-04-16T17:00:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2011/04/16/my-git-workflow-for-mozilla-development</id>
   <content type="html">&lt;p&gt;Since my post on &lt;a href='/2011/02/10/git-conversion-of-mozilla-central.html'&gt;converting mozilla-central to git&lt;/a&gt; I&amp;#8217;ve had a few requests about what my git workflow is for Mozilla Development.&lt;/p&gt;

&lt;p&gt;When working on bugs I&amp;#8217;ll create a git branch for development. The workflow in this branch looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git fetch origin
git checkout -b bug/123456 origin/master
...make changes...
git commit
...make more changes...
git commit&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Occasionally I&amp;#8217;ll want to merge with the latest code from mozilla-central. I do this by rebasing my changes on top of the latest trunk code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git fetch origin
git rebase origin/master&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;ll often have multiple temporary branches as I work on different ideas during the fix. I find being able to diff between the branches, cherry pick patches, etc useful.&lt;/p&gt;

&lt;p&gt;When I&amp;#8217;ve finished with the fix and want to generate a patch for review I rebase on top of trunk and squash all my commits down into one patch. I do this use git&amp;#8217;s interactive rebase:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git fetch origin
git rebase -i origin/master
...squash commits into one commit and set commit message to my checkin commit message...
git hgp &amp;gt;~/mypatch.patch&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The last command, &lt;code&gt;git hgp&lt;/code&gt;, uses an alias I got from &lt;a href='http://blog.mozilla.com/respindola/2011/04/14/producing-patchs-for-hg-with-git/'&gt;Rafael Espindola&amp;#8217;s Blog&lt;/a&gt;. You can install this alias by adding the following to your &lt;code&gt;~/.gitconfig&lt;/code&gt; file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[alias]
hgp = show --format=\&amp;quot;From: %an &amp;lt;%ae&amp;gt;%n%s%n%b\&amp;quot; -U8&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The adds an &amp;#8216;hgp&amp;#8217; git command that does the same as &lt;code&gt;git show&lt;/code&gt; but includes a header for the committers name. This allows an &lt;code&gt;hg import&lt;/code&gt; of the patch to include the correct patch authors details which is useful if you use the &lt;code&gt;checkin-needed&lt;/code&gt; keyword for others to commit the patch.&lt;/p&gt;

&lt;p&gt;I attach the patch file to the bug for review. If I get review comments I then go back to the git branch and make the necessary changes. Regenerating the patch involves repeating the steps above.&lt;/p&gt;

&lt;p&gt;When the patch needs to be committed to mozilla-central it can be imported and pushed directly using mercurial:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;hg clone https://hg.mozilla.org/mozilla-central
cd mozilla-central
hg import ~/mypatch.patch
hg push&lt;/code&gt;&lt;/pre&gt;</content>
 </entry>
 
 <entry>
   <title>Git Conversion of Mozilla Central</title>
   <link href="http://bluishcoder.co.nz/2011/02/10/git-conversion-of-mozilla-central.html"/>
   <updated>2011-02-10T14:00:00+13:00</updated>
   <id>http://bluishcoder.co.nz/2011/02/10/git-conversion-of-mozilla-central</id>
   <content type="html">&lt;p&gt;The Mozilla repository for Firefox development, &lt;a href='http://hg.mozilla.org/mozilla-central'&gt;mozilla-central&lt;/a&gt;, is a mercurial repository. I prefer using &lt;a href='http://git-scm.com/'&gt;git&lt;/a&gt; for version control so I usually do my Firefox development using a &lt;a href='http://www.bluishcoder.co.nz/2008/12/changes-to-git-mirror-of-firefox.html'&gt;git mirror&lt;/a&gt; of the mozilla-central repository.&lt;/p&gt;

&lt;p&gt;To convert the repository into git I used &lt;a href='http://repo.or.cz/w/fast-export.git'&gt;hg-fast-export&lt;/a&gt;. This has worked well over the last couple of years. Unfortunately I&amp;#8217;ve noticed that my git mirror and the official mercurial repository differ slightly. The git mirror contains files that have been deleted or moved in the official repository and lately the mirror has stopped building due to some commits not being correctly converted. As a result I stopped updating my mirror and used mercurial directly.&lt;/p&gt;

&lt;p&gt;I still prefer developing using git though so I tried the &lt;a href='http://hg-git.github.com/'&gt;hg-git mercurial plugin&lt;/a&gt;. This took about six days on my laptop to do the conversion and peaked at 14GB of memory. The result was a git repository with a working tree that, according to diff, is an exact copy of the original mercurial repositories working tree. Another nice feature of the hg-git is that commit id&amp;#8217;s in the resulting git repository are the same across multiple runs of hg-git. This would allow other users to push and pull from a git repository that they converted independently.&lt;/p&gt;

&lt;p&gt;To perform the conversion I installed hg-git and ran the following series of commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir git
$ cd git
$ git init --bare
$ cd ..
$ hg clone https://hg.mozilla.org/mozilla-central hg
$ cd hg
$ hg bookmark -r default master
$ hg push ../git&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Six days and 14GB later, the resulting git repository ended up being about 7GB in size. I did a &lt;code&gt;git gc --aggressive&lt;/code&gt; on it to get this down to 200MB. Incremental updates of new mercurial commits are done with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ cd hg
$ hg pull -u
$ hg bookmark -f -r default master
$ hg push ../git&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;ve pushed a mirror of this to github at &lt;a href='http://github.com/doublec/mozilla-central'&gt;http://github.com/doublec/mozilla-central&lt;/a&gt;. I&amp;#8217;m using this for development and will see if it is able to continue importing without diverging from the original mozilla-central source.&lt;/p&gt;

&lt;p&gt;More information about the use of git for Mozilla development can be found in the followup posts I did on the subject:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='/2011/04/16/my-git-workflow-for-mozilla-development.html'&gt;My Git Workflow for Mozilla Development&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='/2011/10/28/performing-compatible-updates-of-mozilla-central-git-forks.html'&gt;Performing Compatible Updates of Mozilla Central Git Forks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>Changes to git mirror of Firefox repository</title>
   <link href="http://bluishcoder.co.nz/2008/12/04/changes-to-git-mirror-of-firefox.html"/>
   <updated>2008-12-04T17:32:00+13:00</updated>
   <id>http://bluishcoder.co.nz/2008/12/04/changes-to-git-mirror-of-firefox</id>
   <content type="html">&lt;p&gt;Original Post &lt;a href='http://www.bluishcoder.co.nz/2008/12/changes-to-git-mirror-of-firefox.html'&gt;Changes to git mirror of Firefox repository&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Git, Binary Files and Cherry Picking Patches</title>
   <link href="http://bluishcoder.co.nz/2007/09/06/git-binary-files-and-cherry-picking.html"/>
   <updated>2007-09-06T17:03:00+12:00</updated>
   <id>http://bluishcoder.co.nz/2007/09/06/git-binary-files-and-cherry-picking</id>
   <content type="html">&lt;p&gt;Original Post &lt;a href='http://www.bluishcoder.co.nz/2007/09/git-binary-files-and-cherry-picking.html'&gt;Git, Binary Files and Cherry Picking Patches&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 
</feed>

