コード例 #1
0
ファイル: Net.java プロジェクト: sthibaudeau/cdo
  Segment[] createRowSegments(long time) {
    Segment[] segments = NO_SEGMENTS;
    for (int i = tracks.length - 1; i >= 0; --i) {
      Track track = tracks[i];
      Segment segment = track.getSegment(time);

      if (segments == NO_SEGMENTS) {
        if (segment == null) {
          continue;
        }

        segments = new Segment[i + 1];
      }

      segments[i] = segment;
    }

    return segments;
  }
コード例 #2
0
ファイル: Net.java プロジェクト: sthibaudeau/cdo
  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;
  }