Repository: go-gitea/gitea
File: cmd/serv.go (Go)

Code before:
			return fail(ctx, "Key check failed", "Failed to check provided key: %v", err)
		}
		switch key.Type {
		case asymkey_model.KeyTypeDeploy:
			println("Hi there! You've successfully authenticated with the deploy key named " + key.Name + ", but Gitea does not provide shell access.")
		case asymkey_model.KeyTypePrincipal:
			println("Hi there! You've successfully authenticated with the principal " + key.Content + ", but Gitea does not provide shell access.")
		default:
			println("Hi there, " + user.Name + "! You've successfully authenticated with the key named " + key.Name + ", but Gitea does not provide shell access.")
		}
		println("If this is unexpected, please log in with password and setup Gitea under another user.")
		return nil
	} else if c.Bool("debug") {
		log.Debug("SSH_ORIGINAL_COMMAND: %s", os.Getenv("SSH_ORIGINAL_COMMAND"))
	}

	sshCmdArgs, err := shellquote.Split(cmd)
	if err != nil {
		return fail(ctx, "Error parsing arguments", "Failed to parse arguments: %v", err)
	}

	if len(sshCmdArgs) < 2 {
		if git.DefaultFeatures().SupportProcReceive {
			// for AGit Flow
			if cmd == "ssh_info" {
				fmt.Print(`{"type":"gitea","version":1}`)
				return nil
			}
		}
		return fail(ctx, "Too few arguments", "Too few arguments in cmd: %s", cmd)
	}

	repoPath := strings.TrimPrefix(sshCmdArgs[1], "/")
	repoPathFields := strings.SplitN(repoPath, "/", 2)
	if len(repoPathFields) != 2 {
		return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
	}

	username := repoPathFields[0]
	reponame := strings.TrimSuffix(repoPathFields[1], ".git") // “the-repo-name" or "the-repo-name.wiki"

	// LowerCase and trim the repoPath as that's how they are stored.
	// This should be done after splitting the repoPath into username and reponame
	// so that username and reponame are not affected.
	repoPath = strings.ToLower(strings.TrimSpace(repoPath))

	if !repo.IsValidSSHAccessRepoName(reponame) {
		return fail(ctx, "Invalid repo name", "Invalid repo name: %s", reponame)
	}

	if c.Bool("enable-pprof") {

Review comment (refactor):
a little wonder about whether this change is right. Because we hasn't full support agit protocol format. some RefPatterns are different. ref: https://github.com/alibaba/git-repo-go/blob/master/helper/proto-agit.go

Code after:
			return fail(ctx, "Key check failed", "Failed to check provided key: %v", err)
		}
		switch key.Type {
		case asymkey_model.KeyTypeDeploy:
			println("Hi there! You've successfully authenticated with the deploy key named " + key.Name + ", but Gitea does not provide shell access.")
		case asymkey_model.KeyTypePrincipal:
			println("Hi there! You've successfully authenticated with the principal " + key.Content + ", but Gitea does not provide shell access.")
		default:
			println("Hi there, " + user.Name + "! You've successfully authenticated with the key named " + key.Name + ", but Gitea does not provide shell access.")
		}
		println("If this is unexpected, please log in with password and setup Gitea under another user.")
		return nil
	} else if c.Bool("debug") {
		log.Debug("SSH_ORIGINAL_COMMAND: %s", os.Getenv("SSH_ORIGINAL_COMMAND"))
	}

	sshCmdArgs, err := shellquote.Split(cmd)
	if err != nil {
		return fail(ctx, "Error parsing arguments", "Failed to parse arguments: %v", err)
	}

	if len(sshCmdArgs) < 2 {
		if git.DefaultFeatures().SupportProcReceive {
			// for AGit Flow
			if cmd == "ssh_info" {
				fmt.Print(`{"type":"agit","version":1}`)
				return nil
			}
		}
		return fail(ctx, "Too few arguments", "Too few arguments in cmd: %s", cmd)
	}

	repoPath := strings.TrimPrefix(sshCmdArgs[1], "/")
	repoPathFields := strings.SplitN(repoPath, "/", 2)
	if len(repoPathFields) != 2 {
		return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
	}

	username := repoPathFields[0]
	reponame := strings.TrimSuffix(repoPathFields[1], ".git") // “the-repo-name" or "the-repo-name.wiki"

	// LowerCase and trim the repoPath as that's how they are stored.
	// This should be done after splitting the repoPath into username and reponame
	// so that username and reponame are not affected.
	repoPath = strings.ToLower(strings.TrimSpace(repoPath))

	if !repo.IsValidSSHAccessRepoName(reponame) {
		return fail(ctx, "Invalid repo name", "Invalid repo name: %s", reponame)
	}

	if c.Bool("enable-pprof") {