pull.con commit [PATCH] Really fix git-merge-one-file-script this time. (21a08dc)
   1#include "pull.h"
   2
   3#include "cache.h"
   4#include "commit.h"
   5#include "tree.h"
   6
   7int get_tree = 0;
   8int get_history = 0;
   9int get_all = 0;
  10
  11static int process_tree(unsigned char *sha1)
  12{
  13        struct tree *tree = lookup_tree(sha1);
  14        struct tree_entry_list *entries;
  15
  16        if (parse_tree(tree))
  17                return -1;
  18
  19        for (entries = tree->entries; entries; entries = entries->next) {
  20                if (fetch(entries->item.tree->object.sha1))
  21                        return -1;
  22                if (entries->directory) {
  23                        if (process_tree(entries->item.tree->object.sha1))
  24                                return -1;
  25                }
  26        }
  27        return 0;
  28}
  29
  30static int process_commit(unsigned char *sha1)
  31{
  32        struct commit *obj = lookup_commit(sha1);
  33
  34        if (fetch(sha1))
  35                return -1;
  36
  37        if (parse_commit(obj))
  38                return -1;
  39
  40        if (get_tree) {
  41                if (fetch(obj->tree->object.sha1))
  42                        return -1;
  43                if (process_tree(obj->tree->object.sha1))
  44                        return -1;
  45                if (!get_all)
  46                        get_tree = 0;
  47        }
  48        if (get_history) {
  49                struct commit_list *parents = obj->parents;
  50                for (; parents; parents = parents->next) {
  51                        if (has_sha1_file(parents->item->object.sha1))
  52                                continue;
  53                        if (fetch(parents->item->object.sha1)) {
  54                                /* The server might not have it, and
  55                                 * we don't mind. 
  56                                 */
  57                                continue;
  58                        }
  59                        if (process_commit(parents->item->object.sha1))
  60                                return -1;
  61                }
  62        }
  63        return 0;
  64}
  65
  66int pull(char *target)
  67{
  68        int retval;
  69        unsigned char sha1[20];
  70        retval = get_sha1_hex(target, sha1);
  71        if (retval)
  72                return retval;
  73        retval = fetch(sha1);
  74        if (retval)
  75                return retval;
  76        return process_commit(sha1);
  77}