Create two functions for common code in export build and remotebuild modules
authorZhang Qiang <qiang.z.zhang@intel.com>
Tue, 31 Jul 2012 08:32:29 +0000 (16:32 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Tue, 31 Jul 2012 08:32:29 +0000 (16:32 +0800)
gitbuildsys/cmd_build.py
gitbuildsys/cmd_export.py
gitbuildsys/cmd_remotebuild.py
gitbuildsys/utils.py

index 511d189..1065a71 100644 (file)
@@ -246,35 +246,11 @@ def do(opts, args):
 
     try:
         repo = RpmGitRepository(workdir)
-        if opts.commit:
-            repo.rev_parse(opts.commit)
-        is_clean, out = repo.is_clean()
-        status = repo.status()
-        untracked_files = status['??']
-        uncommitted_files = []
-        for stat in status:
-            if stat == '??':
-                continue
-            uncommitted_files.extend(status[stat])
-        if not is_clean and not opts.include_all:
-            if untracked_files:
-                msger.warning('the following untracked files would NOT be '\
-                           'included:\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.warning('the following uncommitted changes would NOT be '\
-                           'included:\n   %s' % '\n   '.join(uncommitted_files))
-            msger.warning('you can specify \'--include-all\' option to '\
-                          'include these uncommitted and untracked files.')
-        if opts.include_all:
-            if untracked_files:
-                msger.info('the following untracked files would be included'  \
-                           ':\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.info('the following uncommitted changes would be included'\
-                           ':\n   %s' % '\n   '.join(uncommitted_files))
     except GitRepositoryError, err:
         msger.error(str(err))
 
+    if not opts.incremental:
+        utils.gitStatusChecker(repo, opts)
     workdir = repo.path
 
     hostarch = get_hostarch()
index 2f40435..112fd7f 100644 (file)
@@ -63,35 +63,10 @@ def do(opts, args):
 
     try:
         repo = RpmGitRepository(workdir)
-        if opts.commit:
-            repo.rev_parse(opts.commit)
-        is_clean, out = repo.is_clean()
-        status = repo.status()
-        untracked_files = status['??']
-        uncommitted_files = []
-        for stat in status:
-            if stat == '??':
-                continue
-            uncommitted_files.extend(status[stat])
-        if not is_clean and not opts.include_all:
-            if untracked_files:
-                msger.warning('the following untracked files would NOT be '\
-                           'included:\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.warning('the following uncommitted changes would NOT be '\
-                           'included:\n   %s' % '\n   '.join(uncommitted_files))
-            msger.warning('you can specify \'--include-all\' option to '\
-                          'include these uncommitted and untracked files.')
-        if opts.include_all:
-            if untracked_files:
-                msger.info('the following untracked files would be included'  \
-                           ':\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.info('the following uncommitted changes would be included'\
-                           ':\n   %s' % '\n   '.join(uncommitted_files))
     except GitRepositoryError, err:
         msger.error(str(err))
 
+    utils.gitStatusChecker(repo, opts)
     workdir = repo.path
 
     if not os.path.exists("%s/packaging" % workdir):
index 3ae024d..b53a9b1 100644 (file)
@@ -32,7 +32,7 @@ import utils
 
 import gbp.rpm
 from gbp.scripts.buildpackage_rpm import main as gbp_build
-from gbp.git import repository, GitRepositoryError
+from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 from gbp.errors import GbpError
 
 OSCRC_TEMPLATE = """[general]
@@ -80,37 +80,12 @@ def do(opts, args):
                            '--include-all')
 
     try:
-        repo = repository.GitRepository(workdir)
-        if opts.commit:
-            repo.rev_parse(opts.commit)
-        is_clean, out = repo.is_clean()
-        status = repo.status()
-        untracked_files = status['??']
-        uncommitted_files = []
-        for stat in status:
-            if stat == '??':
-                continue
-            uncommitted_files.extend(status[stat])
-        if not is_clean and not opts.include_all and not \
-           (opts.buildlog or opts.status):
-            if untracked_files:
-                msger.warning('the following untracked files would NOT be '\
-                           'included:\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.warning('the following uncommitted changes would NOT be '\
-                           'included:\n   %s' % '\n   '.join(uncommitted_files))
-            msger.warning('you can specify \'--include-all\' option to '\
-                          'include these uncommitted and untracked files.')
-        if opts.include_all and not (opts.buildlog or opts.status):
-            if untracked_files:
-                msger.info('the following untracked files would be included'  \
-                           ':\n   %s' % '\n   '.join(untracked_files))
-            if uncommitted_files:
-                msger.info('the following uncommitted changes would be included'\
-                           ':\n   %s' % '\n   '.join(uncommitted_files))
-    except repository.GitRepositoryError, err:
+        repo = RpmGitRepository(workdir)
+    except GitRepositoryError, err:
         msger.error(str(err))
 
+    if not (opts.buildlog or opts.status):
+        utils.gitStatusChecker(repo, opts)
     workdir = repo.path
 
     tmpdir = os.path.join(workdir, 'packaging')
index 092b79b..92e73ec 100644 (file)
@@ -31,6 +31,8 @@ except ImportError:
 
 import errors
 import msger
+from gbp.rpm.git import GitRepositoryError
+from gbp.errors import GbpError
 
 class Workdir(object):
     def __init__(self, path):
@@ -295,3 +297,36 @@ class RepoParser(object):
             return self.repourls[arch] + self.localrepos
 
         return None
+
+def gitStatusChecker(git, opts):
+    try:
+        if opts.commit:
+            git.rev_parse(opts.commit)
+        is_clean, out = git.is_clean()
+        status = git.status()
+    except (GbpError, GitRepositoryError), err:
+        msger.error(str(err))
+
+    untracked_files = status['??']
+    uncommitted_files = []
+    for stat in status:
+        if stat == '??':
+            continue
+        uncommitted_files.extend(status[stat])
+
+    if not is_clean and not opts.include_all:
+        if untracked_files:
+            msger.warning('the following untracked files would NOT be '\
+                       'included:\n   %s' % '\n   '.join(untracked_files))
+        if uncommitted_files:
+            msger.warning('the following uncommitted changes would NOT be '\
+                       'included:\n   %s' % '\n   '.join(uncommitted_files))
+        msger.warning('you can specify \'--include-all\' option to '\
+                      'include these uncommitted and untracked files.')
+    if not is_clean and opts.include_all:
+        if untracked_files:
+            msger.info('the following untracked files would be included'  \
+                       ':\n   %s' % '\n   '.join(untracked_files))
+        if uncommitted_files:
+            msger.info('the following uncommitted changes would be included'\
+                       ':\n   %s' % '\n   '.join(uncommitted_files))