Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function walk() {
while (index < parts.length) {
// When a commit node is found (submodule), enter it's tree.
if (mode === modes.commit) {
// Make sure we have the commit already cached.
if (!check("commit", hash)) return;
// transition into the tree
mode = modes.tree;
hash = storage.get(hash).tree;
}
// When a tree is found, check it's contents for the next path segment.
if (mode === modes.tree) {
// Make sure the tree is cached before doing anything else.
if (!check("tree", hash)) return;
var tree = storage.get(hash);
if (root === partial) {
// If the tree is at a root, also make sure it's .gitmodules data is
// already cached.
var modulesEntry = tree[".gitmodules"];
var modulesHash = modulesEntry && modulesEntry.hash;
if (!storage.hasGitmodules(root, modulesHash)) {
if (callback) {
return storage.storeGitmodules(root, modulesHash, onLoad);
}
throw new Error("Unable to update .gitmodules cache '" + root + "'");
if (!bake) {
if (found) {
entry.hash = hash;
entry.mode = mode;
}
if (callback) return callback(null, entry);
return entry;
}
// In bake mode
if (!found) return callback();
// Resolve commits to be trees
if (mode === modes.commit) {
if (!check("commit", hash)) return;
mode = modes.tree;
hash = storage.get(hash).tree;
}
// Serve the static blob or tree
var type = modes.toType(mode);
entry.hash = hash;
entry.mode = mode;
var overlays = [];
entry.fetch = function (callback) {
return storage.loadAs(root, type, hash, function (err, result) {
if (err) return callback(err);
if (entry.mode === modes.tree) {
return applyOverlays(result, overlays, callback);
}
callback(null, result);
});
readEntry(path, function (err, entry) {
if (err) return callback(err);
// If the repos match or the entry is not a tree, we're done.
if (entry.mode !== modes.tree || targetEntry.root === entry.root) {
return callback(null, entry);
}
var targetRepo = repos[targetEntry.root];
var repo = repos[entry.root];
targetRepo.hasHash("tree", entry.hash, function (err, has) {
if (err) return callback(err);
// If the destination already has the tree hash, we're done.
if (has) return callback(null, entry);
deepCopy(repo, targetRepo, entry, function (err) {
if (err) return callback(err);
callback(null, entry);
});
});
});
});
function onImport(err) {
if (err) return callback(err);
if (i >= names.length) {
return local.saveAs("tree", tree, onSave);
}
var name = names[i++];
var entry = tree[name];
if (modes.isBlob(entry.mode)) {
return importBlob(entry.hash, onImport);
}
if (entry.mode === modes.tree) {
return importTree(entry.hash, onImport);
}
// Skip others.
onImport();
}
}
function treeLoadKey(entry, callback) {
if (entry.mode !== modes.tree) return callback(null, entry);
var type = modes.toType(entry.mode);
return repo.loadAs(type, entry.hash, function (err, body) {
if (err) return callback(err);
entry.body = body;
return callback(null, entry);
});
}
function onTree(err, tree) {
var hash = entry.hash;
if (!tree) return callback(err || new Error("Missing tree " + hash));
entry.mode = modes.tree;
entry.hash = hash;
entry.tree = tree;
callback(null, entry);
}
}
function onEntry(err, entry) {
if (!entry || entry.mode !== modes.tree) return callback(err);
repo.loadAs("tree", entry.hash, onTree);
}
return Object.keys(tree).map(function (name) {
var entry = tree[name];
var path = object.path + name;
if (entry.mode === modes.tree) path += "/";
return {
mode: entry.mode,
hash: entry.hash,
path: path
};
});
}
function onSub(err, data) {
if (err) return callback(err);
callback(null, {
mode: modes.tree,
hash: commit.tree,
repo: data.repo,
config: data.config,
root: path
});
}
});
function onEntry(err, entry) {
if (err) return callback(err);
if (!entry.hash) return callback(err || new Error("Missing entry"));
if (entry.mode === modes.commit) {
return commitToTree(path, entry, onEntry);
}
if (entry.mode === modes.tree) {
var repo = repos[entry.root];
return repo.loadAs("tree", entry.hash, onTree);
}
return callback(new Error("Invalid mode 0" + entry.mode.toString(8)));
function onTree(err, tree) {
var hash = entry.hash;
if (!tree) return callback(err || new Error("Missing tree " + hash));
entry.mode = modes.tree;
entry.hash = hash;
entry.tree = tree;
callback(null, entry);
}
}
}