Using git at Mozilla



All timestamps are based on your local time of:

Posted by: stak
Tags: mozilla
Posted on: 2012-08-27 20:13:15

Ehsan was asking me today about my git workflow at Mozilla; specifically how I push a git branch to try. I figured I'd post it here since other people may find it useful.

My git workflow involves (1) an alias in my ~/.gitconfig to generate a hg-compatible patch from a git commit, and (2) a script that runs that alias on all of the patches in the branch. This is the alias I have in my ~/.gitconfig file:

[alias]
   hgp = "show --binary --format=\"# HG changeset patch%n# User %an <%ae>%n%B\" -U8"

Running git hgp HEAD, for example, will output to stdout a patch that can be imported by mq.

The script to export an entire branch is at github/staktrace/moz-scripts/hgp. Simply drop it on your $PATH and update the DESTDIR variable to some folder you would like the generated patches to end up in. (It is currently hard-coded to $HOME/zspace/patches/.)

For simple usage, just run it without any arguments. All of the commits from master..HEAD will get exported in mq-compatible format to the $DESTDIR, named n-branch-sha, where n is a counter that orders the patches sequentially, branch is the name of the git branch you're on, and sha is the shortened SHA of the commit. For example:

kats@kgupta-air mozilla-git$ git checkout layerview
Switched to branch 'layerview'
kats@kgupta-air mozilla-git$ hgp
kats@kgupta-air mozilla-git$ ls -l ~/zspace/patches/
total 1440
-rw-r--r--    1 kats  staff    6115 27 Aug 20:59 1-layerview-18ea4c9
-rw-r--r--    1 kats  staff    5805 27 Aug 20:59 2-layerview-944d80a
-rw-r--r--    1 kats  staff    5068 27 Aug 20:59 3-layerview-2fcfba1
-rw-r--r--    1 kats  staff    3199 27 Aug 20:59 4-layerview-6339849
drwxr-xr-x  253 kats  staff    8602 27 Aug 09:41 old

The hgp script also takes optional arguments - the first argument is taken as the number of commits to export. So running hgp 3 will export the top three patches on your current branch. The second argument is a branch name, so you can export commits from a branch other than the one you currently have checked out.

One final thing that the script does before it exports the patches, is it moves any existing patches in $DESTDIR from the current branch into a $DESTDIR/old folder. This is because when you make changes to your git commits, the SHA values will change and if the old patches aren't removed then you could end up with two patches with the name 1-layerview-xxxxxxx, and it wouldn't be obvious which one is newer.

Anyway, using the above script I can quickly export a branch into a folder, and then it's a snap to re-import it into a mercurial queue and push it to try (or any other hg tree):

hg qimport ~/zspace/patches/*layerview*
hg qgoto try # I have a "try" patch sitting at the bottom of my default queue
hg qref -e # update any try-push options that need updating
hg push -f try

Posted by nbp at 2012-08-28 20:27:06
Thanks for sharing the hgp alias, this is useful for people who want to import your patches. On my case I am using a modified version of top-git which I found way more practical than patch queues and git branches.

I have been using the try server with my 2-way mirror of mercurial[1], and I modified the try chooser python script to write the result of the interactive command in a file such as I can reuse it in a git-try shell script which is pushing to the master branch of the try remote.

[1] https://github.com/nbp/spidermonkey-dev-tools/tree/master/git-hg-bridge
[ Reply to this ]
Name:
Comment:
Allowed expansions in comments/replies: [i]italic[/i], [u]underline[/u], [b]bold[/b], [code]code[/code], [sub]subscript[/sub], [sup]superscript[/sup], [url=http://some.url]linked text[/url]
Human verification: Sum of thirty-two and twenty-five =
 
 
(c) Kartikaya Gupta, 2004-2025. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!