comparison src/org/tmatesoft/hg/core/HgLogCommand.java @ 403:2747b0723867

FIXMEs: work on exceptions and javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Mar 2012 14:50:51 +0100
parents 1fcc7f7b6d65
children ee8264d80747
comparison
equal deleted inserted replaced
402:1fcc7f7b6d65 403:2747b0723867
511 } 511 }
512 return children; 512 return children;
513 } 513 }
514 514
515 void populate(HgChangeset cs) { 515 void populate(HgChangeset cs) {
516 cachedChangesets.put(cs.getRevision(), cs); 516 cachedChangesets.put(cs.getRevisionIndex(), cs);
517 } 517 }
518 518
519 private HgChangeset[] get(int... changelogRevisionNumber) throws HgInvalidControlFileException { 519 private HgChangeset[] get(int... changelogRevisionIndex) throws HgException {
520 HgChangeset[] rv = new HgChangeset[changelogRevisionNumber.length]; 520 HgChangeset[] rv = new HgChangeset[changelogRevisionIndex.length];
521 IntVector misses = new IntVector(changelogRevisionNumber.length, -1); 521 IntVector misses = new IntVector(changelogRevisionIndex.length, -1);
522 for (int i = 0; i < changelogRevisionNumber.length; i++) { 522 for (int i = 0; i < changelogRevisionIndex.length; i++) {
523 if (changelogRevisionNumber[i] == -1) { 523 if (changelogRevisionIndex[i] == -1) {
524 rv[i] = null; 524 rv[i] = null;
525 continue; 525 continue;
526 } 526 }
527 HgChangeset cached = cachedChangesets.get(changelogRevisionNumber[i]); 527 HgChangeset cached = cachedChangesets.get(changelogRevisionIndex[i]);
528 if (cached != null) { 528 if (cached != null) {
529 rv[i] = cached; 529 rv[i] = cached;
530 } else { 530 } else {
531 misses.add(changelogRevisionNumber[i]); 531 misses.add(changelogRevisionIndex[i]);
532 } 532 }
533 } 533 }
534 if (misses.size() > 0) { 534 if (misses.size() > 0) {
535 final int[] changesets2read = misses.toArray(); 535 final int[] changesets2read = misses.toArray();
536 initTransform(); 536 initTransform();
537 repo.getChangelog().range(this, changesets2read); 537 repo.getChangelog().range(this, changesets2read);
538 for (int changeset2read : changesets2read) { 538 for (int changeset2read : changesets2read) {
539 HgChangeset cs = cachedChangesets.get(changeset2read); 539 HgChangeset cs = cachedChangesets.get(changeset2read);
540 if (cs == null) { 540 if (cs == null) {
541 throw new HgBadStateException(); 541 throw new HgException(String.format("Can't get changeset for revision %d", changeset2read));
542 }
543 // HgChangelog.range may reorder changesets according to their order in the changelog
544 // thus need to find original index
545 boolean sanity = false;
546 for (int i = 0; i < changelogRevisionIndex.length; i++) {
547 if (changelogRevisionIndex[i] == cs.getRevisionIndex()) {
548 rv[i] = cs;
549 sanity = true;
550 break;
542 } 551 }
543 // HgChangelog.range may reorder changesets according to their order in the changelog 552 }
544 // thus need to find original index 553 if (!sanity) {
545 boolean sanity = false; 554 HgInternals.getContext(repo).getLog().error(getClass(), "Index of revision %d:%s doesn't match any of requested", cs.getRevisionIndex(), cs.getNodeid().shortNotation());
546 for (int i = 0; i < changelogRevisionNumber.length; i++) { 555 }
547 if (changelogRevisionNumber[i] == cs.getRevision()) { 556 assert sanity;
548 rv[i] = cs;
549 sanity = true;
550 break;
551 }
552 }
553 assert sanity;
554 } 557 }
555 } 558 }
556 return rv; 559 return rv;
557 } 560 }
558 561
566 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 569 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
567 HgChangeset cs = transform.handle(revisionNumber, nodeid, cset); 570 HgChangeset cs = transform.handle(revisionNumber, nodeid, cset);
568 populate(cs.clone()); 571 populate(cs.clone());
569 } 572 }
570 573
571 public Nodeid changesetRevision() { 574 public Nodeid changesetRevision() throws HgException {
572 if (changesetRevision == null) { 575 if (changesetRevision == null) {
573 changesetRevision = getRevision(historyNode.changeset); 576 changesetRevision = getRevision(historyNode.changeset);
574 } 577 }
575 return changesetRevision; 578 return changesetRevision;
576 } 579 }
577 580
578 public Pair<Nodeid, Nodeid> parentRevisions() { 581 public Pair<Nodeid, Nodeid> parentRevisions() throws HgException {
579 if (parentRevisions == null) { 582 if (parentRevisions == null) {
580 HistoryNode p; 583 HistoryNode p;
581 final Nodeid p1, p2; 584 final Nodeid p1, p2;
582 if ((p = historyNode.parent1) != null) { 585 if ((p = historyNode.parent1) != null) {
583 p1 = getRevision(p.changeset); 586 p1 = getRevision(p.changeset);
592 parentRevisions = new Pair<Nodeid, Nodeid>(p1, p2); 595 parentRevisions = new Pair<Nodeid, Nodeid>(p1, p2);
593 } 596 }
594 return parentRevisions; 597 return parentRevisions;
595 } 598 }
596 599
597 public Collection<Nodeid> childRevisions() { 600 public Collection<Nodeid> childRevisions() throws HgException {
598 if (childRevisions != null) { 601 if (childRevisions != null) {
599 return childRevisions; 602 return childRevisions;
600 } 603 }
601 if (historyNode.children == null) { 604 if (historyNode.children == null) {
602 childRevisions = Collections.emptyList(); 605 childRevisions = Collections.emptyList();
609 } 612 }
610 return childRevisions; 613 return childRevisions;
611 } 614 }
612 615
613 // reading nodeid involves reading index only, guess, can afford not to optimize multiple reads 616 // reading nodeid involves reading index only, guess, can afford not to optimize multiple reads
614 private Nodeid getRevision(int changelogRevisionNumber) { 617 private Nodeid getRevision(int changelogRevisionNumber) throws HgInvalidControlFileException {
615 // XXX pipe through pool 618 // TODO [post-1.0] pipe through pool
616 HgChangeset cs = cachedChangesets.get(changelogRevisionNumber); 619 HgChangeset cs = cachedChangesets.get(changelogRevisionNumber);
617 if (cs != null) { 620 if (cs != null) {
618 return cs.getNodeid(); 621 return cs.getNodeid();
619 } else { 622 } else {
620 try { 623 return repo.getChangelog().getRevision(changelogRevisionNumber);
621 return repo.getChangelog().getRevision(changelogRevisionNumber);
622 } catch (HgException ex) {
623 HgInternals.getContext(repo).getLog().error(getClass(), ex, null);
624 // FIXME propagate, perhaps?
625 return Nodeid.NULL; // FIXME this is quick-n-dirty hack to move forward with introducing exceptions
626 }
627 } 624 }
628 } 625 }
629 } 626 }
630 } 627 }