package org.dstadler.jgit.porcelain;

/*
   Copyright 2013, 2014 Dominik Stadler

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

import java.io.IOException;
import java.util.Map;
import java.util.Properties;

import org.dstadler.jgit.helper.CookbookHelper;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;



/**
 * Simple snippet which shows how to execute the "gc" command to remove unused
 * objects from the .git directory.
 *
 * @author dominik.stadler at gmx.at
 */
public class CollectGarbage {

    public static void main(String[] args) throws IOException, GitAPIException {
        try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
            try (Git git = new Git(repository)) {
                Properties ret = git.gc().call();
                for(Map.Entry<Object, Object> entry : ret.entrySet()) {
                    System.out.println("Ret: " + entry.getKey() + ": " + entry.getValue());
                }
            }
        }
    }
}

@@ -838,24 +838,69 @@
 IException;%0A
+import org.eclipse.jgit.lib.ProgressMonitor;%0A
 import org.e
@@ -927,16 +927,16 @@
 sitory;%0A
-
 %0A%0A%0A/**%0A 
@@ -1381,16 +1381,90 @@
 it.gc().
+%0A                        setProgressMonitor(new PrintlnProgressMonitor()).
 call();%0A
@@ -1637,32 +1637,32 @@
               %7D%0A
-
             %7D%0A  
@@ -1674,11 +1674,712 @@
  %7D%0A    %7D
+%0A%0A    private static class PrintlnProgressMonitor implements ProgressMonitor %7B%0A        @Override%0A        public void start(int totalTasks) %7B%0A            System.out.println(%22Starting work on %22 + totalTasks + %22 tasks%22);%0A        %7D%0A%0A        @Override%0A        public void beginTask(String title, int totalWork) %7B%0A            System.out.println(%22Start %22 + title + %22: %22 + totalWork);%0A        %7D%0A%0A        @Override%0A        public void update(int completed) %7B%0A            System.out.print(completed);%0A        %7D%0A%0A        @Override%0A        public void endTask() %7B%0A            System.out.println(%22Done%22);%0A        %7D%0A%0A        @Override%0A        public boolean isCancelled() %7B%0A            return false;%0A        %7D%0A    %7D
 %0A%7D%0A

Add a progress monitor when calling gc() in the CollectGarbage sample