diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-09-22 11:02:16 -0500 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2010-09-22 11:02:50 -0500 |
commit | b3446bf387a082218843e67bd7a06dff0a662b01 (patch) | |
tree | a8dc9fc4d3f577cbe12e594480679d95625af300 /org.eclipse.jgit.pgm | |
parent | e84d826eb6a0649b74d7d374cd6899f4782e51ee (diff) | |
download | jgit-b3446bf387a082218843e67bd7a06dff0a662b01.tar.gz jgit-b3446bf387a082218843e67bd7a06dff0a662b01.zip |
Update Tag to use TagCommand API
Change-Id: I4f7f8e29c47980536398d73f2a71ed2b2c00f4f2
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java | 66 |
1 files changed, 11 insertions, 55 deletions
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 19454b1868..e6849d7e88 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 @@ -1,6 +1,7 @@ /* - * Copyright (C) 2008, Charles O'Farrell <charleso@charleso.org> + * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008, Charles O'Farrell <charleso@charleso.org> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg.lists@dewire.com> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> @@ -47,14 +48,10 @@ package org.eclipse.jgit.pgm; -import java.text.MessageFormat; - -import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.TagCommand; 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.eclipse.jgit.revwalk.RevWalk; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -74,55 +71,14 @@ class Tag extends TextBuiltin { @Override protected void run() throws Exception { - if (object == null) { - object = db.resolve(Constants.HEAD); - if (object == null) - throw die(MessageFormat.format(CLIText.get().cannotResolve, Constants.HEAD)); - } - - if (!tagName.startsWith(Constants.R_TAGS)) - tagName = Constants.R_TAGS + tagName; + Git git = new Git(db); + TagCommand command = git.tag().setForceUpdate(force).setMessage(message).setName(tagName); - String shortName = tagName.substring(Constants.R_TAGS.length()); - if (!force && db.resolve(tagName) != null) { - throw die(MessageFormat.format(CLIText.get().fatalErrorTagExists - , shortName)); + if (object != null) { + RevWalk walk = new RevWalk(db); + command.setObjectId(walk.parseAny(object)); } - final ObjectLoader ldr = db.open(object); - final ObjectInserter inserter = db.newObjectInserter(); - final ObjectId id; - try { - final org.eclipse.jgit.lib.TagBuilder tag; - - tag = new org.eclipse.jgit.lib.TagBuilder(); - tag.setObjectId(object, ldr.getType()); - tag.setTagger(new PersonIdent(db)); - tag.setMessage(message.replaceAll("\r", "")); - tag.setTag(shortName); - id = inserter.insert(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; - - case REJECTED: - throw die(MessageFormat.format(CLIText.get().fatalErrorTagExists, - shortName)); - - default: - throw die(MessageFormat.format(CLIText.get().failedToLockTag, - shortName, ru.getResult())); - } + command.call(); } } |