Ejemplo n.º 1
0
  public boolean hasSegment(long fromTime, long toTime) {
    Segment segment = getLastSegment();

    while (segment != null) {
      if (segment.getLastCommitTime() < fromTime) {
        return false;
      }

      if (segment.getFirstVisualTime() < toTime) {
        return true;
      }

      segment = segment.getPreviousInTrack();
    }

    return false;
  }
Ejemplo n.º 2
0
  private Segment getOrCreateSegment(Branch branch, long time, boolean afterLast) {
    if (!afterLast && firstCommit != null) {
      Segment[] rowSegments = firstCommit.getRowSegments();
      for (int i = 0; i < rowSegments.length; i++) {
        Segment rowSegment = rowSegments[i];
        if (rowSegment != null && !rowSegment.isComplete()) {
          Branch rowBranch = rowSegment.getBranch();
          boolean complete = rowBranch.getBaseCommitTime() == time;
          rowSegment.adjustVisualTime(time, complete);
        }
      }
    }

    Segment bestSegment = null;
    long visualTime = 0;

    for (int i = 0; i < tracks.length; i++) {
      Track track = tracks[i];

      if (afterLast) {
        Segment lastSegment = track.getLastSegment();
        if (lastSegment != null) {
          if (lastSegment.getBranch() == branch) {
            // If the last segment of this track has the same branch, then just extend it
            return lastSegment;
          }

          if (branch.getBaseCommitBranch() == lastSegment.getBranch()) {
            // Don't block the tracks with the base commit
            continue;
          }

          if (lastCommit != null && lastCommit.getTime() == lastSegment.getLastCommitTime()) {
            // Don't block the track of the last commit
            continue;
          }

          if (visualTime == 0) {
            Segment lastBranchSegment = branch.getLastSegment();
            if (lastBranchSegment != null) {
              visualTime = lastBranchSegment.getLastCommitTime();
            } else {
              visualTime = branch.getBaseCommitTime();
            }
          }

          if (bestSegment == null && lastSegment.getLastCommitTime() < visualTime) {
            bestSegment = lastSegment;
          }
        }
      } else {
        Segment firstSegment = track.getFirstSegment();
        if (firstSegment != null) {
          Branch firstBranch = firstSegment.getBranch();
          if (firstBranch == branch) {
            // If the first segment of this track has the same branch, then just extend it
            return firstSegment;
          }

          if (bestSegment == null) {
            if (!firstSegment.isComplete()) {
              // Don't block the tracks with incomplete segments
              continue;
            }

            if (firstBranch.getBaseCommitBranch() == branch) {
              // Don't block the tracks with the base commit
              continue;
            }

            if (firstSegment.getFirstVisualTime() > branch.getFirstCommitTime()) {
              bestSegment = firstSegment;
            }
          }
        }
      }
    }

    Track track;
    if (bestSegment != null) {
      track = bestSegment.getTrack();
    } else {
      track = createTrack();
    }

    Segment segment = new Segment(track, branch);
    track.addSegment(segment, afterLast);
    branch.addSegment(segment, afterLast);

    if (visualTime != 0) {
      segment.adjustVisualTime(visualTime, true);
    }

    return segment;
  }