git-upload-pack: make sure we close unused pipe ends
[gitweb.git] / upload-pack.c
index 7e3c437d8e1eaca61ccabb29f3097ba9c5c3732e..044c33b09091eefff4f6035286c0b4bd4adf155e 100644 (file)
@@ -1,6 +1,3 @@
-#include <signal.h>
-#include <sys/wait.h>
-#include <sys/poll.h>
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
@@ -58,6 +55,7 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
                /* emergency quit */
                fd = 2;
        if (fd == 2) {
+               /* XXX: are we happy to lose stuff here? */
                xwrite(fd, data, sz);
                return sz;
        }
@@ -121,6 +119,7 @@ static void create_pack_file(void)
                int i;
                struct rev_info revs;
 
+               close(lp_pipe[0]);
                pack_pipe = fdopen(lp_pipe[1], "w");
 
                if (create_full_pack)
@@ -245,7 +244,7 @@ static void create_pack_file(void)
                                        *cp++ = buffered;
                                        outsz++;
                                }
-                               sz = read(pu_pipe[0], cp,
+                               sz = xread(pu_pipe[0], cp,
                                          sizeof(data) - outsz);
                                if (0 < sz)
                                                ;
@@ -270,7 +269,7 @@ static void create_pack_file(void)
                                /* Status ready; we ship that in the side-band
                                 * or dump to the standard error.
                                 */
-                               sz = read(pe_pipe[0], progress,
+                               sz = xread(pe_pipe[0], progress,
                                          sizeof(progress));
                                if (0 < sz)
                                        send_client_data(2, progress, sz);
@@ -565,7 +564,7 @@ static void receive_needs(void)
                        SHALLOW, NOT_SHALLOW);
                while (result) {
                        struct object *object = &result->item->object;
-                       if (!(object->flags & CLIENT_SHALLOW)) {
+                       if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
                                packet_write(1, "shallow %s",
                                                sha1_to_hex(object->sha1));
                                register_shallow(object->sha1);
@@ -582,6 +581,7 @@ static void receive_needs(void)
                                object->flags &= ~CLIENT_SHALLOW;
                                /* make sure the real parents are parsed */
                                unregister_shallow(object->sha1);
+                               object->parsed = 0;
                                parse_commit((struct commit *)object);
                                parents = ((struct commit *)object)->parents;
                                while (parents) {
@@ -673,7 +673,8 @@ int main(int argc, char **argv)
 
        if (!enter_repo(dir, strict))
                die("'%s': unable to chdir or not a git archive", dir);
-
+       if (is_repository_shallow())
+               die("attempt to fetch/clone from a shallow repository");
        upload_pack();
        return 0;
 }