Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ssb-git-repo

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-git-repo - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

134

lib/repo.js

@@ -43,15 +43,2 @@ var pull = require('pull-stream')

function objectsArrayToMap(arr) {
var o = {}
for (var i = 0; i < arr.length; i++) {
var obj = arr[i]
o[obj.sha1] = {
type: obj.type,
length: obj.length,
link: obj.link
}
}
return o
}
function Repo(sbot, id, msg) {

@@ -63,3 +50,3 @@ this.sbot = sbot

this._objects = {/* sha1: {type, length, key} */}
this._externalBlobsRead = {/* blobId */}
this._blobs = {/* sha1: [Buffer] */}

@@ -70,3 +57,2 @@ // queued operations while syncing of old messages

this._headCbs = []
this._hashLookupsMulticb = multicb()
}

@@ -108,11 +94,21 @@

for (var sha1 in c.objects || {}) {
if (!(sha1 in this._objects)) {
var obj = c.objects[sha1]
this._addObject(sha1, obj)
if (Array.isArray(c.objects)) {
for (var i = 0; i < c.objects.length; i++) {
var obj = c.objects[i]
var sha1 = obj && obj.sha1
if (!sha1) continue
if (!(sha1 in this._objects)) {
// complete waiting lookups
this._addObject(sha1, obj)
}
}
} else if (c.objects) {
// old format
for (var sha1 in c.objects) {
if (!(sha1 in this._objects)) {
var obj = c.objects[sha1]
this._addObject(sha1, obj)
}
}
}
if (c.objects_ext)
this._readExternalObjects(c.objects_ext)
}

@@ -130,37 +126,16 @@

for (var sha1 in c.objects || {})
this._objects[sha1] = c.objects[sha1]
if (c.objects_ext)
this._readExternalObjects(c.objects_ext)
if (Array.isArray(c.objects)) {
for (var i = 0; i < c.objects.length; i++) {
var obj = c.objects[i]
var sha1 = obj && obj.sha1
if (!sha1) continue
this._addObject(sha1, obj)
}
} else if (c.objects) {
// old format
for (var sha1 in c.objects)
this._objects[sha1] = c.objects[sha1]
}
}
// read index of git SHA1 -> object info from a blob.
// DEPRECATED
Repo.prototype._readExternalObjects = function (blobId) {
if (!ref.isBlobId(blobId)) return
if (blobId in this._externalBlobsRead)
return
this._externalBlobsRead[blobId] = true
var cb = this._hashLookupsMulticb()
var self = this
this._getBlob(blobId, function (err, read) {
if (err) return cb()
pull(
read,
pull.collect(function (err, bufs) {
if (err) return cb()
var objects
try {
objects = JSON.parse(Buffer.concat(bufs))
} catch(e) {}
if (objects)
for (var sha1 in objects)
self._addObject(sha1, objects[sha1])
cb()
})
)
})
}
Repo.prototype._getBlob = function (key, cb) {

@@ -175,2 +150,16 @@ var blobs = this.sbot.blobs

Repo.prototype._getBlobCached = function (key, cb) {
var blobs = this._blobs
if (key in blobs)
cb(null, pull.values(blobs[key]))
else
this._getBlob(key, function (err, read) {
pull(read, pull.collect(function (err, bufs) {
if (err) return cb(err)
blobs[key] = bufs
cb(null, pull.values(bufs))
}))
})
}
Repo.prototype._hashLookup = function hashLookup(sha1, cb) {

@@ -248,11 +237,3 @@ if (this.synced || sha1 in this._objects)

now = [Date.now()]
var hashLookups = this._hashLookupsMulticb()
this._hashLookupsMulticb(function () {
this.synced = true
// complete waiting requests for lookups
for (var sha1 in this._hashLookups)
this._addObject(sha1, null)
}.bind(this))
pull(

@@ -289,4 +270,6 @@ this.sbot.links({

// done looking up hashes from messages. now wait for objects_ext blobs
hashLookups()
// complete waiting requests for lookups
this.synced = true
for (var sha1 in this._hashLookups)
this._addObject(sha1, null)

@@ -333,3 +316,7 @@ if (live)

if (!blobId) return cb(new Error('Object is missing blob key'))
this._getBlob(blobId, function (err, read) {
if (obj.type == 'blob')
this._getBlob(blobId, gotData)
else
this._getBlobCached(blobId, gotData)
function gotData(err, read) {
if (err) return cb(err)

@@ -341,3 +328,3 @@ cb(null, {

})
})
}
}.bind(this))

@@ -397,3 +384,3 @@ }

link: blobKey,
sha1: sha1 // this gets removed by objectsArrayToMap before publish
sha1: sha1
})

@@ -413,4 +400,4 @@ if (!ended)

msg.objects = objectsArrayToMap(objects)
sbot.publish(msg, function (err, msg) {
msg.objects = objects
sbot.publish(msg, function (err, msgPublished) {
if (err) {

@@ -420,3 +407,6 @@ if (/must not be large/.test(err.message)) {

// TODO: do something better here
cb(new Error('Update is too big to send! Try pushing fewer commits.'))
cb(new Error('Update is too big to send! ' +
'Try pushing fewer commits.\n\n' +
'Message size: ' + JSON.stringify(msg).length + ', ' +
'max size: 8192'))
} else {

@@ -426,3 +416,3 @@ cb(err)

} else {
self._processNewMsg(msg.value.content)
self._processNewMsg(msgPublished.value.content)
setTimeout(cb, 10)

@@ -429,0 +419,0 @@ }

{
"name": "ssb-git-repo",
"version": "1.1.0",
"version": "1.2.0",
"description": "git repos in secure-scuttlebutt",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -67,2 +67,34 @@ # ssb-git-repo

### Schema
#### type: git-repo
```js
{ type: 'git-repo' }
```
Creates a git repo. Note that you can actually push git objects to any message
in your feed, but the `git-repo` type is here to declare that a message will be
for a git repo. It may have properties added later.
#### type: git-update
```js
{
type: 'git-update',
repo: MsgId,
refs: { <ref>: String|null },
objects: [ { type: String, length: Number, sha1: String, link: BlobId } ],
}
```
Updates a repo. Published as a result of `git push`.
- `repo`: id of a message (expected of type `git-repo`) identifying the repo
- `refs`: updates to the repo's refs. a map of ref names to git sha1 hashes.
e.g. `{ 'refs/heads/master': commitId }`
- `objects`: git objects being added to the repo.
- `object.type`: one of `["commit", "tree", "blob", "tag"]`
- `object.length`: size in bytes of the git object
- `object.sha1`: SHA1 hash of the git object
- `object.link`: id of the ssb blob containing the git object's data.
## TODO

@@ -69,0 +101,0 @@

@@ -21,2 +21,23 @@ var test = require('tape')

test('links to objects are detected', function (t) {
ssbGit.createRepo(sbot, function (err, repo) {
t.error(err, 'created repo')
var update = pullGitRepoTests.getUpdate(0)
repo.update(update.refs, update.objects, function (err) {
t.error(err, 'pushed update')
pull(
sbot.links({
dest: '&',
values: true
}),
pull.collect(function (err, msgs) {
t.error(err, 'got links')
t.equals(msgs.length, update.hashes.length, 'links to objects')
t.end()
})
)
})
})
})
test('repo implements abstract pull git repo interface', function (t) {

@@ -23,0 +44,0 @@ ssbGit.createRepo(sbot, function (err, repoA) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc