]> git.proxmox.com Git - libgit2.git/commitdiff
packbuilder: report progress during deltification
authorCarlos Martín Nieto <cmn@dwim.me>
Wed, 6 May 2015 11:09:00 +0000 (13:09 +0200)
committerCarlos Martín Nieto <cmn@dwim.me>
Wed, 13 May 2015 13:52:13 +0000 (15:52 +0200)
This is useful to send to the client while we're performing the work.

The reporting function has a force parameter which makes sure that we
do send out the message of 100% completed, even if this comes before the
next udpate window.

src/pack-objects.c
src/pack-objects.h

index 932764698799c9814b4b95201d436fba7ed98226..e287e33069a7f5969f189e2f5e6d6975b0c4c541 100644 (file)
@@ -893,6 +893,29 @@ static unsigned long free_unpacked(struct unpacked *n)
        return freed_mem;
 }
 
+static int report_delta_progress(git_packbuilder *pb, uint32_t count, bool force)
+{
+       int ret;
+
+       if (pb->progress_cb) {
+               double current_time = git__timer();
+               double elapsed = current_time - pb->last_progress_report_time;
+
+               if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
+                       pb->last_progress_report_time = current_time;
+
+                       ret = pb->progress_cb(
+                               GIT_PACKBUILDER_DELTAFICATION,
+                               count, pb->nr_objects, pb->progress_cb_payload);
+
+                       if (ret)
+                               return giterr_set_after_callback(ret);
+               }
+       }
+
+       return 0;
+}
+
 static int find_deltas(git_packbuilder *pb, git_pobject **list,
                       unsigned int *list_size, unsigned int window,
                       int depth)
@@ -918,6 +941,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
                        break;
                }
 
+               pb->nr_deltified += 1;
+               report_delta_progress(pb, pb->nr_deltified, false);
+
                po = *list++;
                (*list_size)--;
                git_packbuilder__progress_unlock(pb);
@@ -1290,6 +1316,8 @@ static int prepare_pack(git_packbuilder *pb)
                }
        }
 
+       report_delta_progress(pb, pb->nr_objects, true);
+
        pb->done = true;
        git__free(delta_list);
        return 0;
index 9af5c0b095916924fe79839570fc17f516caab74..82dea81f53d0a34dc905139972611b8609315473 100644 (file)
@@ -65,6 +65,7 @@ struct git_packbuilder {
        git_zstream zstream;
 
        uint32_t nr_objects,
+                nr_deltified,
                 nr_alloc,
                 nr_written,
                 nr_remaining;