mercurial/changelog.py
changeset 42141 0e41f40b01cc
parent 42116 caa067ee21dc
child 42142 5382d8f8530b
equal deleted inserted replaced
42140:a4483e380c3e 42141:0e41f40b01cc
    77     items = [
    77     items = [
    78         _string_escape('%s:%s' % (k, pycompat.bytestr(d[k])))
    78         _string_escape('%s:%s' % (k, pycompat.bytestr(d[k])))
    79         for k in sorted(d)
    79         for k in sorted(d)
    80     ]
    80     ]
    81     return "\0".join(items)
    81     return "\0".join(items)
       
    82 
       
    83 def encodecopies(copies):
       
    84     items = [
       
    85         '%s\0%s' % (k, copies[k])
       
    86         for k in sorted(copies)
       
    87     ]
       
    88     return "\n".join(items)
    82 
    89 
    83 def stripdesc(desc):
    90 def stripdesc(desc):
    84     """strip trailing whitespace and leading and trailing empty lines"""
    91     """strip trailing whitespace and leading and trailing empty lines"""
    85     return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
    92     return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
    86 
    93 
   531         last = text.index("\n\n")
   538         last = text.index("\n\n")
   532         l = text[:last].split('\n')
   539         l = text[:last].split('\n')
   533         return l[3:]
   540         return l[3:]
   534 
   541 
   535     def add(self, manifest, files, desc, transaction, p1, p2,
   542     def add(self, manifest, files, desc, transaction, p1, p2,
   536                   user, date=None, extra=None):
   543                   user, date=None, extra=None, p1copies=None, p2copies=None):
   537         # Convert to UTF-8 encoded bytestrings as the very first
   544         # Convert to UTF-8 encoded bytestrings as the very first
   538         # thing: calling any method on a localstr object will turn it
   545         # thing: calling any method on a localstr object will turn it
   539         # into a str object and the cached UTF-8 string is thus lost.
   546         # into a str object and the cached UTF-8 string is thus lost.
   540         user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)
   547         user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)
   541 
   548 
   560             if branch in ("default", ""):
   567             if branch in ("default", ""):
   561                 del extra["branch"]
   568                 del extra["branch"]
   562             elif branch in (".", "null", "tip"):
   569             elif branch in (".", "null", "tip"):
   563                 raise error.StorageError(_('the name \'%s\' is reserved')
   570                 raise error.StorageError(_('the name \'%s\' is reserved')
   564                                          % branch)
   571                                          % branch)
       
   572         if (p1copies or p2copies) and extra is None:
       
   573             extra = {}
       
   574         if p1copies:
       
   575             extra['p1copies'] = encodecopies(p1copies)
       
   576         if p2copies:
       
   577             extra['p2copies'] = encodecopies(p2copies)
       
   578 
   565         if extra:
   579         if extra:
   566             extra = encodeextra(extra)
   580             extra = encodeextra(extra)
   567             parseddate = "%s %s" % (parseddate, extra)
   581             parseddate = "%s %s" % (parseddate, extra)
   568         l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
   582         l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
   569         text = "\n".join(l)
   583         text = "\n".join(l)