Change hash of empty objects

This commit is contained in:
Gergely Polonkai 2016-05-24 12:12:15 +02:00
parent 07f51738cf
commit b5ab65e0a2

View File

@ -18,23 +18,6 @@ notes = [68, 69, 71, 72, 74, 76, 77]
notecount = len(notes) notecount = len(notes)
def gen_history(log, commit):
counter = 0
to_process = [commit]
while len(to_process) > 0:
counter += 1
if counter % 500 == 0:
print("Done with {} commits".format(counter))
commit = to_process.pop()
if not commit in log:
log.append(commit)
to_process += commit.parents
def gen_volume(deletions, insertions, deviation=10): def gen_volume(deletions, insertions, deviation=10):
return max( return max(
deviation, deviation,
@ -58,8 +41,8 @@ def get_file_sha(commit, file_name):
try: try:
t = t[elements.pop(0)] t = t[elements.pop(0)]
except KeyError: except KeyError:
# The file has been deleted # The file has been deleted, return the hash of an empty file
return '0000000000000000000000000000000000000000' return 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
if isinstance(t, Blob): if isinstance(t, Blob):
break break
@ -118,9 +101,46 @@ class GitMIDI(MIDIFile):
self.__repo = None self.__repo = None
self.__branch = branch self.__branch = branch
self.branch_head = None self.branch_head = None
self.__repo_data = None
self.git_log = []
self.__setup_repo() self.__setup_repo()
def gen_repo_data(self, force=False):
"""
Populate __repo_data with the Git history data. If force is
False and the repo_data is already calculated, we do not do
anything.
"""
if self.__repo_data and not force:
return
self.git_log = []
counter = 0
to_process = [self.branch_head]
while len(to_process) > 0:
counter += 1
if counter % 500 == 0:
print("Done with {} commits".format(counter))
commit = to_process.pop()
if not commit in self.git_log:
self.git_log.append(commit)
to_process += commit.parents
self.git_log.sort(key=lambda commit: commit.authored_date)
@property
def repo_data(self):
if self.__repo_data is None:
self.gen_repo_data(force=True)
return self.__repo_data
def write_mem(self): def write_mem(self):
self.writeFile(self.mem_file) self.writeFile(self.mem_file)
self.__written = True self.__written = True
@ -171,17 +191,8 @@ except IndexError:
sys.exit(1) sys.exit(1)
orig_log = [] repo_midi.gen_repo_data()
orig_log = repo_midi.git_log
if args.verbose:
print("Generating Git log…")
gen_history(orig_log, repo_midi.branch_head.commit)
if args.verbose:
print("Sorting commits…")
orig_log.sort(key=lambda commit: commit.authored_date)
if args.verbose: if args.verbose:
print("Generating MIDI data…") print("Generating MIDI data…")