Remove more logic out of trychange.py into scm.py.

The goal is to (almost) completely remove git-try.

TEST=none

Review URL: http://codereview.chromium.org/501166

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35144 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/scm.py b/scm.py
index d23ab62..2e13555 100644
--- a/scm.py
+++ b/scm.py
@@ -14,6 +14,10 @@
 
 import gclient_utils
 
+def ValidateEmail(email):
+ return (re.match(r"^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email)
+         is not None)
+
 
 class GIT(object):
   COMMAND = "git"
@@ -78,10 +82,15 @@
 
   @staticmethod
   def GetBranchRef(cwd):
-    """Returns the short branch name, e.g. 'master'."""
+    """Returns the full branch reference, e.g. 'refs/heads/master'."""
     return GIT.Capture(['symbolic-ref', 'HEAD'], cwd).strip()
 
   @staticmethod
+  def GetBranch(cwd):
+    """Returns the short branch name, e.g. 'master'."""
+    return GIT.ShortBranchName(GIT.BranchRef(cwd))
+
+  @staticmethod
   def IsGitSvn(cwd):
     """Returns true if this repo looks like it's using git-svn."""
     # If you have any "svn-remote.*" config keys, we think you're using svn.
@@ -140,7 +149,7 @@
        e.g. 'origin', 'refs/heads/master'
     """
     remote = '.'
-    branch = GIT.ShortBranchName(GIT.GetBranchRef(cwd))
+    branch = GIT.GetBranch(cwd)
     upstream_branch = None
     upstream_branch = GIT.Capture(
         ['config', 'branch.%s.merge' % branch], error_ok=True).strip()
@@ -181,6 +190,21 @@
         diff[i] = '--- %s' % diff[i+1][4:]
     return ''.join(diff)
 
+  @staticmethod
+  def GetPatchName(cwd):
+    """Constructs a name for this patch."""
+    short_sha = GIT.Capture(['rev-parse', '--short=4', 'HEAD'], cwd).strip()
+    return "%s-%s" % (GIT.GetBranch(cwd), short_sha)
+
+  @staticmethod
+  def GetCheckoutRoot(cwd):
+    """Returns the top level directory of the current repository.
+
+    The directory is returned as an absolute path.
+    """
+    return os.path.abspath(GIT.Capture(['rev-parse', '--show-cdup'],
+                                       cwd).strip())
+
 
 class SVN(object):
   COMMAND = "svn"