MCPcopy Create free account
hub / github.com/git/git / handshake_version

Function handshake_version

sub-process.c:112–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static int handshake_version(struct child_process *process,
113 const char *welcome_prefix, int *versions,
114 int *chosen_version)
115{
116 int version_scratch;
117 int i;
118 char *line;
119 const char *p;
120
121 if (!chosen_version)
122 chosen_version = &version_scratch;
123
124 if (packet_write_fmt_gently(process->in, "%s-client\n",
125 welcome_prefix))
126 return error("Could not write client identification");
127 for (i = 0; versions[i]; i++) {
128 if (packet_write_fmt_gently(process->in, "version=%d\n",
129 versions[i]))
130 return error("Could not write requested version");
131 }
132 if (packet_flush_gently(process->in))
133 return error("Could not write flush packet");
134
135 if (packet_read_line_gently(process->out, NULL, &line) < 0)
136 return error("could not read greeting from subprocess '%s'",
137 process->args.v[0]);
138 if (!line || !skip_prefix(line, welcome_prefix, &p) ||
139 strcmp(p, "-server"))
140 return error("Unexpected line '%s', expected %s-server",
141 line ? line : "<flush packet>", welcome_prefix);
142 if (packet_read_line_gently(process->out, NULL, &line) < 0)
143 return error("could not read version from subprocess '%s'",
144 process->args.v[0]);
145 if (!line || !skip_prefix(line, "version=", &p) ||
146 strtol_i(p, 10, chosen_version))
147 return error("Unexpected line '%s', expected version",
148 line ? line : "<flush packet>");
149 if (packet_read_line_gently(process->out, NULL, &line) < 0)
150 return error("could not read version flush from subprocess '%s'",
151 process->args.v[0]);
152 if (line)
153 return error("Unexpected line '%s', expected flush", line);
154
155 /* Check to make sure that the version received is supported */
156 for (i = 0; versions[i]; i++) {
157 if (versions[i] == *chosen_version)
158 break;
159 }
160 if (!versions[i])
161 return error("Version %d not supported", *chosen_version);
162
163 return 0;
164}
165
166static int handshake_capabilities(struct child_process *process,
167 struct subprocess_capability *capabilities,

Callers 1

subprocess_handshakeFunction · 0.85

Calls 5

packet_write_fmt_gentlyFunction · 0.85
errorFunction · 0.85
packet_flush_gentlyFunction · 0.85
packet_read_line_gentlyFunction · 0.85
strtol_iFunction · 0.85

Tested by

no test coverage detected