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.

ReflogEntryImpl.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
  3. * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@dewire.com> 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. package org.eclipse.jgit.internal.storage.file;
  12. import java.io.Serializable;
  13. import org.eclipse.jgit.internal.JGitText;
  14. import org.eclipse.jgit.lib.CheckoutEntry;
  15. import org.eclipse.jgit.lib.Constants;
  16. import org.eclipse.jgit.lib.ObjectId;
  17. import org.eclipse.jgit.lib.PersonIdent;
  18. import org.eclipse.jgit.lib.ReflogEntry;
  19. import org.eclipse.jgit.util.RawParseUtils;
  20. /**
  21. * Parsed reflog entry
  22. */
  23. public class ReflogEntryImpl implements Serializable, ReflogEntry {
  24. private static final long serialVersionUID = 1L;
  25. private ObjectId oldId;
  26. private ObjectId newId;
  27. private PersonIdent who;
  28. private String comment;
  29. ReflogEntryImpl(byte[] raw, int pos) {
  30. oldId = ObjectId.fromString(raw, pos);
  31. pos += Constants.OBJECT_ID_STRING_LENGTH;
  32. if (raw[pos++] != ' ')
  33. throw new IllegalArgumentException(
  34. JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
  35. newId = ObjectId.fromString(raw, pos);
  36. pos += Constants.OBJECT_ID_STRING_LENGTH;
  37. if (raw[pos++] != ' ') {
  38. throw new IllegalArgumentException(
  39. JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
  40. }
  41. who = RawParseUtils.parsePersonIdentOnly(raw, pos);
  42. int p0 = RawParseUtils.next(raw, pos, '\t');
  43. if (p0 >= raw.length)
  44. comment = ""; // personident has no \t, no comment present //$NON-NLS-1$
  45. else {
  46. int p1 = RawParseUtils.nextLF(raw, p0);
  47. comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : ""; //$NON-NLS-1$
  48. }
  49. }
  50. /* (non-Javadoc)
  51. * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getOldId()
  52. */
  53. /** {@inheritDoc} */
  54. @Override
  55. public ObjectId getOldId() {
  56. return oldId;
  57. }
  58. /* (non-Javadoc)
  59. * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getNewId()
  60. */
  61. /** {@inheritDoc} */
  62. @Override
  63. public ObjectId getNewId() {
  64. return newId;
  65. }
  66. /* (non-Javadoc)
  67. * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getWho()
  68. */
  69. /** {@inheritDoc} */
  70. @Override
  71. public PersonIdent getWho() {
  72. return who;
  73. }
  74. /* (non-Javadoc)
  75. * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#getComment()
  76. */
  77. /** {@inheritDoc} */
  78. @Override
  79. public String getComment() {
  80. return comment;
  81. }
  82. /** {@inheritDoc} */
  83. @SuppressWarnings("nls")
  84. @Override
  85. public String toString() {
  86. return "Entry[" + oldId.name() + ", " + newId.name() + ", " + getWho()
  87. + ", " + getComment() + "]";
  88. }
  89. /* (non-Javadoc)
  90. * @see org.eclipse.jgit.internal.storage.file.ReflogEntry#parseCheckout()
  91. */
  92. /** {@inheritDoc} */
  93. @Override
  94. public CheckoutEntry parseCheckout() {
  95. if (getComment().startsWith(CheckoutEntryImpl.CHECKOUT_MOVING_FROM)) {
  96. return new CheckoutEntryImpl(this);
  97. }
  98. return null;
  99. }
  100. }