Skip to content

include file rename tracking at metrics ingestion #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion ingester/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math # Required for the math.log function
from ingester.commitFile import * # Represents a file
from classifier.classifier import * # Used for classifying each commit
import time
import re

"""
file: repository.py
Expand Down Expand Up @@ -110,6 +110,46 @@ def getCommitStatsProperties( stats, commitFiles, devExperience, author, unixTim

totalModified = fileLa + fileLd

# Check for filepath rename
oldpath, newpath, renamed = "", "", False

# check if the path was partially changed
match = re.search('^(.*)({.+=>.+})(.*)$', fileName)
if match:
oldpath = []
newpath = []
for group in match.groups():
change = re.search('^{(.+)=>(.+)}$', group)
if change:
old, new = change.groups()
oldpath.append(old.strip())
newpath.append(new.strip())
else:
oldpath.append(group)
newpath.append(group)
oldpath = "".join(oldpath).replace("//", "/").strip()
newpath = "".join(newpath).replace("//", "/").strip()
renamed = True

# If not, check if the path was fully changed
else:
match = re.search('^(.+)=>(.+)$', fileName)
if match:
oldpath, newpath = match.groups()
oldpath = oldpath.strip()
newpath = newpath.strip()
renamed = True

if renamed:
# In case of an error in the git history (e.g. due to rewrites),
# the old name may not exist in the dictionary. Therefore this extra
# check is required to avoid KeyErrors
if oldpath in commitFiles:
commitFiles[newpath] = commitFiles[oldpath]
setattr(commitFiles[newpath], 'name', newpath)

fileName = newpath

# have we seen this file already?
if(fileName in commitFiles):
prevFileChanged = commitFiles[fileName]
Expand Down