diff --git a/blame.py b/blame.py index 165765e..6c1e624 100644 --- a/blame.py +++ b/blame.py @@ -23,6 +23,7 @@ from changes import FileDiff import comment import filtering import format +import interval import missing import multiprocessing import re @@ -84,15 +85,18 @@ class BlameThread(threading.Thread): class Blame: def __init__(self, hard): self.blames = {} - ls_tree_r = subprocess.Popen("git ls-tree --name-only -r HEAD", shell=True, bufsize=1, stdout=subprocess.PIPE).stdout + ls_tree_r = subprocess.Popen("git ls-tree --name-only -r " + interval.get_ref(), shell=True, bufsize=1, + stdout=subprocess.PIPE).stdout lines = ls_tree_r.readlines() for i, row in enumerate(lines): row = row.decode("utf-8", "replace").strip().strip("\"").strip("'") row = row.decode("string_escape").strip() + if FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)): if not missing.add(row.strip()): - blame_string = "git blame -w {0} \"".format("-C -C -M" if hard else "") + row.strip() + "\"" + blame_string = "git blame -w {0} ".format("-C -C -M" if hard else "") + \ + interval.get_ref() + " -- \"" + row.strip() + "\"" thread = BlameThread(blame_string, FileDiff.get_extension(row), self.blames, row.strip()) thread.daemon = True thread.start() diff --git a/changes.py b/changes.py index 71008fc..7d42df8 100644 --- a/changes.py +++ b/changes.py @@ -21,12 +21,12 @@ from __future__ import print_function from outputable import Outputable import extensions import filtering +import interval import re import os import subprocess import terminal import textwrap -import sys class FileDiff: def __init__(self, string): @@ -91,7 +91,8 @@ class AuthorInfo: class Changes: def __init__(self, hard): self.commits = [] - git_log_r = subprocess.Popen("git log --pretty=\"%ad|%t|%aN|%s\" --stat=100000,8192 --no-merges -w " + + git_log_r = subprocess.Popen("git log --pretty=\"%ad|%H|%aN|%s\" --stat=100000,8192 --no-merges -w " + + interval.get_since() + interval.get_until() + "{0} --date=short".format("-C -C -M" if hard else ""), shell=True, bufsize=1, stdout=subprocess.PIPE).stdout commit = None @@ -115,6 +116,9 @@ class Changes: filediff = FileDiff(i) commit.add_filediff(filediff) + if interval.has_interval(): + interval.set_ref(self.commits[0].sha) + def get_commits(self): return self.commits diff --git a/gitinspector.py b/gitinspector.py index 6e550e2..e42c7cd 100755 --- a/gitinspector.py +++ b/gitinspector.py @@ -26,6 +26,7 @@ import filtering import format import getopt import help +import interval import metrics import missing import os @@ -81,8 +82,8 @@ if __name__ == "__main__": try: __opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:F:hHlmrTwx:", ["checkout-missing", "exclude=", "file-types=", "format=", "hard", "help", "list-file-types", - "metrics", "responsibilities", "grading", "timeline", - "version"]) + "metrics", "responsibilities", "since=", "grading", + "timeline", "until=", "version"]) for o, a in __opts__: if o in("-c", "--checkout-missing"): missing.set_checkout_missing(True) @@ -102,6 +103,8 @@ if __name__ == "__main__": __run__.include_metrics = True elif o in("-r", "--responsibilities"): __run__.responsibilities = True + elif o in("--since"): + interval.set_since(a) elif o in("--version"): version.output() sys.exit(0) @@ -115,6 +118,8 @@ if __name__ == "__main__": __run__.useweeks = True elif o in("-T", "--timeline"): __run__.timeline = True + elif o in("--until"): + interval.set_until(a) elif o in("-w"): __run__.useweeks = True elif o in("-x", "--exclude"): diff --git a/help.py b/help.py index 7f3300e..8989e70 100644 --- a/help.py +++ b/help.py @@ -42,7 +42,11 @@ Mandatory arguments to long options are mandatory for short options too. analysis of commits -r --responsibilities show which files the different authors seem most responsible for + --since=DATE show statistics for commits more recent than a + specific date -T, --timeline show commit timeline, including author names + --until=DATE show statistics for commits older than a + specific date -w show all statistical information in weeks instead of in months -x, --exclude=PATTERN an exclusion pattern describing file names that diff --git a/interval.py b/interval.py new file mode 100644 index 0000000..863a869 --- /dev/null +++ b/interval.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# coding: utf-8 +# +# Copyright © 2012-2013 Ejwa Software. All rights reserved. +# +# This file is part of gitinspector. +# +# gitinspector is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# gitinspector is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with gitinspector. If not, see . + +__since__ = "" + +__until__ = "" + +__ref__ = "HEAD" + +def has_interval(): + return __since__ + __until__ != "" + +def get_since(): + return __since__ + +def set_since(since): + global __since__ + __since__ = "--since=\"" + since + "\" " + +def get_until(): + return __until__ + +def set_until(until): + global __until__ + __until__ = "--until=\"" + until + "\" " + +def get_ref(): + return __ref__ + +def set_ref(ref): + global __ref__ + __ref__ = ref diff --git a/missing.py b/missing.py index 660c13e..e18105b 100644 --- a/missing.py +++ b/missing.py @@ -19,6 +19,7 @@ from __future__ import print_function from outputable import Outputable +import interval import os import subprocess import terminal @@ -28,7 +29,7 @@ __checkout_missing__ = False __missing_files__ = set() def add(file_name): - if not os.path.exists(file_name): + if not interval.has_interval() and not os.path.exists(file_name): if __checkout_missing__: subprocess.call("git checkout \"" + file_name.strip() + "\"", shell=True) else: