You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TransportFetchCommand.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package org.eclipse.jgit.integrate.remotehelper.internal;
  2. import org.eclipse.jgit.integrate.remotehelper.RemoteHelperCommand;
  3. import org.eclipse.jgit.lib.ObjectId;
  4. import org.eclipse.jgit.lib.Ref;
  5. import org.eclipse.jgit.lib.TextProgressMonitor;
  6. import org.eclipse.jgit.transport.FetchConnection;
  7. import java.util.ArrayList;
  8. import java.util.HashSet;
  9. import java.util.List;
  10. public class TransportFetchCommand extends RemoteHelperCommand {
  11. private final RemoteHelperTransport provider;
  12. public TransportFetchCommand(RemoteHelperTransport provider) {
  13. super(provider.getContext());
  14. this.provider = provider;
  15. }
  16. private ArrayList<FetchDefinition> defs = new ArrayList<>();
  17. @Override
  18. public void handle(List<String> arguments) throws Exception {
  19. defs.add(new FetchDefinition(arguments.get(0), arguments.get(1)));
  20. }
  21. @Override
  22. public void complete() throws Exception {
  23. List<Ref> want = new ArrayList<>();
  24. HashSet<ObjectId> have = new HashSet<>();
  25. for (FetchDefinition def : defs) {
  26. want.add(provider.getFetchConnection().getRef(def.getName()));
  27. }
  28. FetchConnection connection = provider.getFetchConnection();
  29. connection.fetch(
  30. new TextProgressMonitor(),
  31. want,
  32. have
  33. );
  34. connection.close();
  35. defs.clear();
  36. getContext().complete();
  37. }
  38. private static class FetchDefinition {
  39. private final String sha;
  40. private final String name;
  41. FetchDefinition(String sha, String name) {
  42. this.sha = sha;
  43. this.name = name;
  44. }
  45. public String getSha() {
  46. return sha;
  47. }
  48. public String getName() {
  49. return name;
  50. }
  51. }
  52. }