1 /******************************************************************************* 2 * Copyright (c) 2000, 2006 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.internal.ccvs.core.client; 15 16 import java.util.Date; 17 18 import org.eclipse.team.internal.ccvs.core.CVSTag; 19 20 /** 21 * The "cvs rlog..." command 22 */ 23 public class RLog extends RemoteCommand { 24 25 /*** Local options: specific to rlog ***/ 26 public static final LocalOption NO_TAGS = new LocalOption("-N"); //$NON-NLS-1$ 27 public static final LocalOption ONLY_INCLUDE_CHANGES = new LocalOption("-S"); //$NON-NLS-1$ 28 public static final LocalOption REVISIONS_ON_DEFAULT_BRANCH = new LocalOption("-b"); //$NON-NLS-1$ 29 public static final LocalOption LOCAL_DIRECTORY_ONLY = new LocalOption("-l"); //$NON-NLS-1$ 30 /** 31 * Makes a -r option for rlog. Here are the currently supported options: 32 * 33 * <pre>{@code 34 * tag1 tag2 result 35 * ====== ==== ================================= 36 * date date date<date (all revisions between date and later) 37 * tag tag tag:tag (all revisions between tag and tag, must be on same branch) 38 * branch date >date (all revisions of date or later) 39 * branch tag tag: (all revisions from tag to the end of branchs tip) 40 * }</pre> 41 * Valid for: rlog 42 */ makeTagOption(CVSTag tag1, CVSTag tag2)43 public static LocalOption makeTagOption(CVSTag tag1, CVSTag tag2) { 44 int type1 = tag1.getType(); 45 int type2 = tag2.getType(); 46 47 if(type1 == type2) { 48 switch (type1) { 49 case CVSTag.HEAD: 50 case CVSTag.BRANCH: 51 // A range of branches - all revisions on all the branches in that range. 52 case CVSTag.VERSION: 53 // Revisions from tag1 to tag2 (they must be on the same branch). 54 return new LocalOption("-r" + tag1.getName() + ":" + tag2.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ 55 case CVSTag.DATE: 56 // Selects revisions created between DATE1 and DATE2. If DATE1 is after DATE2, use > instead; otherwise, no log messages are retrieved. 57 Date date1 = tag1.asDate(); 58 Date date2 = tag2.asDate(); 59 String operator = "<"; //$NON-NLS-1$ 60 if(date1.compareTo(date2) > 0) { 61 operator = ">"; //$NON-NLS-1$ 62 } 63 return new LocalOption("-d", tag1.getName() + operator + tag2.getName()); //$NON-NLS-1$ 64 default: 65 // Unknow tag type!!! 66 throw new IllegalArgumentException(); 67 } 68 } 69 70 if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.DATE) { 71 return new LocalOption("-d", ">" + tag2.getName()); //$NON-NLS-1$ //$NON-NLS-2$ 72 } 73 74 if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.VERSION) { 75 return new LocalOption("-r" + tag2.getName() + ":", null); //$NON-NLS-1$ //$NON-NLS-2$ 76 } 77 78 // defaults 79 switch (type1) { 80 case CVSTag.HEAD: 81 case CVSTag.BRANCH: 82 // All revisions on this branch 83 case CVSTag.VERSION: 84 // revisions in this tag 85 return new LocalOption("-r" + tag1.getName(), null); //$NON-NLS-1$ 86 case CVSTag.DATE: 87 // Revisions at this date tag 88 return new LocalOption("-d", tag1.getName()); //$NON-NLS-1$ 89 default: 90 // Unknow tag type!!! 91 throw new IllegalArgumentException(); 92 } 93 } 94 95 /*** 96 * Experimental - Used for obtaining the latest revisions on HEAD or the specified branch. 97 * @param tag1 98 * @return the option to use 99 * 100 * Valid for rlog 101 */ getCurrentTag(CVSTag tag1)102 public static LocalOption getCurrentTag(CVSTag tag1) { 103 104 int type = tag1.getType(); 105 106 switch (type){ 107 case CVSTag.HEAD: 108 return new LocalOption("-r"); //$NON-NLS-1$ 109 110 case CVSTag.BRANCH: 111 return new LocalOption("-r" + tag1.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ 112 113 case CVSTag.VERSION: 114 return new LocalOption("-r" + tag1.getName()); //$NON-NLS-1$ 115 116 case CVSTag.DATE: 117 return new LocalOption("-d", tag1.asDate().toString()); //$NON-NLS-1$ 118 default: 119 // Unknow tag type!!! 120 throw new IllegalArgumentException(); 121 } 122 123 } 124 125 @Override getRequestId()126 protected String getRequestId() { 127 return "rlog"; //$NON-NLS-1$ 128 } 129 } 130