Dan Rapp 7 anni fa
parent
commit
d436ac85bb

+ 15
- 2
gitstats/data_generators/gen_loc_data.py Vedi File

@@ -17,7 +17,7 @@ def gen_loc_data(conf, row_processor):
17 17
 
18 18
     :param conf: configuration (mostly used for date limits)
19 19
     :param row_processor: function to receive the callback
20
-    :return: total lines in repo
20
+    :return: (total_files, total_lines) in repo
21 21
     '''
22 22
 
23 23
     # line statistics
@@ -64,7 +64,20 @@ def gen_loc_data(conf, row_processor):
64 64
             else:
65 65
                 logging.warning(f'Failed to handle line "{line}"')
66 66
                 (files, inserted, deleted) = (0, 0, 0)
67
-    return total_lines
67
+
68
+    totals = getpipeoutput(
69
+        ['git diff --shortstat `git hash-object -t tree /dev/null`']
70
+    )
71
+    total_files, remainder = totals.strip().split(' file')
72
+    total_lines = remainder.split('hanged, ')[1].split(' insert')[0]
73
+    try:
74
+        total_files = int(total_files)
75
+        total_lines = int(total_lines)
76
+    except ValueError:
77
+        total_lines = 0
78
+        total_files = 0
79
+        logging.warning(f"Unable to parse results: {totals}")
80
+    return total_files, total_lines
68 81
 
69 82
 
70 83
 if __name__ == "__main__":

+ 7
- 1
gitstats/git_csv_generator.py Vedi File

@@ -43,6 +43,10 @@ class _FileHandles:
43 43
         self.loc_info_writer.writerow(['Repo', 'CommitHash', 'TimeStamp', 'FileCount', 'LinesInserted', 'LinesDeleted',
44 44
                                        'TotalLines'])
45 45
 
46
+        self.repo_info = open(os.path.join(output_dir, 'repo.csv'), 'w', encoding='utf8')
47
+        self.repo_info_writer = csv.writer(self.repo_info)
48
+        self.repo_info_writer.writerow(['Repo', 'TotalFiles', 'TotalLines'])
49
+
46 50
     def close(self):
47 51
         self.author_info.close()
48 52
         self.author_totals_info.close()
@@ -50,6 +54,7 @@ class _FileHandles:
50 54
         self.revision_info.close()
51 55
         self.files_info.close()
52 56
         self.loc_info.close()
57
+        self.repo_info.close()
53 58
 
54 59
 
55 60
 class GitCsvGenerator():
@@ -108,7 +113,8 @@ class GitCsvGenerator():
108 113
         def row_processor(row: LocByDate):
109 114
             self.files.loc_info_writer.writerow([self.projectname, row.hash, row.stamp, row.file_count,
110 115
                                                  row.lines_inserted, row.lines_deleted, row.total_lines])
111
-        gen_loc_data(self.conf, row_processor)
116
+        total_files, total_lines = gen_loc_data(self.conf, row_processor)
117
+        self.files.repo_info_writer.writerow([self.projectname, total_files, total_lines])
112 118
 
113 119
     def get_author_info(self):
114 120
         logging.info(f"Getting author info for {self.projectname}")

+ 1
- 1
gitstats/gitdatacollector.py Vedi File

@@ -62,7 +62,7 @@ class GitDataCollector(DataCollector):
62 62
             self.total_lines_added += row.lines_inserted
63 63
             self.total_lines_removed += row.lines_deleted
64 64
 
65
-        self.total_lines += gen_loc_data(self.conf, row_processor)
65
+        self.total_lines += gen_loc_data(self.conf, row_processor)[1]
66 66
 
67 67
     def get_file_info(self):
68 68
         # extensions and size of files