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.

RefTreeNames.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2016, Google Inc. 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.internal.storage.reftree;
  11. import org.eclipse.jgit.lib.RefDatabase;
  12. /**
  13. * Magic reference name logic for RefTrees.
  14. */
  15. public class RefTreeNames {
  16. /**
  17. * Suffix used on a {@link RefTreeDatabase#getTxnNamespace()} for user data.
  18. * <p>
  19. * A {@link RefTreeDatabase}'s namespace may include a subspace (e.g.
  20. * {@code "refs/txn/stage/"}) containing commit objects from the usual user
  21. * portion of the repository (e.g. {@code "refs/heads/"}). These should be
  22. * packed by the garbage collector alongside other user content rather than
  23. * with the RefTree.
  24. */
  25. private static final String STAGE = "stage/"; //$NON-NLS-1$
  26. /**
  27. * Determine if the reference is likely to be a RefTree.
  28. *
  29. * @param refdb
  30. * database instance.
  31. * @param ref
  32. * reference name.
  33. * @return {@code true} if the reference is a RefTree.
  34. */
  35. public static boolean isRefTree(RefDatabase refdb, String ref) {
  36. if (refdb instanceof RefTreeDatabase) {
  37. RefTreeDatabase b = (RefTreeDatabase) refdb;
  38. if (ref.equals(b.getTxnCommitted())) {
  39. return true;
  40. }
  41. String namespace = b.getTxnNamespace();
  42. if (namespace != null
  43. && ref.startsWith(namespace)
  44. && !ref.startsWith(namespace + STAGE)) {
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. private RefTreeNames() {
  51. }
  52. }