Re: [PATCH v3 3/3] git-p4: fix Git LFS pointer parsing
- From
Sebastian Schuberth <sschuberth@gmail.com>
- Date
- Apr 25, 2016, 07:35 UTC
- Message-ID
- <CAHGBnuO16Y2b3G5pyuG59b+vojRGe_wySmUcAUka9eT2opABdA@mail.gmail.com>
- In-Reply-To
- <8340C6E5-C774-46EE-A1F9-1C4C7DF9CEB9@gmail.com>
On Mon, Apr 25, 2016 at 9:33 AM, Lars Schneider <larsxschneider@gmail.com> wrote:
Show 12 quoted lines
>> if you're omitting lines from the output. Also, the regex matches >> against the whole multi-line string. That is, if the file for some >> reason was ending in '\n\n' instead of just '\n', the '.*' would match >> almost all content of the pointer file, not just the remains of the >> preamble. One way to fix this would be to use >> >> re.sub(r'Git LFS pointer for [^\n]+\n\n', '', pointerFile) >> >> instead. > > In general you are right as "*" is greedy. However, in Python "." matches any > character except a newline [1]. Therefore I think the regex is correct.
Ah, thanks for pointing that out. Looks ok to me then.
Show 6 quoted lines
> Nevertheless... thanks for making me read the line again. I forgot to > assign the pointerFile variable in the version I sent around :-( > > This is how it should be: > > pointerFile = re.sub(r'Git LFS pointer for.*\n\n', '', pointerFile)
Right. Good you've catched that!
-- Sebastian Schuberth