comparison src/org/tmatesoft/hg/core/HgManifestCommand.java @ 565:78a9e26e670d

Refactor common code to initialize changelog revision for a command into standalone class
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 09 Apr 2013 17:15:30 +0200
parents 3ca4ae7bdd38
children 6526d8adbc0f
comparison
equal deleted inserted replaced
564:e6407313bab7 565:78a9e26e670d
1 /* 1 /*
2 * Copyright (c) 2011-2012 TMate Software Ltd 2 * Copyright (c) 2011-2013 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.core; 17 package org.tmatesoft.hg.core;
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.*; 19 import static org.tmatesoft.hg.repo.HgRepository.*;
20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
22 20
23 import java.util.ConcurrentModificationException; 21 import java.util.ConcurrentModificationException;
24 import java.util.LinkedHashMap; 22 import java.util.LinkedHashMap;
25 import java.util.LinkedList; 23 import java.util.LinkedList;
26 import java.util.List; 24 import java.util.List;
27 25
26 import org.tmatesoft.hg.internal.CsetParamKeeper;
28 import org.tmatesoft.hg.internal.PathPool; 27 import org.tmatesoft.hg.internal.PathPool;
29 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
30 import org.tmatesoft.hg.repo.HgManifest; 28 import org.tmatesoft.hg.repo.HgManifest;
29 import org.tmatesoft.hg.repo.HgManifest.Flags;
31 import org.tmatesoft.hg.repo.HgRepository; 30 import org.tmatesoft.hg.repo.HgRepository;
32 import org.tmatesoft.hg.repo.HgManifest.Flags;
33 import org.tmatesoft.hg.repo.HgRuntimeException; 31 import org.tmatesoft.hg.repo.HgRuntimeException;
34 import org.tmatesoft.hg.util.CancelSupport; 32 import org.tmatesoft.hg.util.CancelSupport;
35 import org.tmatesoft.hg.util.CancelledException; 33 import org.tmatesoft.hg.util.CancelledException;
36 import org.tmatesoft.hg.util.Path; 34 import org.tmatesoft.hg.util.Path;
37 import org.tmatesoft.hg.util.PathRewrite; 35 import org.tmatesoft.hg.util.PathRewrite;
68 // XXX if manifest range is different from that of changelog, need conversion utils (external?) 66 // XXX if manifest range is different from that of changelog, need conversion utils (external?)
69 boolean badArgs = rev1 == BAD_REVISION || rev2 == BAD_REVISION || rev1 == WORKING_COPY || rev2 == WORKING_COPY; 67 boolean badArgs = rev1 == BAD_REVISION || rev2 == BAD_REVISION || rev1 == WORKING_COPY || rev2 == WORKING_COPY;
70 badArgs |= rev2 != TIP && rev2 < rev1; // range(3, 1); 68 badArgs |= rev2 != TIP && rev2 < rev1; // range(3, 1);
71 badArgs |= rev1 == TIP && rev2 != TIP; // range(TIP, 2), although this may be legitimate when TIP points to 2 69 badArgs |= rev1 == TIP && rev2 != TIP; // range(TIP, 2), although this may be legitimate when TIP points to 2
72 if (badArgs) { 70 if (badArgs) {
71 // TODO [2.0 API break] throw checked HgBadArgumentException instead
73 throw new IllegalArgumentException(String.format("Bad range: [%d, %d]", rev1, rev2)); 72 throw new IllegalArgumentException(String.format("Bad range: [%d, %d]", rev1, rev2));
74 } 73 }
75 startRev = rev1; 74 startRev = rev1;
76 endRev = rev2; 75 endRev = rev2;
77 return this; 76 return this;
81 * Select changeset for the command using revision index 80 * Select changeset for the command using revision index
82 * @param csetRevisionIndex index of changeset revision 81 * @param csetRevisionIndex index of changeset revision
83 * @return <code>this</code> for convenience. 82 * @return <code>this</code> for convenience.
84 */ 83 */
85 public HgManifestCommand changeset(int csetRevisionIndex) { 84 public HgManifestCommand changeset(int csetRevisionIndex) {
85 // TODO [2.0 API break] shall throw HgBadArgumentException, like other commands do
86 return range(csetRevisionIndex, csetRevisionIndex); 86 return range(csetRevisionIndex, csetRevisionIndex);
87 } 87 }
88 88
89 /** 89 /**
90 * Select changeset for the command 90 * Select changeset for the command
93 * @return <code>this</code> for convenience 93 * @return <code>this</code> for convenience
94 * @throws HgBadArgumentException if failed to find supplied changeset revision 94 * @throws HgBadArgumentException if failed to find supplied changeset revision
95 */ 95 */
96 public HgManifestCommand changeset(Nodeid nid) throws HgBadArgumentException { 96 public HgManifestCommand changeset(Nodeid nid) throws HgBadArgumentException {
97 // XXX also see HgLogCommand#changeset(Nodeid) 97 // XXX also see HgLogCommand#changeset(Nodeid)
98 try { 98 final int csetRevIndex = new CsetParamKeeper(repo).set(nid).get();
99 final int csetRevIndex = repo.getChangelog().getRevisionIndex(nid); 99 return range(csetRevIndex, csetRevIndex);
100 return range(csetRevIndex, csetRevIndex);
101 } catch (HgInvalidRevisionException ex) {
102 throw new HgBadArgumentException("Can't find revision", ex).setRevision(nid);
103 }
104 } 100 }
105 101
106 public HgManifestCommand dirs(boolean include) { 102 public HgManifestCommand dirs(boolean include) {
107 // XXX whether directories with directories only are include or not 103 // XXX whether directories with directories only are include or not
108 // now lists only directories with files 104 // now lists only directories with files