Mercurial: how-to guide to distributed version control

Mercurial is one of the 2 famous free / open source, distributed source control management tools. You may also have heard of Git, another great tool. Both Mercurial & Git are the front runners in distributed version control systems. 2 nice articles compare Mercurial to Git. One called Git vs. Mercurial: Please Relax comparing Git to MacGyver and Mercurial to James Bond. The other article The Differences Between Mercurial and Git. The conclusion was both are great tools so stop worrying and start using the one which you are most comfortable with. I went down the Mercurial route.

Mercurial - Work easier, Work faster

Mercurial is a distributed version control systems (DVCS) which keeps track of software revisions and allows many developers to work on a given project without necessarily being connected to a common network. This is a peer-to-peer approach, as opposed to the client-server approach of centralized systems like Subversion or CVS. It is a more cleaner, faster and refined way of working. More on this is explained on Wiki here.

Let’s get started with Mercurial

As explained above you Mercurial is a DVCS. So you will have a “local” version of Mercurial which may have a number of “repositories” on your development machine. A repository is essentially a package which identifies your application. One for each application. Your code will get “committed” to this local version daily as you work. When you have a working piece of functionality only then you will “push” it to “central”. Central is typically hosted on a remote server (hosted in-house or via a 3rd party like BitBucket) where everyone else in your team can push or clone code to. Typically “central” is hooked up to a continuous integration tool to facilitate nightly builds. More on that in another post. So whatever code you push there make sure it is working!

Local (dev) install or Mercurial

1. Download Mercurial on your development box from here: http://mercurial.selenic.com/

2. Run the install file and follow through with the default questions.

3. Your done.

Quickstart – starting your 1st Mercurial Repository

Source: http://mercurial.selenic.com/

In your terminal / dos window, navigate to a folder where you will either clone a project to or create one and do the following.

Clone a project and push changes

$ hg clone http://selenic.com/repo/hello
$ cd hello
$ (edit files)
$ hg add (new files)
$ hg commit -m 'My changes'
$ hg push

Create a project and commit

$ hg init (project-directory)
$ cd (project-directory)
$ (add some files)
$ hg add
$ hg commit -m 'Initial commit'

Let’s look at each command in more detail:

hg init

Run this 1st time in your working directory to mark that folder as your project repository which you want Mercurial to version control. Mercurial will create a hidden folder there called “.hg”. This is where all the detail (changesets and manifests) on your commits is stored.

hg clone http://(my-domain)/hg/(project-repository)

Run this in your working directory where you want to drag code down from central Mercurial (See below on Central).

hg status

To see what is not yet added & committed yet to the repository.

hg add

If you have new files this command adds them to your repository.

hg commit

Commit your changes to “local” Mercurial. Make this a habit of doing it frequently (at least once a day). Mercurial will ask you to put in comments with your commit. Also make this a habit to put in as much detail into your comments as possible to help others understand your changes + if you have a reference to Jira case / other Agile tracker add this in as well.

hg pull -u

To pull changes and update.

hg push http://(my-domain)/hg/(project-repository)

To push your local repository changes to a central repository.

Tools for Mercurial

Netbeans – IDE Integration

If you are using Netbeans for development and have pointed it to a project where you “hg init” was ran, Netbeans will automatically recognize this and integrate Mercurial into your workflow. In Netbeans, do this by right clicking on your project folder and look under “Mercurial” sub-folder. Get it from here: http://netbeans.org/

MacHG – GUI for managing repositories on the Mac

This is the nicest GUI for Mercurial that I could find for the Mac. It allows you in a nice graphical way to manage a collection of files, to add things to the collection, to save a snapshot of the collection, to restore the collection to an earlier state and in general to work with the files. Get it from here: http://jasonfharris.com/machg/
Alternatively go through a list of other tools here: http://mercurial.selenic.com/wiki/OtherTools

“Central” – home of all repositories

The following is only required if you want to setup Mercurial “central”. A single place (mothership) for all developers to push working code to for storage & versioning. This is also the place where you would hook up a continuous integration tool to facilitate nightly builds.

Bitbucket: free Mercurial code hosting

If you do not have enough resources to run Mercurial “central” in-house or want someone else to manage that for you then use one of the hosted solutions on the internet. Bitbucket from Atlassian (kick ass Aussie firm) can provide you with unlimited private code hosting, free. Yes I use it and I love it. Less maintenance & headaches and everything you learnt above can be applied here.

BitBucket by Atlassian - free Mercurial code hosting

Get your free account here: http://bitbucket.org/

Home solution: In-house Mercurial code hosting

Ok the following will require Ubuntu terminal access to the Ubuntu box where you want to install Mercurial “central”. All of the code below can be highlighted and pasted to run directly in your terminal window to make this process fast.

The following is based on the steps I followed from Emran Hasan’s Blog with some changes to the configuration to make it work on Ubuntu 10.10 based additional input from Stack Overflow.

1. Install Mercurial

sudo apt-get update
sudo apt-get install mercurial

2. Create a store for Mercurial configuration & repository files

cd /var/
sudo mkdir hg
sudo mkdir hg/repos
sudo chown -R www-data:www-data hg/repos

3. Creating a configuration file to host multiple repositories on this server & use CGI to serve the files through Apache:

cd /var/hg
sudo cp /usr/share/doc/mercurial/examples/hgweb.cgi .
sudo chmod a+x hgweb.cgi

4. Configure Mercurial (also refered to as “hg”) to point to point to our new config file:

sudo nano /var/hg/hgweb.cgi

and update the config like this:

config = "/var/hg/hgweb.config"

5. Create the file /var/hg/hgweb.config and write the location of the repositories:

sudo nano hgweb.config

and add this to the file:

[collections]
/var/hg/repos = /var/hg/repos

6. Make “central” accessible via HTTP (optional if you don’t want to setup a SSL certificate).

sudo nano /etc/mercurial/hgrc

add/update this line and save file:

[web]
allow_push = * push_ssl = false

7. Now update the Apache configuration so that it executes the CGI when requested with a /hg prefix:

cd /etc/apache2/sites-available
sudo nano default

at the end of the file (before < /VirtualHost >), add the following and save it:

ScriptAlias /hg "/var/hg/hgweb.cgi"
< Directory "/var/hg/repos" >
   AuthType Basic
   AuthName "Mercurial Repositories"
   AuthUserFile /var/hg/hgusers
   Require valid-user
< /Directory >

8. Add permissions for users who will be accessing central. First add admin account:

sudo cd /var/hg htpasswd -mc hgusers admin

then normal user accounts:

sudo htpasswd -m hgusers

Each request will prompt you for a password.

9. Create a repository

cd /var/hg/repos
sudo mkdir (my-repository)
cd (my-repository)
sudo hg init

Note: Recall “hg init” from above (local setup).

10. Restart apache

sudo /etc/init.d/apache2 restart

and browse: http://(my-domain)/hg
you will be prompted to login (using one of the users names you added above) and see the whole Mercurial central repository.

URL access: http://(my-domain)/hg/(project-repository)
Cloning from “central” to your local:

cd (my-local-project-working-directory)
hg clone http://(my-domain)/hg/(project-repository)

And… that concludes this short introduction to Mercurial. Hope you found it useful!

Bonus: Download this Mercurial Cheat Sheet:
http://www.theroadtosiliconvalley.com/cdn/Mercurial-Usage-v1.0.pdf (847kb)

Mercurial Usage - 1 pager

I have it at my desk. It is the best one I could find out of the many I reviewed.

Happy coding!

Useful links

Hosted Mercurial solutions

More Mercurial education

Bitbucket education

Enjoy!

~ Ernest

Making the switch from Windows to Kubuntu

I finally made the switch from Windows Vista to Linux Free Operating System. I moved to the Kubuntu version of Ubuntu 10.10 (a Linux flavour) as my development box and haven’t looked back. Well I lied, since I did look back a bit at the beginning lol. It has been a an interesting challenge mentally adjusting to new way of doing things, new tools (applications) and driver support. In the end it was definitely worth it.

And why Kubuntu? since it’s basically Ubuntu a Debian-derived Linux distribution with KDE (a prettier desktop) on-top. Ubuntu brings your slower machines to life. While Windows keeps on slowing them down. Ubuntu is a secure, intuitive operating system that powers desktops, servers, netbooks and laptops. Ubuntu is, and always will be, absolutely free. More about it here.

Why I switched

Today all my development is open source. This means I run what I create on a LAMP stack – L stands for Linux Server. Doing development on a Windows box and pushing to a LAMP stack is like clawing your way through quick sand instead of using a ninja sword to slice through your tasks.

One day, I asked myself. Wouldn’t it be kick ass if my dev box would be close to identical to my production boxes. Knowing that whatever I do on my dev box will work in production with high certainty. Yes yes, Ubuntu popped into my mind. Which later after speaking with a fellow Linux hacker changed to Kubuntu.

As you may already know, Kubuntu is highly configurable. You even have access to the source code if you wish to venture that deep. It also has a great X window called KDE. Check out these top the winners from a 5-day competition on Facebook where fans were invited to submit a screenshot of their pimped Ubuntu desktop. No excuses about Ubuntu’s poor UI.

My customized Ubuntu desktop
My customized Kubuntu desktop

Linux apps to replace your Windows apps

Here is a comprehensive list of apps to replace your Windows versions.

Note: Most applications & games on Linux are open source. This mostly means free. Thus, the ones I listed below as alternatives in the Linux world are all free and can be downloaded from your package manager. I use Synaptic Package Manager (SPM). All the software here is verified and malicious free – it’s safe to get all your apps from here. To install SPM, in your terminal window type this in and your done. Simple eh.

sudo apt-get update
sudo apt-get install synaptic

Securitythis one just kills windows. Ubuntu comes with a firewall built in and windows viruses – what are they on Ubuntu – non existent. All you need is software like Gufw to help you “manage” your firewall else you can do it via the terminal / konsole window.
In your terminal window type this in and your done. This cannot get any harder 😉

sudo apt-get install gufw

And if you want hard-core detail on securing Ubuntu, read this post covers the process of securing and hardening the default Debian GNU/Linux distribution installation.

Applications… the following let’s use “Synaptic Package Manager”.

Purpose Windows Linux
Development
Code editor Notepad++ gedit
SFTP, FTP and SCP client WinSCP FileZilla
Telnet/SSH Putty OS Konsole /
terminal window
Code compare Beyond Compare Kompare
MySQL manager and admin tool SQLyog MySQL Workbench
Virtualization VMWare VirtualBox
Multimedia
Video player Windows Media Player VLC
Video editor Sony Vegas Kdenlive
Organize, share & edit your photos Picasa Picasa /
Gwenview
Photo editor Photoshop GIMP
Audio player Windows Media Player Amarok
CD/DVD burner Nero K3b
Other
Office (word, excel, powerpoint etc) Windows Office OpenOffice /
Google Docs
File browser Windows Explorer Dolphin
Internet browsers Chrome Chromium
Antivirus & Firewall Take a pick lol Gufw to manage your Firewall
Silverlight MS Silverlight Moonlight

Additional stuff you can install to make your Kubuntu experience pleasing:

Don’t forget to use your Synaptic Package Manager to look for these apps first. Only when you cannot find them there click on the title of each app below to take you to the website hosting the app and instructions.

  • Docky – shortcut bar that sits at the bottom, top, and/or sides of your screen. You can make it look and behave like mac’s bar.
  • KSnapshot – simple & powerful easy to use screen capture program.
  • Ubuntu Tweak – tweak Ubuntu’s desktop and system options that the default desktop environment doesn’t provide.
  • Beagle – advanced desktop search.
  • FreeMind – premier free mind mapping software written in Java.
  • Etherape – graphical network monitor.
  • Other code editors:
    • JetBrain. Their professional developer tools are kickass! I have trialled their PHPStorm & ReSharper with positive results. They also have editors for Ruby & Python (shakes of excitement). It’s not free but they do have trial versions available for download.
    • Eclipse. Open source IDE editors written in Java.
  • Dropbox – Online backup, file sync, and sharing made easy. Get it here: http://db.tt/QDC0nvU
  • ubuntu-restricted-extras – Essential software which is not already included due to legal or copyright reasons. Gives support for MP3 playback and decoding, Java runtime environment, Microsoft fonts, Flash plugin, DVD playback, and LAME (to create compressed audio files).
  • Adobe Flash & Adobe Air so you can run web applications like TweetDeck.

Missing Windows app/s?

If you still miss or cannot find your favorite Windows applications on Kubuntu, you install Wine to run them on Kubuntu. Wine is a program that offers a compatibility layer allowing Linux users to run some Windows-native applications inside of Linux. You can get Wine from Synaptic Package Manager / package manager or by following the instructions here.

Stuff I still need my Windows box for

  • Photo editing – Photoshop and Lightroom and
  • Video editing – Sony Vegas (goes with my Sony HD cam). The Linux alternative Kdenlive just dosent cut it.

With time I’m sure a super duper speced up Mac (with Dual boot for Kubuntu) will replace both my laptops. Now I need to sell myself why I should move to a Mac and pay double the price for hardware.

PS. If you have suggestions or additions to this post please comment below or contact me.

Happy hacking!

~ Ernest

Save money using coupons

Americans love coupons. Coupons are sexy. Coupons save you money.

