<commit_before>var fs = require('fs');
var manifest = fs.readFileSync(__dirname + '/manifest.json');

var upgrade = function(deps) {
    this.deps = deps;
};

upgrade.prototype = function() {
    var versionParts,
        runMajors = function(manifest, keys) {
            var self = this,
                minors = Object.keys(manifest[keys[0]]);

            minors.sort(function(a, b) {
                return a - b;
            })

            for (var i = 0; i < minors.length; i++) {
                if (parseInt(minors[i], 10) < parseInt(versionParts[0], 10)) {
                    delete manifest[keys[0]][minors[i]];
                    minors.splice(i--, 1);
                } else {
                    break;
                }
            }

            return runMinors.call(this, manifest[keys[0]], minors).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runMajors.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runMinors = function(manifest, keys) {
            var self = this,
                patches = Object.keys(manifest[keys[0]]);

            patches.sort(function(a, b) {
                return a - b;
            })

            for (var i = 0; i < patches.length; i++) {
                if (parseInt(patches[i], 10) < parseInt(versionParts[0], 10)) {
                    delete manifest[keys[0]][patches[i]];
                    patches.splice(i--, 1);
                } else {
                    break;
                }
            }

            return runPatches.call(this, manifest[keys[0]], patches).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runMinors.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runPatches = function(manifest, keys) {
            var self = this;
            return runChangesets.call(this, manifest[keys[0]]).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runPatches.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runChangesets = function(changesets) {
            var self = this,
                changeSetFile = require(__dirname + '/changesets/' + changesets[0]),
                changeSet = new changeSetFile(this.deps);

            return changeSet.up().then(function() {
                changesets.shift();
                if (changesets.length > 0) {
                    return runChangesets.call(self, changesets);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        };

    return {
        run: function(currentVersion){<commit_msg>Fixed issue with upgrade system not respecting version numbers properly<commit_after>var fs = require('fs');
var manifest = fs.readFileSync(__dirname + '/manifest.json');

var upgrade = function(deps) {
    this.deps = deps;
};

upgrade.prototype = function() {
    var versionParts,
        runMajors = function(manifest, keys) {
            var self = this,
                minors = Object.keys(manifest[keys[0]]);

            minors.sort(function(a, b) {
                return a - b;
            })

            for (var i = 0; i < minors.length; i++) {
                if (parseInt(minors[i], 10) < parseInt(versionParts[1], 10)) {
                    delete manifest[keys[0]][minors[i]];
                    minors.splice(i--, 1);
                } else {
                    break;
                }
            }

            return runMinors.call(this, manifest[keys[0]], minors).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runMajors.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runMinors = function(manifest, keys) {
            var self = this,
                patches = Object.keys(manifest[keys[0]]);

            patches.sort(function(a, b) {
                return a - b;
            })

            for (var i = 0; i < patches.length; i++) {
                if (parseInt(patches[i], 10) <= parseInt(versionParts[2], 10)) {
                    delete manifest[keys[0]][patches[i]];
                    patches.splice(i--, 1);
                } else {
                    break;
                }
            }

            return runPatches.call(this, manifest[keys[0]], patches).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runMinors.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runPatches = function(manifest, keys) {
            var self = this;
            return runChangesets.call(this, manifest[keys[0]]).then(function() {
                delete manifest[keys[0]];
                keys.splice(0, 1)
                if (keys.length > 0) {
                    return runPatches.call(self, manifest, keys);
                } else {
                    return self.deps.promise.resolve();
                }
            });
        },
        runChangesets = function(changesets) {
            if (!changesets || changesets.length === 0) {
                return this.deps.promise.resolve();
            }
            var self = this,
                changeSetFile = require(__dirname + '/changesets/' + changesets[0]),
                changeSet = new changeSetFile(this.deps);

            return changeSet.up().then(function() {
                changesets.shift();
                return runChangesets.call(self, changesets);
            });
        };

    return {
        run: function(currentVersion){
{'fraction_non_alphanumeric': 0.1235618597320725, 'fraction_numerical': 0.01103230890464933, 'mean_word_length': 1.2672382993926403, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1956648', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1639, 'n_words': 336}