<commit_before>/*global $,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";
  
  var hashOf = function(content) {
    var hash, i;
    for (hash = 0, i = 0; i < content.length; ++i) {
      hash = (hash << 5) - hash + content.charCodeAt(i);
      hash &= hash;
    }
    return hash;
  };  

  var outgoingHashContainer = function() {
    return $('#file_hashes_outgoing_container');
  };
  
  var incomingHashContainer = function() {
    return $('#file_hashes_incoming_container');
  };
    
  var storeOutgoingFileHash = function(filename) {
    var node = cd.fileContentFor(filename);
    var hash = hashOf(node.val());    
    $('input[data-filename="'+filename+'"]',outgoingHashContainer()).remove();    
    outgoingHashContainer().append(
      $('<input>', {
        'type': 'hidden',
        'data-filename': filename,
        'name': "file_hashes_outgoing[" + filename + "]",
        'value': hash
      })
    );
  };
  
  var allFilesSameAsCurrentTrafficLight = function() {
    var outgoingFilenames = cd.filenames();
    var incomingFilenames = [ ];    
    $('input',incomingHashContainer()).each(function() {
      var filename = $(this).data('filename');
      incomingFilenames.push(filename);
    });    
    incomingFilenames.sort();
    outgoingFilenames.sort();    
    if (JSON.stringify(incomingFilenames) != JSON.stringify(outgoingFilenames)) {
      //alert("incomingFilenames != outgoingFilenames");
      return false;
    }

    //var msg = "\n";
    var allSame = true;
    $.each(incomingFilenames,function(_,filename) {
      var  inNode = $('input[data-filename="'+filename+'"]', incomingHashContainer());
      var outNode = $('input[data-filename="'+filename+'"]', outgoingHashContainer());
      if (filename != 'output' && inNode.attr('value') != outNode.attr('value')) {
        allSame = false;
      }
      //msg += filename + ": in:" +  inNode.attr('value') + "\n";
      //msg += filename + ":out:" + outNode.attr('value') + "\n";
    });
    //msg += "returning " + allSame;
    //alert(msg);
    return allSame;
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.setForkAndTestButtons = function() {
    var same = allFilesSameAsCurrentTrafficLight();
    $('#fork_button').attr('disabled', !same);
    $('#test').attr('disabled', same);
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.storeOutgoingFileHashes = function() {
    outgoingHashContainer().empty();
    $.each(cd.filenames(), function(_,filename) {
      storeOutgoingFileHash(filename);
    });    
  };
    
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.storeIncomingFileHashes = function() {
    incomingHashContainer().empty();
    $.each(cd.filenames(), function(_,filename) {
      var node = cd.fileContentFor(filename);
      var content = node.val();
      var hash = hashOf(content);
      incomingHashContainer().append(
        $('<input>', {
          'type': 'hidden',
          'data-filename': filename,
          'name': "file_hashes_incoming[" + filename + "]",
          'value': hash
        })
      );
    });
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.setContentListeners = function() {    
    $(".file_content").unbind().on("keyup", function() {      
      var filename = $(this).data('filename');
      storeOutgoingFileHash(filename);
      cd.setForkAndTestButtons();
    });    
  };
    
  return cd;
})(cyberDojo || {}, $);



<commit_msg>test button always enabled<commit_after>/*global $,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";
  
  var hashOf = function(content) {
    var hash, i;
    for (hash = 0, i = 0; i < content.length; ++i) {
      hash = (hash << 5) - hash + content.charCodeAt(i);
      hash &= hash;
    }
    return hash;
  };  

  var outgoingHashContainer = function() {
    return $('#file_hashes_outgoing_container');
  };
  
  var incomingHashContainer = function() {
    return $('#file_hashes_incoming_container');
  };
    
  var storeOutgoingFileHash = function(filename) {
    var node = cd.fileContentFor(filename);
    var hash = hashOf(node.val());    
    $('input[data-filename="'+filename+'"]',outgoingHashContainer()).remove();    
    outgoingHashContainer().append(
      $('<input>', {
        'type': 'hidden',
        'data-filename': filename,
        'name': "file_hashes_outgoing[" + filename + "]",
        'value': hash
      })
    );
  };
  
  var allFilesSameAsCurrentTrafficLight = function() {
    var outgoingFilenames = cd.filenames();
    var incomingFilenames = [ ];    
    $('input',incomingHashContainer()).each(function() {
      var filename = $(this).data('filename');
      incomingFilenames.push(filename);
    });    
    incomingFilenames.sort();
    outgoingFilenames.sort();    
    if (JSON.stringify(incomingFilenames) != JSON.stringify(outgoingFilenames)) {
      //alert("incomingFilenames != outgoingFilenames");
      return false;
    }

    //var msg = "\n";
    var allSame = true;
    $.each(incomingFilenames,function(_,filename) {
      var  inNode = $('input[data-filename="'+filename+'"]', incomingHashContainer());
      var outNode = $('input[data-filename="'+filename+'"]', outgoingHashContainer());
      if (filename != 'output' && inNode.attr('value') != outNode.attr('value')) {
        allSame = false;
      }
      //msg += filename + ": in:" +  inNode.attr('value') + "\n";
      //msg += filename + ":out:" + outNode.attr('value') + "\n";
    });
    //msg += "returning " + allSame;
    //alert(msg);
    return allSame;
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.setForkAndTestButtons = function() {
    var same = allFilesSameAsCurrentTrafficLight();
    $('#fork_button').attr('disabled', !same);
    // I could do this...
    //   $('#test').attr('disabled', same);
    // so the test button is only enabled when the file contents
    // is in some way different to the previous traffic-light.
    // Trouble with this is that a new players initial
    // view will be of a disabled test button.
    $('#test').attr('disabled', false);
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.storeOutgoingFileHashes = function() {
    outgoingHashContainer().empty();
    $.each(cd.filenames(), function(_,filename) {
      storeOutgoingFileHash(filename);
    });    
  };
    
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.storeIncomingFileHashes = function() {
    incomingHashContainer().empty();
    $.each(cd.filenames(), function(_,filename) {
      var node = cd.fileContentFor(filename);
      var content = node.val();
      var hash = hashOf(content);
      incomingHashContainer().append(
        $('<input>', {
          'type': 'hidden',
          'data-filename': filename,
          'name': "file_hashes_incoming[" + filename + "]",
          'value': hash
        })
      );
    });
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
  cd.setContentListeners = function() {    
    $(".file_content").unbind().on("keyup", function() {      
      var filename = $(this).data('filename');
      storeOutgoingFileHash(filename);
      cd.setForkAndTestButtons();
    });    
  };
    
  return cd;
})(cyberDojo || {}, $);




{'fraction_non_alphanumeric': 0.19702754295064084, 'fraction_numerical': 0.0008181074447777475, 'mean_word_length': 2.1891304347826086, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578459', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2386, 'n_words': 392}