├── .coveragerc ├── .coveralls.yml ├── .gitattributes ├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── contributing.rst ├── history.rst ├── index.rst ├── installation.rst ├── make.bat ├── readme.rst └── usage.rst ├── git2json ├── __init__.py └── parser.py ├── requirements.txt ├── setup.py ├── tests ├── __init__.py ├── fixtures │ ├── test_git2json-1.txt │ └── test_git2json-2.txt ├── test_git2json.py └── test_regex_commit.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | test* 4 | *virtualenv* 5 | *site-packages* 6 | 7 | [report] 8 | exclude_lines = 9 | pragma: no cover 10 | def __repr__ 11 | raise NotImplementedError 12 | if __name__ == .__main__.: 13 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarmstrong/git2json/4f9e9d47c064fc0621582e19a78ea3fef87e2212/.coveralls.yml -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.txt binary 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | .coverage 26 | .tox 27 | nosetests.xml 28 | 29 | # Translations 30 | *.mo 31 | 32 | # Mr Developer 33 | .mr.developer.cfg 34 | .project 35 | .pydevproject 36 | 37 | # Complexity 38 | output/*.html 39 | output/*/index.html 40 | 41 | # Sphinx 42 | docs/_build -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | language: python 4 | 5 | python: 6 | - "2.7" 7 | - "3.3" 8 | - "3.6" 9 | 10 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 11 | install: 12 | - pip install -r requirements.txt 13 | - pip install flake8 14 | - pip install python-coveralls 15 | 16 | # command to run tests, e.g. python setup.py test 17 | script: 18 | - python setup.py nosetests 19 | - flake8 git2json 20 | - flake8 tests 21 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Tavish Armstrong 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/tarmstrong/git2json/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * Detailed steps to reproduce the bug. 23 | 24 | Fix Bugs 25 | ~~~~~~~~ 26 | 27 | Look through the GitHub issues for bugs. Anything tagged with "bug" 28 | is open to whoever wants to implement it. 29 | 30 | Implement Features 31 | ~~~~~~~~~~~~~~~~~~ 32 | 33 | Look through the GitHub issues for features. Anything tagged with "feature" 34 | is open to whoever wants to implement it. 35 | 36 | Write Documentation 37 | ~~~~~~~~~~~~~~~~~~~ 38 | 39 | Git2JSON could always use more documentation, whether as part of the 40 | official Git2JSON docs, in docstrings, or even on the web in blog posts, 41 | articles, and such. 42 | 43 | Submit Feedback 44 | ~~~~~~~~~~~~~~~ 45 | 46 | The best way to send feedback is to file an issue at https://github.com/tarmstrong/git2json/issues. 47 | 48 | If you are proposing a feature: 49 | 50 | * Explain in detail how it would work. 51 | * Keep the scope as narrow as possible, to make it easier to implement. 52 | * Remember that this is a volunteer-driven project, and that contributions 53 | are welcome :) 54 | 55 | Get Started! 56 | ------------ 57 | 58 | Ready to contribute? Here's how to set up `git2json` for local development. 59 | 60 | 1. Fork the `git2json` repo on GitHub. 61 | 2. Clone your fork locally:: 62 | 63 | $ git clone git@github.com:your_name_here/git2json.git 64 | 65 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 66 | 67 | $ mkvirtualenv git2json 68 | $ cd git2json/ 69 | $ python setup.py develop 70 | 71 | 4. Create a branch for local development:: 72 | 73 | $ git checkout -b name-of-your-bugfix-or-feature 74 | 75 | Now you can make your changes locally. 76 | 77 | 5. When you're done making changes, check that your changes pass flake8 and the 78 | tests, including testing other Python versions with tox:: 79 | 80 | $ flake8 git2json tests 81 | $ python setup.py nosetests 82 | 83 | To get flake8 and tox, just pip install them into your virtualenv. 84 | 85 | 6. Commit your changes and push your branch to GitHub:: 86 | 87 | $ git add . 88 | $ git commit -m "Your detailed description of your changes." 89 | $ git push origin name-of-your-bugfix-or-feature 90 | 91 | 7. Submit a pull request through the GitHub website. 92 | 93 | Pull Request Guidelines 94 | ----------------------- 95 | 96 | Before you submit a pull request, check that it meets these guidelines: 97 | 98 | 1. The pull request should include tests. 99 | 2. If the pull request adds functionality, the docs should be updated. Put 100 | your new functionality into a function with a docstring, and add the 101 | feature to the list in README.rst. 102 | 3. The pull request should work for Python 2.6 and 2.7 (in the future 3.x and PyPy will be supported). Check 103 | https://travis-ci.org/tarmstrong/git2json/pull_requests 104 | and make sure that the tests pass for all supported Python versions. 105 | 106 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | .. :changelog: 2 | 3 | History 4 | ------- 5 | 6 | 0.1.0 (2013-09-23) 7 | ++++++++++++++++++ 8 | 9 | * First release on PyPI. 10 | 11 | 0.1.1 (2013-09-25) 12 | ++++++++++++++++++ 13 | 14 | * Fixed broken PyPI package. 15 | 16 | 0.2.0 (2013-09-28) 17 | ++++++++++++++++++ 18 | 19 | * Parents now an array instead of a single value. 20 | 21 | 0.2.1 (2013-10-07) 22 | ++++++++++++++++++ 23 | 24 | * Re-implemented parser with regular expressions. 25 | * Character encoding issues fixed. 26 | 27 | 0.2.2 (2013-11-09) 28 | ++++++++++++++++++ 29 | 30 | * Fix bug #7 (hidden filenames not parsed correctly): https://github.com/tarmstrong/git2json/issues/7 31 | 32 | 0.2.3 (2013-11-09) 33 | ++++++++++++++++++ 34 | 35 | * Python 3 compatibility 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Tavish Armstrong 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of Git2JSON nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean-pyc clean-build docs 2 | 3 | help: 4 | @echo "clean-build - remove build artifacts" 5 | @echo "clean-pyc - remove Python file artifacts" 6 | @echo "lint - check style with flake8" 7 | @echo "test - run tests quickly with the default Python" 8 | @echo "testall - run tests on every Python version with tox" 9 | @echo "coverage - check code coverage quickly with the default Python" 10 | @echo "docs - generate Sphinx HTML documentation, including API docs" 11 | @echo "release - package and upload a release" 12 | @echo "sdist - package" 13 | 14 | clean: clean-build clean-pyc 15 | 16 | clean-build: 17 | rm -fr build/ 18 | rm -fr dist/ 19 | rm -fr *.egg-info 20 | 21 | clean-pyc: 22 | find . -name '*.pyc' -exec rm -f {} + 23 | find . -name '*.pyo' -exec rm -f {} + 24 | find . -name '*~' -exec rm -f {} + 25 | 26 | lint: 27 | flake8 git2json tests 28 | 29 | test: 30 | python setup.py test 31 | 32 | test-all: 33 | tox 34 | 35 | coverage: 36 | coverage run --source git2json setup.py test 37 | coverage report -m 38 | coverage html 39 | open htmlcov/index.html 40 | 41 | docs: 42 | rm -f docs/git2json.rst 43 | rm -f docs/modules.rst 44 | sphinx-apidoc -o docs/ git2json 45 | $(MAKE) -C docs clean 46 | $(MAKE) -C docs html 47 | open docs/_build/html/index.html 48 | 49 | release: clean 50 | python setup.py sdist upload 51 | 52 | sdist: clean 53 | python setup.py sdist 54 | ls -l dist -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | Git2JSON 3 | =============================== 4 | 5 | .. image:: https://badge.fury.io/py/git2json.png 6 | :target: http://badge.fury.io/py/git2json 7 | 8 | .. image:: https://travis-ci.org/tarmstrong/git2json.png?branch=master 9 | :target: https://travis-ci.org/tarmstrong/git2json 10 | 11 | .. image:: https://pypip.in/d/git2json/badge.png 12 | :target: https://crate.io/packages/git2json?version=latest 13 | 14 | 15 | Convert git logs to JSON for easier analysis. 16 | 17 | * Free software: BSD license 18 | * Documentation: http://git2json.rtfd.org. 19 | 20 | Installation 21 | ------------ 22 | 23 | The easiest way to install ``git2json`` is through pip: 24 | 25 | :: 26 | 27 | pip install git2json 28 | 29 | If you want the most up-to-date version (at a greater risk of encountering 30 | bugs) you can clone this repository and install it manually: 31 | 32 | :: 33 | 34 | git clone https://github.com/tarmstrong/git2json.git 35 | cd git2json 36 | python setup.py install 37 | 38 | Usage 39 | ----- 40 | 41 | :: 42 | 43 | usage: git2json [-h] [--git-dir GIT_DIR] [--since SINCE] 44 | 45 | optional arguments: 46 | -h, --help show this help message and exit 47 | --git-dir GIT_DIR Path to the .git/ directory of the repository you are 48 | targeting 49 | --since SINCE Show commits more recent than a specific date. If 50 | present, this argument is passed through to "git log" 51 | unchecked. 52 | --args SRCS Pass additional arguments to git log 53 | 54 | usage: git2json [-h] [--git-dir GIT_DIR] 55 | 56 | 57 | The resulting JSON log is printed to standard output. 58 | 59 | Example JSON 60 | ------------ 61 | 62 | The following shows the structure of the JSON emitted by the tool. 63 | 64 | :: 65 | 66 | [{ 67 | "committer": { 68 | "date": 1379903278, 69 | "timezone": "-0400", 70 | "name": "Tavish Armstrong", 71 | "email": "tavisharmstrong@gmail.com" 72 | }, 73 | "parents": ["e307663594031738c932877c8589552d5aafc953"], 74 | "author": { 75 | "date": 1379903278, 76 | "timezone": "-0400", 77 | "name": "Tavish Armstrong", 78 | "email": "tavisharmstrong@gmail.com" 79 | }, 80 | "tree": "bd03127651335e3a51241f507f3bf194d8336485", 81 | "commit": "d06454c160218b4a782afad2429abda1add54df0", 82 | "message": "Allow user to specify git-dir on the command line.", 83 | "changes": [ 84 | [23, 3, "git2json/__init__.py"] 85 | ] 86 | }, 87 | // ... More commits 88 | ] 89 | 90 | 91 | Usage Examples 92 | ============== 93 | 94 | * `How Long Does It Take To Review an IPython Pull Request? `_ by Tavish Armstrong (git2json author) 95 | 96 | If you are using ``git2json`` in interesting ways, please share and I will 97 | add your notebooks/blog posts/code to this list. 98 | 99 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # complexity documentation build configuration file, created by 5 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 6 | # 7 | # This file is execfile()d with the current directory set to its containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import sys, os 16 | 17 | # If extensions (or modules to document with autodoc) are in another directory, 18 | # add these directories to sys.path here. If the directory is relative to the 19 | # documentation root, use os.path.abspath to make it absolute, like shown here. 20 | #sys.path.insert(0, os.path.abspath('.')) 21 | 22 | # Get the project root dir, which is the parent dir of this 23 | cwd = os.getcwd() 24 | project_root = os.path.dirname(cwd) 25 | 26 | # Insert the project root dir as the first element in the PYTHONPATH. 27 | # This lets us ensure that the source package is imported, and that its 28 | # version is used. 29 | sys.path.insert(0, project_root) 30 | 31 | import git2json 32 | 33 | # -- General configuration ----------------------------------------------------- 34 | 35 | # If your documentation needs a minimal Sphinx version, state it here. 36 | #needs_sphinx = '1.0' 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be extensions 39 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 40 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] 41 | 42 | # Add any paths that contain templates here, relative to this directory. 43 | templates_path = ['_templates'] 44 | 45 | # The suffix of source filenames. 46 | source_suffix = '.rst' 47 | 48 | # The encoding of source files. 49 | #source_encoding = 'utf-8-sig' 50 | 51 | # The master toctree document. 52 | master_doc = 'index' 53 | 54 | # General information about the project. 55 | project = u'Git2JSON' 56 | copyright = u'2013, Tavish Armstrong' 57 | 58 | # The version info for the project you're documenting, acts as replacement for 59 | # |version| and |release|, also used in various other places throughout the 60 | # built documents. 61 | # 62 | # The short X.Y version. 63 | version = git2json.__version__ 64 | # The full version, including alpha/beta/rc tags. 65 | release = git2json.__version__ 66 | 67 | # The language for content autogenerated by Sphinx. Refer to documentation 68 | # for a list of supported languages. 69 | #language = None 70 | 71 | # There are two options for replacing |today|: either, you set today to some 72 | # non-false value, then it is used: 73 | #today = '' 74 | # Else, today_fmt is used as the format for a strftime call. 75 | #today_fmt = '%B %d, %Y' 76 | 77 | # List of patterns, relative to source directory, that match files and 78 | # directories to ignore when looking for source files. 79 | exclude_patterns = ['_build'] 80 | 81 | # The reST default role (used for this markup: `text`) to use for all documents. 82 | #default_role = None 83 | 84 | # If true, '()' will be appended to :func: etc. cross-reference text. 85 | #add_function_parentheses = True 86 | 87 | # If true, the current module name will be prepended to all description 88 | # unit titles (such as .. function::). 89 | #add_module_names = True 90 | 91 | # If true, sectionauthor and moduleauthor directives will be shown in the 92 | # output. They are ignored by default. 93 | #show_authors = False 94 | 95 | # The name of the Pygments (syntax highlighting) style to use. 96 | pygments_style = 'sphinx' 97 | 98 | # A list of ignored prefixes for module index sorting. 99 | #modindex_common_prefix = [] 100 | 101 | # If true, keep warnings as "system message" paragraphs in the built documents. 102 | #keep_warnings = False 103 | 104 | 105 | # -- Options for HTML output --------------------------------------------------- 106 | 107 | # The theme to use for HTML and HTML Help pages. See the documentation for 108 | # a list of builtin themes. 109 | html_theme = 'default' 110 | 111 | # Theme options are theme-specific and customize the look and feel of a theme 112 | # further. For a list of options available for each theme, see the 113 | # documentation. 114 | #html_theme_options = {} 115 | 116 | # Add any paths that contain custom themes here, relative to this directory. 117 | #html_theme_path = [] 118 | 119 | # The name for this set of Sphinx documents. If None, it defaults to 120 | # " v documentation". 121 | #html_title = None 122 | 123 | # A shorter title for the navigation bar. Default is the same as html_title. 124 | #html_short_title = None 125 | 126 | # The name of an image file (relative to this directory) to place at the top 127 | # of the sidebar. 128 | #html_logo = None 129 | 130 | # The name of an image file (within the static path) to use as favicon of the 131 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 132 | # pixels large. 133 | #html_favicon = None 134 | 135 | # Add any paths that contain custom static files (such as style sheets) here, 136 | # relative to this directory. They are copied after the builtin static files, 137 | # so a file named "default.css" will overwrite the builtin "default.css". 138 | html_static_path = ['_static'] 139 | 140 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 141 | # using the given strftime format. 142 | #html_last_updated_fmt = '%b %d, %Y' 143 | 144 | # If true, SmartyPants will be used to convert quotes and dashes to 145 | # typographically correct entities. 146 | #html_use_smartypants = True 147 | 148 | # Custom sidebar templates, maps document names to template names. 149 | #html_sidebars = {} 150 | 151 | # Additional templates that should be rendered to pages, maps page names to 152 | # template names. 153 | #html_additional_pages = {} 154 | 155 | # If false, no module index is generated. 156 | #html_domain_indices = True 157 | 158 | # If false, no index is generated. 159 | #html_use_index = True 160 | 161 | # If true, the index is split into individual pages for each letter. 162 | #html_split_index = False 163 | 164 | # If true, links to the reST sources are added to the pages. 165 | #html_show_sourcelink = True 166 | 167 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 168 | #html_show_sphinx = True 169 | 170 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 171 | #html_show_copyright = True 172 | 173 | # If true, an OpenSearch description file will be output, and all pages will 174 | # contain a tag referring to it. The value of this option must be the 175 | # base URL from which the finished HTML is served. 176 | #html_use_opensearch = '' 177 | 178 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 179 | #html_file_suffix = None 180 | 181 | # Output file base name for HTML help builder. 182 | htmlhelp_basename = 'git2jsondoc' 183 | 184 | 185 | # -- Options for LaTeX output -------------------------------------------------- 186 | 187 | latex_elements = { 188 | # The paper size ('letterpaper' or 'a4paper'). 189 | #'papersize': 'letterpaper', 190 | 191 | # The font size ('10pt', '11pt' or '12pt'). 192 | #'pointsize': '10pt', 193 | 194 | # Additional stuff for the LaTeX preamble. 195 | #'preamble': '', 196 | } 197 | 198 | # Grouping the document tree into LaTeX files. List of tuples 199 | # (source start file, target name, title, author, documentclass [howto/manual]). 200 | latex_documents = [ 201 | ('index', 'git2json.tex', u'Git2JSON Documentation', 202 | u'Tavish Armstrong', 'manual'), 203 | ] 204 | 205 | # The name of an image file (relative to this directory) to place at the top of 206 | # the title page. 207 | #latex_logo = None 208 | 209 | # For "manual" documents, if this is true, then toplevel headings are parts, 210 | # not chapters. 211 | #latex_use_parts = False 212 | 213 | # If true, show page references after internal links. 214 | #latex_show_pagerefs = False 215 | 216 | # If true, show URL addresses after external links. 217 | #latex_show_urls = False 218 | 219 | # Documents to append as an appendix to all manuals. 220 | #latex_appendices = [] 221 | 222 | # If false, no module index is generated. 223 | #latex_domain_indices = True 224 | 225 | 226 | # -- Options for manual page output -------------------------------------------- 227 | 228 | # One entry per manual page. List of tuples 229 | # (source start file, name, description, authors, manual section). 230 | man_pages = [ 231 | ('index', 'git2json', u'Git2JSON Documentation', 232 | [u'Tavish Armstrong'], 1) 233 | ] 234 | 235 | # If true, show URL addresses after external links. 236 | #man_show_urls = False 237 | 238 | 239 | # -- Options for Texinfo output ------------------------------------------------ 240 | 241 | # Grouping the document tree into Texinfo files. List of tuples 242 | # (source start file, target name, title, author, 243 | # dir menu entry, description, category) 244 | texinfo_documents = [ 245 | ('index', 'git2json', u'Git2JSON Documentation', 246 | u'Tavish Armstrong', 'git2json', 'One line description of project.', 247 | 'Miscellaneous'), 248 | ] 249 | 250 | # Documents to append as an appendix to all manuals. 251 | #texinfo_appendices = [] 252 | 253 | # If false, no module index is generated. 254 | #texinfo_domain_indices = True 255 | 256 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 257 | #texinfo_show_urls = 'footnote' 258 | 259 | # If true, do not generate a @detailmenu in the "Top" node's menu. 260 | #texinfo_no_detailmenu = False -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. complexity documentation master file, created by 2 | sphinx-quickstart on Tue Jul 9 22:26:36 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Git2JSON's documentation! 7 | ====================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | readme 15 | installation 16 | usage 17 | contributing 18 | authors 19 | history 20 | 21 | Indices and tables 22 | ================== 23 | 24 | * :ref:`genindex` 25 | * :ref:`modindex` 26 | * :ref:`search` 27 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | At the command line:: 6 | 7 | $ easy_install git2json 8 | 9 | Or, if you have virtualenvwrapper installed:: 10 | 11 | $ mkvirtualenv git2json 12 | $ pip install git2json -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Usage 3 | ======== 4 | 5 | To use Git2JSON in a project:: 6 | 7 | import git2json -------------------------------------------------------------------------------- /git2json/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Generate a json log of a git repository. 5 | """ 6 | 7 | from __future__ import print_function 8 | import json 9 | import sys 10 | from .parser import parse_commits 11 | 12 | __author__ = 'Tavish Armstrong' 13 | __email__ = 'tavisharmstrong@gmail.com' 14 | __version__ = '0.2.3' 15 | 16 | # ------------------------------------------------------------------- 17 | # Main 18 | 19 | 20 | def main(): 21 | import argparse 22 | parser = argparse.ArgumentParser() 23 | parser.add_argument( 24 | '--git-dir', 25 | default=None, 26 | help='Path to the .git/ directory of the repository you are targeting' 27 | ) 28 | parser.add_argument( 29 | '--since', 30 | default=None, 31 | help=('Show commits more recent than a specific date. If present, ' 32 | 'this argument is passed through to "git log" unchecked. ') 33 | ) 34 | parser.add_argument( 35 | '--args', 36 | default=None, 37 | help=('Pass additional args to the log message,' 38 | 'this argument is passed through to "git log" unchecked. ') 39 | ) 40 | args = parser.parse_args() 41 | if sys.version_info < (3, 0): 42 | print(git2json(run_git_log(args.git_dir, args.since, args.args))) 43 | else: 44 | print(git2jsons(run_git_log(args.git_dir, args.since, args.args))) 45 | 46 | # ------------------------------------------------------------------- 47 | # Main API functions 48 | 49 | 50 | def git2jsons(s): 51 | return json.dumps(list(parse_commits(s)), ensure_ascii=False) 52 | 53 | 54 | def git2json(fil): 55 | return json.dumps(list(parse_commits(fil.read())), ensure_ascii=False) 56 | 57 | 58 | # ------------------------------------------------------------------- 59 | # Functions for interfacing with git 60 | 61 | 62 | def run_git_log(git_dir=None, git_since=None, git_args=None): 63 | '''run_git_log([git_dir]) -> File 64 | 65 | Run `git log --numstat --pretty=raw` on the specified 66 | git repository and return its stdout as a pseudo-File.''' 67 | import subprocess 68 | if git_dir: 69 | command = [ 70 | 'git', 71 | '--git-dir=' + git_dir, 72 | 'log', 73 | '--numstat', 74 | '--pretty=raw' 75 | ] 76 | else: 77 | command = ['git', 'log', '--numstat', '--pretty=raw'] 78 | if git_since is not None: 79 | command.append('--since=' + git_since) 80 | if git_args is not None: 81 | command.append(git_args) 82 | raw_git_log = subprocess.Popen( 83 | command, 84 | stdout=subprocess.PIPE 85 | ) 86 | if sys.version_info < (3, 0): 87 | return raw_git_log.stdout 88 | else: 89 | return raw_git_log.stdout.read().decode('utf-8', 'ignore') 90 | -------------------------------------------------------------------------------- /git2json/parser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Parse git logs. 5 | 6 | These parsing functions expect output of the following command: 7 | 8 | git log --pretty=raw --numstat 9 | 10 | """ 11 | 12 | import re 13 | 14 | __author__ = 'Tavish Armstrong' 15 | __email__ = 'tavisharmstrong@gmail.com' 16 | __version__ = '0.2.1' 17 | 18 | PAT_COMMIT = r''' 19 | ( 20 | commit\ (?P[a-f0-9]+)\n 21 | tree\ (?P[a-f0-9]+)\n 22 | (?P(parent\ [a-f0-9]+\n)*) 23 | (?Pauthor \s+(.+)\s+<(.*)>\s+(\d+)\s+([+\-]\d\d\d\d)\n) 24 | (?Pcommitter \s+(.+)\s+<(.*)>\s+(\d+)\s+([+\-]\d\d\d\d)\n)\n 25 | (?P 26 | (\ \ \ \ [^\n]*\n)* 27 | ) 28 | \n 29 | (?P 30 | (^(\d+|-)\s+(\d+|-)\s+(.*)$\n)* 31 | ) 32 | ) 33 | ''' 34 | RE_COMMIT = re.compile(PAT_COMMIT, re.MULTILINE | re.VERBOSE) 35 | 36 | # ------------------------------------------------------------------- 37 | # Main parsing functions 38 | 39 | 40 | def parse_commits(data): 41 | '''Accept a string and parse it into many commits. 42 | Parse and yield each commit-dictionary. 43 | This function is a generator. 44 | ''' 45 | raw_commits = RE_COMMIT.finditer(data) 46 | for rc in raw_commits: 47 | full_commit = rc.groups()[0] 48 | parts = RE_COMMIT.match(full_commit).groupdict() 49 | parsed_commit = parse_commit(parts) 50 | yield parsed_commit 51 | 52 | 53 | def parse_commit(parts): 54 | '''Accept a parsed single commit. Some of the named groups 55 | require further processing, so parse those groups. 56 | Return a dictionary representing the completely parsed 57 | commit. 58 | ''' 59 | commit = {} 60 | commit['commit'] = parts['commit'] 61 | commit['tree'] = parts['tree'] 62 | parent_block = parts['parents'] 63 | commit['parents'] = [ 64 | parse_parent_line(parentline) 65 | for parentline in 66 | parent_block.splitlines() 67 | ] 68 | commit['author'] = parse_author_line(parts['author']) 69 | commit['committer'] = parse_committer_line(parts['committer']) 70 | message_lines = [ 71 | parse_message_line(msgline) 72 | for msgline in 73 | parts['message'].split("\n") 74 | ] 75 | commit['message'] = "\n".join( 76 | msgline 77 | for msgline in 78 | message_lines 79 | if msgline is not None 80 | ) 81 | commit['changes'] = [ 82 | parse_numstat_line(numstat) 83 | for numstat in 84 | parts['numstats'].splitlines() 85 | ] 86 | return commit 87 | 88 | 89 | # ------------------------------------------------------------------- 90 | # Parsing helper functions 91 | 92 | 93 | def parse_hash_line(line, name): 94 | RE_HASH_LINE = name + r' ([abcdef0-9]+)' 95 | result = re.match(RE_HASH_LINE, line) 96 | if result is None: 97 | return result 98 | else: 99 | return result.groups()[0] 100 | 101 | 102 | def parse_commit_line(line): 103 | return parse_hash_line(line, 'commit') 104 | 105 | 106 | def parse_parent_line(line): 107 | return parse_hash_line(line, 'parent') 108 | 109 | 110 | def parse_tree_line(line): 111 | return parse_hash_line(line, 'tree') 112 | 113 | 114 | def parse_person_line(line, name): 115 | RE_PERSON = name + r' (.+) <(.*)> (\d+) ([+\-]\d\d\d\d)' 116 | result = re.match(RE_PERSON, line) 117 | if result is None: 118 | return result 119 | else: 120 | groups = result.groups() 121 | name = groups[0] 122 | email = groups[1] 123 | timestamp = int(groups[2]) 124 | timezone = groups[3] 125 | d_result = { 126 | 'name': name, 127 | 'email': email, 128 | 'date': timestamp, 129 | 'timezone': timezone, 130 | } 131 | return d_result 132 | 133 | 134 | def parse_committer_line(line): 135 | return parse_person_line(line, 'committer') 136 | 137 | 138 | def parse_author_line(line): 139 | return parse_person_line(line, 'author') 140 | 141 | 142 | def parse_message_line(line): 143 | RE_MESSAGE = r' (.*)' 144 | result = re.match(RE_MESSAGE, line) 145 | if result is None: 146 | return result 147 | else: 148 | return result.groups()[0] 149 | 150 | 151 | def parse_numstat_line(line): 152 | RE_NUMSTAT = r'(\d+|-)\s+(\d+|-)\s+(.*)' 153 | result = re.match(RE_NUMSTAT, line) 154 | if result is None: 155 | return result 156 | else: 157 | (sadd, sdel, fname) = result.groups() 158 | try: 159 | return (int(sadd), int(sdel), fname) 160 | except ValueError: 161 | return (sadd, sdel, fname) 162 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tarmstrong/git2json/4f9e9d47c064fc0621582e19a78ea3fef87e2212/requirements.txt -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import sys 6 | 7 | 8 | try: 9 | from setuptools import setup 10 | except ImportError: 11 | from distutils.core import setup 12 | 13 | if sys.argv[-1] == 'publish': 14 | os.system('python setup.py sdist upload') 15 | sys.exit() 16 | 17 | with open('README.rst') as file_readme: 18 | readme = file_readme.read() 19 | 20 | with open('HISTORY.rst') as file_history: 21 | history = file_history.read().replace('.. :changelog:', '') 22 | 23 | setup( 24 | name='git2json', 25 | version='0.2.3', 26 | description='Convert git logs to JSON for easier analysis.', 27 | long_description=readme + '\n\n' + history, 28 | author='Tavish Armstrong', 29 | author_email='tavisharmstrong@gmail.com', 30 | url='https://github.com/tarmstrong/git2json', 31 | packages=[ 32 | 'git2json', 33 | ], 34 | package_dir={'git2json': 'git2json'}, 35 | entry_points={'console_scripts': ['git2json = git2json:main']}, 36 | include_package_data=True, 37 | install_requires=[ 38 | ], 39 | license="BSD", 40 | zip_safe=False, 41 | keywords='git2json', 42 | classifiers=[ 43 | 'Development Status :: 2 - Pre-Alpha', 44 | 'Intended Audience :: Developers', 45 | 'License :: OSI Approved :: BSD License', 46 | 'Natural Language :: English', 47 | "Programming Language :: Python :: 2", 48 | 'Programming Language :: Python :: 2.6', 49 | 'Programming Language :: Python :: 2.7', 50 | 'Programming Language :: Python :: 3', 51 | 'Programming Language :: Python :: 3.3', 52 | ], 53 | test_suite='tests', 54 | ) 55 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | -------------------------------------------------------------------------------- /tests/fixtures/test_git2json-1.txt: -------------------------------------------------------------------------------- 1 | commit b8295e9af6745b9c466d11bb31a6eef221e231c1 2 | tree ea7fbb2694175423d776f649104ba42520db7cea 3 | parent 795c9e30ee8ad2e1a4e780c439fc50b565670e26 4 | parent 796a90bdeef377041c353019fdae19aaa72a76d3 5 | author Fernando Perez 1380325308 -0700 6 | committer Fernando Perez 1380325308 -0700 7 | 8 | Merge pull request #4294 from minrk/tornado-2 9 | 10 | don't require tornado 3 in `--post serve` 11 | 12 | commit 796a90bdeef377041c353019fdae19aaa72a76d3 13 | tree ea7fbb2694175423d776f649104ba42520db7cea 14 | parent 795c9e30ee8ad2e1a4e780c439fc50b565670e26 15 | author MinRK 1380325245 -0700 16 | committer MinRK 1380325245 -0700 17 | 18 | don't require tornado 3 in `--post serve` 19 | 20 | tornado.log is new in 3.0 21 | 22 | 6 2 IPython/nbconvert/postprocessors/serve.py 23 | 24 | commit 795c9e30ee8ad2e1a4e780c439fc50b565670e26 25 | tree 6bfc9895c0a2219ffafa562ff1c403f06374e544 26 | parent 505d3bd256ee7318bc05c047da5425db89006245 27 | parent b0d6287174b62de9b89190b868317d12b5bc4ae4 28 | author Min RK 1380323422 -0700 29 | committer Min RK 1380323422 -0700 30 | 31 | Merge pull request #4270 from minrk/task-timeout 32 | 33 | adjust Scheduler timeout logic 34 | 35 | Timeout starts when task submission is attempted. That is, it starts each time in resubmit / retry cases. 36 | 37 | Avoids issues of timeout firing only once while a task is pending, when it might come back and be retried after the timeout has fired. 38 | 39 | Also adds a ten second timeout for sync calls in the tests, which should hopefully avoid hangs when things are misbehaving. 40 | 41 | closes #3210 42 | 43 | commit 505d3bd256ee7318bc05c047da5425db89006245 44 | tree 43fb1288ede8d108aab70924a7be31d48303d3a4 45 | parent ae73644953bf2265c93ad12694f1214eecf825ea 46 | parent 07b4962bd787068896f0e2b5dfb977441c7b391a 47 | author Matthias Bussonnier 1380301596 -0700 48 | committer Matthias Bussonnier 1380301596 -0700 49 | 50 | Merge pull request #4278 from minrk/easy_install-a 51 | 52 | add `-a` to easy_install command in libedit warning 53 | 54 | commit ae73644953bf2265c93ad12694f1214eecf825ea 55 | tree 4ed874369e4e0075cb38b6db94274e7988c79eaf 56 | parent 8ac087cefd6db5181f85625e2524a36ff9f3ccbb 57 | parent e51d4d021c57c846ff1ad439d20b3fcc6b1ebc77 58 | author Matthias Bussonnier 1380271407 -0700 59 | committer Matthias Bussonnier 1380271407 -0700 60 | 61 | Merge pull request #4282 from ellisonbg/linebreaks 62 | 63 | Enable automatic line breaks in MathJax. 64 | 65 | commit 8ac087cefd6db5181f85625e2524a36ff9f3ccbb 66 | tree 2e096e0222a4bce05276cb32d9b1adf583cf3fe4 67 | parent 28ebc5fce26f451e45feabfb376db1815018c334 68 | parent 68b0f9d2d5f29c540f7873141cb09026c492d0ef 69 | author Min RK 1380215023 -0700 70 | committer Min RK 1380215023 -0700 71 | 72 | Merge pull request #4279 from ellisonbg/itemname 73 | 74 | Fixing line-height of list items in tree view. 75 | 76 | commit 28ebc5fce26f451e45feabfb376db1815018c334 77 | tree cecc43b0ade5722852be07c3c2263e15b350b31d 78 | parent 929d291e36f28148b95f71e1200174958772fa2b 79 | parent 4c1106f88e7864b9b235a84055e9eb36e7f2a317 80 | author Matthias Bussonnier 1380183460 -0700 81 | committer Matthias Bussonnier 1380183460 -0700 82 | 83 | Merge pull request #4253 from Carreau/fix-4039 84 | 85 | fixes #4039. 86 | 87 | Issues is that $(selector).val() return the associated text if no data 88 | is present (hence one cannot associate explicitely an option to 89 | "undefined") 90 | 91 | fix in doc and example. 92 | 93 | commit e51d4d021c57c846ff1ad439d20b3fcc6b1ebc77 94 | tree 221f34bd5cf8c4e1a5e5547686e03162e257fc86 95 | parent a562753ffb1dc5556726dfeca9f1deff947da84a 96 | author Brian E. Granger 1380162595 -0700 97 | committer Brian E. Granger 1380162595 -0700 98 | 99 | Enable automatic line breaks in MathJax. 100 | 101 | 2 1 IPython/html/static/notebook/js/mathjaxutils.js 102 | 103 | commit 68b0f9d2d5f29c540f7873141cb09026c492d0ef 104 | tree 4877779a25cd192effa80a8c6c4481b0b3ce974e 105 | parent a562753ffb1dc5556726dfeca9f1deff947da84a 106 | author Brian E. Granger 1380158115 -0700 107 | committer Brian E. Granger 1380158115 -0700 108 | 109 | Fixing line-height of list items in tree view. 110 | 111 | 1 0 IPython/html/static/style/ipython.min.css 112 | 1 0 IPython/html/static/style/style.min.css 113 | 4 0 IPython/html/static/tree/less/tree.less 114 | 115 | commit 07b4962bd787068896f0e2b5dfb977441c7b391a 116 | tree 66e7b4569adb7a2cd78e69164240668a9af62116 117 | parent 929d291e36f28148b95f71e1200174958772fa2b 118 | author MinRK 1380153904 -0700 119 | committer MinRK 1380153904 -0700 120 | 121 | add `-a` to easy_install command in libedit warning 122 | 123 | needed if someone has accidentally installed with pip, 124 | in which case `easy_install readline` is a no-op. 125 | 126 | 2 2 IPython/utils/rlineimpl.py 127 | -------------------------------------------------------------------------------- /tests/fixtures/test_git2json-2.txt: -------------------------------------------------------------------------------- 1 | commit b8295e9af6745b9c466d11bb31a6eef221e231c1 2 | tree ea7fbb2694175423d776f649104ba42520db7cea 3 | parent 795c9e30ee8ad2e1a4e780c439fc50b565670e26 4 | parent 796a90bdeef377041c353019fdae19aaa72a76d3 5 | author Fernando Perez 1380325308 -0700 6 | committer Fernando Perez 1380325308 -0700 7 | 8 | Merge pull request #4294 from minrk/tornado-2 9 | 10 | don't require tornado 3 in `--post serve` 11 | 12 | commit 796a90bdeef377041c353019fdae19aaa72a76d3 13 | tree ea7fbb2694175423d776f649104ba42520db7cea 14 | parent 795c9e30ee8ad2e1a4e780c439fc50b565670e26 15 | author MinRK 1380325245 -0700 16 | committer MinRK 1380325245 -0700 17 | 18 | don't require tornado 3 in `--post serve` 19 | 20 | tornado.log is new in 3.0 21 | 22 | 6 2 IPython/nbconvert/postprocessors/serve.py 23 | 6 2 .travis.yml 24 | 25 | -------------------------------------------------------------------------------- /tests/test_git2json.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_git2json 6 | ---------------------------------- 7 | 8 | Tests for `git2json` module. 9 | """ 10 | 11 | import git2json 12 | from nose.tools import eq_ 13 | 14 | 15 | def get_tst_path(): 16 | '''Find where this test module is located so we can reference the fixtures 17 | folder. 18 | 19 | Named with tst to avoid Nose's pattern-matching.''' 20 | import os 21 | tp = os.path.split(__file__)[0] + '/' 22 | return tp 23 | 24 | 25 | def int_test_parse_commits(): 26 | '''Integration test: try to parse an entire git log from a file''' 27 | fixture = open(get_tst_path() + 'fixtures/test_git2json-1.txt') 28 | commits = list(git2json.parse_commits(fixture.read())) 29 | parent = commits[0]['parents'] 30 | assert len(parent) == 2 31 | 32 | parent = commits[1]['parents'] 33 | assert len(parent) == 1 34 | 35 | author = commits[0]['author']['name'] 36 | eq_(author, 'Fernando Perez') 37 | 38 | email = commits[0]['author']['email'] 39 | eq_(email.strip(), 'fernando.perez@berkeley.edu') 40 | 41 | author = commits[1]['author']['name'] 42 | eq_(author, 'MinRK') 43 | 44 | email = commits[1]['author']['email'] 45 | eq_(email, 'benjaminrk@gmail.com') 46 | 47 | committer = commits[0]['committer']['name'] 48 | eq_(committer, 'Fernando Perez') 49 | 50 | email = commits[0]['committer']['email'] 51 | eq_(email.strip(), 'fernando.perez@berkeley.edu') 52 | 53 | committer = commits[1]['committer']['name'] 54 | eq_(committer, 'MinRK') 55 | 56 | email = commits[1]['committer']['email'] 57 | eq_(email, 'benjaminrk@gmail.com') 58 | 59 | eq_(len(commits[0]['changes']), 0) 60 | eq_(len(commits[1]['changes']), 1) 61 | 62 | 63 | def reg_test_7_hidden_files(): 64 | '''Ensure leading periods in hidden file names are parsed. 65 | 66 | Regression test for: 67 | https://github.com/tarmstrong/git2json/issues/7 68 | ''' 69 | fixture = open(get_tst_path() + 'fixtures/test_git2json-2.txt') 70 | commits = list(git2json.parse_commits(fixture.read())) 71 | second_commit = commits[1] 72 | changes = second_commit['changes'] 73 | second_change = changes[1] 74 | fname = second_change[2] 75 | eq_(fname, '.travis.yml') 76 | 77 | 78 | # I think git is stripping out the carriage return in the fixture files 79 | # so I'm going to just hardcode this fixture here. 80 | # In order to appease flake8 I've had to put in some line breaks in the message 81 | # in weird places. This makes the test kind of unreadable, but it works. 82 | CARRIAGE_RETURN_FIXTURE = '''commit 0829acac93a476ff5c13cb95de7ba7d00cf0c563 83 | tree 0a1caf6f9510fb11a8d3a6a45c4af6000d778a5e 84 | parent f4b6fd2ff84ee5edd261bfa9e1771326db1ed2e0 85 | author Tavish Armstrong 1520702534 +0000 86 | committer Tavish Armstrong 1520702662 +0000 87 | 88 | Hi\rthere\n \n Hi\rthere 89 | 90 | 2\t0\tfoo.txt 91 | 92 | commit f4b6fd2ff84ee5edd261bfa9e1771326db1ed2e0 93 | tree cbd2d9864b4b7e1508286ffed2e29c97cf4a6d78 94 | author Tavish Armstrong 1520702520 +0000 95 | committer Tavish Armstrong 1520702520 +0000 96 | 97 | initial commit 98 | 99 | 1\t0\tfoo.txt 100 | ''' 101 | 102 | 103 | def reg_test_empty_message_lines(): 104 | '''Empty lines (usually caused by a carriage return) don't cause crashes. 105 | 106 | Regression test for: 107 | https://github.com/tarmstrong/git2json/issues/11 108 | ''' 109 | fixture = CARRIAGE_RETURN_FIXTURE 110 | commits = list(git2json.parse_commits(fixture)) 111 | eq_(2, len(commits)) 112 | second_commit = commits[0] 113 | message = second_commit['message'] 114 | expected_message = '''Hi\rthere 115 | 116 | Hi\rthere''' 117 | eq_(message, expected_message) 118 | -------------------------------------------------------------------------------- /tests/test_regex_commit.py: -------------------------------------------------------------------------------- 1 | import git2json as g 2 | 3 | 4 | def test_regex_only(): 5 | commit = ( 6 | 'commit 78a7baf74a77055e25914f2d50812c92bd6243bf' 7 | '\ntree b72a934faf0e0bd3a333a6069cc67dd74114bb9b' 8 | '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' 9 | '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' 10 | '\nauthor Tavish Armstrong' 11 | ' 1380495019 -0400' 12 | '\ncommitter Tavish Armstrong' 13 | ' 1380495019 -0400' 14 | '\n\n Start examples section in the README\n' 15 | '\n9\t0\tREADME.rst\n9\t0\tREADME.rst\n' 16 | '\n9\t0\t.travis.yml\n9\t0\t.travis.yml\n\n' 17 | ) 18 | 19 | from git2json.parser import RE_COMMIT 20 | 21 | matches = RE_COMMIT.findall(commit) 22 | assert len(matches) > 0 23 | 24 | 25 | def test_parse_commits(): 26 | commit = ( 27 | 'commit 78a7baf74a77055e25914f2d50812c92bd6243bf' 28 | '\ntree b72a934faf0e0bd3a333a6069cc67dd74114bb9b' 29 | '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' 30 | '\nparent a4d8c6dbab70038b4585f7711873e71f92db47bf' 31 | '\nauthor Tavish Armstrong' 32 | ' 1380495019 -0400' 33 | '\ncommitter Tavish Armstrong' 34 | ' 1380495019 -0400' 35 | '\n\n Start examples section in the README\n' 36 | '\n9\t0\tREADME.rst\n9\t0\tREADME.rst\n\n' 37 | ) 38 | 39 | parsed = list(g.parse_commits(commit)) 40 | assert len(parsed) > 0 41 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py32, py33, pypy 3 | 4 | [testenv] 5 | setenv = 6 | PYTHONPATH = {toxinidir}:{toxinidir} 7 | commands = 8 | python setup.py nosetests 9 | flake8 tests git2json 10 | deps = 11 | -r{toxinidir}/requirements.txt 12 | nose 13 | flake8 14 | --------------------------------------------------------------------------------