Factor out PathDifference into gclient_utils for a later reuse.
Make lack of email address an error.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/507072
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35167 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 97d05ed..af98457 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -317,3 +317,15 @@
return None
path = next[0]
return path
+
+def PathDifference(root, subpath):
+ """Returns the difference subpath minus root."""
+ root = os.path.realpath(root)
+ subpath = os.path.realpath(subpath)
+ if not subpath.startswith(root):
+ return None
+ # If the root does not have a trailing \ or /, we add it so the returned
+ # path starts immediately after the seperator regardless of whether it is
+ # provided.
+ root = os.path.join(root, '')
+ return subpath[len(root):]