id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,work_issues,upstream,reviewer,author,merged,dependencies,stopgaps
12481,Fix branch_current_hg(),jdemeyer,jason,"This is just horrible code (`sage/misc/misc.py`):
{{{
def branch_current_hg():
    """"""
    Return the current hg Mercurial branch name. If the branch is
    'main', which is the default branch, then just '' is returned.
    """"""
    try:
        s = os.popen('ls -l %s/devel/sage'%os.environ['SAGE_ROOT']).read()
    except IOError:
        # this happens when running sage under gdb on macs
        return 'gdb'
    if 'No such file or directory' in s:
        raise RuntimeError, ""unable to determine branch?!""
    # do ls -l and look for a symlink, which `ls` represents by a '->'
    i = s.rfind('->')
    if i == -1:
        raise RuntimeError, ""unable to determine branch?!""
    s = s[i+2:]
    i = s.find('-')
    if i == -1:
        return ''
    br = s[i+1:].strip()
    return br
}}}

For one, this clearly needs an ""os.readlink()"" instead of parsing ""ls"" output.  The ""gdb"" is also broken, since the string ""gdb"" doesn't contain ""->"".  Also the documentation is wrong: is the branch is ""main"", then ""main"" is returned.",defect,closed,major,sage-5.0,misc,fixed,,,,N/A,André Apitzsch,Jeroen Demeyer,sage-5.0.beta4,,
