KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > RLog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13 import java.util.Date JavaDoc;
14
15 import org.eclipse.team.internal.ccvs.core.CVSTag;
16
17 /**
18  * The "cvs rlog..." command
19  */

20 public class RLog extends RemoteCommand {
21     
22     /*** Local options: specific to rlog ***/
23     public static final LocalOption NO_TAGS = new LocalOption("-N"); //$NON-NLS-1$
24
public static final LocalOption ONLY_INCLUDE_CHANGES = new LocalOption("-S"); //$NON-NLS-1$
25
public static final LocalOption REVISIONS_ON_DEFAULT_BRANCH = new LocalOption("-b"); //$NON-NLS-1$
26
public static final LocalOption LOCAL_DIRECTORY_ONLY = new LocalOption("-l"); //$NON-NLS-1$
27
/**
28      * Makes a -r option for rlog. Here are the currently supported options:
29      *
30      * tag1 tag2 result
31      * ==== ==== =================================
32      * date date date<date (all revisions between date and later)
33      * tag tag tag:tag (all revisions between tag and tag, must be on same branch)
34      * branch date >date (all revisions of date or later)
35      * branch tag tag: (all revisions from tag to the end of branchs tip)
36      *
37      * Valid for: rlog
38      */

39     public static LocalOption makeTagOption(CVSTag tag1, CVSTag tag2) {
40         int type1 = tag1.getType();
41         int type2 = tag2.getType();
42         
43         if(type1 == type2) {
44             switch (type1) {
45                 case CVSTag.HEAD:
46                 case CVSTag.BRANCH:
47                     // A range of branches - all revisions on all the branches in that range.
48
case CVSTag.VERSION:
49                     // Revisions from tag1 to tag2 (they must be on the same branch).
50
return new LocalOption("-r" + tag1.getName() + ":" + tag2.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$
51
case CVSTag.DATE:
52                     // Selects revisions created between DATE1 and DATE2. If DATE1 is after DATE2, use > instead; otherwise, no log messages are retrieved.
53
Date JavaDoc date1 = tag1.asDate();
54                     Date JavaDoc date2 = tag2.asDate();
55                     String JavaDoc operator = "<"; //$NON-NLS-1$
56
if(date1.compareTo(date2) > 0) {
57                         operator = ">"; //$NON-NLS-1$
58
}
59                     return new LocalOption("-d", tag1.getName() + operator + tag2.getName()); //$NON-NLS-1$
60
default:
61                     // Unknow tag type!!!
62
throw new IllegalArgumentException JavaDoc();
63             }
64         }
65         
66         if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.DATE) {
67             return new LocalOption("-d", ">" + tag2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
68
}
69         
70         if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.VERSION) {
71             return new LocalOption("-r" + tag2.getName() + ":", null); //$NON-NLS-1$ //$NON-NLS-2$
72
}
73         
74         // defaults
75
switch (type1) {
76             case CVSTag.HEAD:
77             case CVSTag.BRANCH:
78                 // All revisions on this branch
79
case CVSTag.VERSION:
80                 // revisions in this tag
81
return new LocalOption("-r" + tag1.getName(), null); //$NON-NLS-1$
82
case CVSTag.DATE:
83                 // Revisions at this date tag
84
return new LocalOption("-d", tag1.getName()); //$NON-NLS-1$
85
default:
86                 // Unknow tag type!!!
87
throw new IllegalArgumentException JavaDoc();
88         }
89     }
90     
91     /***
92      * Experimental - Used for obtaining the latest revisions on HEAD or the specified branch.
93      * @param tag1
94      * @return the option to use
95      *
96      * Valid for rlog
97      */

98     public static LocalOption getCurrentTag(CVSTag tag1) {
99         
100         int type = tag1.getType();
101         
102         switch (type){
103             case CVSTag.HEAD:
104             return new LocalOption("-r"); //$NON-NLS-1$
105

106             case CVSTag.BRANCH:
107             return new LocalOption("-r" + tag1.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
108

109             case CVSTag.VERSION:
110             return new LocalOption("-r" + tag1.getName()); //$NON-NLS-1$
111

112             case CVSTag.DATE:
113             return new LocalOption("-d", tag1.asDate().toString()); //$NON-NLS-1$
114
default:
115                 // Unknow tag type!!!
116
throw new IllegalArgumentException JavaDoc();
117         }
118         
119     }
120     
121     /* (non-Javadoc)
122      * @see org.eclipse.team.internal.ccvs.core.client.Request#getRequestId()
123      */

124     protected String JavaDoc getRequestId() {
125         return "rlog"; //$NON-NLS-1$
126
}
127 }
128
Popular Tags