Staging
v0.8.1
v0.8.1
https://foss.heptapod.net/mercurial/hgview
Tip revision: 5cb0155137364ae26cc554f3dfb4b462b8b28639 authored by David Douard on 25 September 2009, 12:31:14 UTC
tagged version 1.1.0
tagged version 1.1.0
Tip revision: 5cb0155
util.py
# -*- coding: utf-8 -*-
# util functions
#
# Copyright (C) 2009 Logilab. All rights reserved.
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
"""
Several helper functions
"""
def tounicode(string):
"""
Tries to convert s into a unicode string
"""
for encoding in ('utf-8', 'iso-8859-15', 'cp1252'):
try:
return unicode(string, encoding)
except UnicodeDecodeError:
pass
return unicode(string, 'utf-8', 'replace')
def has_closed_branch_support(repo):
"""
Return True is repository have support for closed branches
"""
# what a hack...
return "closed" in repo.heads.im_func.func_code.co_varnames
def isexec(filectx):
"""
Return True is the file at filectx revision is executable
"""
if hasattr(filectx, "isexec"):
return filectx.isexec()
return "x" in filectx.flags()
def exec_flag_changed(filectx):
"""
Return True if the file referenced by filectx has changed its exec
flag
"""
flag = isexec(filectx)
parents = filectx.parents()
if not parents:
return ""
pflag = isexec(parents[0])
if flag != pflag:
if flag:
return "set"
else:
return "unset"
return ""