Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.Transaction


    //
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), 0);
    HgDataFile df = hgRepo.getFileNode("file1");
    cf.add(df, new ByteArrayDataSource("hello\nworld".getBytes()));
    Transaction tr = newTransaction(hgRepo);
    Nodeid secondRev = cf.commit("SECOND", tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(2, commits.size());
    HgChangeset c1 = commits.get(0);
    HgChangeset c2 = commits.get(1);
View Full Code Here


    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));
View Full Code Here

    RepoUtils.modifyFileAppend(fileD, "A CHANGE\n");
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, fileD);
    cf.add(dfD, contentProvider);
    cf.branch("branch1");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev1 = cf.commit("FIRST",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
    errorCollector.assertEquals(c1.getNodeid(), commitRev1);
View Full Code Here

    new HgAddRemoveCommand(hgRepo).add(Path.create("xx")).remove(Path.create("d")).execute();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), hgRepo.getChangelog().getLastRevision());
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, new File(repoLoc, "xx"));
    cf.add(hgRepo.getFileNode("xx"), contentProvider);
    cf.forget(hgRepo.getFileNode("d"));
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit with add/remove cmd",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).changeset(commitRev).execute();
    HgChangeset cmt = commits.get(0);
    errorCollector.assertEquals(1, cmt.getAddedFiles().size());
    errorCollector.assertEquals("xx", cmt.getAddedFiles().get(0).getPath().toString());
View Full Code Here

    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, fileD);
    cf.add(dfD, contentProvider);
    cf.branch("branch1");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev1 = cf.commit("FIRST",  tr);
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cf.add(dfD, contentProvider = new FileContentSupplier(hgRepo, fileD));
    cf.branch("branch2");
    Nodeid commitRev2 = cf.commit("SECOND",  tr);
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cf.add(dfD, contentProvider = new FileContentSupplier(hgRepo, fileD));
    cf.branch(DEFAULT_BRANCH_NAME);
    Nodeid commitRev3 = cf.commit("THIRD",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(3, commits.size());
    HgChangeset c1 = commits.get(0);
    HgChangeset c2 = commits.get(1);
View Full Code Here

    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    // HgCommitCommand can't do branch yet
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    cf.add(hgRepo.getFileNode("a"), new FileContentSupplier(hgRepo, new File(repoLoc, "a")));
    cf.branch(branch);
    Transaction tr = newTransaction(hgRepo);
    Nodeid commit = cf.commit("FIRST",  tr);
    tr.commit();
    errorCollector.assertEquals("commit with branch shall update WC", branch, hgRepo.getWorkingCopyBranchName());
   
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    eh.run("hg", "tag", tag);
    assertEquals("[sanity]", 0, eh.getExitValue());
View Full Code Here

    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));
View Full Code Here

      //
      // add revisions to changelog, manifest, files
      final Internals implRepo = HgInternals.getImplementationRepo(repo);
      final AddRevInspector insp;
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        incoming.inspectAll(insp = new AddRevInspector(implRepo, tr));
        insp.done();
        tr.commit();
      } catch (HgRuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgIOException ex) {
        tr.rollback();
        throw ex;
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      }
      progress.worked(45);
      added = insp.addedChangesets();
     
View Full Code Here

        cf.forget(df);
      }
      cf.branch(detectBranch());
      cf.user(detectUser());
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        newRevision = cf.commit(message, tr);
        tr.commit();
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgException ex) {
        tr.rollback();
        throw ex;
      }
      return new Outcome(Kind.Success, "Commit ok");
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
View Full Code Here

      ManifestRevision m1, m2, ma;
      m1 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, firstCset);
      m2 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, secondCset);
      ma = new ManifestRevision(cacheRevs, cacheFiles).init(repo, ancestorCset);
      Transaction transaction = implRepo.getTransactionFactory().create(repo);
      ResolverImpl resolver = new ResolverImpl(implRepo, dirstateBuilder, mergeStateBuilder);
      try {
        for (Path f : m1.files()) {
          Nodeid fileRevBase, fileRevA, fileRevB;
          if (m2.contains(f)) {
            fileRevA = m1.nodeid(f);
            fileRevB = m2.nodeid(f);
            fileRevBase = ma.contains(f) ? ma.nodeid(f) : null;
            if (fileRevA.equals(fileRevB)) {
              HgFileRevision fr = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
              resolver.presentState(f, fr, fr, null);
              mediator.same(fr, resolver);
            } else if (fileRevBase == fileRevA) {
              assert fileRevBase != null;
              HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
              HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
              resolver.presentState(f, frBase, frSecond, frBase);
              mediator.fastForwardB(frBase, frSecond, resolver);
            } else if (fileRevBase == fileRevB) {
              assert fileRevBase != null;
              HgFileRevision frBase = new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
              HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
              resolver.presentState(f, frFirst, frBase, frBase);
              mediator.fastForwardA(frBase, frFirst, resolver);
            } else {
              HgFileRevision frBase = fileRevBase == null ? null : new HgFileRevision(repo, fileRevBase, ma.flags(f), f);
              HgFileRevision frFirst = new HgFileRevision(repo, fileRevA, m1.flags(f), f);
              HgFileRevision frSecond= new HgFileRevision(repo, fileRevB, m2.flags(f), f);
              resolver.presentState(f, frFirst, frSecond, frBase);
              mediator.resolve(frBase, frFirst, frSecond, resolver);
            }
          } else {
            // m2 doesn't contain the file, either new in m1, or deleted in m2
            HgFileRevision frFirst = new HgFileRevision(repo, m1.nodeid(f), m1.flags(f), f);
            if (ma.contains(f)) {
              // deleted in m2
              HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
              resolver.presentState(f, frFirst, null, frBase);
              mediator.onlyA(frBase, frFirst, resolver);
            } else {
              // new in m1
              resolver.presentState(f, frFirst, null, null);
              mediator.newInA(frFirst, resolver);
            }
          }
          resolver.apply();
        } // for m1 files
        for (Path f : m2.files()) {
          if (m1.contains(f)) {
            continue;
          }
          HgFileRevision frSecond= new HgFileRevision(repo, m2.nodeid(f), m2.flags(f), f);
          // file in m2 is either new or deleted in m1
          if (ma.contains(f)) {
            // deleted in m1
            HgFileRevision frBase = new HgFileRevision(repo, ma.nodeid(f), ma.flags(f), f);
            resolver.presentState(f, null, frSecond, frBase);
            mediator.onlyB(frBase, frSecond, resolver);
          } else {
            // new in m2
            resolver.presentState(f, null, frSecond, null);
            mediator.newInB(frSecond, resolver);
          }
          resolver.apply();
        }
        resolver.serializeChanged(transaction);
        transaction.commit();
      } catch (HgRuntimeException ex) {
        transaction.rollback();
        mergeStateBuilder.abandon();
        throw ex;
      } catch (HgIOException ex) {
        transaction.rollback();
        mergeStateBuilder.abandon();
        throw ex;
      }
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.Transaction

Copyright © 2018 www.massapicom. 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.