<commit_before>$(function() {
"use strict";

function vercmp(a, b) {
  var re = /^([0-9]*)([^0-9]*)(.*)$/;
  var abits, bbits;
  var anum, bnum;
  while (a.length && b.length) {
    abits = re.exec(a);
    bbits = re.exec(b);
    if ((abits[1] === '') != (bbits[1] === '')) {
      return abits[1] ? -1 : 1;
    }
    if (abits[1] !== '') {
      anum = parseInt(abits[1]);
      bnum = parseInt(bbits[1])
      if (anum !== bnum)
        return anum - bnum;
    }

    if (abits[2] !== bbits[2]) {
      return abits[2] < bbits[2] ? -1 : 1
    }

    a = abits[3];
    b = bbits[3];
  }

  return a.length - b.length;
}

function shorten(ref) {
  var match = /^refs\/(tags|branches)\/(.*)/.exec(ref);
  if (match)
    return match[2];
  match = /^([0-9a-f]{8})[0-9a-f]+$/.exec(ref);
  if (match)
    return match[1];
  return ref;
}

var Match = Backbone.Model.extend({
  initialize: function() {
  },
  url: function() {
    var name = this.get('tree');
    var ref = this.get('version');

    var repo_map;
    if (this.get('backend'))
      repo_map = CodesearchUI.github_repos[this.get('backend')]
    else
      repo_map = CodesearchUI.github_repos[Object.keys(CodesearchUI.github_repos)[0]]
    if (!repo_map[name])
      return null;
    return "https://github.com/" + repo_map[name] +
      "/blob/" + shorten(ref) + "/" + this.get('path') +
      "#L" + this.get('lno');
  }
});

var MatchView = Backbone.View.extend({
  tagName: 'div',
  initialize: function() {
    this.model.on('change', this.render, this);
  },
  render: function() {
    var div = this._render();
    this.$el.empty();
    this.$el.append(div);
    return this;
  },
  _render: function() {
    var h = new HTMLFactory();
    var i;
    var lnos = [];
    var lno = this.model.get('lno');
    for (i = lno - this.model.get('context_before').length;
         i < lno + this.model.get('context_after').length + 1; i++) {
      var elt = h.div({cls: 'lno'}, [i]);
      if (i == lno)
        elt = h.div({cls: 'matchline'}, [elt]);
      lnos.push(elt);
    }
    var lines = [];<commit_msg>Handle "other" githubs; fix github links.<commit_after>$(function() {
"use strict";

function vercmp(a, b) {
  var re = /^([0-9]*)([^0-9]*)(.*)$/;
  var abits, bbits;
  var anum, bnum;
  while (a.length && b.length) {
    abits = re.exec(a);
    bbits = re.exec(b);
    if ((abits[1] === '') != (bbits[1] === '')) {
      return abits[1] ? -1 : 1;
    }
    if (abits[1] !== '') {
      anum = parseInt(abits[1]);
      bnum = parseInt(bbits[1])
      if (anum !== bnum)
        return anum - bnum;
    }

    if (abits[2] !== bbits[2]) {
      return abits[2] < bbits[2] ? -1 : 1
    }

    a = abits[3];
    b = bbits[3];
  }

  return a.length - b.length;
}

function shorten(ref) {
  var match = /^refs\/(tags|branches)\/(.*)/.exec(ref);
  if (match)
    return match[2];
  match = /^([0-9a-f]{8})[0-9a-f]+$/.exec(ref);
  if (match)
    return match[1];
  // If reference is origin/foo, assume that foo is
  // the branch name.
  match = /^origin\/(.*)/.exec(ref);
  if (match) {
    return match[1];
  }
  return ref;
}

var Match = Backbone.Model.extend({
  initialize: function() {
  },
  url: function() {
    var name = this.get('tree');
    var ref = this.get('version');

    var repo_map;
    var backend = Codesearch.in_flight.backend;
    repo_map = CodesearchUI.github_repos[backend];
    if (!repo_map) {
      return null;
    }
    if (!repo_map[name]) {
      return null;
    }

    var base;
    // If 'github' metadata is already a URL, pass it
    // through, but otherwise asume it's a user/repo on
    // the public github site.
    try {
        base = new URL(repo_map[name]).toString();
    } catch(e) {
        base = "https://github.com/" + repo_map[name];
    }
    return base +
      "/blob/" + shorten(ref) + "/" + this.get('path') +
      "#L" + this.get('lno');
  }
});

var MatchView = Backbone.View.extend({
  tagName: 'div',
  initialize: function() {
    this.model.on('change', this.render, this);
  },
  render: function() {
    var div = this._render();
    this.$el.empty();
    this.$el.append(div);
    return this;
  },
  _render: function() {
    var h = new HTMLFactory();
    var i;
    var lnos = [];
    var lno = this.model.get('lno');
    for (i = lno - this.model.get('context_before').length;
         i < lno + this.model.get('context_after').length + 1; i++) {
      var elt = h.div({cls: 'lno'}, [i]);
      if (i == lno)
        elt = h.div({cls: 'matchline'}, [elt]);
      lnos.push(elt);
    }
    var lines = [];
{'fraction_non_alphanumeric': 0.20848911370134154, 'fraction_numerical': 0.012755663074554651, 'mean_word_length': 2.4016454749439045, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2122861', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1742, 'n_words': 380}