Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 237:9249ca818ddf
Recognize blocks enclosed with merge tool markers.
BUGS: Right now they will be skipped. What to do with them. Push upstream?
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 31 Oct 2018 09:40:53 +0100 |
| parents | 5e5aac8160d0 |
| children | f28cfbaf9b59 |
| files | extensions/timestamps.py |
| diffstat | 1 files changed, 52 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/timestamps.py Wed Oct 31 09:00:41 2018 +0100 +++ b/extensions/timestamps.py Wed Oct 31 09:40:53 2018 +0100 @@ -369,10 +369,10 @@ if fn.startswith(' ') or fn.startswith('\t') \ or fn.endswith(' ') or fn.endswith('\t'): return "@%s@" % fn.replace('@', "@@") - if "," in fn or '@' in fn or '#' in fn: - return "@%s@" % fn.replace('@', "@@") - else: - return fn + for c in ",@#<|=>": + if c in fn: + return "@%s@" % fn.replace('@', "@@") + return fn def db_reader(fp): @@ -387,6 +387,7 @@ c = fp.read(1) record = [] field = [] + merge_block = '' while c: if c in '\r\n': # record separator @@ -394,7 +395,11 @@ if f or record: record.append(f) # an empty line is an empty record - yield record + + # XXX FIXME: which of the merge blocks to return? + if not merge_block: + yield record + record = [] field = [] if c == '\r': @@ -436,22 +441,46 @@ sf.append(c2) c2 = fp.read(1) field = sf - elif not record and not field and c == '#': - # comment: `#' at the beginning of a line - comment = ['#'] - while True: + elif not record and not field and c in "#<|=>": + if c == '#': + # comment: `#' at the beginning of a line + comment = ['#'] + while True: + c3 = fp.peek(1) + if c3 and c3[0] in '\r\n': + # end of comment + break + # + # the next character will be read below: + # just stay at the eol char + # + else: + c2 = fp.read(1) + comment.append(c2) + field = comment + else: + # hit of merge markers c3 = fp.peek(1) - if c3 and c3[0] in '\r\n': - # end of comment - break - # - # the next character will be read below: - # just stay at the eol char - # + + if c3 and c3[0] == c: + merge_block = c + # skip to eol + while True: + c3 = fp.peek(1) + if c3 and c3[0] in '\r\n': + break + # + # the next character will be read below: + # just stay at the eol char + # + else: + fp.read(1) + # the "merge rev" block is really the last marker + if merge_block == '>': + merge_block = '' else: - c2 = fp.read(1) - comment.append(c2) - field = comment + # just a normal char + field.append(c) elif c in " \t": if field: field.append(c) @@ -466,7 +495,10 @@ if f or record: record.append(f) # an empty line is an empty record: do not yield trailing empty lines - yield record + + # XXX FIXME: which of the merge blocks to return? + if not merge_block: + yield record def db_writer(fp):
