sapling/hggit/util.py
2014-02-19 18:49:42 -08:00

34 lines
1.1 KiB
Python

"""Compatability functions for old Mercurial versions."""
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
def parse_hgsub(lines):
"""Fills OrderedDict with hgsub file content passed as list of lines"""
rv = OrderedDict()
for l in lines:
ls = l.strip();
if not ls or ls[0] == '#': continue
name, value = l.split('=', 1)
rv[name.strip()] = value.strip()
return rv
def serialize_hgsub(data):
"""Produces a string from OrderedDict hgsub content"""
return ''.join(['%s = %s\n' % (n,v) for n,v in data.iteritems()])
def parse_hgsubstate(lines):
"""Fills OrderedDict with hgsubtate file content passed as list of lines"""
rv = OrderedDict()
for l in lines:
ls = l.strip();
if not ls or ls[0] == '#': continue
value, name = l.split(' ', 1)
rv[name.strip()] = value.strip()
return rv
def serialize_hgsubstate(data):
"""Produces a string from OrderedDict hgsubstate content"""
return ''.join(['%s %s\n' % (data[n], n) for n in sorted(data)])