feat: skip already-indexed revisions, add --force flag
When indexing a revision that already exists, the indexer now returns early with information about the existing revision instead of re-indexing. Use the --force flag to re-index an existing revision. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,12 +50,17 @@ func main() {
|
||||
Name: "no-files",
|
||||
Usage: "Skip indexing file contents (faster, disables get_file tool)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "force",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "Force re-indexing even if revision already exists",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
if c.NArg() < 1 {
|
||||
return fmt.Errorf("revision argument required")
|
||||
}
|
||||
return runIndex(c, c.Args().First(), !c.Bool("no-files"))
|
||||
return runIndex(c, c.Args().First(), !c.Bool("no-files"), c.Bool("force"))
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -162,7 +167,7 @@ func runServe(c *cli.Context) error {
|
||||
return server.Run(ctx, os.Stdin, os.Stdout)
|
||||
}
|
||||
|
||||
func runIndex(c *cli.Context, revision string, indexFiles bool) error {
|
||||
func runIndex(c *cli.Context, revision string, indexFiles bool, force bool) error {
|
||||
ctx := context.Background()
|
||||
|
||||
store, err := openStore(c.String("database"))
|
||||
@@ -178,11 +183,22 @@ func runIndex(c *cli.Context, revision string, indexFiles bool) error {
|
||||
indexer := nixos.NewIndexer(store)
|
||||
|
||||
fmt.Printf("Indexing revision: %s\n", revision)
|
||||
result, err := indexer.IndexRevision(ctx, revision)
|
||||
|
||||
var result *nixos.IndexResult
|
||||
if force {
|
||||
result, err = indexer.ReindexRevision(ctx, revision)
|
||||
} else {
|
||||
result, err = indexer.IndexRevision(ctx, revision)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("indexing failed: %w", err)
|
||||
}
|
||||
|
||||
if result.AlreadyIndexed {
|
||||
fmt.Printf("Revision already indexed (%d options). Use --force to re-index.\n", result.OptionCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("Indexed %d options in %s\n", result.OptionCount, result.Duration)
|
||||
fmt.Printf("Git hash: %s\n", result.Revision.GitHash)
|
||||
if result.Revision.ChannelName != "" {
|
||||
|
||||
Reference in New Issue
Block a user