]> source.dussan.org Git - jgit.git/commitdiff
Add shortening of note ref names to NoteMap 04/3504/3
authorKevin Sawicki <kevin@github.com>
Mon, 23 May 2011 18:39:33 +0000 (11:39 -0700)
committerKevin Sawicki <kevin@github.com>
Mon, 23 May 2011 18:39:33 +0000 (11:39 -0700)
Change-Id: I224190bbb41c7cbea38388d0148ecc6dc68f3a14
Signed-off-by: Kevin Sawicki <kevin@github.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMap.java

index 94fdc69e80c77ddc4bfa4c13c204119472c58a93..84b10f3c538a3c0ce0e66bf76157ea3e8b2c42d8 100644 (file)
@@ -522,6 +522,14 @@ public class NoteMapTest extends RepositoryTestCase {
                assertEquals(2, count(it));
        }
 
+       public void testShorteningNoteRefName() throws Exception {
+               String expectedShortName = "review";
+               String noteRefName = Constants.R_NOTES + expectedShortName;
+               assertEquals(expectedShortName, NoteMap.shortenRefName(noteRefName));
+               String nonNoteRefName = Constants.R_HEADS + expectedShortName;
+               assertEquals(nonNoteRefName, NoteMap.shortenRefName(expectedShortName));
+       }
+
        private RevCommit commitNoteMap(NoteMap map) throws IOException {
                tr.tick(600);
 
index 0d4d6b9147c2e1df9750976ce02d8746157d49aa..3c4347823b5d9f2eae3f3c760a02318e2069140a 100644 (file)
@@ -80,6 +80,19 @@ public class NoteMap implements Iterable<Note> {
                return r;
        }
 
+       /**
+        * Shorten the note ref name by trimming off the {@link Constants#R_NOTES}
+        * prefix if it exists.
+        *
+        * @param noteRefName
+        * @return a more user friendly note name
+        */
+       public static String shortenRefName(String noteRefName) {
+               if (noteRefName.startsWith(Constants.R_NOTES))
+                       return noteRefName.substring(Constants.R_NOTES.length());
+               return noteRefName;
+       }
+
        /**
         * Load a collection of notes from a branch.
         *