libnodegit



Jaseem Abid

jaseemabid@gmail.com

B090264CS

NIT Calicut 

Prelude!



GIT 

JAVASCRIPT 

PRESS ↓

GIT 


 Free and open source distributed 
version control system

fast
scalable
*awesome*

Major features


Branching and Merging
Small and Fast
Distributed
Data Assurance
Staging Area
Free and Open Source

JAVASCRIPT 



JavaScript  is an awesome  programming language that is widely used to give sophisticated functionality to web pages.



*Generally* used for behavior in webpages along 
with the DOM


But in no way tied to DOM


  • node.js
  • Google's Chrome extensions
  • Apple's Dashboard Widgets
  • Microsoft's Gadgets
  • Inside PDF files [Adobe's Acrobat Reader]
  • Adobe Creative Suite,  Photoshop
  • OpenOffice.org scripting 
  • App.js 
  • The Unity game engine
  • Google Spreadsheets  
  • IRC clients, like ChatZilla or XChat
  • What is libnodegit ?



    A JavaScript API for git repositories with
    node.js and libgit2





    LIBnodegit = libgit2 + node.js 

    LIBGIT2



    libgit2 is a portable, pure C implementation of the Git core methods provided as a re-entrant linkable library with a solid API, allowing you to write native speed custom Git applications in any language which supports C bindings.

    LiBGIT2



    text file repository  => C API



    Very low level API



    
        #include <git2.h>
        git_repository *repo;
        git_repository_open(&repo, "/path/to/repo.git");
    
        /* do stuff with the repository */
    
        git_repository_free(repo);
    
    

    Node.js


    Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

    node.js


    C => C++ => JavaScript

    Why libnodegit ?


    Because JavaScript and git are so far apart !

    So ?


    Building web apps powered by 
    git is a hard task

    Use cases


    • Programmable scripting layer on top of git 
    • Data with the API - Apps with JavaScript.
      let creativity flow! 
    • Installable GUI apps - App.js 
    • Web UI/visualizations
    • API for machine consumption - feeds, data end points
    • Easy Integration with CI servers,  IRC etc
    • Quikly expose git repositories to the web

    API Example 


    TASK : List files in the git repository


    github ls 


      ✈ git ls-files


    .gitignore
    .gitmodules
    README.md
    binding.gyp
    docs
    lib/index.js
    package.json
    src/TODO
    src/head.cc
    src/index.cc
    ....
    ....
    

    shell :)


    git ls-files | JavaScript 

    This **|** is what we need node.js and v8 for

    API 

    l = require 'libnodegit'
    
    repo = new l.Repository "~/Projects/libnodegit"
    
    console.log repo.index()

      ✈ coffee examples/index.coffee
    
    [ { path: '.gitignore',
        sha: '47daa783f3d9663a938b48629121a997f2c80c61',
        size: 87,
        device: 2052,
        inode: 13238282,
        uid: 1000,
        gid: 100,
        ctime: 1349736253,
        mtime: 1349736253 },
      { ... },
      { ... },
      { ... } ]

    What will libnodegit do ?

    Quick features 

    • Quick simple read - write access
    • Everyday commands will be implemented first 
    • Network features
    • Packaged install 
    • Asynchronous API
    • Error handling 
    • Extensible  architecture 
    • Performance  

    Milestones


    Implementation details 

    1


    Familiarization with git, libgit2 and node.js


    The v8 C++ API underneath node.js is complicated and need to be mastered. It also requires a good understanding of the C++ language, the git object store and the plumbing commands.


    Design the JavaScript API

    3


    Read and write repository configurations and settings

    Open a repository with a given path, retrieve and update information like user
    information, config variables, description, branches, tags, remotes, submodules etc

    4


     File and diff viewing

    Git diff, blame, show file/blob contents

    5


    API for manipulating repository index

    Retrieve state of the repository index (dirty/clean)
    Information on files in the index, their hash, size, mime type etc
    API to add, ignore, stage, unstage and reset files
    API to view staged and unstaged data.

    6


    API for git branching


    git branch, merge, checkout etc


     


    7


     Network & initialization features

    Provide API for init, push, pull, clone etc.

    8


    History walking

    History walking from standard reference points like branches, tags etc and more
    advanced options like shortlog and log –oneline.

    9


    API history rewrites, undoing, rebase

    Git revert, reset, rebase, interactive rebase, reorder, squashing etc

    10


    git submodules


    11


    API to add new commits to the repository

    git commit, amend etc

    12


    API for accessing notes, stashes, cherry-picking


    13


    API for dealing with git object store

    git gc, bundle, purne, fsck

    14


    Asynchronous API

    Provide a callback based asynchronous API for huge performance improvements.
    Instead of leaving it to the end as a big step, this will be implemented gradually as the project progress.

    WHAT CAN LIBNODEGIT DO NOW ?


    ** DEMO ** 

    Challenges 


    • Too many tools required for a "hello world"
    • v8 API is complicated
    • Too less d11n on v8 other than source
    • Jumping into v8 is hard
    • Git is huge 
    • OO API design is time consuming



    Thank you


    libnodegit

    By jaseemabid