Mercurial > hg
diff mercurial/util.py @ 2956:6dddcba7596a
merge.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 18 Aug 2006 21:17:28 -0700 |
parents | 3d5547845158 |
children | 494521a3f142 |
line wrap: on
line diff
--- a/mercurial/util.py Sun Jul 23 09:04:14 2006 -0700 +++ b/mercurial/util.py Fri Aug 18 21:17:28 2006 -0700 @@ -2,6 +2,8 @@ util.py - Mercurial utility functions and platform specfic implementations Copyright 2005 K. Thananchayan <thananck@yahoo.com> + Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> + Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> This software may be used and distributed according to the terms of the GNU General Public License, incorporated herein by reference. @@ -12,7 +14,7 @@ from i18n import gettext as _ from demandload import * -demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") +demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile") demandload(globals(), "os threading time") # used by parsedate @@ -93,23 +95,6 @@ return p_name return default -def patch(strip, patchname, ui): - """apply the patch <patchname> to the working directory. - a list of patched files is returned""" - patcher = find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') - fp = os.popen('%s -p%d < "%s"' % (patcher, strip, patchname)) - files = {} - for line in fp: - line = line.rstrip() - ui.status("%s\n" % line) - if line.startswith('patching file '): - pf = parse_patch_output(line) - files.setdefault(pf, 1) - code = fp.close() - if code: - raise Abort(_("patch command failed: %s") % explain_exit(code)[0]) - return files.keys() - def binary(s): """return true if a string is binary data using diff's heuristic""" if s and '\0' in s[:4096]: @@ -510,6 +495,20 @@ except AttributeError: return os.name == 'nt' and 'command' in os.environ.get('comspec', '') +getuser_fallback = None + +def getuser(): + '''return name of current user''' + try: + return getpass.getuser() + except ImportError: + # import of pwd will fail on windows - try fallback + if getuser_fallback: + return getuser_fallback() + # raised if win32api not available + raise Abort(_('user name not available - set USERNAME ' + 'environment variable')) + # Platform specific variants if os.name == 'nt': demandload(globals(), "msvcrt") @@ -593,6 +592,9 @@ def samestat(s1, s2): return False + def shellquote(s): + return '"%s"' % s.replace('"', '\\"') + def explain_exit(code): return _("exited with status %d") % code, code @@ -682,6 +684,9 @@ else: raise + def shellquote(s): + return "'%s'" % s.replace("'", "'\\''") + def testpid(pid): '''return False if pid dead, True if running or not sure''' try: @@ -982,3 +987,11 @@ if nbytes >= divisor * multiplier: return format % (nbytes / float(divisor)) return units[-1][2] % nbytes + +def drop_scheme(scheme, path): + sc = scheme + ':' + if path.startswith(sc): + path = path[len(sc):] + if path.startswith('//'): + path = path[2:] + return path