It has always been an American Sunday paper tradition to clip coupons out for the week ahead. With the maturity of technology this landscape evolved and now most coupons are located online as the newspaper industry declines. So before you head out to shop in Silicon Valley, visit one of the following coupon sites to grab a bargain and save more of your money using coupons.

You might have already noticed that in the header navigation (above) of this site (The Road to Silicon Valley) I have already hooked up a “Save money” section to provide you with quick access to FREE at home printable grocery coupons and internet coupon codes. Those are powered by the no.1 coupon provider in America, Coupons.com. Keep on reading below to learn more about the best options to save money.

Coupons

A coupon is a ticket or document that can be exchanged for a financial discount or rebate when purchasing a product. Customarily, coupons are issued by manufacturers of consumer packaged goods or by retailers, to be used in retail stores as a part of sales promotions. Basically printing a coupon is like printing money without any commitment to purchase required (unlike group buying below which is the opposite).

Top 2 sites in the USA for printable coupons are:

  • Coupons.com – Top 50 U.S. web property and No. 1 in the Coupons/Rewards category*—as well as Grocery iQ® and Coupons.com mobile applications for iPhone® devices and the Android operating system. Coupons.com Free GroceryIQ mobile application is superb and does all the hardwork for you by connecting coupons and your SafeWay loyalty card program to your shopping list. It couldn’t get easier to plan your shopping and load coupons!
  • Coupon Mom – Stephanie Nelson is The Savings Mom on ABC News’ Good Morning America, where she has been a regular contributor since 2004. Her Good Morning America segments have taught viewers how to save in many areas, including travel, clothing, restaurants, groceries, gifts, theme parks, gardening and entertainment.

Group buying

Group buying works that if a certain number of people sign up for the offer, then the deal becomes available to all; if the predetermined minimum is not met, no one gets the deal that day. Basically you have to “purchase” the deal in order to save X amount eg. buy for $10 and get $20 worth of goods. So there is a level of commitment required. Unlike coupons where no purchase commitment is required.

Top 2 sites in the USA which allow you to participate in group daily deals are:

  • Groupon – the big boy in group buying. No doubt you would have heard of them. Easy to use and always great products & services to buy. I’m a regular user of their simple, easy to use and efficient service.
  • Living Social – this is a Groupon competitor. Not as popular as Groupon but they do feature some good deals. The beauty of using these 2 sites is if a limited (1 per purchase) deal appears on Groupon you can go to Living Social and purchase it here too.

Coupon codes

Also known as internet coupons since you need to be making an online purchase to take advantage of these – think godaddy codes. Internet coupons typically provide for reduced cost or free shipping, a specific dollar or percentage discount, or some other offer to encourage consumers to purchase specific products or to purchase from specific retailers. Nearly every online retailer or website has a place within its shopping cart or checkout process for promo codes or coupon codes. Use the sites below to get your discount codes when making any online purchase.

Top 2 sites in the USA which allow you to get internet coupon codes are:

  • RetailMeNot – offers discount coupons for more than 65,000 stores around the world. They have been around for a long time and always provide quality active coupon codes.
  • Coupons.com – a one-stop shop provider for printable grocery coupons, local coupon, coupon codes and daily deals. Don’t forget to sign up to their free newsletter so you never miss a great deal.

Other specials to watch out for

Finally, regularly visit your favorite store’s website. They will always feature one-off limited time discounts especially around holidays. Any holiday in the USA is a good reason for these companies to lure you into their store via a great deal – some even up to 50% off during Thanksgiving festive season. I find subscribing to their newsletter always keeps me in the loop. And if you want to spend more time outside with your family and friends at night, then check out this Ware custom fire pit Naperville.

Best deals can be found during the following times of the year:

  1. Black Friday (3rd Friday of November) – the day after Thanksgiving (3rd Thursday of November).
  2. Christmas sales (before and after 25th of December).
  3. Half year sales and other random public holidays. Get to know American public holidays.

So next time you plan on shopping don’t forget to check the above websites and save anywhere from 10-30% on your shopping bill. While your there, sign up to their newsletters / daily alerts so you never miss that deal. The money saved from this simple habit can be used for your education, your start-up or directed toward a number of other investment vehicles.

Here’s to happy savings!

~ Ernest

Links mentioned in this post

  • Coupons – Coupons, Grocery Coupons, Printable Coupons, Restaurant Coupons, Coupon Codes
  • CouponMom – Cut your grocery bill in half!
  • Groupon – local daily deals
  • LivingSocial – local daily deals
  • RetailMeNot – Coupon codes and discounts for 65000 online stores!