dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Implement --fun flag for dolt init

Open abmyii opened this issue 1 year ago • 8 comments

Closes #4015.

Hopefully not the most messy implementation. I'm not sure modifying the time was the best solution, but it seemed to work OK.

In all my tests it took ~3-5 mins to find a matching commit hash.

abmyii avatar Aug 06 '22 23:08 abmyii

This is so cool! Thank you.

timsehn avatar Aug 08 '22 14:08 timsehn

Just blow away and re-create create the new repo storage over and over until it matches the condition you want.

Do you mean delete the repo and recreate it until the commit matches?

abmyii avatar Aug 08 '22 17:08 abmyii

Just blow away and re-create create the new repo storage over and over until it matches the condition you want.

Do you mean delete the repo and recreate it until the commit matches?

Yup, that's right.

zachmu avatar Aug 08 '22 17:08 zachmu

Hmm, so I tried that before too (I had a similar idea but in the InitRepoWithTime function itself) but dEnv.bestEffortDeleteAll didn't seem to do anything, and it doesn't work now either. I'll try to dig around a bit and see if I can figure out why.

abmyii avatar Aug 08 '22 17:08 abmyii

@zachmu Is there a way to clear the DoltCliConfig or reset dEnv? I'm running into https://github.com/dolthub/dolt/blob/20e4f9b015105a4827e0264a9fd844ec17dfabec/go/libraries/utils/config/config_hierarchy.go#L52 when trying to reinitialize the repo.

abmyii avatar Aug 08 '22 19:08 abmyii

Is there a way to clear the DoltCliConfig or reset dEnv? I'm running into

So I fixed this using dEnv.Config, _ = env.LoadDoltCliConfig(env.GetCurrentUserHomeDir, dEnv.FS) (probably a terrible hack, but worked). However, I left it running for over two hours and it didn't generate a matching commit in that time (vs 3/5 mins with the original version). Any ideas why?

		commit, _ := dEnv.HeadCommit(context.Background())
		hash, _ := commit.HashOf()

		reg := regexp.MustCompile("^d[o0][1l]t")
		for !reg.MatchString(hash.String()) {
			dEnv.FS.Delete(dEnv.GetDoltDir(), true)

			dEnv.Config, _ = env.LoadDoltCliConfig(env.GetCurrentUserHomeDir, dEnv.FS)
			dEnv.InitRepoWithTime(context.Background(), types.Format_Default, name, email, initBranch, time.Now())

			commit, _ = dEnv.HeadCommit(context.Background())
			hash, _ = commit.HashOf()
			println(hash.String())
		}

(My entire code, below line 135 - https://github.com/dolthub/dolt/blob/a8dacbf42fc31b0ed1cecada8df26392255a11e5/go/cmd/dolt/commands/init.go#L135)

abmyii avatar Aug 09 '22 00:08 abmyii

@zachmu https://github.com/abmyii/dolt/tree/init-fun-new - cleaner implementation, but as before it often just runs in an infinite loop. I had one instance where it completed in around a minute but apart from that it just keeps running. It's also quite volatile - running ls .dolt whilst its running causes the Delete to fail and the program to stop.

abmyii avatar Aug 09 '22 17:08 abmyii

It's also quite volatile - running ls .dolt whilst its running causes the Delete to fail and the program to stop.

I just realised this is due to me having dolt branch --show-current 2> /dev/null | sed -e 's/\(.*\)/(\1) /' in my bashrc - it seems to make a tmp folder every time that is run, which is a bit annoying as now I've probably cluttered quite a few folders with .tmp dirs. Are they necessary?

abmyii avatar Aug 09 '22 18:08 abmyii

I'm going to close this as we were never able to drive to resolution.

timsehn avatar Sep 26 '22 18:09 timsehn