<commit_before>class Water.CommitRequest extends Backbone.Model
  initialize: () ->
    @pendingFiles = []
    @processedfiles = []
    @errorFiles = []
    @breadcrumbs = @get("breadcrumbs")
  
  # Triggered when an upload is started, saves the filename and the target path for future reference
  # Returns a hash to identify the file
  addFile: (filename) =>
    clientside_hash = (filename + (new Date()).toString()).hashCode()
    @pendingFiles.push(filename: filename, path: @breadcrumbs.path, clientside_hash: clientside_hash)
    return clientside_hash

  # Triggered when (and only when) an upload was successful. 
  # Removes the file from @pendingFiles and adds it to @processedFiles.
  uploadSuccessful: (options) => 
    for pendingFile in @pendingFiles
      if pendingFile.clientside_hash is options.hash
        @processedfiles.push(id: options.id, to: @breadcrumbs.path + pendingFile.filename)
    @pendingFiles = 
      (pendingFile for pendingFile in @pendingFiles when pendingFile.clientside_hash isnt options.hash)
    @checkStatus()
    
  # Triggered when an upload is completed with an error. 
  # TODO: do something useful with the information  
  errorForFile: (hash, error) =>
    for pendingFile in @pendingFiles
      if pendingFile.clientside_hash is filename
        @errorFiles.push(filename: filename)
    @pendingFiles = (pendingFile for pendingFile in @pendingFiles when pendingFile.clientside_hash isnt hash)
    @checkStatus()
  
  # Checks whether all @pendingFiles have been processed.
  # If so, calls @send
  checkStatus: () =>
    if @pendingFiles.length is 0
      request = 
        command: "add"
        branch: gon.ref
        commit_message: "<PASSWORD>"
        files: @processedfiles
      @send(request)
      
  # Triggered when all files have been uploaded, sends the commit_request
  send: (request) =>
    @trigger("sending_commit_request")
    $.ajax gon.commit_request_path, 
      type: "POST"
      data: commit_request: JSON.stringify(request)
      success: (data) => @request_success(data)
      error: (jqXHR, textStatus, errorThrown) =>
        console.log("Error: ", jqXHR, textStatus, errorThrown)
      
  # Triggered when the commit request has been received.
  # TODO: handle errors
  request_success: (data) =>
    @pendingFiles = []
    @processedfiles = []
    @errorFiles = []
    @trigger("commit_request_process_started")
    
  commit_request_completed: () =>
    @trigger("commit_request_completed")
    
  requestCompleted: () =>
    @trigger("commit_request_completed")
  <commit_msg>Add remove action to client-side commit_request<commit_after>class Water.CommitRequest extends Backbone.Model
  initialize: () ->
    @pendingFiles = []
    @processedfiles = []
    @errorFiles = []
    @breadcrumbs = @get("breadcrumbs")
  
  # Triggered when an upload is started, saves the filename and the target path for future reference
  # Returns a hash to identify the file
  addFile: (filename) =>
    clientside_hash = (filename + (new Date()).toString()).hashCode()
    @pendingFiles.push(filename: filename, path: @breadcrumbs.path, clientside_hash: clientside_hash)
    return clientside_hash

  # Triggered when (and only when) an upload was successful. 
  # Removes the file from @pendingFiles and adds it to @processedFiles.
  uploadSuccessful: (options) => 
    for pendingFile in @pendingFiles
      if pendingFile.clientside_hash is options.hash
        @processedfiles.push(id: options.id, to: @breadcrumbs.path + pendingFile.filename)
    @pendingFiles = 
      (pendingFile for pendingFile in @pendingFiles when pendingFile.clientside_hash isnt options.hash)
    @checkStatus()
    
  # Triggered when an upload is completed with an error. 
  # TODO: do something useful with the information  
  errorForFile: (hash, error) =>
    for pendingFile in @pendingFiles
      if pendingFile.clientside_hash is filename
        @errorFiles.push(filename: filename)
    @pendingFiles = (pendingFile for pendingFile in @pendingFiles when pendingFile.clientside_hash isnt hash)
    @checkStatus()
  
  # Checks whether all @pendingFiles have been processed.
  # If so, calls @send
  checkStatus: () =>
    if @pendingFiles.length is 0
      request = 
        command: "add"
        branch: gon.ref
        commit_message: "<PASSWORD>"
        files: @processedfiles
      @send(request)
      
  # Triggered when all files have been uploaded, sends the commit_request
  send: (request) =>
    @trigger("sending_commit_request")
    $.ajax gon.commit_request_path, 
      type: "POST"
      data: commit_request: JSON.stringify(request)
      success: (data) => @request_success(data)
      error: (jqXHR, textStatus, errorThrown) =>
        console.log("Error: ", jqXHR, textStatus, errorThrown)
      
  # Triggered when the commit request has been received.
  # TODO: handle errors
  request_success: (data) =>
    @pendingFiles = []
    @processedfiles = []
    @errorFiles = []
    @trigger("commit_request_process_started")
  
  #
  # Removes a file
  #
  remove: (file_path) =>
    console.log "Remove!"
    if @pendingFiles.length isnt 0
      return
    request = 
      {
        command: "remove",
        branch: gon.ref,
        commit_message: null,
        files: [
          file_path
        ]
      }
    @send(request)
  
  
  commit_request_completed: () =>
    @trigger("commit_request_completed")
    
  requestCompleted: () =>
    @trigger("commit_request_completed")
  
{'fraction_non_alphanumeric': 0.09712822388878727, 'fraction_numerical': 0.000548747027620267, 'mean_word_length': 3.2852664576802506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '2768168', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1579, 'n_words': 447}