comparison src/org/tmatesoft/hg/internal/KeywordFilter.java @ 418:528b6780a8bd

A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 22 Mar 2012 21:02:20 +0100
parents 2fadf8695f8a
children 9c9c442b5f2e
comparison
equal deleted inserted replaced
417:ccd7d25e5aea 418:528b6780a8bd
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 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 *
69 for (String s : keywords.keySet()) { 69 for (String s : keywords.keySet()) {
70 if (s.length() > l) { 70 if (s.length() > l) {
71 l = s.length(); 71 l = s.length();
72 } 72 }
73 } 73 }
74 // FIXME later may implement #filter() not to read full kw value (just "$kw:"). However, limit of maxLen + 2 would keep valid. 74 // TODO post-1.0 later may implement #filter() not to read full kw value (just "$kw:"). However, limit of maxLen + 2 would keep valid.
75 // for buffers less then minBufferLen, there are chances #filter() implementation would never end 75 // for buffers less then minBufferLen, there are chances #filter() implementation would never end
76 // (i.e. for input "$LongestKey"$ 76 // (i.e. for input "$LongestKey"$
77 minBufferLen = l + 2 + (isExpanding ? 0 : 120 /*any reasonable constant for max possible kw value length*/); 77 minBufferLen = l + 2 + (isExpanding ? 0 : 120 /*any reasonable constant for max possible kw value length*/);
78 } 78 }
79 79
111 int i = indexOf(src, '$', keywordStart+1, true); 111 int i = indexOf(src, '$', keywordStart+1, true);
112 if (i == -1) { 112 if (i == -1) {
113 // end of buffer reached 113 // end of buffer reached
114 if (rv == null) { 114 if (rv == null) {
115 if (keywordStart == x) { 115 if (keywordStart == x) {
116 // FIXME in fact, x might be equal to keywordStart and to src.position() here ('$' is first character in the buffer, 116 // TODO post-1.0 in fact, x might be equal to keywordStart and to src.position() here ('$' is first character in the buffer,
117 // and there are no other '$' not eols till the end of the buffer). This would lead to deadlock (filter won't consume any 117 // and there are no other '$' not eols till the end of the buffer). This would lead to deadlock (filter won't consume any
118 // bytes). To prevent this, either shall copy bytes [keywordStart..buffer.limit()) to local buffer and use it on the next invocation, 118 // bytes). To prevent this, either shall copy bytes [keywordStart..buffer.limit()) to local buffer and use it on the next invocation,
119 // or add lookup of the keywords right after first '$' is found (do not wait for closing '$'). For now, large enough src buffer would be sufficient 119 // or add lookup of the keywords right after first '$' is found (do not wait for closing '$'). For now, large enough src buffer would be sufficient
120 // not to run into such situation 120 // not to run into such situation
121 throw new IllegalStateException("Try src buffer of a greater size"); 121 throw new IllegalStateException("Try src buffer of a greater size");
257 return String.format("%s,v %s %s %s", path, revision(), date(), username()); 257 return String.format("%s,v %s %s %s", path, revision(), date(), username());
258 } 258 }
259 259
260 private String revision() { 260 private String revision() {
261 try { 261 try {
262 // FIXME add cset's nodeid into Changeset class 262 // TODO post-1.0 Either add cset's nodeid into Changeset class or use own inspector
263 // when accessing changelog, see below, #getChangeset
263 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP); 264 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP);
264 return repo.getChangelog().getRevision(csetRev).shortNotation(); 265 return repo.getChangelog().getRevision(csetRev).shortNotation();
265 } catch (HgException ex) { 266 } catch (HgException ex) {
266 HgInternals.getContext(repo).getLog().error(getClass(), ex, null); 267 HgInternals.getContext(repo).getLog().error(getClass(), ex, null);
267 return Nodeid.NULL.shortNotation(); // XXX perhaps, might return anything better? Not sure how hg approaches this. 268 return Nodeid.NULL.shortNotation(); // XXX perhaps, might return anything better? Not sure how hg approaches this.
288 return String.format("%tY/%<tm/%<td %<tH:%<tM:%<tS", d); 289 return String.format("%tY/%<tm/%<td %<tH:%<tM:%<tS", d);
289 } 290 }
290 291
291 private RawChangeset getChangeset() throws HgInvalidControlFileException { 292 private RawChangeset getChangeset() throws HgInvalidControlFileException {
292 if (latestFileCset == null) { 293 if (latestFileCset == null) {
293 // XXX consider use of ChangelogHelper 294 // TODO post-1.0 Use of TIP is likely incorrect in cases when working copy is not based
295 // on latest revision. Perhaps, a constant like HgRepository.DIRSTATE_PARENT may come handy
296 // Besides, it's reasonable to pass own inspector instead of implicit use of RawCsetCollector
297 // to get changeset nodeid/index right away. Also check ChangelogHelper if may be of any use
294 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP); 298 int csetRev = repo.getFileNode(path).getChangesetRevisionIndex(HgRepository.TIP);
295 latestFileCset = repo.getChangelog().range(csetRev, csetRev).get(0); 299 latestFileCset = repo.getChangelog().range(csetRev, csetRev).get(0);
296 } 300 }
297 return latestFileCset; 301 return latestFileCset;
298 } 302 }