Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectInserter$Filter


  }

  private DirCache createTemporaryIndex(ObjectId headId, DirCache index,
      RevWalk rw)
      throws IOException {
    ObjectInserter inserter = null;

    // get DirCacheBuilder for existing index
    DirCacheBuilder existingBuilder = index.builder();

    // get DirCacheBuilder for newly created in-core index to build a
    // temporary index for this commit
    DirCache inCoreIndex = DirCache.newInCore();
    DirCacheBuilder tempBuilder = inCoreIndex.builder();

    onlyProcessed = new boolean[only.size()];
    boolean emptyCommit = true;

    TreeWalk treeWalk = new TreeWalk(repo);
    int dcIdx = treeWalk.addTree(new DirCacheBuildIterator(existingBuilder));
    int fIdx = treeWalk.addTree(new FileTreeIterator(repo));
    int hIdx = -1;
    if (headId != null)
      hIdx = treeWalk.addTree(rw.parseTree(headId));
    treeWalk.setRecursive(true);

    String lastAddedFile = null;
    while (treeWalk.next()) {
      String path = treeWalk.getPathString();
      // check if current entry's path matches a specified path
      int pos = lookupOnly(path);

      CanonicalTreeParser hTree = null;
      if (hIdx != -1)
        hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);

      DirCacheIterator dcTree = treeWalk.getTree(dcIdx,
          DirCacheIterator.class);

      if (pos >= 0) {
        // include entry in commit

        FileTreeIterator fTree = treeWalk.getTree(fIdx,
            FileTreeIterator.class);

        // check if entry refers to a tracked file
        boolean tracked = dcTree != null || hTree != null;
        if (!tracked)
          break;

        // for an unmerged path, DirCacheBuildIterator will yield 3
        // entries, we only want to add one
        if (path.equals(lastAddedFile))
          continue;

        lastAddedFile = path;

        if (fTree != null) {
          // create a new DirCacheEntry with data retrieved from disk
          final DirCacheEntry dcEntry = new DirCacheEntry(path);
          long entryLength = fTree.getEntryLength();
          dcEntry.setLength(entryLength);
          dcEntry.setLastModified(fTree.getEntryLastModified());
          dcEntry.setFileMode(fTree.getIndexFileMode(dcTree));

          boolean objectExists = (dcTree != null && fTree
              .idEqual(dcTree))
              || (hTree != null && fTree.idEqual(hTree));
          if (objectExists) {
            dcEntry.setObjectId(fTree.getEntryObjectId());
          } else {
            if (FileMode.GITLINK.equals(dcEntry.getFileMode()))
              dcEntry.setObjectId(fTree.getEntryObjectId());
            else {
              // insert object
              if (inserter == null)
                inserter = repo.newObjectInserter();
              long contentLength = fTree.getEntryContentLength();
              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, contentLength,
                    inputStream));
              } finally {
                inputStream.close();
              }
View Full Code Here


    FileUtils.createNewFile(file2);
    writer = new PrintWriter(file2);
    writer.print("content b");
    writer.close();

    ObjectInserter newObjectInserter = db.newObjectInserter();
    DirCache dc = db.lockDirCache();
    DirCacheBuilder builder = dc.builder();

    addEntryToBuilder("b.txt", file2, newObjectInserter, builder, 0);
    addEntryToBuilder("a.txt", file, newObjectInserter, builder, 1);
View Full Code Here

  @Test
  public void testFindObjects() throws Exception {
    final DirCache tree0 = DirCache.newInCore();
    final DirCacheBuilder b0 = tree0.builder();
    ObjectReader or = db.newObjectReader();
    ObjectInserter oi = db.newObjectInserter();

    DirCacheEntry aDotB = createEntry("a.b", EXECUTABLE_FILE);
    b0.add(aDotB);
    DirCacheEntry aSlashB = createEntry("a/b", REGULAR_FILE);
    b0.add(aSlashB);
    DirCacheEntry aSlashCSlashD = createEntry("a/c/d", REGULAR_FILE);
    b0.add(aSlashCSlashD);
    DirCacheEntry aZeroB = createEntry("a0b", SYMLINK);
    b0.add(aZeroB);
    b0.finish();
    assertEquals(4, tree0.getEntryCount());
    ObjectId tree = tree0.writeTree(oi);

    // Find the directories that were implicitly created above.
    TreeWalk tw = new TreeWalk(or);
    tw.addTree(tree);
    ObjectId a = null;
    ObjectId aSlashC = null;
    while (tw.next()) {
      if (tw.getPathString().equals("a")) {
        a = tw.getObjectId(0);
        tw.enterSubtree();
        while (tw.next()) {
          if (tw.getPathString().equals("a/c")) {
            aSlashC = tw.getObjectId(0);
            break;
          }
        }
        break;
      }
    }

    assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
    assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));
    assertEquals(null, TreeWalk.forPath(or, "/a", tree));
    assertEquals(null, TreeWalk.forPath(or, "/a/", tree));

    assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b", tree)
        .getObjectId(0));
    assertEquals(null, TreeWalk.forPath(or, "/a.b", tree));
    assertEquals(null, TreeWalk.forPath(or, "/a.b/", tree));
    assertEquals(aDotB.getObjectId(), TreeWalk.forPath(or, "a.b/", tree)
        .getObjectId(0));

    assertEquals(aZeroB.getObjectId(), TreeWalk.forPath(or, "a0b", tree)
        .getObjectId(0));

    assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "a/b", tree)
        .getObjectId(0));
    assertEquals(aSlashB.getObjectId(), TreeWalk.forPath(or, "b", a)
        .getObjectId(0));

    assertEquals(aSlashC, TreeWalk.forPath(or, "a/c", tree).getObjectId(0));
    assertEquals(aSlashC, TreeWalk.forPath(or, "c", a).getObjectId(0));

    assertEquals(aSlashCSlashD.getObjectId(),
        TreeWalk.forPath(or, "a/c/d", tree).getObjectId(0));
    assertEquals(aSlashCSlashD.getObjectId(), TreeWalk
        .forPath(or, "c/d", a).getObjectId(0));

    or.release();
    oi.release();
  }
