Skip to content

Commit 8c4ed4f

Browse files
committed
Allow python optimization, repair bad asserts
Since assert statements are removed when using `python -O`, it is not okay to wrap any statements or expressions which have required side-effects with assert. The edit, goto, refresh, and squash commands all had problematic assert-wrapped statements. Signed-off-by: Peter Grayson <[email protected]>
1 parent 883f8a0 commit 8c4ed4f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

stgit/commands/edit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def failed(reason='Edited patch did not apply.'):
178178
trans = transaction.StackTransaction(stack, 'edit', allow_conflicts=True)
179179
if patchname in trans.applied:
180180
popped = trans.applied[trans.applied.index(patchname) + 1:]
181-
assert not trans.pop_patches(lambda pn: pn in popped)
181+
popped_extra = trans.pop_patches(lambda pn: pn in popped)
182+
assert not popped_extra
182183
else:
183184
popped = []
184185
trans.patches[patchname] = stack.repository.commit(cd)

stgit/commands/goto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def func(parser, options, args):
5959

6060
if patch in trans.applied:
6161
to_pop = set(trans.applied[trans.applied.index(patch) + 1:])
62-
assert not trans.pop_patches(lambda pn: pn in to_pop)
62+
popped_extra = trans.pop_patches(lambda pn: pn in to_pop)
63+
assert not popped_extra
6364
elif patch in trans.unapplied:
6465
try:
6566
to_push = trans.unapplied[:trans.unapplied.index(patch) + 1]

stgit/commands/refresh.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,21 @@ def absorb_applied(trans, iw, patch_name, temp_name, edit_fun):
221221
# Pop any patch on top of the patch we're refreshing.
222222
to_pop = trans.applied[trans.applied.index(patch_name) + 1:]
223223
if len(to_pop) > 1:
224-
popped = trans.pop_patches(lambda pn: pn in to_pop)
225-
assert not popped # no other patches were popped
224+
popped_extra = trans.pop_patches(lambda pn: pn in to_pop)
225+
assert not popped_extra # no other patches were popped
226226
trans.push_patch(temp_name, iw)
227-
assert to_pop.pop() == temp_name
227+
top_name = to_pop.pop()
228+
assert top_name == temp_name
228229

229230
# Absorb the temp patch.
230231
temp_cd = trans.patches[temp_name].data
231232
assert trans.patches[patch_name] == temp_cd.parent
232233
trans.patches[patch_name] = trans.stack.repository.commit(
233234
edit_fun(trans.patches[patch_name].data.set_tree(temp_cd.tree)))
234-
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet=True)
235-
assert not popped # the temp patch was topmost
235+
popped_extra = trans.delete_patches(
236+
lambda pn: pn == temp_name, quiet=True
237+
)
238+
assert not popped_extra # the temp patch was topmost
236239
temp_absorbed = True
237240

238241
# Push back any patch we were forced to pop earlier.
@@ -255,8 +258,8 @@ def absorb_unapplied(trans, iw, patch_name, temp_name, edit_fun):
255258
if we had to leave it for the user to deal with."""
256259

257260
# Pop the temp patch.
258-
popped = trans.pop_patches(lambda pn: pn == temp_name)
259-
assert not popped # the temp patch was topmost
261+
popped_extra = trans.pop_patches(lambda pn: pn == temp_name)
262+
assert not popped_extra # the temp patch was topmost
260263

261264
# Try to create the new tree of the refreshed patch. (This is the
262265
# same operation as pushing the temp patch onto the patch we're
@@ -275,8 +278,10 @@ def absorb_unapplied(trans, iw, patch_name, temp_name, edit_fun):
275278
# the temp patch.
276279
trans.patches[patch_name] = trans.stack.repository.commit(
277280
edit_fun(patch_cd.set_tree(new_tree)))
278-
popped = trans.delete_patches(lambda pn: pn == temp_name, quiet=True)
279-
assert not popped # the temp patch was not applied
281+
popped_extra = trans.delete_patches(
282+
lambda pn: pn == temp_name, quiet=True
283+
)
284+
assert not popped_extra # the temp patch was not applied
280285
return True
281286
else:
282287
# Nope, we couldn't create the new tree, so we'll just have to

stgit/commands/squash.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def make_squashed_patch(trans, new_commit_data):
133133
new_commit_data = _squash_patches(
134134
trans, patches, msg, save_template, no_verify
135135
)
136-
assert not trans.delete_patches(lambda pn: pn in patches)
136+
popped_extra = trans.delete_patches(lambda pn: pn in patches)
137+
assert not popped_extra
137138
make_squashed_patch(trans, new_commit_data)
138139

139140
# Push the new patch if necessary, and any unrelated patches we've

0 commit comments

Comments
 (0)