Skip to content

Commit 1e1b43c

Browse files
authored
fix: consider the entire structure when calculating the work hash. (#241)
1 parent 5a2ab95 commit 1e1b43c

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UTIL_VERSION := 0.5.27
1+
UTIL_VERSION := 0.5.28
22
UTIL_NAME := codeplag
33
PWD := $(shell pwd)
44

src/codeplag/types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def __lt__(self: Self, other: object) -> bool:
106106
return str(self.filepath) < str(other.filepath)
107107

108108
def get_sha256(self: Self) -> str:
109-
return hashlib.sha256(str(self.tokens).encode("utf-8")).hexdigest()
109+
return hashlib.sha256(
110+
str([element.uid for element in self.structure]).encode("utf-8")
111+
).hexdigest()
110112

111113

112114
class NodeStructurePlaceDict(TypedDict):

test/unit/codeplag/cplag/test_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_get_features(second_cursor: Cursor) -> None:
121121
101, 106, 202, 214, 100, 100,
122122
101, 214, 103, 100, 101, 100,
123123
101, 114, 100, 101, 100, 101]
124-
assert features.sha256 == "957da24c9f9340954aaa9df303922a0fbdcea69b6d3556c2bd462d195ab89052"
124+
assert features.sha256 == "e60cabdc857dad1c75022143429806e146ad5fe299528fc47426a2f0c5c2f9a7"
125125

126126

127127
def test_bad_encoding_syms(third_cursor: Cursor) -> None:
@@ -141,4 +141,4 @@ def test_bad_encoding_syms(third_cursor: Cursor) -> None:
141141
assert features.count_unodes == 18
142142
assert len(features.structure) == 167
143143
assert len(features.tokens) == 167
144-
assert features.sha256 == "40f5feba75390d171f3e719be450989150aa232878ed4d10e0736221bad29b91"
144+
assert features.sha256 == "236f1b7ea02c3f68e390c7e155fec1a198d4c9ab3d8306d613df8399189291de"

test/unit/codeplag/pyplag/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ def test_get_features_from_ast():
3939
"my_func[6]",
4040
"If[12]",
4141
]
42-
assert features.sha256 == "f231b049ada761d534bb611cc7e92efdf8fd985d8092a72a132e79becff338d0"
42+
assert features.sha256 == "cc112603b970b41f72e0488dcc6f9e26889a9298c752e61a25d3e10caf512e43"

test/unit/codeplag/test_getfeatures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ def test_set_sha256(self, tmp_path: Path) -> None:
9292
features = set_sha256(lambda: features)()
9393

9494
assert (
95-
features.sha256 == "0c049903ce2330190375d4c1f2e489888c9ebe39daf75b2564e591e8bc1afe72"
95+
features.sha256 == "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945"
9696
)
9797
assert features.modify_date

0 commit comments

Comments
 (0)