diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-08-20 15:18:25 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-08-20 17:38:53 -0700 |
commit | 707912b35d3375ea70808e176e028aa086d01451 (patch) | |
tree | 720f2af31a599e54a714e683f7385a1fc8fbb6b4 /org.eclipse.jgit.pgm | |
parent | b46b635c0389e01a55b2f9c490e5b6c54a8ce640 (diff) | |
download | jgit-707912b35d3375ea70808e176e028aa086d01451.tar.gz jgit-707912b35d3375ea70808e176e028aa086d01451.zip |
Make Tag class only for writing
The Tag class now only supports the creation of an annotated tag
object. To read an annotated tag, applictions should use RevTag.
This permits us to have exactly one implementation, and RevTag's
is faster and more bug-free.
Change-Id: Ib573f7e15f36855112815269385c21dea532e2cf
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.pgm')
3 files changed, 38 insertions, 8 deletions
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties index 2fff6d4630..dc738d3856 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties @@ -44,6 +44,7 @@ expectedNumberOfbytes=Expected {0} bytes. exporting=Exporting {0} failedToCommitIndex=failed to commit index failedToLockIndex=failed to lock index +failedToLockTag=Failed to lock tag {0}: {1} fatalError=fatal: {0} fatalErrorTagExists=fatal: tag '{0}' exists fatalThisProgramWillDestroyTheRepository=fatal: This program will destroy the repository\nfatal:\nfatal:\nfatal: {0}\nfatal:\nfatal: To continue, add {1} to the command line\nfatal: diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java index 14dcb1f50d..dd0f6dbea6 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java @@ -97,6 +97,7 @@ public class CLIText extends TranslationBundle { /***/ public String exporting; /***/ public String failedToCommitIndex; /***/ public String failedToLockIndex; + /***/ public String failedToLockTag; /***/ public String fatalError; /***/ public String fatalErrorTagExists; /***/ public String fatalThisProgramWillDestroyTheRepository; diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java index c798950a2e..df986a88bc 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java @@ -51,8 +51,10 @@ import java.text.MessageFormat; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.lib.RefUpdate; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -80,19 +82,45 @@ class Tag extends TextBuiltin { if (!tagName.startsWith(Constants.R_TAGS)) tagName = Constants.R_TAGS + tagName; + + String shortName = tagName.substring(Constants.R_TAGS.length()); if (!force && db.resolve(tagName) != null) { throw die(MessageFormat.format(CLIText.get().fatalErrorTagExists - , tagName.substring(Constants.R_TAGS.length()))); + , shortName)); } final ObjectLoader ldr = db.open(object); + final ObjectInserter inserter = db.newObjectInserter(); + final ObjectId id; + try { + org.eclipse.jgit.lib.Tag tag = new org.eclipse.jgit.lib.Tag(); + tag.setObjectId(object, ldr.getType()); + tag.setTagger(new PersonIdent(db)); + tag.setMessage(message.replaceAll("\r", "")); + tag.setTag(shortName); + id = inserter.insert(Constants.OBJ_TAG, inserter.format(tag)); + inserter.flush(); + } finally { + inserter.release(); + } + + RefUpdate ru = db.updateRef(tagName); + ru.setForceUpdate(force); + ru.setNewObjectId(id); + ru.setRefLogMessage("tagged " + shortName, false); + switch (ru.update()) { + case NEW: + case FAST_FORWARD: + case FORCED: + break; - org.eclipse.jgit.lib.Tag tag = new org.eclipse.jgit.lib.Tag(db); - tag.setObjId(object); - tag.setType(Constants.typeString(ldr.getType())); - tag.setTagger(new PersonIdent(db)); - tag.setMessage(message.replaceAll("\r", "")); - tag.setTag(tagName.substring(Constants.R_TAGS.length())); - tag.tag(); + case REJECTED: + throw die(MessageFormat.format(CLIText.get().fatalErrorTagExists, + shortName)); + + default: + throw die(MessageFormat.format(CLIText.get().failedToLockTag, + shortName, ru.getResult())); + } } } |