|
|
@@ -6,7 +6,6 @@ import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.Locale;
|
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -171,65 +170,57 @@ class HttpGitProtocol extends BaseGitProtocol {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void PushBlobs(final GitCommit.Builder commit, final OnStreamResponseListener<Void> response) {
|
|
|
+ @Override
|
|
|
+ public void PushPack(final GitCommit commit, Pacman pack, final OnStreamResponseListener<Void> response) {
|
|
|
GetRefs(new OnResponseListener<GitRef[]>() {
|
|
|
@Override
|
|
|
public void OnResponse(final GitRef[] result) {
|
|
|
- GitRef myRef = null;
|
|
|
- for (GitRef ref: result) {
|
|
|
- if (ref.GetBranch().equals(fConfig.GetBranch()))
|
|
|
- myRef = ref;
|
|
|
+ final GitRef myRef = GetHeadRef(result);
|
|
|
+ if (myRef == null) {
|
|
|
+ response.OnError("Branch " +fConfig.GetBranch() + " not found on remote for pushing", null);
|
|
|
+ return;
|
|
|
}
|
|
|
- if (myRef != null) {
|
|
|
- final GitRef finalRef = myRef;
|
|
|
- response.OnMsg("Pushing over " +myRef.GetBranch() +" revision " +myRef.GetHash());
|
|
|
- try {
|
|
|
- HashMap<String, String> headers = new HashMap<>();
|
|
|
- headers.put("Content-Type", "application/x-git-receive-pack-request");
|
|
|
- ProtoPost(new URL(fConfig.GetUrl() +"/git-receive-pack"), headers, fConfig, new OnResponseListener<byte[]>() {
|
|
|
- @Override
|
|
|
- public void OnResponse(byte[] result) {
|
|
|
- response.OnResponse(null);
|
|
|
- }
|
|
|
+ response.OnMsg("Pushing over " +myRef.GetBranch() +" revision " +myRef.GetHash());
|
|
|
+ try {
|
|
|
+ HashMap<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/x-git-receive-pack-request");
|
|
|
+ ProtoPost(new URL(fConfig.GetUrl() +"/git-receive-pack"), headers, fConfig, new OnResponseListener<byte[]>() {
|
|
|
+ @Override
|
|
|
+ public void OnResponse(byte[] result) {
|
|
|
+ response.OnResponse(null);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void OnError(String msg, Throwable e) {
|
|
|
- log.log(Level.SEVERE, "git-receive-pack error", e);
|
|
|
- response.OnError(msg, e);
|
|
|
- }
|
|
|
- }, new OnResponseListener<OutputStream>() {
|
|
|
- @Override
|
|
|
- public void OnResponse(OutputStream result) {
|
|
|
- byte[] msgLine = (finalRef.GetHash() + " " + GitSha1.BytesToString(GitSha1.getRawSha1OfPackable(commit.Build())) +" " +finalRef.GetBranch()).getBytes();
|
|
|
- try {
|
|
|
- result.write(String.format(Locale.US, "%04X", msgLine.length +4).getBytes());
|
|
|
- result.write(msgLine);
|
|
|
- result.write("0000".getBytes());
|
|
|
- Pacman pac = new Pacman(commit.PreparePack());
|
|
|
- if (!pac.Write(result)) {
|
|
|
- OnError("Pack error", null);
|
|
|
- return;
|
|
|
- }
|
|
|
- result.close();
|
|
|
- }
|
|
|
- catch (IOException e) {
|
|
|
- log.log(Level.SEVERE, "Cannot git-upload-pack: " +e.getMessage(), e);
|
|
|
- OnError(e.getMessage(), e);
|
|
|
+ @Override
|
|
|
+ public void OnError(String msg, Throwable e) {
|
|
|
+ log.log(Level.SEVERE, "git-receive-pack error", e);
|
|
|
+ response.OnError(msg, e);
|
|
|
+ }
|
|
|
+ }, new OnResponseListener<OutputStream>() {
|
|
|
+ @Override
|
|
|
+ public void OnResponse(OutputStream result) {
|
|
|
+ try {
|
|
|
+ result.write(GitLine(myRef.GetHash() + " " + GitSha1.BytesToString(GitSha1.getRawSha1OfPackable(commit)) +" " +myRef.GetBranch()));
|
|
|
+ result.write(GitLine(null));
|
|
|
+ if (!pack.Write(result)) {
|
|
|
+ OnError("Pack error", null);
|
|
|
+ return;
|
|
|
}
|
|
|
+ result.close();
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void OnError(String msg, Throwable e) {
|
|
|
- response.OnError(msg, e);
|
|
|
+ catch (IOException e) {
|
|
|
+ log.log(Level.SEVERE, "Cannot git-upload-pack: " +e.getMessage(), e);
|
|
|
+ OnError(e.getMessage(), e);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- catch (IOException e) {
|
|
|
- response.OnError(e.getMessage(), e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- response.OnError("Branch " +fConfig.GetBranch() + " not found on remote for pushing", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void OnError(String msg, Throwable e) {
|
|
|
+ response.OnError(msg, e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ response.OnError(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|