org.eclipse.jgit_2.3.1.201302201838-r

16:45:34.348 INFO  jd.cli.Main - Decompiling org.eclipse.jgit_2.3.1.201302201838-r.jar
package org.eclipse.jgit.api;

 enum MergeResult$MergeStatus$5
{
  MergeResult$MergeStatus$5()
  {
    super(paramString, paramInt, null);
  }
  
  public String toString()
  {
    return "Merged";
  }
  
  public boolean isSuccessful()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.MergeResult.MergeStatus.5
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

class ApplyCommand$1 {}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.ApplyCommand.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.Transport.Operation;

public class PushCommand
  extends TransportCommand<PushCommand, Iterable<PushResult>>
{
  private String remote = "origin";
  private final List<RefSpec> refSpecs;
  private ProgressMonitor monitor = NullProgressMonitor.INSTANCE;
  private String receivePack = "git-receive-pack";
  private boolean dryRun;
  private boolean force;
  private boolean thin = false;
  
  protected PushCommand(Repository repo)
  {
    super(repo);
    refSpecs = new ArrayList(3);
  }
  
  public Iterable<PushResult> call()
    throws GitAPIException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
  {
    checkCallable();
    
    ArrayList<PushResult> pushResults = new ArrayList(3);
    try
    {
      if (refSpecs.isEmpty())
      {
        RemoteConfig config = new RemoteConfig(repo.getConfig(), getRemote());
        
        refSpecs.addAll(config.getPushRefSpecs());
      }
      if (refSpecs.isEmpty())
      {
        Ref head = repo.getRef("HEAD");
        if ((head != null) && (head.isSymbolic())) {
          refSpecs.add(new RefSpec(head.getLeaf().getName()));
        }
      }
      if (force) {
        for (int i = 0; i < refSpecs.size(); i++) {
          refSpecs.set(i, ((RefSpec)refSpecs.get(i)).setForceUpdate(true));
        }
      }
      List<Transport> transports = Transport.openAll(repo, remote, Transport.Operation.PUSH);
      for (Transport transport : transports)
      {
        transport.setPushThin(thin);
        if (receivePack != null) {
          transport.setOptionReceivePack(receivePack);
        }
        transport.setDryRun(dryRun);
        configure(transport);
        
        Collection<RemoteRefUpdate> toPush = transport.findRemoteRefUpdatesFor(refSpecs);
        try
        {
          PushResult result = transport.push(monitor, toPush);
          pushResults.add(result);
        }
        catch (org.eclipse.jgit.errors.TransportException e)
        {
          throw new org.eclipse.jgit.api.errors.TransportException(e.getMessage(), e);
        }
        finally
        {
          transport.close();
        }
      }
    }
    catch (URISyntaxException e)
    {
      throw new InvalidRemoteException(MessageFormat.format(getinvalidRemote, new Object[] { remote }));
    }
    catch (org.eclipse.jgit.errors.TransportException e)
    {
      throw new org.eclipse.jgit.api.errors.TransportException(e.getMessage(), e);
    }
    catch (NotSupportedException e)
    {
      throw new JGitInternalException(getexceptionCaughtDuringExecutionOfPushCommand, e);
    }
    catch (IOException e)
    {
      throw new JGitInternalException(getexceptionCaughtDuringExecutionOfPushCommand, e);
    }
    return pushResults;
  }
  
  public PushCommand setRemote(String remote)
  {
    checkCallable();
    this.remote = remote;
    return this;
  }
  
  public String getRemote()
  {
    return remote;
  }
  
  public PushCommand setReceivePack(String receivePack)
  {
    checkCallable();
    this.receivePack = receivePack;
    return this;
  }
  
  public String getReceivePack()
  {
    return receivePack;
  }
  
  public int getTimeout()
  {
    return timeout;
  }
  
  public ProgressMonitor getProgressMonitor()
  {
    return monitor;
  }
  
  public PushCommand setProgressMonitor(ProgressMonitor monitor)
  {
    checkCallable();
    this.monitor = monitor;
    return this;
  }
  
  public List<RefSpec> getRefSpecs()
  {
    return refSpecs;
  }
  
  public PushCommand setRefSpecs(RefSpec... specs)
  {
    checkCallable();
    refSpecs.clear();
    Collections.addAll(refSpecs, specs);
    return this;
  }
  
  public PushCommand setRefSpecs(List<RefSpec> specs)
  {
    checkCallable();
    refSpecs.clear();
    refSpecs.addAll(specs);
    return this;
  }
  
  public PushCommand setPushAll()
  {
    refSpecs.add(Transport.REFSPEC_PUSH_ALL);
    return this;
  }
  
  public PushCommand setPushTags()
  {
    refSpecs.add(Transport.REFSPEC_TAGS);
    return this;
  }
  
  public PushCommand add(Ref ref)
  {
    refSpecs.add(new RefSpec(ref.getLeaf().getName()));
    return this;
  }
  
  public PushCommand add(String nameOrSpec)
  {
    if (0 <= nameOrSpec.indexOf(':'))
    {
      refSpecs.add(new RefSpec(nameOrSpec));
    }
    else
    {
      Ref src;
      try
      {
        src = repo.getRef(nameOrSpec);
      }
      catch (IOException e)
      {
        throw new JGitInternalException(getexceptionCaughtDuringExecutionOfPushCommand, e);
      }
      if (src != null) {
        add(src);
      }
    }
    return this;
  }
  
  public boolean isDryRun()
  {
    return dryRun;
  }
  
  public PushCommand setDryRun(boolean dryRun)
  {
    checkCallable();
    this.dryRun = dryRun;
    return this;
  }
  
  public boolean isThin()
  {
    return thin;
  }
  
  public PushCommand setThin(boolean thin)
  {
    checkCallable();
    this.thin = thin;
    return this;
  }
  
  public boolean isForce()
  {
    return force;
  }
  
  public PushCommand setForce(boolean force)
  {
    checkCallable();
    this.force = force;
    return this;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.PushCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.ReflogEntry;

public class StashListCommand
  extends GitCommand<Collection<RevCommit>>
{
  public StashListCommand(Repository repo)
  {
    super(repo);
  }
  
  public Collection<RevCommit> call()
    throws GitAPIException, InvalidRefNameException
  {
    checkCallable();
    try
    {
      if (repo.getRef("refs/stash") == null) {
        return Collections.emptyList();
      }
    }
    catch (IOException e)
    {
      throw new InvalidRefNameException(MessageFormat.format(getcannotRead, new Object[] { "refs/stash" }), e);
    }
    ReflogCommand refLog = new ReflogCommand(repo);
    refLog.setRef("refs/stash");
    Collection<ReflogEntry> stashEntries = refLog.call();
    if (stashEntries.isEmpty()) {
      return Collections.emptyList();
    }
    List<RevCommit> stashCommits = new ArrayList(stashEntries.size());
    
    RevWalk walk = new RevWalk(repo);
    walk.setRetainBody(true);
    try
    {
      for (ReflogEntry entry : stashEntries) {
        try
        {
          stashCommits.add(walk.parseCommit(entry.getNewId()));
        }
        catch (IOException e)
        {
          throw new JGitInternalException(MessageFormat.format(getcannotReadCommit, new Object[] { entry.getNewId() }), e);
        }
      }
    }
    finally
    {
      walk.dispose();
    }
    return stashCommits;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.StashListCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

public enum ResetCommand$ResetType
{
  SOFT,  MIXED,  HARD,  MERGE,  KEEP;
  
  private ResetCommand$ResetType() {}
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.ResetCommand.ResetType
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NotMergedException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;

public class DeleteBranchCommand
  extends GitCommand<List<String>>
{
  private final Set<String> branchNames = new HashSet();
  private boolean force;
  
  protected DeleteBranchCommand(Repository repo)
  {
    super(repo);
  }
  
  public List<String> call()
    throws GitAPIException, NotMergedException, CannotDeleteCurrentBranchException
  {
    checkCallable();
    List<String> result = new ArrayList();
    if (branchNames.isEmpty()) {
      return result;
    }
    try
    {
      String currentBranch = repo.getFullBranch();
      RevWalk walk;
      RevCommit tip;
      if (!force)
      {
        walk = new RevWalk(repo);
        tip = walk.parseCommit(repo.resolve("HEAD"));
        for (String branchName : branchNames) {
          if (branchName != null)
          {
            Ref currentRef = repo.getRef(branchName);
            if (currentRef != null)
            {
              RevCommit base = walk.parseCommit(repo.resolve(branchName));
              if (!walk.isMergedInto(base, tip)) {
                throw new NotMergedException();
              }
            }
          }
        }
      }
      setCallable(false);
      for (String branchName : branchNames) {
        if (branchName != null)
        {
          Ref currentRef = repo.getRef(branchName);
          if (currentRef != null)
          {
            String fullName = currentRef.getName();
            if (fullName.equals(currentBranch)) {
              throw new CannotDeleteCurrentBranchException(MessageFormat.format(getcannotDeleteCheckedOutBranch, new Object[] { branchName }));
            }
            RefUpdate update = repo.updateRef(fullName);
            update.setRefLogMessage("branch deleted", false);
            update.setForceUpdate(true);
            RefUpdate.Result deleteResult = update.delete();
            
            boolean ok = true;
            switch (deleteResult)
            {
            case IO_FAILURE: 
            case LOCK_FAILURE: 
            case REJECTED: 
              ok = false;
              break;
            }
            if (ok)
            {
              result.add(fullName);
              if (fullName.startsWith("refs/heads/"))
              {
                String shortenedName = fullName.substring("refs/heads/".length());
                
                StoredConfig cfg = repo.getConfig();
                cfg.unsetSection("branch", shortenedName);
                
                cfg.save();
              }
            }
            else
            {
              throw new JGitInternalException(MessageFormat.format(getdeleteBranchUnexpectedResult, new Object[] { deleteResult.name() }));
            }
          }
        }
      }
      return result;
    }
    catch (IOException ioe)
    {
      throw new JGitInternalException(ioe.getMessage(), ioe);
    }
  }
  
  public DeleteBranchCommand setBranchNames(String... branchnames)
  {
    checkCallable();
    branchNames.clear();
    for (String branch : branchnames) {
      branchNames.add(branch);
    }
    return this;
  }
  
  public DeleteBranchCommand setForce(boolean force)
  {
    checkCallable();
    this.force = force;
    return this;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.DeleteBranchCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.DeletePath;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.IndexDiffFilter;
import org.eclipse.jgit.treewalk.filter.SkipWorkTreeFilter;

public class StashCreateCommand
  extends GitCommand<RevCommit>
{
  private static final String MSG_INDEX = "index on {0}: {1} {2}";
  private static final String MSG_WORKING_DIR = "WIP on {0}: {1} {2}";
  private String indexMessage = "index on {0}: {1} {2}";
  private String workingDirectoryMessage = "WIP on {0}: {1} {2}";
  private String ref = "refs/stash";
  private PersonIdent person;
  
  public StashCreateCommand(Repository repo)
  {
    super(repo);
    person = new PersonIdent(repo);
  }
  
  public StashCreateCommand setIndexMessage(String message)
  {
    indexMessage = message;
    return this;
  }
  
  public StashCreateCommand setWorkingDirectoryMessage(String message)
  {
    workingDirectoryMessage = message;
    return this;
  }
  
  public StashCreateCommand setPerson(PersonIdent person)
  {
    this.person = person;
    return this;
  }
  
  public StashCreateCommand setRef(String ref)
  {
    this.ref = ref;
    return this;
  }
  
  private RevCommit parseCommit(ObjectReader reader, ObjectId headId)
    throws IOException
  {
    RevWalk walk = new RevWalk(reader);
    walk.setRetainBody(true);
    return walk.parseCommit(headId);
  }
  
  private CommitBuilder createBuilder(ObjectId headId)
  {
    CommitBuilder builder = new CommitBuilder();
    PersonIdent author = person;
    if (author == null) {
      author = new PersonIdent(repo);
    }
    builder.setAuthor(author);
    builder.setCommitter(author);
    builder.setParentId(headId);
    return builder;
  }
  
  private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage)
    throws IOException
  {
    Ref currentRef = repo.getRef(ref);
    RefUpdate refUpdate = repo.updateRef(ref);
    refUpdate.setNewObjectId(commitId);
    refUpdate.setRefLogIdent(refLogIdent);
    refUpdate.setRefLogMessage(refLogMessage, false);
    if (currentRef != null) {
      refUpdate.setExpectedOldObjectId(currentRef.getObjectId());
    } else {
      refUpdate.setExpectedOldObjectId(ObjectId.zeroId());
    }
    refUpdate.forceUpdate();
  }
  
  private Ref getHead()
    throws GitAPIException
  {
    try
    {
      Ref head = repo.getRef("HEAD");
      if ((head == null) || (head.getObjectId() == null)) {
        throw new NoHeadException(getheadRequiredToStash);
      }
      return head;
    }
    catch (IOException e)
    {
      throw new JGitInternalException(getstashFailed, e);
    }
  }
  
  public RevCommit call()
    throws GitAPIException
  {
    checkCallable();
    
    Ref head = getHead();
    ObjectReader reader = repo.newObjectReader();
    try
    {
      RevCommit headCommit = parseCommit(reader, head.getObjectId());
      DirCache cache = repo.lockDirCache();
      ObjectInserter inserter = repo.newObjectInserter();
      TreeWalk treeWalk;
      ObjectId commitId;
      try
      {
        treeWalk = new TreeWalk(reader);
        treeWalk.setRecursive(true);
        treeWalk.addTree(headCommit.getTree());
        treeWalk.addTree(new DirCacheIterator(cache));
        treeWalk.addTree(new FileTreeIterator(repo));
        treeWalk.setFilter(AndTreeFilter.create(new SkipWorkTreeFilter(1), new IndexDiffFilter(1, 2)));
        if (!treeWalk.next()) {
          return null;
        }
        MutableObjectId id = new MutableObjectId();
        List<DirCacheEditor.PathEdit> wtEdits = new ArrayList();
        List<String> wtDeletes = new ArrayList();
        do
        {
          AbstractTreeIterator headIter = treeWalk.getTree(0, AbstractTreeIterator.class);
          
          DirCacheIterator indexIter = (DirCacheIterator)treeWalk.getTree(1, DirCacheIterator.class);
          
          WorkingTreeIterator wtIter = (WorkingTreeIterator)treeWalk.getTree(2, WorkingTreeIterator.class);
          if ((headIter != null) && (indexIter != null) && (wtIter != null))
          {
            if (!indexIter.getDirCacheEntry().isMerged()) {
              throw new UnmergedPathsException(new UnmergedPathException(indexIter.getDirCacheEntry()));
            }
            if ((!wtIter.idEqual(indexIter)) && (!wtIter.idEqual(headIter)))
            {
              treeWalk.getObjectId(id, 0);
              final DirCacheEntry entry = new DirCacheEntry(treeWalk.getRawPath());
              
              entry.setLength(wtIter.getEntryLength());
              entry.setLastModified(wtIter.getEntryLastModified());
              entry.setFileMode(wtIter.getEntryFileMode());
              long contentLength = wtIter.getEntryContentLength();
              InputStream in = wtIter.openEntryStream();
              try
              {
                entry.setObjectId(inserter.insert(3, contentLength, in));
              }
              finally {}
              wtEdits.add(new DirCacheEditor.PathEdit(entry)
              {
                public void apply(DirCacheEntry ent)
                {
                  ent.copyMetaData(entry);
                }
              });
            }
          }
          else if (indexIter == null)
          {
            wtDeletes.add(treeWalk.getPathString());
          }
          else if ((wtIter == null) && (headIter != null))
          {
            wtDeletes.add(treeWalk.getPathString());
          }
        } while (treeWalk.next());
        String branch = Repository.shortenRefName(head.getTarget().getName());
        
        CommitBuilder builder = createBuilder(headCommit);
        builder.setTreeId(cache.writeTree(inserter));
        builder.setMessage(MessageFormat.format(indexMessage, new Object[] { branch, headCommit.abbreviate(7).name(), headCommit.getShortMessage() }));
        
        ObjectId indexCommit = inserter.insert(builder);
        if ((!wtEdits.isEmpty()) || (!wtDeletes.isEmpty()))
        {
          DirCacheEditor editor = cache.editor();
          for (DirCacheEditor.PathEdit edit : wtEdits) {
            editor.add(edit);
          }
          for (String path : wtDeletes) {
            editor.add(new DirCacheEditor.DeletePath(path));
          }
          editor.finish();
        }
        builder.addParentId(indexCommit);
        builder.setMessage(MessageFormat.format(workingDirectoryMessage, new Object[] { branch, headCommit.abbreviate(7).name(), headCommit.getShortMessage() }));
        
        builder.setTreeId(cache.writeTree(inserter));
        commitId = inserter.insert(builder);
        inserter.flush();
        
        updateStashRef(commitId, builder.getAuthor(), builder.getMessage());
      }
      finally
      {
        inserter.release();
      }
      new ResetCommand(repo).setMode(ResetCommand.ResetType.HARD).call();
      
      return parseCommit(reader, commitId);
    }
    catch (IOException e)
    {
      throw new JGitInternalException(getstashFailed, e);
    }
    finally
    {
      reader.release();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.StashCreateCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import org.eclipse.jgit.lib.AbbreviatedObjectId;

public class RebaseCommand$Step
{
  RebaseCommand.Action action;
  AbbreviatedObjectId commit;
  byte[] shortMessage;
  
  RebaseCommand$Step(RebaseCommand.Action action)
  {
    this.action = action;
  }
  
  public RebaseCommand.Action getAction()
  {
    return action;
  }
  
  public void setAction(RebaseCommand.Action action)
  {
    this.action = action;
  }
  
  public AbbreviatedObjectId getCommit()
  {
    return commit;
  }
  
  public byte[] getShortMessage()
  {
    return shortMessage;
  }
  
  public String toString()
  {
    return "Step[" + action + ", " + (commit == null ? "null" : commit) + ", " + (shortMessage == null ? "null" : new String(shortMessage)) + "]";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.RebaseCommand.Step
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.util.Comparator;
import org.eclipse.jgit.lib.Ref;

class ListTagCommand$1
  implements Comparator<Ref>
{
  ListTagCommand$1(ListTagCommand paramListTagCommand) {}
  
  public int compare(Ref o1, Ref o2)
  {
    return o1.getName().compareTo(o2.getName());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.ListTagCommand.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.text.MessageFormat;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.internal.JGitText;

public enum RebaseCommand$Action
{
  PICK("pick", "p"),  REWORD("reword", "r"),  EDIT("edit", "e");
  
  private final String token;
  private final String shortToken;
  
  private RebaseCommand$Action(String token, String shortToken)
  {
    this.token = token;
    this.shortToken = shortToken;
  }
  
  public String toToken()
  {
    return token;
  }
  
  public String toString()
  {
    return "Action[" + token + "]";
  }
  
  static Action parse(String token)
  {
    for (Action action : ) {
      if ((token.equals(token)) || (shortToken.equals(token))) {
        return action;
      }
    }
    throw new JGitInternalException(MessageFormat.format(getunknownOrUnsupportedCommand, new Object[] { token, values() }));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.RebaseCommand.Action
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.PatchApplyException;
import org.eclipse.jgit.api.errors.PatchFormatException;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.HunkHeader;
import org.eclipse.jgit.patch.Patch;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;

public class ApplyCommand
  extends GitCommand<ApplyResult>
{
  private InputStream in;
  
  ApplyCommand(Repository repo)
  {
    super(repo);
  }
  
  public ApplyCommand setPatch(InputStream in)
  {
    checkCallable();
    this.in = in;
    return this;
  }
  
  public ApplyResult call()
    throws GitAPIException, PatchFormatException, PatchApplyException
  {
    checkCallable();
    ApplyResult r = new ApplyResult();
    try
    {
      Patch p = new Patch();
      try
      {
        p.parse(in);
      }
      finally
      {
        in.close();
      }
      if (!p.getErrors().isEmpty()) {
        throw new PatchFormatException(p.getErrors());
      }
      for (FileHeader fh : p.getFiles())
      {
        DiffEntry.ChangeType type = fh.getChangeType();
        File f = null;
        switch (type)
        {
        case ADD: 
          f = getFile(fh.getNewPath(), true);
          apply(f, fh);
          break;
        case MODIFY: 
          f = getFile(fh.getOldPath(), false);
          apply(f, fh);
          break;
        case DELETE: 
          f = getFile(fh.getOldPath(), false);
          if (!f.delete()) {
            throw new PatchApplyException(MessageFormat.format(getcannotDeleteFile, new Object[] { f }));
          }
          break;
        case RENAME: 
          f = getFile(fh.getOldPath(), false);
          File dest = getFile(fh.getNewPath(), false);
          if (!f.renameTo(dest)) {
            throw new PatchApplyException(MessageFormat.format(getrenameFileFailed, new Object[] { f, dest }));
          }
          break;
        case COPY: 
          f = getFile(fh.getOldPath(), false);
          byte[] bs = IO.readFully(f);
          FileOutputStream fos = new FileOutputStream(getFile(fh.getNewPath(), true));
          try
          {
            fos.write(bs);
          }
          finally
          {
            fos.close();
          }
        }
        r.addUpdatedFile(f);
      }
    }
    catch (IOException e)
    {
      throw new PatchApplyException(MessageFormat.format(getpatchApplyException, new Object[] { e.getMessage() }), e);
    }
    setCallable(false);
    return r;
  }
  
  private File getFile(String path, boolean create)
    throws PatchApplyException
  {
    File f = new File(getRepository().getWorkTree(), path);
    if (create) {
      try
      {
        File parent = f.getParentFile();
        FileUtils.mkdirs(parent, true);
        FileUtils.createNewFile(f);
      }
      catch (IOException e)
      {
        throw new PatchApplyException(MessageFormat.format(getcreateNewFileFailed, new Object[] { f }), e);
      }
    }
    return f;
  }
  
  private void apply(File f, FileHeader fh)
    throws IOException, PatchApplyException
  {
    RawText rt = new RawText(f);
    List<String> oldLines = new ArrayList(rt.size());
    for (int i = 0; i < rt.size(); i++) {
      oldLines.add(rt.getString(i));
    }
    List<String> newLines = new ArrayList(oldLines);
    for (HunkHeader hh : fh.getHunks())
    {
      StringBuilder hunk = new StringBuilder();
      for (int j = hh.getStartOffset(); j < hh.getEndOffset(); j++) {
        hunk.append((char)hh.getBuffer()[j]);
      }
      RawText hrt = new RawText(hunk.toString().getBytes());
      List<String> hunkLines = new ArrayList(hrt.size());
      for (int i = 0; i < hrt.size(); i++) {
        hunkLines.add(hrt.getString(i));
      }
      int pos = 0;
      for (int j = 1; j < hunkLines.size(); j++)
      {
        String hunkLine = (String)hunkLines.get(j);
        switch (hunkLine.charAt(0))
        {
        case ' ': 
          if (!((String)newLines.get(hh.getNewStartLine() - 1 + pos)).equals(hunkLine.substring(1))) {
            throw new PatchApplyException(MessageFormat.format(getpatchApplyException, new Object[] { hh }));
          }
          pos++;
          break;
        case '-': 
          if (!((String)newLines.get(hh.getNewStartLine() - 1 + pos)).equals(hunkLine.substring(1))) {
            throw new PatchApplyException(MessageFormat.format(getpatchApplyException, new Object[] { hh }));
          }
          newLines.remove(hh.getNewStartLine() - 1 + pos);
          break;
        case '+': 
          newLines.add(hh.getNewStartLine() - 1 + pos, hunkLine.substring(1));
          
          pos++;
        }
      }
    }
    if (!isNoNewlineAtEndOfFile(fh)) {
      newLines.add("");
    }
    if (!rt.isMissingNewlineAtEnd()) {
      oldLines.add("");
    }
    if (!isChanged(oldLines, newLines)) {
      return;
    }
    StringBuilder sb = new StringBuilder();
    for (String l : newLines) {
      sb.append(l).append('\n');
    }
    sb.deleteCharAt(sb.length() - 1);
    FileWriter fw = new FileWriter(f);
    fw.write(sb.toString());
    fw.close();
  }
  
  private static boolean isChanged(List<String> ol, List<String> nl)
  {
    if (ol.size() != nl.size()) {
      return true;
    }
    for (int i = 0; i < ol.size(); i++) {
      if (!((String)ol.get(i)).equals(nl.get(i))) {
        return true;
      }
    }
    return false;
  }
  
  private boolean isNoNewlineAtEndOfFile(FileHeader fh)
  {
    HunkHeader lastHunk = (HunkHeader)fh.getHunks().get(fh.getHunks().size() - 1);
    RawText lhrt = new RawText(lastHunk.getBuffer());
    return lhrt.getString(lhrt.size() - 1).equals("\\ No newline at end of file");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.ApplyCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.io.IOException;
import java.text.MessageFormat;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.transport.FetchResult;

public class PullCommand
  extends TransportCommand<PullCommand, PullResult>
{
  private static final String DOT = ".";
  private ProgressMonitor monitor = NullProgressMonitor.INSTANCE;
  private PullRebaseMode pullRebaseMode = PullRebaseMode.USE_CONFIG;
  
  private static enum PullRebaseMode
  {
    USE_CONFIG,  REBASE,  NO_REBASE;
    
    private PullRebaseMode() {}
  }
  
  protected PullCommand(Repository repo)
  {
    super(repo);
  }
  
  public PullCommand setProgressMonitor(ProgressMonitor monitor)
  {
    this.monitor = monitor;
    return this;
  }
  
  public PullCommand setRebase(boolean useRebase)
  {
    checkCallable();
    pullRebaseMode = (useRebase ? PullRebaseMode.REBASE : PullRebaseMode.NO_REBASE);
    return this;
  }
  
  public PullResult call()
    throws GitAPIException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException, TransportException
  {
    checkCallable();
    
    monitor.beginTask(getpullTaskName, 2);
    String branchName;
    try
    {
      String fullBranch = repo.getFullBranch();
      if (fullBranch == null) {
        throw new NoHeadException(getpullOnRepoWithoutHEADCurrentlyNotSupported);
      }
      if (!fullBranch.startsWith("refs/heads/")) {
        throw new DetachedHeadException();
      }
      branchName = fullBranch.substring("refs/heads/".length());
    }
    catch (IOException e)
    {
      throw new JGitInternalException(getexceptionCaughtDuringExecutionOfPullCommand, e);
    }
    if (!repo.getRepositoryState().equals(RepositoryState.SAFE)) {
      throw new WrongRepositoryStateException(MessageFormat.format(getcannotPullOnARepoWithState, new Object[] { repo.getRepositoryState().name() }));
    }
    Config repoConfig = repo.getConfig();
    String remote = repoConfig.getString("branch", branchName, "remote");
    if (remote == null) {
      remote = "origin";
    }
    String remoteBranchName = repoConfig.getString("branch", branchName, "merge");
    
    boolean doRebase = false;
    switch (pullRebaseMode)
    {
    case REBASE: 
      doRebase = true;
      break;
    case NO_REBASE: 
      doRebase = false;
      break;
    case USE_CONFIG: 
    default: 
      doRebase = repoConfig.getBoolean("branch", branchName, "rebase", false);
    }
    if (remoteBranchName == null)
    {
      String missingKey = "branch." + branchName + "." + "merge";
      
      throw new InvalidConfigurationException(MessageFormat.format(getmissingConfigurationForKey, new Object[] { missingKey }));
    }
    boolean isRemote = !remote.equals(".");
    FetchResult fetchRes;
    String remoteUri;
    FetchResult fetchRes;
    if (isRemote)
    {
      String remoteUri = repoConfig.getString("remote", remote, "url");
      if (remoteUri == null)
      {
        String missingKey = "remote." + remote + "." + "url";
        
        throw new InvalidConfigurationException(MessageFormat.format(getmissingConfigurationForKey, new Object[] { missingKey }));
      }
      if (monitor.isCancelled()) {
        throw new CanceledException(MessageFormat.format(getoperationCanceled, new Object[] { getpullTaskName }));
      }
      FetchCommand fetch = new FetchCommand(repo);
      fetch.setRemote(remote);
      fetch.setProgressMonitor(monitor);
      configure(fetch);
      
      fetchRes = fetch.call();
    }
    else
    {
      remoteUri = "local repository";
      fetchRes = null;
    }
    monitor.update(1);
    if (monitor.isCancelled()) {
      throw new CanceledException(MessageFormat.format(getoperationCanceled, new Object[] { getpullTaskName }));
    }
    AnyObjectId commitToMerge;
    AnyObjectId commitToMerge;
    if (isRemote)
    {
      Ref r = null;
      if (fetchRes != null)
      {
        r = fetchRes.getAdvertisedRef(remoteBranchName);
        if (r == null) {
          r = fetchRes.getAdvertisedRef("refs/heads/" + remoteBranchName);
        }
      }
      if (r == null) {
        throw new JGitInternalException(MessageFormat.format(getcouldNotGetAdvertisedRef, new Object[] { remoteBranchName }));
      }
      commitToMerge = r.getObjectId();
    }
    else
    {
      try
      {
        commitToMerge = repo.resolve(remoteBranchName);
        if (commitToMerge == null) {
          throw new RefNotFoundException(MessageFormat.format(getrefNotResolved, new Object[] { remoteBranchName }));
        }
      }
      catch (IOException e)
      {
        throw new JGitInternalException(getexceptionCaughtDuringExecutionOfPullCommand, e);
      }
    }
    String upstreamName = "branch '" + Repository.shortenRefName(remoteBranchName) + "' of " + remoteUri;
    PullResult result;
    PullResult result;
    if (doRebase)
    {
      RebaseCommand rebase = new RebaseCommand(repo);
      RebaseResult rebaseRes = rebase.setUpstream(commitToMerge).setUpstreamName(upstreamName).setProgressMonitor(monitor).setOperation(RebaseCommand.Operation.BEGIN).call();
      
      result = new PullResult(fetchRes, remote, rebaseRes);
    }
    else
    {
      MergeCommand merge = new MergeCommand(repo);
      merge.include(upstreamName, commitToMerge);
      MergeResult mergeRes = merge.call();
      monitor.update(1);
      result = new PullResult(fetchRes, remote, mergeRes);
    }
    monitor.endTask();
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jgit.api.PullCommand
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jgit.api;

import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.Transport;

public class LsRemoteCommand
  extends TransportCommand<LsRemoteCommand, Collection<Ref>>
{
  private String remote = "origin";
  private boolean heads;
  private boolean tags;
  private String uploadPack;
  
  public LsRemoteCommand(Repository repo)
  {
    super(repo);
  }
  
  public LsRemoteCommand setRemote(String remote)
  {
    checkCallable();
    this.remote = remote;
    return this;
  }
  
  public LsRemoteCommand setHeads(boolean heads)
  {
    this.heads = heads;
    return this;
  }
  
  public LsRemoteCommand setTags(boolean tags)
  {
    this.tags = tags;
    return this;
  }
  
  public LsRemoteCommand setUploadPack(String uploadPack)
  {
    this.uploadPack = uploadPack;
    return this;
  }
  
  public Collection<Ref> call()
    throws GitAPIException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
  {
    checkCallable();
    
    Transport transport = null;
    FetchConnection fc = null;
    try
    {
      transport = Transport.open(repo, remote);
      transport.setOptionUploadPack(uploadPack);
      configure(transport);
      Collection<RefSpec> refSpecs = new ArrayList(1);
      if (tags) {
        refSpecs.add(new RefSpec("refs/tags/*:refs/remotes/origin/tags/*"));
      }
      if (heads) {
        refSpecs.add(new RefSpec("refs/heads/*:refs/remotes/origin/*"));
      }
      Map<String, Ref> refmap = new HashMap();
      fc = transport.openFetch();
      Collection<Ref> refs = fc.getRefs();
      Iterator i$;
      if (refSpecs.isEmpty()) {
        for (Ref r : refs) {
          refmap.put(r.getName(), r);
        }
      } else {
        for (i$ = refs.iterator(); i$.hasNext();)
        {
          r = (Ref)i$.next();
          for (RefSpec rs : refSpecs) {
            if (rs.matchSource(r))
            {
              refmap.put(r.getName(), r);
              break;
            }
          }
        }
      }
      Ref r;
      return refmap.values();
    }
    catch (URISyntaxException e)
    {
      throw new InvalidRemoteException(MessageFormat.format(getinvalidRemote, new Object[] { remote }));
    }
    catch (NotSupportedException e)
    {
      throw new JGitInternalException(gete
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd