Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit323c042

Browse files
committed
Add type of change to files_dict of a commit
This allows to not only get the total, inserted or deleted number oflines being changed but also the type of change likeAdded (A), Copied (C), Deleted (D), Modified (M), Renamed (R),type changed (T), Unmerged (U), Unknown (X), or pairing Broken (B)
1 parent3d3c86c commit323c042

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ Contributors are:
5454
-Wenhan Zhu <wzhu.cosmos _at_ gmail.com>
5555
-Eliah Kagan <eliah.kagan _at_ gmail.com>
5656
-Ethan Lin <et.repositories _at_ gmail.com>
57+
-Jonas Scharpf <jonas.scharpf _at_ checkmk.com>
5758

5859
Portions derived from other open source works and are clearly marked.

‎git/objects/commit.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,20 @@ def stats(self) -> Stats:
377377
:return:
378378
:class:`Stats`
379379
"""
380-
ifnotself.parents:
381-
text=self.repo.git.diff_tree(self.hexsha,"--",numstat=True,no_renames=True,root=True)
382-
text2=""
383-
forlineintext.splitlines()[1:]:
380+
defprocess_lines(lines:List[str])->str:
381+
text=""
382+
forfile_info,lineinzip(lines,lines[len(lines)//2 :]):
383+
change_type=file_info.split("\t")[0][-1]
384384
(insertions,deletions,filename)=line.split("\t")
385-
text2+="%s\t%s\t%s\n"% (insertions,deletions,filename)
386-
text=text2
385+
text+="%s\t%s\t%s\t%s\n"% (change_type,insertions,deletions,filename)
386+
returntext
387+
388+
ifnotself.parents:
389+
lines=self.repo.git.diff_tree(self.hexsha,"--",numstat=True,no_renames=True,root=True,raw=True).splitlines()[1:]
390+
text=process_lines(lines)
387391
else:
388-
text=self.repo.git.diff(self.parents[0].hexsha,self.hexsha,"--",numstat=True,no_renames=True)
392+
lines=self.repo.git.diff(self.parents[0].hexsha,self.hexsha,"--",numstat=True,no_renames=True,raw=True).splitlines()
393+
text=process_lines(lines)
389394
returnStats._list_from_string(self.repo,text)
390395

391396
@property

‎git/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class Files_TD(TypedDict):
248248
insertions:int
249249
deletions:int
250250
lines:int
251+
change_type:str
251252

252253

253254
classTotal_TD(TypedDict):

‎git/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ class Stats:
910910
deletions = number of deleted lines as int
911911
insertions = number of inserted lines as int
912912
lines = total number of lines changed as int, or deletions + insertions
913+
change_type = type of change as str, A|C|D|M|R|T|U|X|B
913914
914915
``full-stat-dict``
915916
@@ -938,7 +939,7 @@ def _list_from_string(cls, repo: "Repo", text: str) -> "Stats":
938939
"files": {},
939940
}
940941
forlineintext.splitlines():
941-
(raw_insertions,raw_deletions,filename)=line.split("\t")
942+
(change_type,raw_insertions,raw_deletions,filename)=line.split("\t")
942943
insertions=raw_insertions!="-"andint(raw_insertions)or0
943944
deletions=raw_deletions!="-"andint(raw_deletions)or0
944945
hsh["total"]["insertions"]+=insertions
@@ -949,6 +950,7 @@ def _list_from_string(cls, repo: "Repo", text: str) -> "Stats":
949950
"insertions":insertions,
950951
"deletions":deletions,
951952
"lines":insertions+deletions,
953+
"change_type":change_type,
952954
}
953955
hsh["files"][filename.strip()]=files_dict
954956
returnStats(hsh["total"],hsh["files"])

‎test/test_commit.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ def test_stats(self):
135135
commit=self.rorepo.commit("33ebe7acec14b25c5f84f35a664803fcab2f7781")
136136
stats=commit.stats
137137

138-
defcheck_entries(d):
138+
defcheck_entries(d,has_change_type=False):
139139
assertisinstance(d,dict)
140-
forkeyin ("insertions","deletions","lines"):
140+
keys= ("insertions","deletions","lines")
141+
ifhas_change_type:
142+
keys+= ("change_type", )
143+
forkeyinkeys:
141144
assertkeyind
142145

143146
# END assertion helper
@@ -148,7 +151,7 @@ def check_entries(d):
148151
assert"files"instats.total
149152

150153
for_filepath,dinstats.files.items():
151-
check_entries(d)
154+
check_entries(d,True)
152155
# END for each stated file
153156

154157
# Check that data is parsed properly.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp