Skip to content

Commit

Permalink
Fix remaining unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Nov 13, 2024
1 parent 9d7c4af commit 2a96ea6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
22 changes: 12 additions & 10 deletions openhands/resolver/patching/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,12 @@ def parse_git_binary_diff(text):
assert len(line) >= 6 and ((len(line) - 1) % 5) == 0
new_encoded += line[1:]
elif 0 == len(line):
decoded = base64.b85decode(new_encoded)
added_data = zlib.decompress(decoded)
assert new_size == len(added_data)
change = Change(None, 0, added_data, None)
changes.append(change)
if new_encoded:
decoded = base64.b85decode(new_encoded)
added_data = zlib.decompress(decoded)
assert new_size == len(added_data)
change = Change(None, 0, added_data, None)
changes.append(change)
new_size = 0
new_encoded = ""
else:
Expand All @@ -998,11 +999,12 @@ def parse_git_binary_diff(text):
assert len(line) >= 6 and ((len(line) - 1) % 5) == 0
old_encoded += line[1:]
elif 0 == len(line):
decoded = base64.b85decode(old_encoded)
removed_data = zlib.decompress(decoded)
assert old_size == len(removed_data)
change = Change(0, None, None, removed_data)
changes.append(change)
if old_encoded:
decoded = base64.b85decode(old_encoded)
removed_data = zlib.decompress(decoded)
assert old_size == len(removed_data)
change = Change(0, None, None, removed_data)
changes.append(change)
old_size = 0
old_encoded = ""
else:
Expand Down
18 changes: 8 additions & 10 deletions openhands/resolver/patching/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ def split_by_regex(items, regex):
splits.append(items)
return splits

k = None
for i in indices:
if k is None:
splits.append(items[0:i])
k = i
else:
splits.append(items[k:i])
k = i
# Add first chunk before first match
splits.append(items[0:indices[0]])

# Add chunks between matches
for i in range(len(indices) - 1):
splits.append(items[indices[i]:indices[i + 1]])

if k is not None and k < len(items):
splits.append(items[k:])
# Add final chunk after last match
splits.append(items[indices[-1]:])

return splits

Expand Down

0 comments on commit 2a96ea6

Please sign in to comment.