1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.internal.storage.file;
13
14 import java.io.Serializable;
15
16 import org.eclipse.jgit.internal.JGitText;
17 import org.eclipse.jgit.lib.CheckoutEntry;
18 import org.eclipse.jgit.lib.Constants;
19 import org.eclipse.jgit.lib.ObjectId;
20 import org.eclipse.jgit.lib.PersonIdent;
21 import org.eclipse.jgit.lib.ReflogEntry;
22 import org.eclipse.jgit.util.RawParseUtils;
23
24
25
26
27 public class ReflogEntryImpl implements Serializable, ReflogEntry {
28 private static final long serialVersionUID = 1L;
29
30 private ObjectId oldId;
31
32 private ObjectId newId;
33
34 private PersonIdent who;
35
36 private String comment;
37
38 ReflogEntryImpl(byte[] raw, int pos) {
39 oldId = ObjectId.fromString(raw, pos);
40 pos += Constants.OBJECT_ID_STRING_LENGTH;
41 if (raw[pos++] != ' ')
42 throw new IllegalArgumentException(
43 JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
44 newId = ObjectId.fromString(raw, pos);
45 pos += Constants.OBJECT_ID_STRING_LENGTH;
46 if (raw[pos++] != ' ') {
47 throw new IllegalArgumentException(
48 JGitText.get().rawLogMessageDoesNotParseAsLogEntry);
49 }
50 who = RawParseUtils.parsePersonIdentOnly(raw, pos);
51 int p0 = RawParseUtils.next(raw, pos, '\t');
52 if (p0 >= raw.length)
53 comment = "";
54 else {
55 int p1 = RawParseUtils.nextLF(raw, p0);
56 comment = p1 > p0 ? RawParseUtils.decode(raw, p0, p1 - 1) : "";
57 }
58 }
59
60
61
62
63
64 @Override
65 public ObjectId getOldId() {
66 return oldId;
67 }
68
69
70
71
72
73 @Override
74 public ObjectId getNewId() {
75 return newId;
76 }
77
78
79
80
81
82 @Override
83 public PersonIdent getWho() {
84 return who;
85 }
86
87
88
89
90
91 @Override
92 public String getComment() {
93 return comment;
94 }
95
96
97 @SuppressWarnings("nls")
98 @Override
99 public String toString() {
100 return "Entry[" + oldId.name() + ", " + newId.name() + ", " + getWho()
101 + ", " + getComment() + "]";
102 }
103
104
105
106
107
108 @Override
109 public CheckoutEntry parseCheckout() {
110 if (getComment().startsWith(CheckoutEntryImpl.CHECKOUT_MOVING_FROM)) {
111 return new CheckoutEntryImpl(this);
112 }
113 return null;
114 }
115 }