<commit_before>package commands

import (
	"fmt"
	"os"

	"github.com/git-lfs/git-lfs/errors"
	"github.com/git-lfs/git-lfs/git"
	"github.com/git-lfs/git-lfs/lfs"
	"github.com/rubyist/tracerx"
	"github.com/spf13/cobra"
)

var (
	pushDryRun    = false
	pushObjectIDs = false
	pushAll       = false
	useStdin      = false

	// shares some global vars and functions with command_pre_push.go
)

func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
	tracerx.Printf("Upload refs %v to remote %v", refnames, ctx.Remote)

	gitscanner := lfs.NewGitScanner(nil)
	if err := gitscanner.RemoteForPush(ctx.Remote); err != nil {
		ExitWithError(err)
	}
	defer gitscanner.Close()

	refs, err := refsByNames(refnames)
	if err != nil {
		Error(err.Error())
		Exit("Error getting local refs.")
	}

	for _, ref := range refs {
		if err = uploadLeftOrAll(gitscanner, ctx, ref.Name); err != nil {
			Print("Error scanning for Git LFS files in the %q ref", ref.Name)
			ExitWithError(err)
		}
	}

	ctx.Await()
}

func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, ref string) error {
	var multiErr error
	cb := func(p *lfs.WrappedPointer, err error) {
		if err != nil {
			if multiErr != nil {
				multiErr = fmt.Errorf("%v\n%v", multiErr, err)
			} else {
				multiErr = err
			}
			return
		}

		uploadPointers(ctx, p)
	}

	if pushAll {
		if err := g.ScanRefWithDeleted(ref, cb); err != nil {
			return err
		}
	}
	if err := g.ScanLeftToRemote(ref, cb); err != nil {
		return err
	}

	return multiErr
}

func uploadsWithObjectIDs(ctx *uploadContext, oids []string) {
	for _, oid := range oids {<commit_msg>commands/push: only scan once, not twice<commit_after>package commands

import (
	"fmt"
	"os"

	"github.com/git-lfs/git-lfs/errors"
	"github.com/git-lfs/git-lfs/git"
	"github.com/git-lfs/git-lfs/lfs"
	"github.com/rubyist/tracerx"
	"github.com/spf13/cobra"
)

var (
	pushDryRun    = false
	pushObjectIDs = false
	pushAll       = false
	useStdin      = false

	// shares some global vars and functions with command_pre_push.go
)

func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) {
	tracerx.Printf("Upload refs %v to remote %v", refnames, ctx.Remote)

	gitscanner := lfs.NewGitScanner(nil)
	if err := gitscanner.RemoteForPush(ctx.Remote); err != nil {
		ExitWithError(err)
	}
	defer gitscanner.Close()

	refs, err := refsByNames(refnames)
	if err != nil {
		Error(err.Error())
		Exit("Error getting local refs.")
	}

	for _, ref := range refs {
		if err = uploadLeftOrAll(gitscanner, ctx, ref.Name); err != nil {
			Print("Error scanning for Git LFS files in the %q ref", ref.Name)
			ExitWithError(err)
		}
	}

	ctx.Await()
}

func uploadLeftOrAll(g *lfs.GitScanner, ctx *uploadContext, ref string) error {
	var multiErr error
	cb := func(p *lfs.WrappedPointer, err error) {
		if err != nil {
			if multiErr != nil {
				multiErr = fmt.Errorf("%v\n%v", multiErr, err)
			} else {
				multiErr = err
			}
			return
		}

		uploadPointers(ctx, p)
	}

	if pushAll {
		if err := g.ScanRefWithDeleted(ref, cb); err != nil {
			return err
		}
	} else {
		if err := g.ScanLeftToRemote(ref, cb); err != nil {
			return err
		}
	}

	return multiErr
}

func uploadsWithObjectIDs(ctx *uploadContext, oids []string) {
	for _, oid := range oids {
{'fraction_non_alphanumeric': 0.13388480392156862, 'fraction_numerical': 0.0012254901960784314, 'mean_word_length': 3.48489010989011, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3591655', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1248, 'n_words': 298}