return side_pid;
}
-static int get_pack(int xd[2])
+static int get_pack(int xd[2], char **pack_lockfile)
{
int status;
pid_t pid, side_pid;
char hdr_arg[256];
const char **av;
int do_keep = keep_pack;
+ int keep_pipe[2];
side_pid = setup_sideband(fd, xd);
}
if (do_keep) {
+ if (pack_lockfile && pipe(keep_pipe))
+ die("fetch-pack: pipe setup failure: %s", strerror(errno));
*av++ = "index-pack";
*av++ = "--stdin";
if (!quiet && !no_progress)
die("fetch-pack: unable to fork off %s", argv[0]);
if (!pid) {
dup2(fd[0], 0);
+ if (do_keep && pack_lockfile) {
+ dup2(keep_pipe[1], 1);
+ close(keep_pipe[0]);
+ close(keep_pipe[1]);
+ }
close(fd[0]);
close(fd[1]);
execv_git_cmd(argv);
}
close(fd[0]);
close(fd[1]);
+ if (do_keep && pack_lockfile) {
+ close(keep_pipe[1]);
+ *pack_lockfile = index_pack_lockfile(keep_pipe[0]);
+ close(keep_pipe[0]);
+ }
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR)
die("waiting for %s: %s", argv[0], strerror(errno));
die("%s died of unnatural causes %d", argv[0], status);
}
-static struct ref *do_fetch_pack(int fd[2], int nr_match, char **match)
+static struct ref *do_fetch_pack(int fd[2],
+ int nr_match,
+ char **match,
+ char **pack_lockfile)
{
struct ref *ref;
unsigned char sha1[20];
*/
fprintf(stderr, "warning: no common commits\n");
- if (get_pack(fd))
+ if (get_pack(fd, pack_lockfile))
die("git-fetch-pack: fetch failed.");
all_done:
if (!dest)
usage(fetch_pack_usage);
- ref = fetch_pack(dest, nr_heads, heads);
+ ref = fetch_pack(dest, nr_heads, heads, NULL);
ret = !ref;
return ret;
}
-struct ref *fetch_pack(const char *dest, int nr_heads, char **heads)
+struct ref *fetch_pack(const char *dest,
+ int nr_heads,
+ char **heads,
+ char **pack_lockfile)
{
int i, ret;
int fd[2];
return NULL;
if (heads && nr_heads)
nr_heads = remove_duplicates(nr_heads, heads);
- ref = do_fetch_pack(fd, nr_heads, heads);
+ ref = do_fetch_pack(fd, nr_heads, heads, pack_lockfile);
close(fd[0]);
close(fd[1]);
ret = finish_connect(pid);
int ret = transport_fetch_refs(transport, ref_map);
if (!ret)
store_updated_refs(transport->url, ref_map);
+ transport_unlock_pack(transport);
return ret;
}
void setup_fetch_pack(struct fetch_pack_args *args);
-struct ref *fetch_pack(const char *dest, int nr_heads, char **heads);
+struct ref *fetch_pack(const char *dest, int nr_heads, char **heads, char **pack_lockfile);
#endif
/* Generic functions for using commit walkers */
-static int fetch_objs_via_walker(const struct transport *transport,
+static int fetch_objs_via_walker(struct transport *transport,
int nr_objs, struct ref **to_fetch)
{
char *dest = xstrdup(transport->url);
return result;
}
-static int fetch_refs_from_bundle(const struct transport *transport,
+static int fetch_refs_from_bundle(struct transport *transport,
int nr_heads, struct ref **to_fetch)
{
struct bundle_transport_data *data = transport->data;
return refs;
}
-static int fetch_refs_via_pack(const struct transport *transport,
+static int fetch_refs_via_pack(struct transport *transport,
int nr_heads, struct ref **to_fetch)
{
struct git_transport_data *data = transport->data;
for (i = 0; i < nr_heads; i++)
heads[i] = xstrdup(to_fetch[i]->name);
- refs = fetch_pack(dest, nr_heads, heads);
+ refs = fetch_pack(dest, nr_heads, heads, &transport->pack_lockfile);
for (i = 0; i < nr_heads; i++)
free(heads[i]);
ret->url = url;
ret->remote_refs = NULL;
ret->fetch = !!fetch;
+ ret->pack_lockfile = NULL;
}
return ret;
}
return rc;
}
+void transport_unlock_pack(struct transport *transport)
+{
+ if (transport->pack_lockfile) {
+ unlink(transport->pack_lockfile);
+ free(transport->pack_lockfile);
+ transport->pack_lockfile = NULL;
+ }
+}
+
int transport_disconnect(struct transport *transport)
{
int ret = 0;
struct ref *remote_refs;
const struct transport_ops *ops;
+ char *pack_lockfile;
};
#define TRANSPORT_PUSH_ALL 1
const char *value);
struct ref *(*get_refs_list)(const struct transport *transport);
- int (*fetch)(const struct transport *transport, int refs_nr, struct ref **refs);
+ int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
int (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);
int (*disconnect)(struct transport *connection);
struct ref *transport_get_remote_refs(struct transport *transport);
int transport_fetch_refs(struct transport *transport, struct ref *refs);
-
+void transport_unlock_pack(struct transport *transport);
int transport_disconnect(struct transport *transport);
#endif