Skip to content

Commit 314d473

Browse files
committed
run 'cvs annotate' with branch tag if there is one and no specific revision is selected
fixes #1632
1 parent 539fec5 commit 314d473

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
775775

776776
<!-- Change root in CVS test repository -->
777777
<!-- Strange indentation in line two levels below to get newline correctly -->
778+
<!-- This will be changed again in the CVS tests -->
778779
<concat destfile="${test.cvs.repo}/CVS/Root" append="no" force="yes" eol="unix">${basedir}/${test.cvs.root}/
779780
</concat>
780781

src/org/opensolaris/opengrok/history/CVSRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ Annotation annotate(File file, String revision) throws IOException {
296296
if (revision != null) {
297297
cmd.add("-r");
298298
cmd.add(revision);
299+
} else if (getBranch() != null && !getBranch().isEmpty()) {
300+
cmd.add("-r");
301+
cmd.add(getBranch());
299302
}
300303
cmd.add(file.getName());
301304

test/org/opensolaris/opengrok/history/CVSRepositoryTest.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import static org.junit.Assert.*;
4545
import org.opensolaris.opengrok.util.Executor;
46+
import org.opensolaris.opengrok.util.IOUtils;
4647
import org.opensolaris.opengrok.util.TestRepository;
4748

4849
/**
@@ -78,24 +79,15 @@ private void setUpTestRepository() throws IOException {
7879
repository = new TestRepository();
7980
repository.create(getClass().getResourceAsStream("repositories.zip"));
8081

81-
// Fix the CVS/Root so that it points to the temporary directory
82-
// rather than the workspace directory.
83-
// Normally this would be bad idea since every subdirectory includes
84-
// CVS/Root file however in this case there is just one such file
85-
// as the repository is flat in terms of directory structure.
86-
// This is done so that 'cvs update' does not change the "upstream"
87-
// cvsroot directory entries.
88-
// The alternative would be to checkout cvsrepo from cvsroot.
89-
// XXX no proper path separators + newline char below
90-
File root = new File(repository.getSourceRoot(), "cvs_test/cvsrepo/CVS/Root");
91-
if (root.isFile()) {
92-
FileChannel outChan = new FileOutputStream(root, true).getChannel();
93-
outChan.truncate(0);
94-
outChan.close();
95-
}
96-
FileWriter fw = new FileWriter(root);
97-
fw.write(repository.getSourceRoot() + "/cvs_test/cvsroot\n");
98-
fw.close();
82+
// Checkout cvsrepo anew in order to get the CVS/Root files point to
83+
// the temporary directory rather than the OpenGrok workspace directory
84+
// it was created from. This is necessary since 'cvs update' changes
85+
// the CVS parent directory after branch has been created.
86+
File root = new File(repository.getSourceRoot(), "cvs_test");
87+
File cvsrepodir = new File(root, "cvsrepo");
88+
IOUtils.removeRecursive(cvsrepodir.toPath());
89+
File cvsroot = new File(root, "cvsroot");
90+
runCvsCommand(root, "-d", cvsroot.getAbsolutePath(), "checkout", "cvsrepo");
9991
}
10092

10193
@After
@@ -114,23 +106,21 @@ public void setUp() {
114106
}
115107

116108
/**
117-
* Run the 'cvs' command.
109+
* Run the 'cvs' command with some arguments.
118110
*
119111
* @param reposRoot directory of the repository root
120-
* @param command command to run
121-
* @param arg argument to use for the command
112+
* @param args arguments to use for the command
122113
*/
123-
private static void runCvsCommand(File reposRoot, String command, String ... args) {
114+
private static void runCvsCommand(File reposRoot, String ... args) {
124115
List<String> cmdargs = new ArrayList<>();
125116
cmdargs.add(CVSRepository.CMD_FALLBACK);
126-
cmdargs.add(command);
127117
for (String arg: args) {
128118
cmdargs.add(arg);
129119
}
130120
Executor exec = new Executor(cmdargs, reposRoot);
131121
int exitCode = exec.exec();
132122
if (exitCode != 0) {
133-
fail("cvs " + command + " failed."
123+
fail("cvs command '" + cmdargs.toString() + "'failed."
134124
+ "\nexit code: " + exitCode
135125
+ "\nstdout:\n" + exec.getOutputString()
136126
+ "\nstderr:\n" + exec.getErrorString());
@@ -152,7 +142,8 @@ public void testGetBranchNoBranch() throws Exception {
152142
}
153143

154144
/**
155-
* Get the CVS repository, create new branch and verify getBranch() returns it.
145+
* Get the CVS repository, create new branch and verify getBranch() returns it
146+
* and check newly added commits annotate with branch revision numbers.
156147
* @throws Exception
157148
*/
158149
@Test
@@ -171,6 +162,20 @@ public void testGetBranchNewBranch() throws Exception {
171162
= (CVSRepository) RepositoryFactory.getRepository(root);
172163

173164
assertEquals("mybranch", cvsrepo.getBranch());
165+
166+
// Change the content and commit.
167+
File mainC = new File(root, "main.c");
168+
FileChannel outChan = new FileOutputStream(mainC, true).getChannel();
169+
outChan.truncate(0);
170+
outChan.close();
171+
FileWriter fw = new FileWriter(mainC);
172+
fw.write("#include <foo.h>\n");
173+
fw.close();
174+
runCvsCommand(root, "commit", "-m", "change on a branch", "main.c");
175+
176+
// Check that annotation for the changed line has branch revision.
177+
Annotation annotation = cvsrepo.annotate(mainC, null);
178+
assertEquals("1.2.2.1", annotation.getRevision(1));
174179
}
175180

176181
/**

0 commit comments

Comments
 (0)