You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HugeCommitMessageTest.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.lib;
  11. import static org.junit.Assert.assertTrue;
  12. import java.util.List;
  13. import org.eclipse.jgit.api.Git;
  14. import org.eclipse.jgit.junit.RepositoryTestCase;
  15. import org.eclipse.jgit.revwalk.RevCommit;
  16. import org.eclipse.jgit.storage.file.WindowCacheConfig;
  17. import org.eclipse.jgit.storage.pack.PackConfig;
  18. import org.junit.Test;
  19. public class HugeCommitMessageTest extends RepositoryTestCase {
  20. private static final int HUGE_SIZE = Math.max(15 * WindowCacheConfig.MB,
  21. PackConfig.DEFAULT_BIG_FILE_THRESHOLD + WindowCacheConfig.MB);
  22. // Larger than the 5MB fallback limit in RevWalk.getCachedBytes(RevObject
  23. // obj, ObjectLoader ldr), and also larger than the default
  24. // streamFileThreshold.
  25. @Test
  26. public void testHugeCommitMessage() throws Exception {
  27. try (Git git = new Git(db)) {
  28. writeTrashFile("foo", "foo");
  29. git.add().addFilepattern("foo").call();
  30. WindowCacheConfig wc = new WindowCacheConfig();
  31. wc.setStreamFileThreshold(HUGE_SIZE + WindowCacheConfig.MB);
  32. wc.install();
  33. RevCommit commit = git.commit()
  34. .setMessage(insanelyHugeCommitMessage()).call();
  35. Ref master = db.findRef("master");
  36. List<Ref> actual = git.branchList().setContains(commit.getName())
  37. .call();
  38. assertTrue("Should be contained in branch master",
  39. actual.contains(master));
  40. }
  41. }
  42. private String insanelyHugeCommitMessage() {
  43. final String oneLine = "012345678901234567890123456789012345678901234567890123456789\n";
  44. StringBuilder b = new StringBuilder(HUGE_SIZE + oneLine.length());
  45. // Give the message a real header; otherwise even writing the reflog
  46. // message may run into troubles because RevCommit.getShortMessage()
  47. // will return the whole message.
  48. b.append("An insanely huge commit message\n\n");
  49. while (b.length() < HUGE_SIZE) {
  50. b.append(oneLine);
  51. }
  52. return b.toString();
  53. }
  54. }