From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [PATCH] Implement simple tags
Date: Mon, 14 May 2007 01:39:14 +0200 [thread overview]
Message-ID: <11790995571082-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <11790995572233-git-send-email-robin.rosenberg@dewire.com>
This is just a reference in <gitdir>/refs/tags with the SHA-1
of the tagged object.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../src/org/spearce/jgit/lib/Repository.java | 14 +++++++-------
org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java | 20 ++++++++++++++++----
.../tst/org/spearce/jgit/lib/T0003_Basic.java | 13 +++++++++++++
3 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index 482f41d..76191be 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -262,17 +262,17 @@ public class Repository {
public Tag mapTag(String revstr) throws IOException {
final ObjectId id = resolve(revstr);
- return id != null ? mapTag(id) : null;
+ return id != null ? mapTag(revstr, id) : null;
}
- public Tag mapTag(final ObjectId id) throws IOException {
+ public Tag mapTag(final String refName, final ObjectId id) throws IOException {
final ObjectLoader or = openObject(id);
if (or == null)
return null;
final byte[] raw = or.getBytes();
if (Constants.TYPE_TAG.equals(or.getType()))
- return new Tag(this, id, raw);
- throw new IncorrectObjectTypeException(id, Constants.TYPE_TAG);
+ return new Tag(this, id, refName, raw);
+ return new Tag(this, id, refName, null);
}
public RefLock lockRef(final String ref) throws IOException {
@@ -469,7 +469,7 @@ public class Repository {
return listFilesRecursively(new File(refsDir, "heads"), null);
}
- public Collection getTags() {
+ public Collection<String> getTags() {
return listFilesRecursively(new File(refsDir, "tags"), null);
}
@@ -535,10 +535,10 @@ public class Repository {
return ret;
}
- private Collection listFilesRecursively(File root, File start) {
+ private Collection<String> listFilesRecursively(File root, File start) {
if (start == null)
start = root;
- Collection ret = new ArrayList();
+ Collection<String> ret = new ArrayList();
File[] files = start.listFiles();
for (int i = 0; i < files.length; ++i) {
if (files[i].isDirectory())
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
index 877c440..d5c6b54 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Tag.java
@@ -44,10 +44,16 @@ public class Tag {
objdb = db;
}
- public Tag(final Repository db, final ObjectId id, final byte[] raw) {
+ public Tag(final Repository db, final ObjectId id, String refName, final byte[] raw) {
objdb = db;
- tagId = id;
- objId = ObjectId.fromString(raw, 7);
+ if (raw != null) {
+ tagId = id;
+ objId = ObjectId.fromString(raw, 7);
+ } else
+ objId = id;
+ if (refName.startsWith("refs/tags/"))
+ refName = refName.substring(10);
+ tag = refName;
this.raw = raw;
}
@@ -119,7 +125,13 @@ public class Tag {
public void tag() throws IOException {
if (getTagId() != null)
throw new IllegalStateException("exists " + getTagId());
- setTagId(new ObjectWriter(objdb).writeTag(this));
+ if (tagger!=null || message!=null || type!=null) {
+ ObjectId tagid = new ObjectWriter(objdb).writeTag(this);
+ setTagId(tagid);
+ objdb.writeRef("refs/heads/"+getTag(),tagid);
+ } else {
+ objdb.writeRef("refs/heads/"+getTag(),objId);
+ }
}
public String toString() {
diff --git a/org.spearce.jgit/tst/org/spearce/jgit/lib/T0003_Basic.java b/org.spearce.jgit/tst/org/spearce/jgit/lib/T0003_Basic.java
index 0302a45..115e391 100644
--- a/org.spearce.jgit/tst/org/spearce/jgit/lib/T0003_Basic.java
+++ b/org.spearce.jgit/tst/org/spearce/jgit/lib/T0003_Basic.java
@@ -338,6 +338,19 @@ public class T0003_Basic extends RepositoryTestCase {
assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().toString());
}
+ public void test020b_createBlobPlainTag() throws IOException {
+ test020_createBlobTag();
+ Tag t = new Tag(db);
+ t.setTag("test020b");
+ t.setObjId(new ObjectId("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
+ t.tag();
+
+ Tag mapTag = db.mapTag("test020b");
+ assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().toString());
+
+ // We do not repeat the plain tag test for other object types
+ }
+
public void test021_createTreeTag() throws IOException {
final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
final Tree almostEmptyTree = new Tree(db);
--
1.5.1.1
next prev parent reply other threads:[~2007-05-13 23:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-13 23:39 This week in EGIT - more tags Robin Rosenberg
2007-05-13 23:39 ` Robin Rosenberg [this message]
2007-05-13 23:39 ` [PATCH] Write refs when creating tags Robin Rosenberg
2007-05-13 23:39 ` [PATCH] Implement packed refs Robin Rosenberg
2007-05-13 23:39 ` [PATCH] Show tags in history view Robin Rosenberg
2007-05-14 22:45 ` [PATCH] Implement packed refs Shawn O. Pearce
2007-05-14 22:49 ` Robin Rosenberg
2007-05-13 23:48 ` The first patch in the series Robin Rosenberg
2007-05-13 23:48 ` [PATCH] Require JDK1.5 Robin Rosenberg
2007-05-14 1:07 ` Grzegorz Kulewski
2007-05-14 7:21 ` Noel Grandin
2007-05-14 17:24 ` Robin Rosenberg
2007-05-14 20:56 ` [PATCH] Set required execution enviroment Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11790995571082-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).