<commit_before>import * as React from 'react'
import List from '../list'
import { Dispatcher } from '../../lib/dispatcher'
import Repository from '../../models/repository'
import { Branch } from '../../lib/local-git-operations'

const RowHeight = 22

interface IBranchesProps {
  readonly defaultBranch: Branch | null
  readonly currentBranch: Branch | null
  readonly allBranches: ReadonlyArray<Branch>
  readonly recentBranches: ReadonlyArray<Branch>
  readonly dispatcher: Dispatcher
  readonly repository: Repository
}

export default class Branches extends React.Component<IBranchesProps, void> {
  public componentDidMount() {
    this.props.dispatcher.loadBranches(this.props.repository)
  }

  private renderRow(branchItems: ReadonlyArray<BranchListItem>, row: number) {
    const item = branchItems[row]
    if (item.kind === 'branch') {
      const branch = item.branch
      return <div>{branch.name}</div>
    } else {
      return <div><strong>{item.label}</strong></div>
    }
  }

  private onSelectionChanged(branchItems: ReadonlyArray<BranchListItem>, row: number) {
    const item = branchItems[row]
    if (item.kind !== 'branch') { return }

    const branch = item.branch
    this.props.dispatcher.closePopup()
    this.props.dispatcher.checkoutBranch(this.props.repository, branch.name)
  }

  public render() {
    const branchItems = groupedBranches(this.props.defaultBranch, this.props.currentBranch, this.props.allBranches, this.props.recentBranches)
    return (
      <div id='branches' className='panel'>
        <List rowCount={branchItems.length}
              rowRenderer={row => this.renderRow(branchItems, row)}
              rowHeight={RowHeight}
              selectedRow={-1}
              onSelectionChanged={row => this.onSelectionChanged(branchItems, row)}/>
      </div>
    )
  }
}

type BranchListItem = { kind: 'branch', branch: Branch } | { kind: 'label', label: string }

function groupedBranches(defaultBranch: Branch | null, currentBranch: Branch | null, allBranches: ReadonlyArray<Branch>, recentBranches: ReadonlyArray<Branch>): ReadonlyArray<BranchListItem> {
  const items = new Array<BranchListItem>()

  if (defaultBranch) {
    items.push({ kind: 'label', label: 'Default Branch' })
    items.push({ kind: 'branch', branch: defaultBranch })
  }

  items.push({ kind: 'label', label: 'Recent Branches' })
  const recentBranchNames = new Set<string>()
  const currentBranchName = currentBranch ? currentBranch.name : null
  recentBranches.forEach(branch => {
    if (branch.name !== currentBranchName) {
      items.push({ kind: 'branch', branch: branch })
    }
    recentBranchNames.add(branch.name)
  })

  items.push({ kind: 'label', label: 'Other Branches' })
  allBranches.forEach(branch => {
    if (!recentBranchNames.has(branch.name)) {
      items.push({ kind: 'branch', branch: branch })
    }
  })

  return items
}
<commit_msg>Don't show the default branch in the recent branches<commit_after>import * as React from 'react'
import List from '../list'
import { Dispatcher } from '../../lib/dispatcher'
import Repository from '../../models/repository'
import { Branch } from '../../lib/local-git-operations'

const RowHeight = 22

interface IBranchesProps {
  readonly defaultBranch: Branch | null
  readonly currentBranch: Branch | null
  readonly allBranches: ReadonlyArray<Branch>
  readonly recentBranches: ReadonlyArray<Branch>
  readonly dispatcher: Dispatcher
  readonly repository: Repository
}

export default class Branches extends React.Component<IBranchesProps, void> {
  public componentDidMount() {
    this.props.dispatcher.loadBranches(this.props.repository)
  }

  private renderRow(branchItems: ReadonlyArray<BranchListItem>, row: number) {
    const item = branchItems[row]
    if (item.kind === 'branch') {
      const branch = item.branch
      return <div>{branch.name}</div>
    } else {
      return <div><strong>{item.label}</strong></div>
    }
  }

  private onSelectionChanged(branchItems: ReadonlyArray<BranchListItem>, row: number) {
    const item = branchItems[row]
    if (item.kind !== 'branch') { return }

    const branch = item.branch
    this.props.dispatcher.closePopup()
    this.props.dispatcher.checkoutBranch(this.props.repository, branch.name)
  }

  public render() {
    const branchItems = groupedBranches(this.props.defaultBranch, this.props.currentBranch, this.props.allBranches, this.props.recentBranches)
    return (
      <div id='branches' className='panel'>
        <List rowCount={branchItems.length}
              rowRenderer={row => this.renderRow(branchItems, row)}
              rowHeight={RowHeight}
              selectedRow={-1}
              onSelectionChanged={row => this.onSelectionChanged(branchItems, row)}/>
      </div>
    )
  }
}

type BranchListItem = { kind: 'branch', branch: Branch } | { kind: 'label', label: string }

function groupedBranches(defaultBranch: Branch | null, currentBranch: Branch | null, allBranches: ReadonlyArray<Branch>, recentBranches: ReadonlyArray<Branch>): ReadonlyArray<BranchListItem> {
  const items = new Array<BranchListItem>()

  if (defaultBranch) {
    items.push({ kind: 'label', label: 'Default Branch' })
    items.push({ kind: 'branch', branch: defaultBranch })
  }

  items.push({ kind: 'label', label: 'Recent Branches' })
  const recentBranchNames = new Set<string>()
  const defaultBranchName = defaultBranch ? defaultBranch.name : null
  recentBranches.forEach(branch => {
    if (branch.name !== defaultBranchName) {
      items.push({ kind: 'branch', branch: branch })
    }
    recentBranchNames.add(branch.name)
  })

  items.push({ kind: 'label', label: 'Other Branches' })
  allBranches.forEach(branch => {
    if (!recentBranchNames.has(branch.name)) {
      items.push({ kind: 'branch', branch: branch })
    }
  })

  return items
}

{'fraction_non_alphanumeric': 0.13030042918454934, 'fraction_numerical': 0.0010300429184549357, 'mean_word_length': 3.8509575353871774, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 49, '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': '5298040', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1715, 'n_words': 400}