]> git.proxmox.com Git - libgit2.git/commitdiff
Start the runner
authorCarlos Martín Nieto <carlos@cmartin.tk>
Thu, 7 Jul 2011 17:08:45 +0000 (19:08 +0200)
committerCarlos Martín Nieto <carlos@cmartin.tk>
Tue, 2 Aug 2011 19:41:05 +0000 (21:41 +0200)
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
include/git2/indexer.h
src/indexer.c

index be1752027612502ae2973e52347141bf0fdd3c61..34f25b97cf9dd1534d4a44aaed4b56a207b9459f 100644 (file)
@@ -1,15 +1,19 @@
 #ifndef _INCLUDE_git_indexer_h__
 #define _INCLUDE_git_indexer_h__
 
-typedef struct git_pack_indexer {
-       struct pack_file *pack;
-       git_vector objects;
-       git_vector deltas;
-       struct stat st;
-} git_pack_indexer;
+#include "git2/common.h"
+
+typedef struct git_indexer_stats {
+       unsigned int total;
+       unsigned int parsed;
+} git_indexer_stats;
+
+
+typedef struct git_pack_indexer git_pack_indexer;
 
 GIT_EXTERN(int) git_pack_indexer_new(git_pack_indexer **out, const char *packname);
-GIT_EXTERN(void) git_pack_indexer_free(git_pack_indexer *idx)
+GIT_EXTERN(int) git_pack_indexer_run(git_pack_indexer *idx, int (*cb)(const git_indexer_stats *, void *), void *data);
+GIT_EXTERN(void) git_pack_indexer_free(git_pack_indexer *idx);
 
 
 #endif
index b63efc0883c703970269bc6d0498713a7c8282dd..97f08dae1b11d81d1e34d4b7d7a1162eea1b22fa 100644 (file)
  * Boston, MA 02110-1301, USA.
  */
 
+#include "git2/indexer.h"
+
 #include "common.h"
 #include "pack.h"
+#include "mwindow.h"
 #include "posix.h"
 
+typedef struct git_pack_indexer {
+       struct pack_file *pack;
+       git_vector objects;
+       git_vector deltas;
+       struct stat st;
+       git_indexer_stats stats;
+} git_pack_indexer;
+
 static int parse_header(git_pack_indexer *idx)
 {
        struct pack_header hdr;
@@ -59,6 +70,8 @@ static int parse_header(git_pack_indexer *idx)
        if (error < GIT_SUCCESS)
                goto cleanup;
 
+       idx->stats.total = hdr.hdr_entries;
+
        return GIT_SUCCESS;
 
 cleanup:
@@ -123,6 +136,27 @@ cleanup:
        return error;
 }
 
+/*
+ * Create the index. Every time something interesting happens
+ * (something has been parse or resolved), the callback gets called
+ * with some stats so it can tell the user how hard we're working
+ */
+int git_pack_indexer_run(git_pack_indexer *idx, int (*cb)(const git_indexer_stats *, void *), void *data)
+{
+       git_mwindow_file *mwf = &idx->pack->mwf;
+       int error;
+
+       error = git_mwindow_file_register(mwf);
+       if (error < GIT_SUCCESS)
+               return git__rethrow(error, "Failed to register mwindow file");
+
+       /* notify early */
+       if (cb)
+               cb(&idx->stats, data);
+
+       return error;
+}
+
 void git_pack_indexer_free(git_pack_indexer *idx)
 {
        p_close(idx->pack->pack_fd);