Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix correctly formatting pkt mesg responses

  • Loading branch information...
commit 2948e19aa05a8c351824a8cd0be2e2392535eb40 1 parent 78217e3
Maksim Lin authored

Showing 1 changed file with 16 additions and 7 deletions. Show diff stats Hide diff stats

  1. +16 7 routes/index.js
23 routes/index.js
@@ -27,13 +27,11 @@ exports.getInfoRefs = function(req, res){
27 27
28 28 var packet = "# service=git-receive-pack\n";
29 29 var length = packet.length + 4;
30   - var hex = "0123456789abcdef";
31   - var prefix = hex.charAt (length >> 12) & 0xf;
32   - prefix = prefix + hex.charAt(length >> 8) & 0xf;
33   - prefix = prefix + hex.charAt(length >> 4) & 0xf;
34   - prefix = prefix + hex.charAt(length) & 0xf;
35   - res.write(prefix+packet+"0000");
36   - console.log(prefix+packet+"0000");
  30 +
  31 + var prefix = (packet.length+4).toString(16);
  32 + var line = pad(prefix, 4)+packet+"0000";
  33 + res.write(line);
  34 + console.log(line);
37 35
38 36 var git = spawn('git-receive-pack', ['--stateless-rpc', '--advertise-refs', '/home/maks/tmp/gitserver-repos/gitserver']);
39 37 //git.stdout.pipe(res);
@@ -66,3 +64,14 @@ exports.postReceivePack = function(req, res) {
66 64 res.end();
67 65 });
68 66 };
  67 +
  68 +/**
  69 + * num - number to pad
  70 + * pad - number of places to pad to
  71 + * chr - character to use for padding, default to '0'
  72 + */
  73 +function pad(num, pad, chr) {
  74 + var pad_char = typeof chr !== 'undefined' ? chr : '0';
  75 + var pad = new Array(1 + pad).join(pad_char);
  76 + return (pad + num).slice(-pad.length);
  77 +}

0 comments on commit 2948e19

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