Browse Source

Update Tag to use TagCommand API

Change-Id: I4f7f8e29c47980536398d73f2a71ed2b2c00f4f2
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
stable-0.10
Chris Aniszczyk 14 years ago
parent
commit
b3446bf387
  1. 66
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java

66
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();
}
}

Loading…
Cancel
Save