This commit is contained in:
René Pfeuffer
2020-08-27 10:48:54 +02:00
parent 7d33744e73
commit 565ec3ff3c
4 changed files with 21 additions and 27 deletions

View File

@@ -394,22 +394,15 @@ public final class GitUtil
*/
public static Long getTagTime(org.eclipse.jgit.lib.Repository repository, ObjectId objectId) throws IOException {
try (RevWalk walk = new RevWalk(repository)) {
return GitUtil.getTagTime(repository, walk, objectId);
return GitUtil.getTagTime(walk, objectId);
}
}
/**
* @since 2.5.0
*/
public static Long getTagTime(org.eclipse.jgit.lib.Repository repository,
RevWalk revWalk, ObjectId objectId)
throws IOException {
public static Long getTagTime(RevWalk revWalk, ObjectId objectId) throws IOException {
if (objectId != null) {
if (revWalk == null) {
revWalk = new RevWalk(repository);
}
final RevObject revObject = revWalk.parseAny(objectId);
if (revObject instanceof RevTag) {
return ((RevTag) revObject).getTaggerIdent().getWhen().getTime();

View File

@@ -132,7 +132,7 @@ public class GitTagsCommand extends AbstractGitCommand implements TagsCommand {
if (revObject != null) {
String name = GitUtil.getTagName(ref);
tag = new Tag(name, revObject.getId().name(), GitUtil.getTagTime(repository, revWalk, ref.getObjectId()));
tag = new Tag(name, revObject.getId().name(), GitUtil.getTagTime(revWalk, ref.getObjectId()));
}
} catch (IOException ex) {

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.client.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -89,7 +89,7 @@ public class GitTagCommand implements TagCommand
{
walk = new RevWalk(git.getRepository());
revObject = walk.parseAny(id);
tagTime = GitUtil.getTagTime(git.getRepository(), walk, id);
tagTime = GitUtil.getTagTime(walk, id);
}
finally
{

View File

@@ -21,17 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.api;
import com.google.common.collect.Lists;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.hamcrest.Matchers.*;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -43,9 +37,16 @@ import sonia.scm.repository.spi.HookChangesetProvider;
import sonia.scm.repository.spi.HookChangesetRequest;
import sonia.scm.repository.spi.HookChangesetResponse;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link HgHookTagProvider}.
*
*
* @author Sebastian Sdorra
*/
@RunWith(MockitoJUnitRunner.class)
@@ -53,7 +54,7 @@ public class HgHookTagProviderTest {
@Mock
private HookChangesetProvider changesetProvider;
@InjectMocks
private HgHookTagProvider tagProvider;
@@ -63,9 +64,9 @@ public class HgHookTagProviderTest {
@Test
public void testGetDeletedTags() {
prepareChangesets(new Changeset("1", Long.MIN_VALUE, null));
assertThat(tagProvider.getDeletedTags(), empty());
assertThat(tagProvider.getDeletedTags()).isEmpty();
}
/**
* Tests {@link HgHookTagProvider#getCreatedTags()}.
*/
@@ -77,20 +78,20 @@ public class HgHookTagProviderTest {
c2.getTags().add("2.0.0");
Changeset c3 = new Changeset("3", Long.MIN_VALUE, null);
prepareChangesets(c1, c2, c3);
List<Tag> tags = tagProvider.getCreatedTags();
assertNotNull(tags);
assertEquals(2, tags.size());
Tag t1 = tags.get(0);
assertEquals("1", t1.getRevision());
assertEquals("1.0.0", t1.getName());
Assertions.assertThat(t1.getDate()).contains(Long.MIN_VALUE);
assertThat(t1.getDate()).contains(Long.MIN_VALUE);
Tag t2 = tags.get(1);
assertEquals("2", t2.getRevision());
assertEquals("2.0.0", t2.getName());
Assertions.assertThat(t2.getDate()).contains(Long.MAX_VALUE);
assertThat(t2.getDate()).contains(Long.MAX_VALUE);
}
private void prepareChangesets(Changeset... changesets){