The Artima Developer Community
Sponsored Link

Java Buzz Forum
Extending git

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Mathias Bogaert

Posts: 344
Nickname: pathos
Registered: Aug, 2003

Mathias Bogaert is a senior software architect at Intrasoft mainly doing projects for the EC.
Extending git Posted: Apr 3, 2013 3:06 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Mathias Bogaert.
Original Post: Extending git
Feed Title: Scuttlebutt
Feed URL: http://feeds.feedburner.com/AtlassianDeveloperBlog
Feed Description: tech gossip by mathias
Latest Java Buzz Posts
Latest Java Buzz Posts by Mathias Bogaert
Latest Posts From Scuttlebutt

Advertisement
While Mercurial has a well defined (albeit internal) API that can be used to write extensions that extend the functionality of Mercurial, git’s extension model follows the Unix philosophy of composing small, simple programs to achieve a similar effect. What that means is that git “extensions” can be written in any language and by following a few simple rules it’s still possible to add commands that appear as if they were built-in. Example: git activity To see the activity on all the branches in a repository I’ve implemented a git activity command. git activity shows the latest commit on every branch, sorted by recency. It shows the following output when executed in the Rails repository: The script is written in bash and fairly straightforward. We set up colours and parse some command line options the scripts supports (e.g. to turn off colours, to limit the output) and then run git for-each-ref to output information about each ref. #!/bin/bash set -e GIT_OPTS="" OUTPUT_FILTER="cat" # no-op commit_id_format=$(tput setaf 1) date_format=$(tput bold; tput setaf 4) author_format=$(tput setaf 2) ref_name_format=$(tput setaf 3) bold=$(tput bold) reset=$(tput sgr0) function usage() {     echo ""     echo "git activity"     echo ""     echo "  See 'man git-activity' for further information" } # actually parse the options and do stuff while [[ $1 = -?* ]]; do     case $1 in         -h|--help)             usage             exit 0             ;;         --fetch)             echo "Fetch updates"             git fetch -q             ;;         -c|--count)             shift             limit=${1-"10"}             #OUTPUT_FILTER="tail -n ${limit}"             GIT_OPTS="--count=${limit}"             ;;         --no-color|--no-colour)             commit_id_format=""             date_format=""             author_format=""             ref_name_format=""             bold=""             reset=""             ;;         *) ;;     esac shift done # Use newline as a field separator IFS=$(echo -en "\n\b") # Use tac if available, otherwise tail with the possibly-not-always-available # -r flag (for reverse output) TAC=$(which tac || echo 'tail -r') for line in $(git for-each-ref ${GIT_OPTS} refs/remotes --format="%(authordate:relative)|%(objectname:short)|%(authorname)|%(refname:short)|%(subject)" --sort="-authordate"); do     fields=(`echo $line | tr "|" "\n"`)     printf "${date_format}%15s${reset} ${commit_id_format}%s${reset} - ${author_format}[%s]${reset} (${ref_name_format}%s${reset}): %s\n" ${fields[*]} done | eval $TAC # reverse sort the output to show the newest entry last The important rules to follow to make this script available as a git sub-command are: It should be named git-COMMANDNAME, in this case it’s called git-activity and it needs to be executable [...]

Read: Extending git

Topic: Lessons to learn from Hibernate Core implementation Previous Topic   Next Topic Topic: Life Beyond Rete – R.I.P Rete 2013 :)


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us