Examples of ByteArrayChannel


Examples of org.tmatesoft.hg.internal.ByteArrayChannel

  @Test
  public void testKeywordSplitInBuffer() throws Exception {
    initRepo();
    final byte[] in1 = "1\n$Id:whatever".getBytes();
    final byte[] in2 = " continues here$\n3\n".getBytes();
    ByteArrayChannel out = new ByteArrayChannel();
    final Filter kwFilter = createFilter(Filter.Direction.ToRepo);
    out.write(kwFilter.filter(ByteBuffer.wrap(in1)));
    out.write(kwFilter.filter(ByteBuffer.wrap(in2)));
    Assert.assertEquals("1\n$Id$\n3\n", new String(out.toArray()));
    // Same as above, to extreme - only $ in the first buffer
    final Filter kwFilter2 = createFilter(Filter.Direction.ToRepo);
    out = new ByteArrayChannel();
    out.write(kwFilter2.filter(ByteBuffer.wrap("1\n$".getBytes())));
    out.write(kwFilter2.filter(ByteBuffer.wrap("Id:whatever continues here$\n3\n".getBytes())));
    Assert.assertEquals("1\n$Id$\n3\n", new String(out.toArray()));
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

  @Test
  public void testIncompleteKeyword() throws Exception {
    initRepo();
    final byte[] in1 = "1\n$Id:whatever".getBytes();
    final byte[] in2 = " id doesn't close here\n3\n".getBytes();
    ByteArrayChannel out = new ByteArrayChannel();
    final Filter kwFilter = createFilter(Filter.Direction.ToRepo);
    out.write(kwFilter.filter(ByteBuffer.wrap(in1)));
    out.write(kwFilter.filter(ByteBuffer.wrap(in2)));
    byte[] expected = new byte[in1.length + in2.length];
    System.arraycopy(in1, 0, expected, 0, in1.length);
    System.arraycopy(in2, 0, expected, in1.length, in2.length);
    Assert.assertEquals(new String(expected), new String(out.toArray()));
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

    // The question is whether original Hg treats this case (same content, different parents and hence nodeids) as 'modified' or 'clean'
  }

  private boolean areTheSame(FileInfo f, HgDataFile dataFile, Nodeid revision) throws HgRuntimeException {
    // XXX consider adding HgDataDile.compare(File/byte[]/whatever) operation to optimize comparison
    ByteArrayChannel bac = new ByteArrayChannel();
    try {
      int fileRevisionIndex = dataFile.getRevisionIndex(revision);
      // need content with metadata striped off - although theoretically chances are metadata may be different,
      // WC doesn't have it anyway
      dataFile.content(fileRevisionIndex, bac);
    } catch (CancelledException ex) {
      // silently ignore - can't happen, ByteArrayChannel is not cancellable
    }
    return areTheSame(f, bac.toArray(), dataFile.getPath());
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

  @Test
  public void testContent() throws Exception {
    repo = Configuration.get().find("log-1");
    final byte[] expectedContent = new byte[] { 'a', ' ', 13, 10 };
    ByteArrayChannel ch = new ByteArrayChannel();
    repo.getFileNode("dir/b").content(0, ch);
    assertArrayEquals(expectedContent, ch.toArray());
    repo.getFileNode("d").content(HgRepository.TIP, ch = new ByteArrayChannel() );
    assertArrayEquals(expectedContent, ch.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

  }

  @Test
  public void testStripMetadata() throws Exception {
    repo = Configuration.get().find("log-1");
    ByteArrayChannel ch = new ByteArrayChannel();
    HgDataFile dir_b = repo.getFileNode("dir/b");
    Assert.assertTrue(dir_b.isCopy());
    Assert.assertEquals("b", dir_b.getCopySourceName().toString());
    Assert.assertEquals("e44751cdc2d14f1eb0146aa64f0895608ad15917", dir_b.getCopySourceRevision().toString());
    dir_b.content(0, ch);
    // assert rawContent has 1 10 ... 1 10
    assertArrayEquals("a \r\n".getBytes(), ch.toArray());
    //
    // try once again to make sure metadata records/extracts correct offsets
    dir_b.content(0, ch = new ByteArrayChannel());
    assertArrayEquals("a \r\n".getBytes(), ch.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

    final File repoDir = RepoUtils.initEmptyTempRepo("testWorkingCopyFileAccess");
    final Map<String, ?> props = Collections.singletonMap(Internals.CFG_PROPERTY_REVLOG_STREAM_CACHE, false);
    repo = new HgLookup(new BasicSessionContext(props, null)).detect(repoDir);
    File f1 = new File(repoDir, "file1");
    final String c1 = "First", c2 = "Second", c3 = "Third";
    ByteArrayChannel ch;
    ExecHelper exec = new ExecHelper(new OutputParser.Stub(), repoDir);
    // commit cset 0
    write(f1, c1);
    exec.run("hg", "add");
    Assert.assertEquals(0, exec.getExitValue());
    exec.run("hg", "commit", "-m", "c0");
    Assert.assertEquals(0, exec.getExitValue());
    // commit cset 1
    write(f1, c2);
    exec.run("hg", "commit", "-m", "c1");
    assertEquals(0, exec.getExitValue());
    //
    // modify working copy
    write(f1, c3);
    //
    HgDataFile df = repo.getFileNode(f1.getName());
    // 1. Shall take content of the file from the dir
    df.workingCopy(ch = new ByteArrayChannel());
    assertArrayEquals(c3.getBytes(), ch.toArray());
    // 2. Shall supply working copy even if no local file is there
    f1.delete();
    assertFalse(f1.exists());
    df = repo.getFileNode(f1.getName());
    df.workingCopy(ch = new ByteArrayChannel());
    assertArrayEquals(c2.getBytes(), ch.toArray());
    //
    // 3. Shall extract revision of the file that corresponds actual parents (from dirstate) not the TIP as it was 
    exec.run("hg", "update", "-r", "0");
    assertEquals(0, exec.getExitValue());
    f1.delete();
    assertFalse(f1.exists());
    // there's no file and workingCopy shall do some extra work to find out actual revision to check out
    df = repo.getFileNode(f1.getName());
    df.workingCopy(ch = new ByteArrayChannel());
    assertArrayEquals(c1.getBytes(), ch.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

    HgDataFile hgTags = repo.getRepo().getFileNode(HgTags.getPath());
    if (hgTags.exists()) {
      for (int i = 0; i <= hgTags.getLastRevision(); i++) { // TODO post-1.0 in fact, would be handy to have walk(start,end)
        // method for data files as well, though it looks odd.
        try {
          ByteArrayChannel sink = new ByteArrayChannel();
          hgTags.content(i, sink);
          final String content = new String(sink.toArray(), "UTF8");
          readGlobal(new StringReader(content));
        } catch (CancelledException ex) {
           // IGNORE, can't happen, we did not configure cancellation
          repo.getLog().dump(getClass(), Debug, ex, null);
        } catch (IOException ex) {
View Full Code Here

Examples of org.tmatesoft.hg.internal.ByteArrayChannel

      if (cached != null) {
        return cached.second();
      }
      HgDataFile df = getFile(clogRevIndex);
      try {
        ByteArrayChannel c;
        df.content(fileRevIndex, c = new ByteArrayChannel());
        LineSequence rv = LineSequence.newlines(c.toArray());
        lruCache.addFirst(new Pair<Integer, LineSequence>(clogRevIndex, rv));
        if (lruCache.size() > limit) {
          lruCache.removeLast();
        }
        return rv;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.