builtin/apply: move 'threeway' global into 'struct apply_state'