I've run into an interesting problem that I believe doesn't have a well-known solution.
-
I've run into an interesting problem that I believe doesn't have a well-known solution.
Given a diff file, compute a derived diff file which only removes/adds lines that match a regular expression, leaving non-matching lines unchanged.
I would appreciate suggestions/advice!
If I solve it myself, I'll write a blog post.
@krans what's your use case for this? The closest I've come across in the past is using `EDITOR=<some sed command> git add -e <file>` to prevent +/- lines that don't match a regex from being committed.
-
@krans what's your use case for this? The closest I've come across in the past is using `EDITOR=<some sed command> git add -e <file>` to prevent +/- lines that don't match a regex from being committed.
@mag I'm changing the wording in a log message and there are about 1500 tests affected.
Ooh, that is potentially *exactly* what I need — if the files I needed to update were in a git repository.
-
I've run into an interesting problem that I believe doesn't have a well-known solution.
Given a diff file, compute a derived diff file which only removes/adds lines that match a regular expression, leaving non-matching lines unchanged.
I would appreciate suggestions/advice!
If I solve it myself, I'll write a blog post.
-
@dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.
-
@dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.
@dascandy (I tried this already)
-
@dascandy (I tried this already)
@krans I did kinda expect that and yeah, that context is unregexable
-
@dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.
@krans 2nd regex does do that? That's why I prefix the !KeEp to those you want to keep, so I can then remove the +/- from the rest. Should replace with space though, lemme fix that
-
@krans 2nd regex does do that? That's why I prefix the !KeEp to those you want to keep, so I can then remove the +/- from the rest. Should replace with space though, lemme fix that
@dascandy Context lines need to be reordered. Consider:
context1
-old
-irrelevant1
+new
+irrelevant2
context2The positions of the "irrelevant1" and "new" lines in the diff have to be swapped.
-
@dascandy Context lines need to be reordered. Consider:
context1
-old
-irrelevant1
+new
+irrelevant2
context2The positions of the "irrelevant1" and "new" lines in the diff have to be swapped.
@krans Right, that's not a thing regexes can do. I was expecting something to be wrong still but couldn't quite find what. I'm also somewhat sure the header lines would be wrong in counts, which is also not fixable in regex.
Best of luck!
-
@krans Right, that's not a thing regexes can do. I was expecting something to be wrong still but couldn't quite find what. I'm also somewhat sure the header lines would be wrong in counts, which is also not fixable in regex.
Best of luck!
@krans Thinking of your example, surely that's not automatically decideable?
context1
-irrelevant1
-old
+new
+irrelevant2
context2Should the output become
context1
irrelevant1
new
irrelevant2
context2or
context1
new
irrelevant1
irrelevant2
context2
?or any other potential resultant output?
-
R relay@relay.infosec.exchange shared this topic