View Full Code Here

  private RevObject writeBlob(final Repository repo, final String data)
      throws IOException {
    final RevWalk revWalk = new RevWalk(repo);
    final byte[] bytes = Constants.encode(data);
    final ObjectInserter inserter = repo.newObjectInserter();
    final ObjectId id;
    try {
      id = inserter.insert(Constants.OBJ_BLOB, bytes);
      inserter.flush();
    } finally {
      inserter.release();
    }
    try {
      parse(id);
      fail("Object " + id.name() + " should not exist in test repository");
    } catch (MissingObjectException e) {
View Full Code Here

      newTag.setMessage(message);
      newTag.setTagger(tagger);
      newTag.setObjectId(id);

      // write the tag object
      ObjectInserter inserter = repo.newObjectInserter();
      try {
        ObjectId tagId = inserter.insert(newTag);
        inserter.flush();

        String tag = newTag.getTag();
        return updateTagRef(tagId, revWalk, tag, newTag.toString());

      } finally {
        inserter.release();
      }

    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfTagCommand,
View Full Code Here

    }

    if (repo.isBare()) {
      DirCache index = DirCache.newInCore();
      DirCacheBuilder builder = index.builder();
      ObjectInserter inserter = repo.newObjectInserter();
      RevWalk rw = new RevWalk(repo);
      try {
        Config cfg = new Config();
        for (Project proj : bareProjects) {
          String name = proj.path;
          String nameUri = proj.name;
          cfg.setString("submodule", name, "path", name); //$NON-NLS-1$ //$NON-NLS-2$
          cfg.setString("submodule", name, "url", nameUri); //$NON-NLS-1$ //$NON-NLS-2$
          // create gitlink
          DirCacheEntry dcEntry = new DirCacheEntry(name);
          ObjectId objectId;
          if (ObjectId.isId(proj.revision))
            objectId = ObjectId.fromString(proj.revision);
          else {
            objectId = callback.sha1(nameUri, proj.revision);
          }
          if (objectId == null)
            throw new RemoteUnavailableException(nameUri);
          dcEntry.setObjectId(objectId);
          dcEntry.setFileMode(FileMode.GITLINK);
          builder.add(dcEntry);

          for (CopyFile copyfile : proj.copyfiles) {
            byte[] src = callback.readFile(
                nameUri, proj.revision, copyfile.src);
            objectId = inserter.insert(Constants.OBJ_BLOB, src);
            dcEntry = new DirCacheEntry(copyfile.dest);
            dcEntry.setObjectId(objectId);
            dcEntry.setFileMode(FileMode.REGULAR_FILE);
            builder.add(dcEntry);
          }
        }
        String content = cfg.toText();

        // create a new DirCacheEntry for .gitmodules file.
        final DirCacheEntry dcEntry = new DirCacheEntry(Constants.DOT_GIT_MODULES);
        ObjectId objectId = inserter.insert(Constants.OBJ_BLOB,
            content.getBytes(Constants.CHARACTER_ENCODING));
        dcEntry.setObjectId(objectId);
        dcEntry.setFileMode(FileMode.REGULAR_FILE);
        builder.add(dcEntry);

        builder.finish();
        ObjectId treeId = index.writeTree(inserter);

        // Create a Commit object, populate it and write it
        ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
        CommitBuilder commit = new CommitBuilder();
        commit.setTreeId(treeId);
        if (headId != null)
          commit.setParentIds(headId);
        commit.setAuthor(author);
        commit.setCommitter(author);
        commit.setMessage(RepoText.get().repoCommitMessage);

        ObjectId commitId = inserter.insert(commit);
        inserter.flush();

        RefUpdate ru = repo.updateRef(Constants.HEAD);
        ru.setNewObjectId(commitId);
        ru.setExpectedOldObjectId(headId != null ? headId : ObjectId.zeroId());
        Result rc = ru.update(rw);
View Full Code Here

    }
  }

  private ObjectId insertTag(final TagBuilder tag) throws IOException,
      UnsupportedEncodingException {
    ObjectInserter oi = db.newObjectInserter();
    try {
      ObjectId id = oi.insert(tag);
      oi.flush();
      return id;
    } finally {
      oi.release();
    }
  }
View Full Code Here

      b.finish();
      o.finish();
      t.finish();
    }

    final ObjectInserter ow = db.newObjectInserter();
    final ObjectId b = commit(ow, treeB, new ObjectId[] {});
    final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
    final ObjectId t = commit(ow, treeT, new ObjectId[] { b });

    Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
View Full Code Here

      b.finish();
      o.finish();
      t.finish();
    }

    final ObjectInserter ow = db.newObjectInserter();
    final ObjectId b = commit(ow, treeB, new ObjectId[] {});
    final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
    final ObjectId t = commit(ow, treeT, new ObjectId[] { b });

    Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
View Full Code Here

      b.finish();
      o.finish();
      t.finish();
    }

    final ObjectInserter ow = db.newObjectInserter();
    final ObjectId b = commit(ow, treeB, new ObjectId[] {});
    final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
    final ObjectId t = commit(ow, treeT, new ObjectId[] { b });

    Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.ObjectInserter$Filter

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.