FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patchwork/patchwork/hasher.py at main · getpatchwork/patchwork · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
getpatchwork
/
patchwork
Public
Notifications
You must be signed in to change notification settings
Fork
90
Star
315
Code
Issues
97
Pull requests
22
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
patchwork
/
patchwork
/
hasher.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (55 loc) · 1.83 KB
Breadcrumbs
patchwork
/
patchwork
/
hasher.py
Copy path
File metadata and controls
74 lines (55 loc) · 1.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
#
# Patchwork - automated patch tracking system
# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""Hash generation for diffs."""
import
hashlib
import
re
import
sys
HUNK_RE
=
re
.
compile
(
r'^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@'
)
FILENAME_RE
=
re
.
compile
(
r'^(---|\+\+\+) (\S+)'
)
def
hash_diff
(
diff
):
"""Generate a hash from a diff."""
# normalise spaces
diff
=
diff
.
replace
(
'
\r
'
,
''
)
diff
=
diff
.
strip
()
+
'
\n
'
prefixes
=
[
'-'
,
'+'
,
' '
]
hashed
=
hashlib
.
sha1
()
for
line
in
diff
.
split
(
'
\n
'
):
if
len
(
line
)
<=
0
:
continue
hunk_match
=
HUNK_RE
.
match
(
line
)
filename_match
=
FILENAME_RE
.
match
(
line
)
if
filename_match
:
# normalise -p1 top-directories
if
filename_match
.
group
(
1
)
==
'---'
:
filename
=
'a/'
else
:
filename
=
'b/'
filename
+=
'/'
.
join
(
filename_match
.
group
(
2
).
split
(
'/'
)[
1
:])
line
=
filename_match
.
group
(
1
)
+
' '
+
filename
elif
hunk_match
:
# remove line numbers, but leave line counts
def
fn
(
x
):
if
not
x
:
return
1
return
int
(
x
)
line_nos
=
list
(
map
(
fn
,
hunk_match
.
groups
()))
line
=
'@@ -%d +%d @@'
%
tuple
(
line_nos
)
elif
line
[
0
]
in
prefixes
:
# if we have a +, - or context line, leave as-is
pass
else
:
# other lines are ignored
continue
hashed
.
update
((
line
+
'
\n
'
).
encode
(
'utf-8'
))
return
hashed
.
hexdigest
()
def
main
(
args
):
"""Hash a diff provided by stdin.
This is required by scripts found in /tools
"""
print
(
hash_diff
(
'
\n
'
.
join
(
sys
.
stdin
.
readlines
())))
if
__name__
==
'__main__'
:
sys
.
exit
(
main
(
sys
.
argv
))
Back
|
FazBrowse Home
|
New Git URL