2022-07-21

GIT Timeline Comments

With GIT it's possible to attach notes to objects, this option allows expanding a commit message without changing the commit itself. Alternatively, a comment inside the commit history can be included in form of an empty commit.

The VLANG code below when compiled creates the executable gittimeline.exe which provides the possibility to add comments and retrieve the commit history directly from the command line (similar to git timeline for the python REPL).

    // filename: gittimeline.v
    import os
    import cli { Command, Flag }

    fn annotate_func(cmd Command) ? {
    // empty commit with a comment
       mut err := os.Result{}
       note := cmd.args[0]
       err = os.execute("git commit --allow-empty -m '$note'") 
       if err.exit_code == 0 {
           println(err.output)
           }
    }
    fn timeline_func(cmd Command) ? {
       err := os.execute_or_exit("git log --graph --all --format=format:'(%cr) %s%d' --date-order --abbrev-commit --date=relative") 
       if err.exit_code == 0 {
           println(err.output)
       }
    }

    fn main() {
        mut cmd := Command{
            name: 'gittimeline'
            description: 'Annotate/Display Timeline.'
            version: '0.2'
        }

        mut timeline := Command{
            name: 'timeline'
            description: 'Timeline'
            usage: '<name>'
        //  required_args: 1
            execute: timeline_func
        }

        mut annotate := Command{
            name: 'annotate'
            description: 'Annotate'
            usage: '<name>'
            required_args: 1
            execute: annotate_func
        }

        cmd.add_command(annotate)
        cmd.add_command(timeline)
        cmd.setup()
        cmd.parse(os.args)
    }
    

A comment to the commit history can be created from the command line as:

   $ gittimeline.exe annotate "My comment"

The command:

   $ gittimeline.exe timeline | tig

displays the repository's timeline inside tig which functions as a pager. More than one comment can be consolidated into a note by interactive rebase the commit history, squashing a set of comments together. Rebase can only be applied to your own local commits before pushing them to the remote repository.

The option to automatically create an empty commit when a task is completed will be part of the CSVTODO desktop application next release.