Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[lib] completed the JSON part of the reciprocating recieve pack parser

  • Loading branch information...
commit ea398de45e840afd1dff2ae68104708257275e3d 1 parent 7cc7cac
Paolo Fragomeni authored November 10, 2012

Showing 2 changed files with 36 additions and 15 deletions. Show diff stats Hide diff stats

  1. 1  lib/push.js
  2. 50  lib/repo.js
1  lib/push.js
@@ -68,7 +68,6 @@ var push = module.exports = function push(opts) {
68 68
     // points to.
69 69
     //
70 70
     var data = '';
71  
-    var mode = 'utf8';
72 71
 
73 72
     socket.on('data', function(msg) {
74 73
 
50  lib/repo.js
@@ -34,21 +34,37 @@ var Repo = module.exports = function Repo(opts) {
34 34
   // and fast-forwarding of sha1 refs (heads/tags) 
35 35
   // on the remote end.
36 36
   //
37  
-  stream
38  
-    .pipe(JSONStream.createReadStream())
39  
-    .on('data', function(obj) {
  37
+  var data = '';
40 38
 
41  
-      var msg, type, data;
  39
+  stream.on('data', function(msg) {
42 40
 
43  
-      try {
44  
-        msg = JSON.parse(String(data));
45  
-      }
46  
-      catch(ex) {
47  
-        throw new Error('Data error');
48  
-      }
  41
+    data += msg.toString();
  42
+
  43
+    var parts = data.split('\n');
  44
+    data = parts.pop();
  45
+
  46
+    parts.forEach(function (part) {
  47
+      processData(part);
  48
+    });
  49
+  }); 
  50
+
  51
+  var processData = function processData(part) {
  52
+
  53
+    var json = false;
  54
+
  55
+    try {
  56
+      json = JSON.parse(part));
  57
+    } catch(_) {}
49 58
 
50  
-      var type = msg.meta.type;
51  
-      var data = msg.data;
  59
+    //
  60
+    // During the negotiation phase we will receive
  61
+    // JSON, after that the packfiles will be sent
  62
+    // in binary format.
  63
+    //
  64
+    if (json) {
  65
+
  66
+      var type = json.meta.type;
  67
+      var data = json.data;
52 68
 
53 69
       //
54 70
       // The first message we receive should be a `send-pack`.
@@ -96,15 +112,21 @@ var Repo = module.exports = function Repo(opts) {
96 112
               path: that.refs
97 113
             }
98 114
           });
99  
-
100 115
         }
101 116
         else {
102 117
 
103 118
           socket.end();
104 119
         }
105 120
       }
106  
-    });
  121
+    }
  122
+    else {
107 123
 
  124
+      //
  125
+      // TODO: consume binary data streamed in.
  126
+      // consume
  127
+      //
  128
+    }
  129
+  }
108 130
 };
109 131
 
110 132
 util.inherits(Repo, Stream);

0 notes on commit ea398de

Please sign in to comment.
Something went wrong with that request. Please try again.