View Javadoc
1   /*
2    * Copyright (C) 2009, Google Inc.
3    * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  
12  package org.eclipse.jgit.pgm;
13  
14  import java.io.BufferedInputStream;
15  import java.io.IOException;
16  
17  import org.eclipse.jgit.internal.storage.file.ObjectDirectoryPackParser;
18  import org.eclipse.jgit.lib.ObjectInserter;
19  import org.eclipse.jgit.lib.TextProgressMonitor;
20  import org.eclipse.jgit.transport.PackParser;
21  import org.kohsuke.args4j.Option;
22  
23  @Command(usage = "usage_IndexPack")
24  class IndexPack extends TextBuiltin {
25  	@Option(name = "--fix-thin", usage = "usage_fixAThinPackToBeComplete")
26  	private boolean fixThin;
27  
28  	@Option(name = "--index-version", usage = "usage_indexFileFormatToCreate")
29  	private int indexVersion = -1;
30  
31  	/** {@inheritDoc} */
32  	@Override
33  	protected void run() {
34  		BufferedInputStream in = new BufferedInputStream(ins);
35  		try (ObjectInserter inserter = db.newObjectInserter()) {
36  			PackParser p = inserter.newPackParser(in);
37  			p.setAllowThin(fixThin);
38  			if (indexVersion != -1 && p instanceof ObjectDirectoryPackParser) {
39  				ObjectDirectoryPackParser imp = (ObjectDirectoryPackParser) p;
40  				imp.setIndexVersion(indexVersion);
41  			}
42  			p.parse(new TextProgressMonitor(errw));
43  			inserter.flush();
44  		} catch (IOException e) {
45  			throw die(e.getMessage(), e);
46  		}
47  	}
48  }