Skip to content

Commit 2bfde70

Browse files
committed
filter out inactive branch tags in Mercurial
fixes #4741
1 parent 358fb5d commit 2bfde70

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/MercurialRepository.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -634,12 +634,15 @@ protected void buildTagList(File directory, CommandTimeoutType cmdType) {
634634
ArrayList<String> argv = new ArrayList<>();
635635
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
636636
argv.add(RepoCommand);
637-
argv.add("tags");
637+
argv.add("log");
638+
argv.add("-b");
639+
argv.add(getBranch());
640+
argv.add("--rev=reverse(tag())");
638641
argv.add("--template");
639642
// Use '|' as a revision separator rather than ':' to avoid collision with the commonly used
640-
// separator within the revision string (which is not used in the 'hg tags' output but better
643+
// separator within the revision string (which is not used in this output but better
641644
// safe than sorry).
642-
argv.add("{rev}|{tag}\\n");
645+
argv.add("{latesttag % \"{rev}|{tag}\\n\"}");
643646

644647
Executor executor = new Executor(argv, directory,
645648
RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));

opengrok-indexer/src/test/java/org/opengrok/indexer/history/MercurialRepositoryTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -483,8 +483,9 @@ void testBuildTagListInitial() throws Exception {
483483
}
484484

485485
/**
486-
* Clone the original repository, add new tag, check that the extracted tags contain the pre-existing
487-
* and new one.
486+
* Clone the original repository, create branch and add tag to the branch, switch back to the original branch,
487+
* add new tag, check that the extracted tags contain the pre-existing and new one
488+
* but not the non-default branch tag.
488489
*/
489490
@Test
490491
void testBuildTagListOneMore() throws Exception {
@@ -494,6 +495,18 @@ void testBuildTagListOneMore() throws Exception {
494495
// Clone the internal repository because it will be modified.
495496
// This avoids interference with other tests in this class.
496497
runHgCommand(this.repositoryRoot, "clone", this.repositoryRoot.toString(), repositoryRootPath.toString());
498+
499+
// Branch the repo and add one changeset.
500+
runHgCommand(repositoryRoot, "unbundle",
501+
Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString());
502+
// Switch to the branch.
503+
runHgCommand(repositoryRoot, "update", "mybranch");
504+
final String branchTagName = "branch_tag";
505+
runHgCommand(repositoryRoot, "tag", branchTagName);
506+
507+
// Switch back to the default branch.
508+
runHgCommand(repositoryRoot, "update", "default");
509+
497510
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
498511
assertNotNull(hgRepo);
499512
// Using double space on purpose to test the parsing of tags.

0 commit comments

Comments
 (0)