Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotent patching #109

Open
mandarjog opened this issue Apr 24, 2023 · 1 comment
Open

Idempotent patching #109

mandarjog opened this issue Apr 24, 2023 · 1 comment

Comments

@mandarjog
Copy link

I am using the following patch to convert unchecked Debug to wrapped by if logging.isDebugEnabled() .
I would like to make this idempotent so it can be repeatedly applied.

How do I do that?

@@
var x expression
@@
-logging.L(x).Debug(...)
+if logging.IsDebugEnabled(x) {
+    logging.L(x).Debug(...)
+}
@abhinav
Copy link
Contributor

abhinav commented Apr 25, 2023

Hey @mandarjog, this isn't currently possible.
You basically have to undo and redo the patch to make it idempotent.
The undo catches existing variants, and the redo covers them all:

@@
var x expression
@@
-if logging.IsDebugEnabled(x) {
    logging.L(x).Debug(...)
-}

@@
var x expression
@@
+if logging.IsDebugEnabled(x) {
    logging.L(x).Debug(...)
+}

One of the options that was considered for the language was a ! prefix (in place of - or +) to mean "code here doesn't match this". If implemented, that could work here, although it would still require duplicating some of the patch content:

@@
var x expression
@@
+if logging.IsDebugEnabled(x) {
!if logging.IsDebugEnabled(x) {
    logging.L(x).Debug(...)
!}
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants