Friday, January 14, 2011

How GitChangeSet.java works..

The parsing code within GitChangeSet.java (do a git clone https://github.com/hudson/Hudson-GIT-plugin.git) works great great. The way the plug-in works is to do "git diff whatchanged --no-abbrev -M --pretty=raw" (see GitAPI).java. The diff structures that are parsed appears as follows:

tree 92b84d3b8bba31b80f011bf9f957190ad14b299c
parent 15a87109192f74dc9f82af23c9ffa047d8379622
author John Smith  1294997088 -0800
committer John Smith  1294997548 -0800

Within GitChangeSet.java, the regex to parse through and extract the author, commiter, email address, timestamp, and time zone is performed. Everything looks great. Within the getAuthor() method, there is a line that attempts to create the user if the name does not exist. This line will create a User object with the csAuthor field passed-in, and a boolean field as the 2nd parameter determines whether to create a new account if the userid is not passed.

We can see a similar pattern in HudsonPrivateSecurityRealm.java (you need to git clone https://github.com/hudson/hudson.git)

// register the user                                                                                                                                                               
        User user = createAccount(si.username,si.password1);
        user.addProperty(new Mailer.UserProperty(si.email));
        user.setFullName(si.fullname);
        return user;

No comments:

Post a Comment