Loading ...
Sorry, an error occurred while loading the content.

(off topic) patches in emails

Expand Messages
  • Matt Dunford
    Since I m naturally lazy, I threw together a python script that extracts Bram s patches out of his emails and applies them to the dev source (without exiting
    Message 1 of 6 , Mar 30, 2001
    • 0 Attachment
      Since I'm naturally lazy, I threw together a python script that extracts
      Bram's patches out of his emails and applies them to the dev source
      (without exiting my emailer). I thought I'd post it to the list just in
      case anyone else finds some use for it. Or has a better solution. ;-)

      If one uses mutt, the following macro comes in handy.
      macro index ",patch" "|~/patch.py "

      %> cat patch.py
      #!/path/to/python
      # extracts and applies a patch from an email

      import sys, string, re, os

      # default patching directory (you may want to change this)
      srcdir = 'path/to/vim/src'

      pargs = '' # cmdline args to be sent to 'patch' program
      if not '-d' in sys.argv:
      # you may override the default 'srcdir' var
      # by specifying the '-d' flag
      # example: patch -d path/to/mutt
      pargs = '-d '+srcdir
      try:
      pargs = pargs + string.join(sys.argv[1:],' ')
      except: pass

      lines = sys.stdin.readlines()
      max = len(lines)
      eop = 0 # line number indicating end of patch
      patch_flag = 0

      for i in range(max):
      line = lines[i]
      # find the start of the patch in the email
      if patch_flag == 0 and re.match('^\*\*\* ',line):
      # read the next two lines (just to make sure)
      l1,l2 = lines[i+1],lines[i+2]
      if re.match('^--- ',l1) and re.match('^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*',l2):
      patch_flag = 1 # ok, found the start of a patch

      # record the line number of where the patch ends
      if patch_flag:
      if not re.match('^[*-]{3}',line) and not re.match('^[-+! ] ',line):
      eop = i
      break

      if eop == 0:
      eop = max # no garble at the end of the patch

      if not patch_flag:
      # apparently there is no patch, mistake?
      print 'error: No patch found'
      sys.exit(1)

      lines = lines[:eop] # extract only the lines we want
      f = os.popen('patch '+pargs,'w')
      f.writelines(lines)

      --
      The spirit of a man upholdeth his
      infirmity: but a spirit that is easily
      angered, who can bear?
      -- Proverbs 18:13
      --
    • Douglas L Potts
      ... [--- snip ---] ... [--- snip ---] Cool script, but patch can take care of pulling the patch out of the e-mail text for you. -Doug --
      Message 2 of 6 , Mar 30, 2001
      • 0 Attachment
        On Fri, Mar 30, 2001 at 02:47:26PM +0200 Matt Dunford wrote:
        > Since I'm naturally lazy, I threw together a python script that extracts
        > Bram's patches out of his emails and applies them to the dev source
        > (without exiting my emailer). I thought I'd post it to the list just in
        > case anyone else finds some use for it. Or has a better solution. ;-)
        [--- snip ---]
        > # find the start of the patch in the email
        [--- snip ---]

        Cool script, but patch can take care of pulling the patch out of the
        e-mail text for you.

        -Doug

        --
        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        Douglas L. Potts Url: http://www.bigfoot.com/~pottsdl
        "But you can't expect to wield supreme executive power just 'cause some watery
        tart threw a sword at you!" -Dennis, "Monty Python and the Holy Grail"
        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
      • Matt Dunford
        ... Really? Maybe there s something wrong with my version of patch then. It s finicky when it encounters a signature. Sometimes it succeeds in patching the
        Message 3 of 6 , Mar 30, 2001
        • 0 Attachment
          * Douglas L Potts <potts.13@...> [010330 08:51]:
          > On Fri, Mar 30, 2001 at 02:47:26PM +0200 Matt Dunford wrote:
          > > Since I'm naturally lazy, I threw together a python script that extracts
          > > Bram's patches out of his emails and applies them to the dev source
          > > (without exiting my emailer). I thought I'd post it to the list just in
          > > case anyone else finds some use for it. Or has a better solution. ;-)
          > [--- snip ---]
          > > # find the start of the patch in the email
          > [--- snip ---]
          >
          > Cool script, but patch can take care of pulling the patch out of the
          > e-mail text for you.

          Really? Maybe there's something wrong with my version of patch
          then. It's finicky when it encounters a signature. Sometimes it
          succeeds in patching the source, sometimes it pukes with an error like
          this:

          Malformed patch at line 69:
          patch: Second character must be a ' ' character.

          --
          If you fight against all your sensations, you will have no
          standard by which to refer, and thus no means of judging even those
          sensations which you claim are false.
          -- Epicurus
          --
        • Jon Miner
          ... What version of patch are you running (and on what OS?) You probably can solve your problems by installing GNU Patch, ftp://ftp.gnu.org/gnu/patch/ jon
          Message 4 of 6 , Mar 31, 2001
          • 0 Attachment
            * Matt Dunford (zoot@...) [010330 08:18]:
            > Really? Maybe there's something wrong with my version of patch
            > then. It's finicky when it encounters a signature. Sometimes it
            > succeeds in patching the source, sometimes it pukes with an error like
            > this:
            >
            > Malformed patch at line 69:
            > patch: Second character must be a ' ' character.

            What version of patch are you running (and on what OS?) You probably
            can "solve" your problems by installing GNU Patch,
            ftp://ftp.gnu.org/gnu/patch/

            jon

            --
            .Jonathan J. Miner------------------Division of Information Technology.
            |miner@... University Of Wisconsin - Madison|
            |608/262.9655 Room 3149 Computer Science|
            `---------------------------------------------------------------------'

            Beauty? What's that?
            -- Larry Wall in <199710221937.MAA25131@...>
            (218)
          • Matt Dunford
            ... Thanks for the advice. I ll look into gnu patch. Right now I m stuck on a Solaris box. % uname -a SunOS io 5.5.1 Generic_103640-24 sun4m sparc
            Message 5 of 6 , Mar 31, 2001
            • 0 Attachment
              * Jon Miner <miner@...> [010331 09:03]:
              > * Matt Dunford (zoot@...) [010330 08:18]:
              > > Really? Maybe there's something wrong with my version of patch
              > > then. It's finicky when it encounters a signature. Sometimes it
              > > succeeds in patching the source, sometimes it pukes with an error like
              > > this:
              > >
              > > Malformed patch at line 69:
              > > patch: Second character must be a ' ' character.
              >
              > What version of patch are you running (and on what OS?) You probably
              > can "solve" your problems by installing GNU Patch,
              > ftp://ftp.gnu.org/gnu/patch/

              Thanks for the advice. I'll look into gnu patch. Right now I'm stuck
              on a Solaris box.

              %> uname -a
              SunOS io 5.5.1 Generic_103640-24 sun4m sparc SUNW,SPARCstation-5
              %> patch --version
              patch: Invalid options.
              patch: Usage: patch [-blNR] [-c|-e|-n] [-d dir] [-D define] [-i patchfile]\
              [-o outfile] [-p num] [-r rejectfile] [file]

              --
              I vowed victims for prosperity, this
              day I have paid my vows.
              -- Proverbs 7:13
              --
            • Jon Miner
              ... Install GNU patch, but be sure to use the --program-prefix=g switch to configure (which will name the executable gpatch) or --prefix=/usr/local/gnu (or
              Message 6 of 6 , Mar 31, 2001
              • 0 Attachment
                * Matt Dunford (zoot@...) [010331 13:01]:
                > * Jon Miner <miner@...> [010331 09:03]:
                > > * Matt Dunford (zoot@...) [010330 08:18]:
                > > > Really? Maybe there's something wrong with my version of patch
                > > > then. It's finicky when it encounters a signature. Sometimes it
                > > > succeeds in patching the source, sometimes it pukes with an error like
                > > > this:
                > > >
                > > > Malformed patch at line 69:
                > > > patch: Second character must be a ' ' character.
                > >
                > > What version of patch are you running (and on what OS?) You probably
                > > can "solve" your problems by installing GNU Patch,
                > > ftp://ftp.gnu.org/gnu/patch/
                >
                > Thanks for the advice. I'll look into gnu patch. Right now I'm stuck
                > on a Solaris box.

                Install GNU patch, but be sure to use the --program-prefix=g switch to
                configure (which will name the executable gpatch) or
                --prefix=/usr/local/gnu (or something like that) so that you don't
                replace the solaris patch. I've found that commercial unices can have
                problems when you replace their utilities with GNU ones..

                jon

                --
                .Jonathan J. Miner------------------Division of Information Technology.
                |miner@... University Of Wisconsin - Madison|
                |608/262.9655 Room 3149 Computer Science|
                `---------------------------------------------------------------------'

                There's something to be said for returning the whole syntax tree.
                -- Larry Wall in <199710221833.LAA24741@...>
                (209)
              Your message has been successfully submitted and would be delivered to recipients shortly.