Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] JGit GC unable to remove old pack files on Windows

Hello Matthias,

Thank you a lot.
I've tested with both JGit '5.8.0-SNAPSHOT' and '' – and I confirm that the bug is not reproduced anymore.

On 09.06.2020 19:57, Matthias Sohn wrote:
On Tue, Jun 9, 2020 at 2:13 PM Malyshkin, Denis <dmalyshkin@xxxxxxxxxx> wrote:

The simple example of code, mentioned in the previous email.

class Main {

    private static File REPO_DIR = new File("testRepo");
    private static final String REPO_URL = "";
    public static final String REF_SPEC_BARE = "+refs/heads/*:refs/heads/*";
    public static final String TAG_SPEC = "+refs/tags/*:refs/tags/*";

    public static void main(String[] args) {

        System.out.println("Start cloning...");
        CloneCommand cloneCommand = new CloneCommand();

        try (Git git = {
            Repository repo = git.getRepository();
            System.out.println("Cloned. Press Enter key when the repository is changed...");

            try (Transport tn =, REPO_URL)) {
                ProgressMonitor monitor = new TextProgressMonitor();
                tn.fetch(monitor, Arrays.asList(new RefSpec(REF_SPEC_BARE), new RefSpec(TAG_SPEC)));

            System.out.println("Fetched. Starting GC...");
            GC gc = new GC((FileRepository) repo);
            PackConfig pConfig = new PackConfig(repo);
            pConfig.setBuildBitmaps(false);   // disable bitmap indexes
            System.out.println("GC completed!");
        } catch (Exception e) {


On Tue, Jun 9, 2020 at 5:40 PM Malyshkin, Denis <dmalyshkin@xxxxxxxxxx> wrote:

We found an issue with the JGit GC on Windows.
I've attached a simple example to expose this issue. Steps to reproduce:
  1. Clone some repository using JGit.
  2. Add commits to the repository on the git server side (for example, push commits from another computer).
  3. Fetch the cloned repository using JGit.
  4. Call the JGit GC on the cloned repository.
  5. After the GC the cloned repository 'objects/pack' folder contains all packs -- both existed before the GC and created during the GC.
  6. If you repeat steps 2-4 then new pack files appears on every iteration. And all old pack files remain in the repository 'objects/pack' folder.
It seems this is a bug.
The logic of the bug is the following:
  1. The JGit clone & fetch operations mark the created pack files as 'read-only' in the ObjectDirectoryPackParser.parse method:
  2. JGit GC operation also marks the created pack files as 'read-only' in the GC.writePack method:
  3. JGit uses Files.delete() method in the GC.removeOldPack to remove old pack files:
  4. This Files.delete() method unable to remove 'read-only' files on Windows (please see, throws an exception, but this exception is silently ignored:
  5. As a result all pack files remain in the repository, but nobody knows that something goes wrong:
It seems that the R/O attribute should be cleared before deleting old pack files.

this is which was fixed recently.
Use the nightly build 5.8.0-SNAPSHOT until 5.8 is released next Wednesday.



                    ISS Art website
Best regards,
Denis Malyshkin, Senior C++ Developer
ISS Art, LLC - custom software development company
Skype: dmalyshkin
Phone: +73812909808
 Read ISS Art Blog    Find ISS Art on Facebook    Join ISS Art on LinkedIn    Follow ISS Art on Twitter    Visit ISS Art on
IMPORTANT: The contents of this email and any attachments are confidential and intended for the named recipient(s) only. If you have received this email by mistake, please notify the sender immediately and delete it from your system. You may not copy this email or disclose its contents to anyone. Thank you.

Back to the top