aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java
blob: 9d26978d661b4ec6e21f2d8c5773a8bd82a1c224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2023, Google LLC and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.internal.storage.dfs;

import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackList;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.transport.InMemoryPack;
import org.eclipse.jgit.transport.PackParser;
import org.junit.Before;
import org.junit.Test;

public class DfsPackParserTest {
  private InMemoryRepository repo;


	@Before
	public void setUp() throws Exception {
		DfsRepositoryDescription desc = new DfsRepositoryDescription("test");
		repo = new InMemoryRepository(desc);
		repo.getConfig().setInt(CONFIG_PACK_SECTION, null,
				CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX, 0);
	}

	@Test
	public void parse_writeObjSizeIdx() throws IOException {
		InMemoryPack pack = new InMemoryPack();

		// Sha1 of the blob "a"
		ObjectId blobA = ObjectId
				.fromString("2e65efe2a145dda7ee51d1741299f848e5bf752e");

		pack.header(2);
		pack.write(Constants.OBJ_BLOB << 4 | 1);
		pack.deflate(new byte[] { 'a' });

		pack.write(Constants.OBJ_REF_DELTA << 4 | 4);
		pack.copyRaw(blobA);
		pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' });
		pack.digest();

		try (ObjectInserter ins = repo.newObjectInserter()) {
			PackParser parser = ins.newPackParser(pack.toInputStream());
			parser.parse(NullProgressMonitor.INSTANCE,
					NullProgressMonitor.INSTANCE);
			ins.flush();
		}

		repo.getObjectDatabase().getReaderOptions().setUseObjectSizeIndex(true);
		DfsReader reader = repo.getObjectDatabase().newReader();
		PackList packList = repo.getObjectDatabase().getPackList();
		assertEquals(1, packList.packs.length);
		assertEquals(1, packList.packs[0].getIndexedObjectSize(reader,
				packList.packs[0].findIdxPosition(reader, blobA)));
	}
}