chiark / gitweb /
Allow 'import' to cherry-pick a commit object
[stgit] / stgit / commands / common.py
index 160dd37dca1fd1b4b051fec668183a6b93e9fda5..c6d45351a0932870d8187c310212d44dcbfd6fa6 100644 (file)
@@ -30,16 +30,8 @@ class CmdException(Exception):
     pass
 
 
-# Global variables
-try:
-    crt_series = stack.Series()
-except (IOError, stack.StackException, git.GitException), err:
-    print >> sys.stderr, err
-    sys.exit(2)
-
-
 # Utility functions
-def git_id(string):
+def git_id(string, strict = False):
     """Return the GIT id
     """
     if not string:
@@ -61,6 +53,10 @@ def git_id(string):
             id_file = os.path.join(path, git_id)
             if os.path.isfile(id_file):
                 return read_string(id_file)
+
+        # maybe GIT knows more about this id
+        if not strict:
+            return git_id
     elif len(string_list) == 2:
         patch_name = string_list[0]
         if patch_name == '':
@@ -104,7 +100,7 @@ def print_crt_patch():
         print 'No patches applied'
 
 def resolved(filename):
-    git.update_cache([filename])
+    git.update_cache([filename], force = True)
     for ext in ['.local', '.older', '.remote']:
         fn = filename + ext
         if os.path.isfile(fn):
@@ -121,8 +117,18 @@ def name_email(string):
     """Return a tuple consisting of the name and email parsed from a
     standard 'name <email>' string
     """
-    names = re.split('([^<>]*)<([^<>]*)>', string)
-    if len(names) != 4:
+    str_list = re.findall('^(.*)\s+<(.*)>$', string)
+    if not str_list:
         raise CmdException, 'Incorrect "name <email>" string: %s' % string
 
-    return tuple([names[1].strip(), names[2].strip()])
+    return str_list[0]
+
+def name_email_date(string):
+    """Return a tuple consisting of the name, email and date parsed
+    from a 'name <email> date' string
+    """
+    str_list = re.findall('^(.*)\s+<(.*)>\s+(.*)$', string)
+    if not str_list:
+        raise CmdException, 'Incorrect "name <email> date" string: %s' % string
+
+    return str_list[0]