<commit_before># **revision.coffee**
# This module generates a past revision of a data file and caches it in 'data/rev'.
#
# The saved file has the name of the id of the point in the journal's history
# that the revision represents.

create = (revIndex, data) ->
  journal = data.journal
  revTitle = data.title
  revStory = []
  revJournal = []
  for journalEntry in journal.slice 0, (+revIndex)+1
    itemSplicedIn = false
    itemEdited = false
    revJournal.push(journalEntry)
    switch journalEntry.type
      when 'create'
        if journalEntry.item.title?
          revTitle = journalEntry.item.title
      when 'add'
        if journalEntry.after?
          for storyItem, i in revStory
            if storyItem.id == journalEntry.after
              itemSplicedIn = true
              revStory.splice(i+1,0,journalEntry.item)
              break
          if !itemSplicedIn #defensive coding for if we don't have a story item to put this after
            revStory.push journalEntry.item
        else
          revStory.push journalEntry.item
      when 'edit'
        for storyItem, i in revStory
          if storyItem.id == journalEntry.id
            revStory[i] = journalEntry.item
            itemEdited = true
            break
        if !itemEdited  #the first journal entry for welcome visitors is an edit
          revStory.push(journalEntry.item)
      when 'move'
        items = []
        for storyItem in revStory
          items[storyItem.id] = storyItem
        revStory = []
        for itemId in journalEntry.order
          revStory.push(items[itemId])
      when 'remove'
        removeId = journalEntry.id;
        for storyItem, i in revStory
          if storyItem.id == removeId
            revStory.splice(i,1)
            break
      #when 'fork'   # do nothing when fork
  return {story: revStory, journal: revJournal, title: revTitle}


exports.create = create<commit_msg>First round of simplification: using comprehensions<commit_after># **revision.coffee**
# This module generates a past revision of a data file and caches it in 'data/rev'.
#
# The saved file has the name of the id of the point in the journal's history
# that the revision represents.

create = (revIndex, data) ->
  journal = data.journal
  revTitle = data.title
  revStory = []
  revJournal = []
  for journalEntry in journal.slice 0, (+revIndex)+1
    itemSplicedIn = false
    itemEdited = false
    revJournal.push(journalEntry)
    switch journalEntry.type
      when 'create'
        if journalEntry.item.title?
          revTitle = journalEntry.item.title
      when 'add'
        for storyItem, i in revStory when storyItem.id == journalEntry.after
          itemSplicedIn = true
          revStory.splice(i+1,0,journalEntry.item)
          break
        if !itemSplicedIn #defensive coding for if we don't have a story item to put this after
          revStory.push journalEntry.item
      when 'edit'
        for storyItem, i in revStory when storyItem.id == journalEntry.id
          revStory[i] = journalEntry.item
          itemEdited = true
          break
        if !itemEdited  #the first journal entry for welcome visitors is an edit
          revStory.push(journalEntry.item)
      when 'move'
        items = []
        for storyItem in revStory
          items[storyItem.id] = storyItem
        revStory = []
        for itemId in journalEntry.order
          revStory.push(items[itemId])
      when 'remove'
        for storyItem, i in revStory when storyItem.id == journalEntry.id
          revStory.splice(i,1)
          break
      #when 'fork'   # do nothing when fork
  return {story: revStory, journal: revJournal, title: revTitle}


exports.create = create
{'fraction_non_alphanumeric': 0.07488510408218438, 'fraction_numerical': 0.002703433360367667, 'mean_word_length': 2.2947462154942118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2102277', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1025, 'n_words': 345}