[gitg/commit] Separated stage status enumerator in separate file
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/commit] Separated stage status enumerator in separate file
- Date: Tue, 25 Jun 2013 06:43:23 +0000 (UTC)
commit 407b6908a06e1a746f9419b09b2cea7da89c0c42
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 | 27 +++--
libgitg/gitg-stage-status-enumerator.vala | 173 +++++++++++++++++++++++++++++
libgitg/gitg-stage.vala | 150 +-------------------------
3 files changed, 188 insertions(+), 162 deletions(-)
---
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index c934778..2918cc8 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -29,19 +29,20 @@ AM_VALAFLAGS = \
Gitg-1.0.gir: libgitg-1.0.la
libgitg.h: libgitg-1.0.la
-VALA_FILES = \
- gitg-assembly-info.vala \
- gitg-branch.vala \
- gitg-branch-base.vala \
- gitg-repository.vala \
- gitg-ref.vala \
- gitg-ref-base.vala \
- gitg-lane.vala \
- gitg-lanes.vala \
- gitg-color.vala \
- gitg-init.vala \
- gitg-commit.vala \
- gitg-stage.vala \
+VALA_FILES = \
+ gitg-assembly-info.vala \
+ gitg-branch.vala \
+ gitg-branch-base.vala \
+ gitg-repository.vala \
+ gitg-ref.vala \
+ gitg-ref-base.vala \
+ gitg-lane.vala \
+ gitg-lanes.vala \
+ gitg-color.vala \
+ gitg-init.vala \
+ gitg-commit.vala \
+ gitg-stage.vala \
+ gitg-stage-status-enumerator.vala \
gitg-commit-model.vala
# Ignore all warnings for vala code...
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]