Affichage des articles dont le libellé est programmation. Afficher tous les articles
Affichage des articles dont le libellé est programmation. Afficher tous les articles

mercredi 25 septembre 2013

displaying Gerrit review history in git log

Over the last few weeks, several people complained I should share my tip'n tricks with more people. They are apparently worth a post.  I am giving it a try there to show you how to make available in your git cli the Gerrit review informations. I will start with some context then spurt magical commands to let you make it happen on your own computer.

In the beginning of 2012, the Wikimedia Foundation switched from Subversion to Git. The main reason for the switch was to prevent committers from inserting bad code in the central repository. Thus lowering the stress when deploying said code on the production site.  The only way to do it is to elect a gatekeeper between patch authors and the reference repository used for deployment. In Linux, that is more or less the role of Linus Torvalds. At Wikimedia we selected Gerrit which is used at Google to accept patches for their Android platform.

The Gerrit workflow is pretty simple: authors send their patches to Gerrit, he and others comment or amend the patch, rinse and repeat until there is no more to say. After a few iterations, the community ends up with a robust patch which is worth entering the reference repository. A few people are allowed to approve the change and have it actually merged.

The history that led to the final commit is available (example for a patch I wrote: https://gerrit.wikimedia.org/r/75569) and is very valuable whenever a bug appear: the comments can give you an idea of the design choices and list out every single person that get involved in the patch. If the original author is not available, you can most probably reach out to the person that review the code. When you are facing an issue in production, the more people to ask the merrier.

It is too cumbersome to have to open the browser in the Gerrit web interface. Aging, I rely more and more on terminals and command lines. How would I get the commit history from the command line without having to parse some Gerrit json? Luckily, there is a way to get all the reviewing history saved locally and thus available offline.

Internally, Gerrit relies a lot upon git, its internal configuration for a given repository is even available (under refs/meta/config). The review history for a repository is thus stored in Git as well and it lives under refs/notes.

You can thus fetch all the review history:
git fetch -v origin refs/notes/*:refs/notes/*
Then configure your repository to always show the notes in git log:
git config --local notes.displayRef refs/notes/review
End result:

$ git log -n1 1dad0218
commit 1dad021840bf936b0e130ddda3459d11f0ad8421
Author: Antoine Musso 
Date:   Wed Jul 24 12:08:52 2013 +0200

    SpecialPrefixindex formatting methods are now protected
    
    namespacePrefixForm() and showPrefixChunk() accepted additional
    arguments to slightly alter the form such as hiding redirects.  The
    argument has been removed in favor of class property just like
    stripprefix introduced earlier and the method have been made protected
    since there is no point in calling them out of the special page scope.
    
    Change-Id: I55728fd2634f8a935a033052dcce3c7247cb1aa3

Notes (review):
    Verified+2: jenkins-bot
    Code-Review+2: Matmarex 
    Submitted-by: jenkins-bot
    Submitted-at: Fri, 30 Aug 2013 19:41:21 +0000
    Reviewed-on: https://gerrit.wikimedia.org/r/75569
    Project: mediawiki/core
    Branch: refs/heads/master


On this patchset, we can see that Matmarex has accepted the change :-) You can prevent notes from displaying whenever you like by passing --no-notes to the git log command. Note: you will have to fetch the notes from time to time since they are not fetched by default. An alias would be useful:
git config --global alias.fetchreviews \ 'fetch -v gerrit refs/notes/review:refs/notes/review'
You can then refresh notes by nvoking git fetchreviews.

Summary:

* Get notes: git fetch -v origin refs/notes/review:refs/notes/review
* Configure git to always show them: git config --local notes.displayRef refs/notes/review

lundi 18 juillet 2011

git cheat sheet

This post is supposed to be a cheat sheet for git commands. Much like the previous mac port post (in french).

regrouping commits

# back to master & up-to-date:
git checkout master
git pull
# create a new clean branch
git checkout -b clean_new_feature
# merge in the branch with ton of commits
git merge messy_feature
# The clean_new_feature branch now has everything needed.
# Move its pointer back to the origin so our merge is considered
# a series of unstaged changes:
git reset origin/master
git status # review the differences :)
git add .
git add -u # you wants to send file deletions too
git commit


You now have all the commits regrouped in one new branch named 'clean_new_feature'. You can now request a pull&merge to upstream.


advancing remote branch

(master)$ git checkout -b localbranch nickname/master
Branch localbranch set up to track remote branch master from nickname.
Switched to a new branch 'localbranch'
(localbranch)$ git merge origin/master
Updating 1234567..9abcdef
Fast-forward
...
X files changed, Y insertions(+), Z deletions(-)
(localbranch)$ git status
# On branch localbranch
# Your branch is ahead of 'nickname/master' by T commits.
#
nothing to commit (working directory clean)
(localbranch)$ git push
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:nickname/repository.git
   1234567..9abcdef  master -> master
(localbranch)$ git status
# On branch localbranch
nothing to commit (working directory clean)
(localbranch)$





pushing local branch to a remote branch

$ git push nickname localbranch:remotebranchname

This would push your local branch named 'localbranch' to the 'nickname' repository under the branch name 'remotebranchname'. Simple isn't it?

mardi 9 février 2010

PHP serialize() et json_encode

En réponse à Julien sur twitter.
Voici un comparatif rapide des fonctions PHP5 permettant de coder un objet en phrase. Cette pratique est utile lorsque l'on souhaite conserver une structure longue à initialiser pour la recharger ensuite très rapidement.

J'ai utilisé en source un tableau unidimensionnel provenant du logiciel MediaWiki. Il s'agit d'une liste de références à des messages en anglais et traduits en français. Le fichier est codé en UTF-8.

Le script sous PHP 5.2.11:


<?php
# Load a one dimension array named $messages
include "mediawiki/languages/messages/MessagesFr.php";

function code_time_for( $function, $on, $iter ) {
    $start = microtime(true);
    for( $i=0;$i<$iter;$i++) {
        call_user_func( $function, $on );
    }
    $end = microtime(true);
    return
        sprintf("Ran $iter x %-11s in: %9.3f ms", $function, 1000*($end - $start));
}

$msg_ser  = serialize( $messages );
$msg_json = serialize( $messages );
$times = 777;

# Lets have a look at encoding:
print code_time_for( 'serialize'  , $messages, $times ) . "\n";
print code_time_for( 'json_encode', $messages, $times ) . "\n";
# And then compare decoding functions:
print code_time_for( 'unserialize', $msg_ser , $times ) . "\n";
print code_time_for( 'json_decode', $msg_json, $times ) . "\n";


Le résultat avec 777 occurrences :

Ran 777 x serialize   in:  1211.259 ms
Ran 777 x json_encode in:  3897.529 ms
Ran 777 x unserialize in:  1359.995 ms
Ran 777 x json_decode in:  1888.151 ms


Les fonctions PHP restent plus performantes. En tout cas pour ce tableau.

jeudi 15 octobre 2009

... de lignes de perl pour illustrer un fork

Ceci est un vieux message je l'avais commencé en juin 2008 et jamais publié. Le principe était de rédiger un exemple d'utilisation de fork() en perl. Je n'ai pas réellement relu le code et il nécessiterait un bon coup de balai, il aura au moins le mérite d'être publié. Le résultat de l'exécution est à la suite.