Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Repository


     *      added to the {@code transformer}; otherwise, {@code false}.
     */
    public static boolean addCommitProperties(Transformer transformer, File baseDir, int abbrevLen, Log log) {
        try {
            RepositoryBuilder builder = new RepositoryBuilder();
            Repository repository = builder.findGitDir(baseDir).readEnvironment().build();
            ObjectId objectId = repository.resolve(Constants.HEAD);
            if (objectId != null) {
                transformer.setParameter("repository.commit", objectId.getName());
                transformer.setParameter("repository.commit.short", objectId.abbreviate(abbrevLen).name());
                return true;
            } else {
View Full Code Here


            if (args.length != 2) {
                throw new IllegalArgumentException("Invalid git command line: " + command);
            }
            File srcGitdir = new File(rootDir, args[1]);
            RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(srcGitdir, FS.DETECTED);
            Repository db = key.open(true /* must exist */);
            if ("git-upload-pack".equals(args[0])) {
                new UploadPack(db).upload(in, out, err);
            } else if ("git-receive-pack".equals(args[0])) {
                new ReceivePack(db).receive(in, out, err);
            } else {
View Full Code Here

    private Thread worker;

    InternalLocalFetchConnection() 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() {
          // The client (BasePackFetchConnection) can write
          // a huge burst before it reads again. We need to
          // force the buffer to be big enough, otherwise it
          // will deadlock both threads.
          {
            buffer = new byte[MIN_CLIENT_BUFFER];
          }
        };
        out_w = new PipedOutputStream(out_r);
      } catch (IOException err) {
        dst.close();
        throw new TransportException(uri, JGitText.get().cannotConnectPipes, err);
      }

      worker = new Thread("JGit-Upload-Pack") {
        public void run() {
          try {
            final UploadPack rp = createUploadPack(dst);
            rp.upload(out_r, in_w, null);
          } catch (IOException err) {
            // Client side of the pipes should report the problem.
            err.printStackTrace();
          } catch (RuntimeException err) {
            // Clients side will notice we went away, and report.
            err.printStackTrace();
          } 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

    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

   * @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

    if (generator.getConfigUrl() == null)
      return new SubmoduleStatus(SubmoduleStatusType.UNINITIALIZED, path,
          id);

    // Report uninitialized if no submodule repository
    Repository subRepo = generator.getRepository();
    if (subRepo == null)
      return new SubmoduleStatus(SubmoduleStatusType.UNINITIALIZED, path,
          id);

    ObjectId headId = subRepo.resolve(Constants.HEAD);

    // Report uninitialized if no HEAD commit in submodule repository
    if (headId == null)
      return new SubmoduleStatus(SubmoduleStatusType.UNINITIALIZED, path,
          id, headId);
View Full Code Here

                    in.close();
                  }
                  builder.add(entry);
                  lastAddedFile = path;
                } else {
                  Repository subRepo = Git.open(
                      new File(repo.getWorkTree(), path))
                      .getRepository();
                  ObjectId subRepoHead = subRepo
                      .resolve(Constants.HEAD);
                  if (subRepoHead != null) {
                    entry.setObjectId(subRepoHead);
                    builder.add(entry);
                    lastAddedFile = path;
View Full Code Here

        // Skip submodules not registered in parent repository's config
        String url = generator.getConfigUrl();
        if (url == null)
          continue;

        Repository submoduleRepo = generator.getRepository();
        // Clone repository is not present
        if (submoduleRepo == null) {
          CloneCommand clone = Git.cloneRepository();
          configure(clone);
          clone.setURI(url);
          clone.setDirectory(generator.getDirectory());
          if (monitor != null)
            clone.setProgressMonitor(monitor);
          submoduleRepo = clone.call().getRepository();
        }

        RevWalk walk = new RevWalk(submoduleRepo);
        RevCommit commit = walk.parseCommit(generator.getObjectId());

        String update = generator.getConfigUpdate();
        if (ConfigConstants.CONFIG_KEY_MERGE.equals(update)) {
          MergeCommand merge = new MergeCommand(submoduleRepo);
          merge.include(commit);
          merge.call();
        } else if (ConfigConstants.CONFIG_KEY_REBASE.equals(update)) {
          RebaseCommand rebase = new RebaseCommand(submoduleRepo);
          rebase.setUpstream(commit);
          rebase.call();
        } else {
          // Checkout commit referenced in parent repository's index
          // as a detached HEAD
          DirCacheCheckout co = new DirCacheCheckout(submoduleRepo,
              submoduleRepo.lockDirCache(), commit.getTree());
          co.setFailOnConflict(true);
          co.checkout();
          RefUpdate refUpdate = submoduleRepo.updateRef(
              Constants.HEAD, true);
          refUpdate.setNewObjectId(commit);
          refUpdate.forceUpdate();
        }
        updated.add(generator.getPath());
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

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.