Examples of HgDataFile


Examples of org.tmatesoft.hg.repo.HgDataFile

    }
    if (sink == null) {
      throw new IllegalArgumentException("Need an output channel");
    }
    try {
      HgDataFile dataFile = repo.getFileNode(file);
      if (!dataFile.exists()) {
        // TODO may benefit from repo.getStoragePath to print revlog location in addition to human-friendly file path
        throw new HgPathNotFoundException(String.format("File %s not found in the repository", file), file);
      }
      int revToExtract;
      if (cset != null) {
        // TODO HgChangesetFileSneaker is handy, but bit too much here, shall extract follow rename code into separate utility
        HgChangesetFileSneaker fsneaker = new HgChangesetFileSneaker(repo);
        fsneaker.changeset(cset).followRenames(true);
        Outcome o = fsneaker.check(file);
        if (!o.isOk()) {
          if (o.getException() instanceof HgRuntimeException) {
            throw new HgLibraryFailureException(o.getMessage(), (HgRuntimeException) o.getException());
          }
          throw new HgBadArgumentException(o.getMessage(), o.getException()).setFileName(file).setRevision(cset);
        }
        if (!fsneaker.exists()) {
          throw new HgPathNotFoundException(o.getMessage(), file).setRevision(cset);
        }
        Nodeid toExtract = fsneaker.revision();
        if (fsneaker.hasAnotherName()) {
          dataFile = repo.getFileNode(fsneaker.filename());
        }
        revToExtract = dataFile.getRevisionIndex(toExtract);
      } else if (revision != null) {
        revToExtract = dataFile.getRevisionIndex(revision);
      } else {
        revToExtract = revisionIndex;
      }
      ByteChannel sinkWrap;
      if (getCancelSupport(null, false) == null) {
        // no command-specific cancel helper, no need for extra proxy
        // sink itself still may supply CS
        sinkWrap = sink;
      } else {
        // try CS from sink, if any. at least there is CS from command
        CancelSupport cancelHelper = getCancelSupport(sink, true);
        cancelHelper.checkCancelled();
        sinkWrap = new ByteChannelProxy(sink, cancelHelper);
      }
      dataFile.contentWithFilters(revToExtract, sinkWrap);
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    }
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

  private HgRepository repo;
 
  @Test
  public void testFlagsInManifest() throws HgRuntimeException {
    HgDataFile link = repo.getFileNode("file-link");
    HgDataFile exec = repo.getFileNode("file-exec");
    HgDataFile file = repo.getFileNode("regular-file");
    assertEquals(Flags.Link, link.getFlags(TIP));
    assertEquals(Flags.Exec, exec.getFlags(TIP));
    assertEquals(Flags.RegularFile, file.getFlags(TIP));
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

    final ProgressSupport progress = getProgressSupport(inspector);
    final CancelSupport cancellation = getCancelSupport(inspector, true);
    cancellation.checkCancelled();
    progress.start(200);
    try {
      HgDataFile df = repo.getFileNode(file);
      if (!df.exists()) {
        return;
      }
      final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0);
      final int annotateRevIndex = annotateRevision.get(TIP);
      HgDiffCommand cmd = new HgDiffCommand(repo).file(df);
      cmd.range(changesetStart, annotateRevIndex);
      cmd.set(cancellation);
      cmd.set(new ProgressSupport.Sub(progress, 100));
      //
//      ReverseAnnotateInspector ai = new ReverseAnnotateInspector();
      ForwardAnnotateInspector ai = new ForwardAnnotateInspector();
      cmd.order(ai.iterateDirection());
      //
      cmd.executeAnnotate(ai);
      cancellation.checkCancelled();
      final int lastCsetWithFileChange;
      Nodeid fileRev = repo.getManifest().getFileRevision(annotateRevIndex, df.getPath());
      if (fileRev != null) {
        lastCsetWithFileChange = df.getChangesetRevisionIndex(df.getRevisionIndex(fileRev));
      } else {
        lastCsetWithFileChange = annotateRevIndex;
      }
      ai.report(lastCsetWithFileChange, inspector, new ProgressSupport.Sub(progress, 100), cancellation);
    } catch (HgRuntimeException ex) {
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

    new ExecHelper(new OutputParser.Stub(), repoLoc).run("hg", "add", fname);
    //
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", 0, new HgLogCommand(hgRepo).execute().size());
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), NO_REVISION);
    HgDataFile df = hgRepo.getFileNode(fname);
    final byte[] initialContent = "hello\nworld".getBytes();
    cf.add(df, new ByteArrayDataSource(initialContent));
    String comment = "commit 1";
    Transaction tr = newTransaction(hgRepo);
    Nodeid c1Rev = cf.commit(comment,  tr);
    tr.commit();
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
    errorCollector.assertEquals(1, c1.getAffectedFiles().size());
    errorCollector.assertEquals(df.getPath(), c1.getAffectedFiles().get(0));
    errorCollector.assertEquals(0, c1.getRevisionIndex());
    errorCollector.assertEquals(Nodeid.NULL, c1.getFirstParentRevision());
    errorCollector.assertEquals(Nodeid.NULL, c1.getSecondParentRevision());
    errorCollector.assertEquals(HgRepository.DEFAULT_BRANCH_NAME, c1.getBranch());
    errorCollector.assertEquals(comment, c1.getComment());
    errorCollector.assertEquals(c1Rev, c1.getNodeid());
    ByteArrayChannel bac = new ByteArrayChannel();
    new HgCatCommand(hgRepo).file(df.getPath()).execute(bac);
    assertArrayEquals(initialContent, bac.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

 
  @Test
  public void testCommitIntoBranch() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit2branch", false);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    HgChangeset parentCset = new HgLogCommand(hgRepo).range(parentCsetRevIndex, parentCsetRevIndex).execute().get(0);
    assertEquals("[sanity]", DEFAULT_BRANCH_NAME, parentCset.getBranch());
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

   */
  @Test
  public void testSequentialCommits() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-sequential-commits", false);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

  public void testCommandBasics() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-cmd", false);
    // PhasesHelper relies on file existence to tell phase enablement
    RepoUtils.createFile(new File(repoLoc, HgRepositoryFiles.Phaseroots.getPath()), "");
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfB = hgRepo.getFileNode("b");
    assertTrue("[sanity]", dfB.exists());
    File fileB = new File(repoLoc, "b");
    assertTrue("[sanity]", fileB.canRead());
    RepoUtils.modifyFileAppend(fileB, " 1 \n");

    HgCommitCommand cmd = new HgCommitCommand(hgRepo);
    assertFalse(cmd.isMergeCommit());
    Outcome r = cmd.message("FIRST").execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c1 = cmd.getCommittedRevision();
   
    // check that modified files are no longer reported as such
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Modified).isEmpty());
    errorCollector.assertEquals(1, status.get(dfB.getPath()).size());
    errorCollector.assertTrue(status.get(dfB.getPath()).contains(Kind.Clean));
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    cmd = new HgCommitCommand(hgRepo);
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    Nodeid activeBookmarkRevision = hgRepo.getBookmarks().getRevision(activeBookmark);
    assertEquals("[sanity]", activeBookmarkRevision, hgRepo.getWorkingCopyParents().first());
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", dfD.exists());
    assertTrue("[sanity]", fileD.canRead());

    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

    RepoUtils.createFile(newFile, newFileContent);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    new HgAddRemoveCommand(hgRepo).add(Path.create("xx")).execute();
    // save the reference to HgDataFile without valid RevlogStream (entry in the dirstate
    // doesn't make it valid)
    final HgDataFile newFileNode = hgRepo.getFileNode("xx");
    assertFalse(newFileNode.exists());
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Added).isEmpty());
    errorCollector.assertTrue(status.get(newFileNode.getPath()).contains(Kind.Clean));
    //
    errorCollector.assertTrue(newFileNode.exists());
    final ByteArrayChannel read1 = new ByteArrayChannel();
    newFileNode.content(0, read1);
    errorCollector.assertEquals("Read from existing HgDataFile instance", newFileContent, read1.toArray());
    final ByteArrayChannel read2 = new ByteArrayChannel();
    hgRepo.getFileNode(newFileNode.getPath()).content(0, read2);
    errorCollector.assertEquals("Read from fresh HgDataFile instance", newFileContent, read2.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgDataFile

    File repoLoc = RepoUtils.copyRepoToTempLocation("log-1", "test-commit-rollback");
    final Path newFilePath = Path.create("xx");
    final File newFile = new File(repoLoc, newFilePath.toString());
    RepoUtils.createFile(newFile, "xyz");
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfB = hgRepo.getFileNode("b");
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfB.exists());
    assertTrue("[sanity]", dfD.exists());
    final File modifiedFile = new File(repoLoc, "b");
    RepoUtils.modifyFileAppend(modifiedFile, " 1 \n");
    //
    new HgAddRemoveCommand(hgRepo).add(newFilePath).remove(dfD.getPath()).execute();
    //
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    assertTrue(status.getErrors().isEmpty());
    assertTrue(status.get(Kind.Added).contains(newFilePath));
    assertTrue(status.get(Kind.Modified).contains(dfB.getPath()));
    assertTrue(status.get(Kind.Removed).contains(dfD.getPath()));
    assertEquals(DEFAULT_BRANCH_NAME, hgRepo.getWorkingCopyBranchName());
    //
    final int lastClogRevision = hgRepo.getChangelog().getLastRevision();
    final int lastManifestRev = hgRepo.getManifest().getLastRevision();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), lastClogRevision);
    cf.add(hgRepo.getFileNode("xx"), new FileContentSupplier(hgRepo, newFile));
    cf.add(dfB, new FileContentSupplier(hgRepo, modifiedFile));
    cf.forget(dfD);
    cf.branch("another-branch");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit to fail",  tr);
    tr.rollback();
    //
    errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());
    errorCollector.assertEquals(lastManifestRev, hgRepo.getManifest().getLastRevision());
    errorCollector.assertEquals(DEFAULT_BRANCH_NAME, DirstateReader.readBranch(Internals.getInstance(hgRepo)));
    errorCollector.assertFalse(hgRepo.getChangelog().isKnown(commitRev));
    errorCollector.assertFalse(hgRepo.getFileNode("xx").exists());
    // check dirstate
    status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Added).contains(newFilePath));
    errorCollector.assertTrue(status.get(Kind.Modified).contains(dfB.getPath()));
    errorCollector.assertTrue(status.get(Kind.Removed).contains(dfD.getPath()));
   
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc);
  }
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.