Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. 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.

Scheduled Pinned Locked Moved Uncategorized
11 Posts 3 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • krans@mastodon.me.ukK This user is from outside of this forum
    krans@mastodon.me.ukK This user is from outside of this forum
    krans@mastodon.me.uk
    wrote last edited by
    #1

    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.

    mag@mastodon.me.ukM dascandy@infosec.exchangeD 2 Replies Last reply
    0
    • krans@mastodon.me.ukK krans@mastodon.me.uk

      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.

      mag@mastodon.me.ukM This user is from outside of this forum
      mag@mastodon.me.ukM This user is from outside of this forum
      mag@mastodon.me.uk
      wrote last edited by
      #2

      @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@mastodon.me.ukK 1 Reply Last reply
      0
      • mag@mastodon.me.ukM mag@mastodon.me.uk

        @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@mastodon.me.ukK This user is from outside of this forum
        krans@mastodon.me.ukK This user is from outside of this forum
        krans@mastodon.me.uk
        wrote last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • krans@mastodon.me.ukK krans@mastodon.me.uk

          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@infosec.exchangeD This user is from outside of this forum
          dascandy@infosec.exchangeD This user is from outside of this forum
          dascandy@infosec.exchange
          wrote last edited by
          #4

          @krans

          s/^[+-].*regex/!KeEp&/
          s/^[+-]/ /
          s/!KeEp//

          ?

          krans@mastodon.me.ukK 1 Reply Last reply
          0
          • dascandy@infosec.exchangeD dascandy@infosec.exchange

            @krans

            s/^[+-].*regex/!KeEp&/
            s/^[+-]/ /
            s/!KeEp//

            ?

            krans@mastodon.me.ukK This user is from outside of this forum
            krans@mastodon.me.ukK This user is from outside of this forum
            krans@mastodon.me.uk
            wrote last edited by
            #5

            @dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.

            krans@mastodon.me.ukK dascandy@infosec.exchangeD 2 Replies Last reply
            0
            • krans@mastodon.me.ukK krans@mastodon.me.uk

              @dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.

              krans@mastodon.me.ukK This user is from outside of this forum
              krans@mastodon.me.ukK This user is from outside of this forum
              krans@mastodon.me.uk
              wrote last edited by
              #6

              @dascandy (I tried this already)

              dascandy@infosec.exchangeD 1 Reply Last reply
              0
              • krans@mastodon.me.ukK krans@mastodon.me.uk

                @dascandy (I tried this already)

                dascandy@infosec.exchangeD This user is from outside of this forum
                dascandy@infosec.exchangeD This user is from outside of this forum
                dascandy@infosec.exchange
                wrote last edited by
                #7

                @krans I did kinda expect that and yeah, that context is unregexable

                1 Reply Last reply
                0
                • krans@mastodon.me.ukK krans@mastodon.me.uk

                  @dascandy This creates patches that don't apply, because non-matching deletion lines must be converted into context lines.

                  dascandy@infosec.exchangeD This user is from outside of this forum
                  dascandy@infosec.exchangeD This user is from outside of this forum
                  dascandy@infosec.exchange
                  wrote last edited by
                  #8

                  @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@mastodon.me.ukK 1 Reply Last reply
                  0
                  • dascandy@infosec.exchangeD dascandy@infosec.exchange

                    @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@mastodon.me.ukK This user is from outside of this forum
                    krans@mastodon.me.ukK This user is from outside of this forum
                    krans@mastodon.me.uk
                    wrote last edited by
                    #9

                    @dascandy Context lines need to be reordered. Consider:

                    context1
                    -old
                    -irrelevant1
                    +new
                    +irrelevant2
                    context2

                    The positions of the "irrelevant1" and "new" lines in the diff have to be swapped.

                    dascandy@infosec.exchangeD 1 Reply Last reply
                    0
                    • krans@mastodon.me.ukK krans@mastodon.me.uk

                      @dascandy Context lines need to be reordered. Consider:

                      context1
                      -old
                      -irrelevant1
                      +new
                      +irrelevant2
                      context2

                      The positions of the "irrelevant1" and "new" lines in the diff have to be swapped.

                      dascandy@infosec.exchangeD This user is from outside of this forum
                      dascandy@infosec.exchangeD This user is from outside of this forum
                      dascandy@infosec.exchange
                      wrote last edited by
                      #10

                      @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!

                      dascandy@infosec.exchangeD 1 Reply Last reply
                      0
                      • dascandy@infosec.exchangeD dascandy@infosec.exchange

                        @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!

                        dascandy@infosec.exchangeD This user is from outside of this forum
                        dascandy@infosec.exchangeD This user is from outside of this forum
                        dascandy@infosec.exchange
                        wrote last edited by
                        #11

                        @krans Thinking of your example, surely that's not automatically decideable?

                        context1
                        -irrelevant1
                        -old
                        +new
                        +irrelevant2
                        context2

                        Should the output become
                        context1
                        irrelevant1
                        new
                        irrelevant2
                        context2

                        or

                        context1
                        new
                        irrelevant1
                        irrelevant2
                        context2
                        ?

                        or any other potential resultant output?

                        1 Reply Last reply
                        1
                        0
                        • R relay@relay.infosec.exchange shared this topic
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups