[gitg/wip/commit: 23/28] Get head tree asynchronously
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/commit: 23/28] Get head tree asynchronously
- Date: Wed, 3 Jul 2013 14:55:25 +0000 (UTC)
commit c66b61e969748d73a81ea9384c343b0b7042df2c
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Wed Jul 3 16:41:22 2013 +0200
Get head tree asynchronously
libgitg/gitg-stage.vala | 38 +++++++++++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 11040d8..0fc0267 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -24,6 +24,7 @@ public class Stage : Object
{
private weak Repository d_repository;
private Mutex d_index_mutex;
+ private Ggit.Tree? d_head_tree;
internal Stage(Repository repository)
{
@@ -37,12 +38,37 @@ public class Stage : Object
});
}
- public StageStatusEnumerator file_status()
+ public async Ggit.Tree? get_head_tree() throws Error
{
- if (d_enumerator == null)
+ if (d_head_tree != null)
{
+ return d_head_tree;
}
+ Error? e = null;
+
+ yield Async.thread(() => {
+ try
+ {
+ var head = d_repository.get_head();
+ var commit = (Ggit.Commit)head.lookup();
+
+ d_head_tree = commit.get_tree();
+ }
+ catch (Error err)
+ {
+ e = err;
+ }
+ });
+
+ if (e != null)
+ {
+ throw e;
+ }
+
+ return d_head_tree;
+ }
+
public StageStatusEnumerator file_status(Ggit.StatusOptions? options = null)
{
return new StageStatusEnumerator(d_repository, options);
@@ -80,12 +106,9 @@ public class Stage : Object
*/
public async void revert(File file) throws Error
{
- yield thread_index((index) => {
- // lookup the tree of HEAD
- var head = d_repository.get_head();
- var commit = (Ggit.Commit)head.lookup();
- var tree = commit.get_tree();
+ var tree = yield get_head_tree();
+ yield thread_index((index) => {
// get path relative to the repository working directory
var wd = d_repository.get_workdir();
var path = wd.get_relative_path(file);
@@ -98,6 +121,7 @@ public class Stage : Object
var blob = d_repository.lookup<Ggit.Blob>(id);
var stream = file.replace(null, false, FileCreateFlags.NONE);
+
stream.write_all(blob.get_raw_content(), null);
stream.close();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]