[gitg/wip/commit: 2/28] Separated stage status enumerator in separate file



commit e088612650dfd009818ff1e74afc4e2cac4aa634
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Tue Jun 25 08:43:15 2013 +0200

    Separated stage status enumerator in separate file

 libgitg/Makefile.am                       |    3 +-
 libgitg/gitg-stage-status-enumerator.vala |  173 +++++++++++++++++++++++++++++
 libgitg/gitg-stage.vala                   |  150 +-------------------------
 3 files changed, 176 insertions(+), 150 deletions(-)
---
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index a035668..d2940f8 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -60,7 +60,8 @@ VALA_FILES =                                  \
        gitg-dash-view.vala                     \
        gitg-when-mapped.vala                   \
        gitg-progress-bin.vala                  \
-       gitg-stage.vala
+       gitg-stage.vala                         \
+       gitg-stage-status-enumerator.vala
 
 # Ignore all warnings for vala code...
 libgitg_1_0_la_CFLAGS =                \
diff --git a/libgitg/gitg-stage-status-enumerator.vala b/libgitg/gitg-stage-status-enumerator.vala
new file mode 100644
index 0000000..6240d53
--- /dev/null
+++ b/libgitg/gitg-stage-status-enumerator.vala
@@ -0,0 +1,173 @@
+/*
+ * This file is part of gitg
+ *
+ * Copyright (C) 2013 - Jesse van den Kieboom
+ *
+ * gitg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gitg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gitg. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Gitg
+{
+
+public class StageStatusFile
+{
+       private string d_path;
+       private Ggit.StatusFlags d_flags;
+
+       public StageStatusFile(string path, Ggit.StatusFlags flags)
+       {
+               d_path = path;
+               d_flags = flags;
+       }
+
+       public string path
+       {
+               get { return d_path; }
+       }
+
+       public Ggit.StatusFlags flags
+       {
+               get { return d_flags; }
+       }
+}
+
+public class StageStatusEnumerator
+{
+       private Repository d_repository;
+       private Thread<void *> d_thread;
+       private StageStatusFile[] d_files;
+       private int d_offset;
+       private int d_callback_num;
+       private Cancellable d_cancellable;
+       private SourceFunc d_callback;
+
+       internal StageStatusEnumerator(Repository repository)
+       {
+               d_repository = repository;
+
+               d_files = new StageStatusFile[100];
+               d_files.length = 0;
+               d_cancellable = new Cancellable();
+
+               try
+               {
+                       d_thread = new Thread<void *>.try("gitg-status-enumerator", run_status);
+               } catch {}
+       }
+
+       ~StageStatusEnumerator()
+       {
+               lock (d_files)
+               {
+                       if (d_cancellable != null)
+                       {
+                               d_cancellable.cancel();
+                       }
+               }
+
+               d_thread.join();
+       }
+
+       private void *run_status()
+       {
+               try
+               {
+                       d_repository.file_status_foreach(null, (path, flags) => {
+                               lock (d_files)
+                               {
+                                       d_files += new StageStatusFile(path, flags);
+
+                                       if (d_callback != null && d_files.length >= d_callback_num)
+                                       {
+                                               var cb = (owned)d_callback;
+                                               d_callback = null;
+
+                                               Idle.add((owned)cb);
+                                       }
+                               }
+
+                               if (d_cancellable.is_cancelled())
+                               {
+                                       return 1;
+                               }
+
+                               return 0;
+                       });
+               } catch {}
+
+               lock (d_files)
+               {
+                       d_cancellable = null;
+               }
+
+               return null;
+       }
+
+       private StageStatusFile[] fill_files(int num)
+       {
+               int n = 0;
+
+               StageStatusFile[] ret = new StageStatusFile[int.min(num, d_files.length - d_offset)];
+               ret.length = 0;
+
+               // d_files is already locked here, so it's safe to access
+               while (d_offset < d_files.length)
+               {
+                       if (n == num)
+                       {
+                               break;
+                       }
+
+                       ret += d_files[d_offset];
+                       d_offset++;
+
+                       ++n;
+               }
+
+               return ret;
+       }
+
+       public async StageStatusFile[] next_files(int num)
+       {
+               SourceFunc callback = next_files.callback;
+               StageStatusFile[] ret;
+
+               lock (d_files)
+               {
+                       if (d_cancellable == null)
+                       {
+                               // Already finished
+                               return fill_files(num);
+                       }
+                       else
+                       {
+                               d_callback = (owned)callback;
+                               d_callback_num = num;
+                       }
+               }
+
+               yield;
+
+               lock (d_files)
+               {
+                       ret = fill_files(num);
+               }
+
+               return ret;
+       }
+}
+
+}
+
+// ex:set ts=4 noet
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 5dba8f9..cc1369d 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of gitg
  *
- * Copyright (C) 2012 - Jesse van den Kieboom
+ * Copyright (C) 2013 - Jesse van den Kieboom
  *
  * gitg is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,154 +20,6 @@
 namespace Gitg
 {
 
-public class StageStatusFile
-{
-       private string d_path;
-       private Ggit.StatusFlags d_flags;
-
-       public StageStatusFile(string path, Ggit.StatusFlags flags)
-       {
-               d_path = path;
-               d_flags = flags;
-       }
-
-       public string path
-       {
-               get { return d_path; }
-       }
-
-       public Ggit.StatusFlags flags
-       {
-               get { return d_flags; }
-       }
-}
-
-public class StageStatusEnumerator
-{
-       private Repository d_repository;
-       private Thread<void *> d_thread;
-       private StageStatusFile[] d_files;
-       private int d_offset;
-       private int d_callback_num;
-       private Cancellable d_cancellable;
-       private SourceFunc d_callback;
-
-       internal StageStatusEnumerator(Repository repository)
-       {
-               d_repository = repository;
-
-               d_files = new StageStatusFile[100];
-               d_files.length = 0;
-               d_cancellable = new Cancellable();
-
-               try
-               {
-                       d_thread = new Thread<void *>.try("gitg-status-enumerator", run_status);
-               } catch {}
-       }
-
-       ~StageStatusEnumerator()
-       {
-               lock (d_files)
-               {
-                       if (d_cancellable != null)
-                       {
-                               d_cancellable.cancel();
-                       }
-               }
-
-               d_thread.join();
-       }
-
-       private void *run_status()
-       {
-               try
-               {
-                       d_repository.file_status_foreach(null, (path, flags) => {
-                               lock (d_files)
-                               {
-                                       d_files += new StageStatusFile(path, flags);
-
-                                       if (d_callback != null && d_files.length >= d_callback_num)
-                                       {
-                                               var cb = (owned)d_callback;
-                                               d_callback = null;
-
-                                               Idle.add((owned)cb);
-                                       }
-                               }
-
-                               if (d_cancellable.is_cancelled())
-                               {
-                                       return 1;
-                               }
-
-                               return 0;
-                       });
-               } catch {}
-
-               lock (d_files)
-               {
-                       d_cancellable = null;
-               }
-
-               return null;
-       }
-
-       private StageStatusFile[] fill_files(int num)
-       {
-               int n = 0;
-
-               StageStatusFile[] ret = new StageStatusFile[int.min(num, d_files.length - d_offset)];
-               ret.length = 0;
-
-               // d_files is already locked here, so it's safe to access
-               while (d_offset < d_files.length)
-               {
-                       if (n == num)
-                       {
-                               break;
-                       }
-
-                       ret += d_files[d_offset];
-                       d_offset++;
-
-                       ++n;
-               }
-
-               return ret;
-       }
-
-       public async StageStatusFile[] next_files(int num)
-       {
-               SourceFunc callback = next_files.callback;
-               StageStatusFile[] ret;
-
-               lock (d_files)
-               {
-                       if (d_cancellable == null)
-                       {
-                               // Already finished
-                               return fill_files(num);
-                       }
-                       else
-                       {
-                               d_callback = (owned)callback;
-                               d_callback_num = num;
-                       }
-               }
-
-               yield;
-
-               lock (d_files)
-               {
-                       ret = fill_files(num);
-               }
-
-               return ret;
-       }
-}
-
 public class Stage
 {
        private Repository d_repository;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]