From f0f0295ca50d0e8a71314af7ff322658c5ada950 Mon Sep 17 00:00:00 2001 From: dehain Date: Sun, 25 Feb 2018 14:09:13 -0600 Subject: [PATCH 1/4] Corrected output of fixes. Fixed indentation of line that was causing only the last fix to be displayed. --- bugspots/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bugspots/__init__.py b/bugspots/__init__.py index 8af6add..8275bba 100644 --- a/bugspots/__init__.py +++ b/bugspots/__init__.py @@ -121,7 +121,7 @@ def get_code_hotspots(options): hotspots[filename] += hotspot_factor - print(" -%s" % message) + print(" -%s" % message) sorted_hotspots = sorted(hotspots, key=hotspots.get, reverse=True) From c2850bd09aa01ff089fdcb3940e32c4d87f13e12 Mon Sep 17 00:00:00 2001 From: dehain Date: Sun, 25 Feb 2018 14:10:26 -0600 Subject: [PATCH 2/4] Added parameter for not fetching from remote. Added a parameter (--no-fetch) that specifies to not attempt fetching from the remote. This is useful in situations where there is no connectivity to the remote. --- bugspots/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bugspots/__init__.py b/bugspots/__init__.py index 8275bba..a8d045e 100644 --- a/bugspots/__init__.py +++ b/bugspots/__init__.py @@ -61,14 +61,14 @@ def get_current_vcs(path="."): raise Exception("Not found a valid VCS repository") -def get_fix_commits(branch, days): +def get_fix_commits(branch, days, nofetch): vcs = get_current_vcs() def get_changesets(days_ago): current_branch = vcs.get_current_version_label() if current_branch != branch: - vcs._do_checkout(branch) + vcs._do_checkout(branch, not nofetch) for log in vcs.get_log(): (date, message, id) = (log['date'], log['message'], @@ -88,7 +88,7 @@ def get_changesets(days_ago): def get_code_hotspots(options): - commits = get_fix_commits(options.branch, options.days) + commits = get_fix_commits(options.branch, options.days, options.nofetch) if not commits: print("Not found commits matching search criteria") @@ -159,6 +159,10 @@ def parse_options(): type=str, metavar='branch') + parser.add_argument("--nofetch", + help='Do not attempt to fetch changes from remote', + action='store_true') + args = parser.parse_args() return args From 0710a435f141266d38b19169774ab464f4bcc421 Mon Sep 17 00:00:00 2001 From: dehain Date: Sun, 25 Feb 2018 14:20:22 -0600 Subject: [PATCH 3/4] Added parameter for using the current branch. Added a parameter (--current-branch) that will use whatever the currently checked out branch is rather than requiring the branch to be specified or defaulting to master. --- bugspots/__init__.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/bugspots/__init__.py b/bugspots/__init__.py index a8d045e..fdec8af 100644 --- a/bugspots/__init__.py +++ b/bugspots/__init__.py @@ -61,23 +61,32 @@ def get_current_vcs(path="."): raise Exception("Not found a valid VCS repository") -def get_fix_commits(branch, days, nofetch): +def get_fix_commits(b, days, nofetch, use_current_branch): vcs = get_current_vcs() def get_changesets(days_ago): current_branch = vcs.get_current_version_label() + branch = b + if use_current_branch: + branch = current_branch + if current_branch != branch: - vcs._do_checkout(branch, not nofetch) + try: + vcs._do_checkout(branch, not nofetch) + current_branch = vcs.get_current_version_label() + except: + print("Error checking out branch: %s\n" % branch) - for log in vcs.get_log(): - (date, message, id) = (log['date'], log['message'], - log['id']) + if(current_branch == branch): + for log in vcs.get_log(): + (date, message, id) = (log['date'], log['message'], + log['id']) - commit_date = date.replace(tzinfo=None) - if commit_date >= days_ago and \ - description_regex.search(message): - yield((message, commit_date, vcs.get_affected_files(id))) + commit_date = date.replace(tzinfo=None) + if commit_date >= days_ago and \ + description_regex.search(message): + yield((message, commit_date, vcs.get_affected_files(id))) days_ago = (datetime.datetime.now() - datetime.timedelta(days=days)) @@ -88,7 +97,7 @@ def get_changesets(days_ago): def get_code_hotspots(options): - commits = get_fix_commits(options.branch, options.days, options.nofetch) + commits = get_fix_commits(options.branch, options.days, options.nofetch, options.current_branch) if not commits: print("Not found commits matching search criteria") @@ -163,6 +172,10 @@ def parse_options(): help='Do not attempt to fetch changes from remote', action='store_true') + parser.add_argument("--current-branch", + help='Use current branch', + action='store_true') + args = parser.parse_args() return args From 6636169b493a63e2d59ba822e7bfc5a6e15745d9 Mon Sep 17 00:00:00 2001 From: dehain Date: Sun, 25 Feb 2018 18:09:53 -0600 Subject: [PATCH 4/4] Change error code when no results found. Changed error code when no results are found from returning (-1) to simply returning 0. I don't think that not finding results is an error and this is an issue when I use this script with another script that depends on the return code indicating success or failure. --- bugspots/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bugspots/__init__.py b/bugspots/__init__.py index fdec8af..660f4e9 100644 --- a/bugspots/__init__.py +++ b/bugspots/__init__.py @@ -101,7 +101,7 @@ def get_code_hotspots(options): if not commits: print("Not found commits matching search criteria") - sys.exit(-1) + sys.exit(0) print_summary(".", options.branch, len(commits), options.days)