mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 00:28:25 +01:00
Added the ability to limit results by date range (Fixes issue 1).
This can now be done by supplying one (or both) of the "--since" and "--until" parameters to the gitinspector executable. These parameters work in the same manner as they do in git and accept the same values. Statistics will only be generated from data between the given interval.
This commit is contained in:
parent
cd3de23da2
commit
f4c3285cb8
6 changed files with 74 additions and 7 deletions
8
blame.py
8
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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"):
|
||||
|
|
4
help.py
4
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
|
||||
|
|
49
interval.py
Normal file
49
interval.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
__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
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue