2 * Copyright (C) 20067 Robin Rosenberg <robin.rosenberg@dewire.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.lib
;
19 import java
.io
.BufferedReader
;
20 import java
.io
.ByteArrayInputStream
;
21 import java
.io
.IOException
;
22 import java
.io
.InputStreamReader
;
24 import org
.spearce
.jgit
.errors
.CorruptObjectException
;
27 private final Repository objdb
;
29 private ObjectId tagId
;
31 private PersonIdent tagger
;
33 private String message
;
41 private ObjectId objId
;
43 public Tag(final Repository db
) {
47 public Tag(final Repository db
, final ObjectId id
, final byte[] raw
) {
50 objId
= ObjectId
.fromString(raw
, 7);
54 public PersonIdent
getAuthor() {
59 public void setAuthor(final PersonIdent a
) {
63 public String
getMessage() {
68 private void decode() {
69 // FIXME: handle I/O errors
72 BufferedReader br
= new BufferedReader(new InputStreamReader(
73 new ByteArrayInputStream(raw
)));
74 String n
= br
.readLine();
75 if (n
== null || !n
.startsWith("object ")) {
76 throw new CorruptObjectException(tagId
, "no object");
78 objId
= new ObjectId(n
.substring(7));
80 if (n
== null || !n
.startsWith("type ")) {
81 throw new CorruptObjectException(tagId
, "no type");
83 type
= n
.substring("type ".length());
86 if (n
== null || !n
.startsWith("tag ")) {
87 throw new CorruptObjectException(tagId
, "no tag name");
89 tag
= n
.substring("tag ".length());
92 if (n
== null || !n
.startsWith("tagger ")) {
93 throw new CorruptObjectException(tagId
, "no tagger");
95 tagger
= new PersonIdent(n
.substring("tagger ".length()));
98 if (n
== null || !n
.equals("")) {
99 throw new CorruptObjectException(tagId
,
102 StringBuffer tempMessage
= new StringBuffer();
103 char[] readBuf
= new char[2048];
105 while ((readLen
= br
.read(readBuf
)) > 0) {
106 tempMessage
.append(readBuf
, 0, readLen
);
108 message
= tempMessage
.toString();
109 } catch (IOException e
) {
117 public void setMessage(final String m
) {
121 public void tag() throws IOException
{
122 if (getTagId() != null)
123 throw new IllegalStateException("exists " + getTagId());
124 setTagId(new ObjectWriter(objdb
).writeTag(this));
127 public String
toString() {
128 return "tag[" + getTag() + getType() + getObjId() + " " + getAuthor() + "]";
131 public ObjectId
getTagId() {
135 public void setTagId(ObjectId tagId
) {
139 public PersonIdent
getTagger() {
144 public void setTagger(PersonIdent tagger
) {
145 this.tagger
= tagger
;
148 public String
getType() {
153 public void setType(String type
) {
157 public String
getTag() {
161 public void setTag(String tag
) {
165 public ObjectId
getObjId() {
169 public void setObjId(ObjectId objId
) {