oldv: match the v commit in the vc log by `--grep`, falling back to `--before=`

pull/8068/head
Delyan Angelov 2021-01-12 11:30:48 +02:00
parent 3289dff7ff
commit 49ec2c86ae
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 25 additions and 14 deletions

View File

@ -51,15 +51,26 @@ pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, stri
// or slightly before that time will be able to build the historic v: // or slightly before that time will be able to build the historic v:
vline := scripting.run('git rev-list -n1 --timestamp "$commit" ') vline := scripting.run('git rev-list -n1 --timestamp "$commit" ')
v_timestamp, v_commithash := line_to_timestamp_and_commit(vline) v_timestamp, v_commithash := line_to_timestamp_and_commit(vline)
scripting.verbose_trace(@FN, 'v_timestamp: $v_timestamp | v_commithash: $v_commithash')
check_v_commit_timestamp_before_self_rebuilding(v_timestamp) check_v_commit_timestamp_before_self_rebuilding(v_timestamp)
scripting.chdir(vcdir) scripting.chdir(vcdir)
scripting.run('git checkout master') scripting.run('git checkout master')
//
mut vccommit := ''
vcbefore_subject_match := scripting.run('git rev-list HEAD -n1 --timestamp --grep=${v_commithash[0..7]} ')
scripting.verbose_trace(@FN, 'vcbefore_subject_match: $vcbefore_subject_match')
if vcbefore_subject_match.len > 3 {
_, vccommit = line_to_timestamp_and_commit(vcbefore_subject_match)
} else {
scripting.verbose_trace(@FN, 'the v commit did not match anything in the vc log; try --timestamp instead.')
vcbefore := scripting.run('git rev-list HEAD -n1 --timestamp --before=$v_timestamp ') vcbefore := scripting.run('git rev-list HEAD -n1 --timestamp --before=$v_timestamp ')
_, vccommit_before := line_to_timestamp_and_commit(vcbefore) _, vccommit = line_to_timestamp_and_commit(vcbefore)
scripting.run('git checkout "$vccommit_before" ') }
scripting.verbose_trace(@FN, 'vccommit: $vccommit')
scripting.run('git checkout "$vccommit" ')
scripting.run('wc *.c') scripting.run('wc *.c')
scripting.chdir(cdir) scripting.chdir(cdir)
return v_commithash, vccommit_before return v_commithash, vccommit
} }
pub fn clone_or_pull(remote_git_url string, local_worktree_path string) { pub fn clone_or_pull(remote_git_url string, local_worktree_path string) {
@ -110,7 +121,7 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
scripting.chdir(vgit_context.path_v) scripting.chdir(vgit_context.path_v)
scripting.run('git checkout $vgit_context.commit_v') scripting.run('git checkout $vgit_context.commit_v')
v_commithash, vccommit_before := prepare_vc_source(vgit_context.path_vc, vgit_context.path_v, v_commithash, vccommit_before := prepare_vc_source(vgit_context.path_vc, vgit_context.path_v,
vgit_context.commit_v) 'HEAD')
vgit_context.commit_v__hash = v_commithash vgit_context.commit_v__hash = v_commithash
vgit_context.commit_vc_hash = vccommit_before vgit_context.commit_vc_hash = vccommit_before
if os.exists('cmd/v') { if os.exists('cmd/v') {