chiark / gitweb /
Support git-svn refs in the form of rN
[fdroidserver.git] / fdroidserver / common.py
index c568a908e2337098790c912a089db733d6454e26..38c71509b723b213d1b1bee8ca2cde92792542d1 100644 (file)
@@ -259,9 +259,9 @@ def read_app_args(args, allapps, allow_vercodes=False):
         for p in vercodes:
             if p not in allids:
                 logging.critical("No such package: %s" % p)
-        raise Exception("Found invalid app ids in arguments")
+        raise FDroidException("Found invalid app ids in arguments")
     if not apps:
-        raise Exception("No packages specified")
+        raise FDroidException("No packages specified")
 
     error = False
     for app in apps:
@@ -277,7 +277,7 @@ def read_app_args(args, allapps, allow_vercodes=False):
                     logging.critical("No such vercode %s for app %s" % (v, app['id']))
 
     if error:
-        raise Exception("Found invalid vercodes for some apps")
+        raise FDroidException("Found invalid vercodes for some apps")
 
     return apps
 
@@ -299,7 +299,7 @@ def apknameinfo(filename):
     try:
         result = (m.group(1), m.group(2))
     except AttributeError:
-        raise Exception("Invalid apk name: %s" % filename)
+        raise FDroidException("Invalid apk name: %s" % filename)
     return result
 
 
@@ -406,13 +406,21 @@ class vcs:
         if deleterepo:
             shutil.rmtree(self.local)
 
-        self.gotorevisionx(rev)
+        exc = None
+
+        try:
+            self.gotorevisionx(rev)
+        except FDroidException, e:
+            exc = e
 
         # If necessary, write the .fdroidvcs file.
-        if writeback:
+        if writeback and not self.clone_failed:
             with open(fdpath, 'w') as f:
                 f.write(cdata)
 
+        if exc is not None:
+            raise exc
+
     # Derived classes need to implement this. It's called once basic checking
     # has been performend.
     def gotorevisionx(self, rev):
@@ -617,7 +625,11 @@ class vcs_gitsvn(vcs):
         if rev:
             nospaces_rev = rev.replace(' ', '%20')
             # Try finding a svn tag
-            p = SilentPopen(['git', 'checkout', 'tags/' + nospaces_rev], cwd=self.local)
+            for treeish in ['origin/', '']:
+                p = SilentPopen(['git', 'checkout', treeish + 'tags/' + nospaces_rev],
+                                cwd=self.local)
+                if p.returncode == 0:
+                    break
             if p.returncode != 0:
                 # No tag found, normal svn rev translation
                 # Translate svn rev into git format
@@ -634,7 +646,10 @@ class vcs_gitsvn(vcs):
                         treeish += 'master'
                         svn_rev = rev
 
-                    p = SilentPopen(['git', 'svn', 'find-rev', 'r' + svn_rev, treeish], cwd=self.local)
+                    svn_rev = svn_rev if svn_rev[0] == 'r' else 'r' + svn_rev
+
+                    p = SilentPopen(['git', 'svn', 'find-rev', svn_rev, treeish],
+                                    cwd=self.local)
                     git_rev = p.output.rstrip()
 
                     if p.returncode == 0 and git_rev:
@@ -901,7 +916,7 @@ def ant_subprojects(root_dir):
 
 def remove_debuggable_flags(root_dir):
     # Remove forced debuggable flags
-    logging.info("Removing debuggable flags from %s" % root_dir)
+    logging.debug("Removing debuggable flags from %s" % root_dir)
     for root, dirs, files in os.walk(root_dir):
         if 'AndroidManifest.xml' in files:
             path = os.path.join(root, 'AndroidManifest.xml')
@@ -1357,10 +1372,10 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
         for d in update_dirs:
             subdir = os.path.join(root_dir, d)
             if d == '.':
-                logging.info("Updating main project")
+                logging.debug("Updating main project")
                 cmd = parms + ['-p', d]
             else:
-                logging.info("Updating subproject %s" % d)
+                logging.debug("Updating subproject %s" % d)
                 cmd = lparms + ['-p', d]
             p = FDroidPopen(cmd, cwd=root_dir)
             # Check to see whether an error was returned without a proper exit
@@ -1666,7 +1681,7 @@ def FDroidPopen(commands, cwd=None, shell=False, output=True):
     while not stdout_reader.eof():
         while not stdout_queue.empty():
             line = stdout_queue.get()
-            if output and options.verbose:
+            if output or options.verbose:
                 # Output directly to console
                 sys.stderr.write(line)
                 sys.stderr.flush()