Saturday 15 March 2014

git - Can you get the number of lines of code from a Github repository? -



git - Can you get the number of lines of code from a Github repository? -

in github repository can see "language statistics", displays percentage of project that's written in language. doesn't, however, display how many lines of code project consists of. often, want impression of scale , complexity of project, , count of lines of code can give first impression. 500 lines of code implies relatively simple project, 100,000 lines of code implies large/complicated project.

so, possible lines of code written in various languages github repository, preferably without cloning it?

this question (count number of lines in git repository) asks how count lines of code in local git repository, but:

you have clone project, massive. cloning project wine, example, takes ages. you count lines in files wouldn't code, i13n files. if count just (for example) ruby files, you'd potentially miss massive amount of code in other languages, javascript. you'd have know beforehand languages project uses. you'd have repeat count every language project uses.

all in all, potentially far time intensive "quickly checking scale of project".

a shell script, cloc-git

you can shell script count number of lines in remote git repository 1 command:

class="lang-bash prettyprint-override">#!/usr/bin/env bash git clone --depth 1 "$1" temp-linecount-repo && printf "('temp-linecount-repo' deleted automatically)\n\n\n" && cloc temp-linecount-repo && rm -rf temp-linecount-repo installation

this script requires cloc (“count lines of code”) installed. cloc can installed bundle manager – example, brew install cloc homebrew.

you can install script saving code file cloc-git, running chmod +x cloc-git, , moving file folder in $path such /usr/local/bin.

usage

the script takes 1 argument, git clone accept. examples https://github.com/evalempire/perl5i.git (https) or git@github.com:evalempire/perl5i.git (ssh). can text sidebar of github project page.

example output:

$ cloc-git https://github.com/evalempire/perl5i.git cloning 'temp-linecount-repo'... remote: counting objects: 200, done. remote: compressing objects: 100% (182/182), done. remote: total 200 (delta 13), reused 158 (delta 9), pack-reused 0 receiving objects: 100% (200/200), 296.52 kib | 110.00 kib/s, done. resolving deltas: 100% (13/13), done. checking connectivity... done. ('temp-linecount-repo' deleted automatically) 171 text files. 166 unique files. 17 files ignored. http://cloc.sourceforge.net v 1.62 t=1.13 s (134.1 files/s, 9764.6 lines/s) ------------------------------------------------------------------------------- language files blank comment code ------------------------------------------------------------------------------- perl 149 2795 1425 6382 json 1 0 0 270 yaml 2 0 0 198 ------------------------------------------------------------------------------- sum: 152 2795 1425 6850 ------------------------------------------------------------------------------- alternatives run commands manually

if don’t want bother saving , installing shell script, can run commands manually. example:

$ git clone --depth 1 https://github.com/evalempire/perl5i.git $ cloc perl5i $ rm -rf perl5i linguist

if want results match github’s language percentages exactly, can seek installing linguist instead of cloc. according its readme, need gem install linguist , run linguist. couldn’t work (issue #2223).

git github

No comments:

Post a Comment