Browse Source

Merge "Update Tag to use TagCommand API"

stable-0.10
Shawn Pearce 14 years ago committed by Code Review
parent
commit
4ac3d9814c
  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) 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.lists@dewire.com>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
@ -47,14 +48,10 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import java.text.MessageFormat; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.TagCommand;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.revwalk.RevWalk;
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.Argument;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
@ -74,55 +71,14 @@ class Tag extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
if (object == null) { Git git = new Git(db);
object = db.resolve(Constants.HEAD); TagCommand command = git.tag().setForceUpdate(force).setMessage(message).setName(tagName);
if (object == null)
throw die(MessageFormat.format(CLIText.get().cannotResolve, Constants.HEAD));
}
if (!tagName.startsWith(Constants.R_TAGS))
tagName = Constants.R_TAGS + tagName;
String shortName = tagName.substring(Constants.R_TAGS.length()); if (object != null) {
if (!force && db.resolve(tagName) != null) { RevWalk walk = new RevWalk(db);
throw die(MessageFormat.format(CLIText.get().fatalErrorTagExists command.setObjectId(walk.parseAny(object));
, shortName));
} }
final ObjectLoader ldr = db.open(object); command.call();
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()));
}
} }
} }

Loading…
Cancel
Save