Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Repository


    private Thread worker;

    InternalLocalPushConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
      final PipedOutputStream in_w;

      final PipedInputStream out_r;
      final PipedOutputStream out_w;
      try {
        in_r = new PipedInputStream();
        in_w = new PipedOutputStream(in_r);

        out_r = new PipedInputStream();
        out_w = new PipedOutputStream(out_r);
      } catch (IOException err) {
        dst.close();
        throw new TransportException(uri, JGitText.get().cannotConnectPipes, err);
      }

      worker = new Thread("JGit-Receive-Pack") {
        public void run() {
          try {
            final ReceivePack rp = createReceivePack(dst);
            rp.receive(out_r, in_w, System.err);
          } catch (IOException err) {
            // Client side of the pipes should report the problem.
          } catch (RuntimeException err) {
            // Clients side will notice we went away, and report.
          } finally {
            try {
              out_r.close();
            } catch (IOException e2) {
              // Ignore close failure, we probably crashed above.
            }

            try {
              in_w.close();
            } catch (IOException e2) {
              // Ignore close failure, we probably crashed above.
            }

            dst.close();
          }
        }
      };
      worker.start();
View Full Code Here


   * @return the newly created {@code Git} object with associated repository
   */
  public Git call() throws JGitInternalException {
    try {
      URIish u = new URIish(uri);
      Repository repository = init(u);
      FetchResult result = fetch(repository, u);
      if (!noCheckout)
        checkout(repository, result);
      return new Git(repository);
    } catch (IOException ioe) {
View Full Code Here

  void execute(final DaemonClient client, final String commandLine)
      throws IOException, ServiceNotEnabledException,
      ServiceNotAuthorizedException {
    final String name = commandLine.substring(command.length() + 1);
    Repository db = client.getDaemon().openRepository(client, name);
    if (db == null)
      return;
    try {
      if (isEnabledFor(db))
        execute(client, db);
    } finally {
      db.close();
    }
  }
View Full Code Here

  public Repository open(final C req, final String name)
      throws RepositoryNotFoundException, ServiceNotEnabledException {
    if (isUnreasonableName(name))
      throw new RepositoryNotFoundException(name);

    Repository db = exports.get(nameWithDotGit(name));
    if (db != null) {
      db.incrementOpen();
      return db;
    }

    for (File base : exportBase) {
      File dir = FileKey.resolve(new File(base, name), FS.DETECTED);
      if (dir == null)
        continue;

      try {
        FileKey key = FileKey.exact(dir, FS.DETECTED);
        db = RepositoryCache.open(key, true);
      } catch (IOException e) {
        throw new RepositoryNotFoundException(name, e);
      }

      try {
        if (isExportOk(req, name, db)) {
          // We have to leak the open count to the caller, they
          // are responsible for closing the repository if we
          // complete successfully.
          return db;
        } else
          throw new ServiceNotEnabledException();

      } catch (RuntimeException e) {
        db.close();
        throw new RepositoryNotFoundException(name, e);

      } catch (IOException e) {
        db.close();
        throw new RepositoryNotFoundException(name, e);

      } catch (ServiceNotEnabledException e) {
        db.close();
        throw e;
      }
    }

    if (exportBase.size() == 1) {
View Full Code Here

   */
  public Set<ObjectId> getAdditionalHaves() {
    HashSet<ObjectId> r = new HashSet<ObjectId>();
    for (AlternateHandle d : objectDatabase. myAlternates()) {
      if (d instanceof AlternateRepository) {
        Repository repo;

        repo = ((AlternateRepository) d).repository;
        for (Ref ref : repo.getAllRefs().values()) {
          if (ref.getObjectId() != null)
            r.add(ref.getObjectId());
          if (ref.getPeeledObjectId() != null)
            r.add(ref.getPeeledObjectId());
        }
        r.addAll(repo.getAdditionalHaves());
      }
    }
    return r;
  }
View Full Code Here

    return new TrackingRefUpdate(transport.local, spec, newId, "fetch");
  }

  private void deleteStaleTrackingRefs(final FetchResult result,
      final RevWalk walk) throws TransportException {
    final Repository db = transport.local;
    for (final Ref ref : db.getAllRefs().values()) {
      final String refname = ref.getName();
      for (final RefSpec spec : toFetch) {
        if (spec.matchDestination(refname)) {
          final RefSpec s = spec.expandFromDestination(refname);
          if (result.getAdvertisedRef(s.getSource()) == null) {
View Full Code Here

   public CherryPickResult cherryPickNoMerge(final Git git, Ref src) throws GitAPIException,
            CantMergeCommitException
   {
      // Does the same as the original git-cherryPick
      // except commiting after running merger
      Repository repo = git.getRepository();

      RevCommit newHead = null;
      List<Ref> cherryPickedRefs = new LinkedList<Ref>();

      RevWalk revWalk = new RevWalk(repo);
      try
      {
         // get the head commit
         Ref headRef = repo.getRef(Constants.HEAD);
         if (headRef == null)
            throw new NoHeadException(
                     JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
         RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

         newHead = headCommit;

         // get the commit to be cherry-picked
         // handle annotated tags
         ObjectId srcObjectId = src.getPeeledObjectId();
         if (srcObjectId == null)
            srcObjectId = src.getObjectId();
         RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

         // get the parent of the commit to cherry-pick
         if (srcCommit.getParentCount() == 0)
            throw new CantMergeCommitException("Commit with zero parents cannot be merged");

         if (srcCommit.getParentCount() > 1)
            throw new MultipleParentsNotAllowedException(
                     MessageFormat.format(
                              JGitText.get().canOnlyCherryPickCommitsWithOneParent,
                              srcCommit.name(),
                              Integer.valueOf(srcCommit.getParentCount())));

         RevCommit srcParent = srcCommit.getParent(0);
         revWalk.parseHeaders(srcParent);

         ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE
                  .newMerger(repo);
         merger.setWorkingTreeIterator(new FileTreeIterator(repo));
         merger.setBase(srcParent.getTree());
         if (merger.merge(headCommit, srcCommit))
         {
            DirCacheCheckout dco = new DirCacheCheckout(repo,
                     headCommit.getTree(), repo.lockDirCache(),
                     merger.getResultTreeId());
            dco.setFailOnConflict(true);
            dco.checkout();

            cherryPickedRefs.add(src);
         }
         else
         {
            if (merger.failed())
               return new CherryPickResult(merger.getFailingPaths());

            // there are merge conflicts
            String message = new MergeMessageFormatter()
                     .formatWithConflicts(srcCommit.getFullMessage(),
                              merger.getUnmergedPaths());

            repo.writeCherryPickHead(srcCommit.getId());
            repo.writeMergeCommitMsg(message);

            return CherryPickResult.CONFLICT;
         }
      }
      catch (IOException e)
View Full Code Here

        eventPublisher.register(this);
    }

    private Repository getRepository(String id, AbstractExtensionEvent event) throws NoHeadException, NoMessageException, ConcurrentRefUpdateException, WrongRepositoryStateException, IOException, NoFilepatternException
    {
        Repository repo = repositories.get(id);
        if (repo == null)
        {
            final File repoDir = new File(repositoriesDir, id);
            FileRepositoryBuilder builder = new FileRepositoryBuilder();
            repo = builder.setWorkTree(repoDir).
                    setGitDir(new File(repoDir, ".git")).
                    setMustExist(false).
                    build();
            Bundle bundle = findBundleForPlugin(bundleContext, id);
            if (bundle != null)
            {
                if (!repo.getObjectDatabase().exists())
                {
                    repo.create();
                    updateRepositoryIfDirty(repo, event, bundle);
                }
                else
                {
                    long modified = repo.getConfig().getLong("speakeasy", null, BUNDLELASTMODIFIED, 0);
                    if (modified != bundle.getLastModified())
                    {
                        updateRepositoryIfDirty(repo, event, bundle);
                    }
                }


            }
            else if (ExtensionValidate.isValidExtensionKey(id) &&
                    !repo.getDirectory().exists())
            {
                repo.create();
            }
            repositories.put(id, repo);
        }
        return repo;
    }
View Full Code Here

   */
  public Set<ObjectId> getAdditionalHaves() {
    HashSet<ObjectId> r = new HashSet<ObjectId>();
    for (AlternateHandle d : objectDatabase. myAlternates()) {
      if (d instanceof AlternateRepository) {
        Repository repo;

        repo = ((AlternateRepository) d).repository;
        for (Ref ref : repo.getAllRefs().values()) {
          if (ref.getObjectId() != null)
            r.add(ref.getObjectId());
          if (ref.getPeeledObjectId() != null)
            r.add(ref.getPeeledObjectId());
        }
        r.addAll(repo.getAdditionalHaves());
      }
    }
    return r;
  }
View Full Code Here

   * @param directory
   * @param e
   * @return non-null submodule id
   */
  protected byte[] idSubmodule(File directory, Entry e) {
    final Repository submoduleRepo;
    try {
      submoduleRepo = SubmoduleWalk.getSubmoduleRepository(directory,
          e.getName());
    } catch (IOException exception) {
      return zeroid;
    }
    if (submoduleRepo == null)
      return zeroid;

    final ObjectId head;
    try {
      head = submoduleRepo.resolve(Constants.HEAD);
    } catch (IOException exception) {
      return zeroid;
    } finally {
      submoduleRepo.close();
    }
    if (head == null)
      return zeroid;
    final byte[] id = new byte[Constants.OBJECT_ID_LENGTH];
    head.copyRawTo(id, 0);
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.Repository

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.