Merge branch 'ar/string-list-foreach'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 19:14:38 +0000 (12:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 19:14:38 +0000 (12:14 -0700)
* ar/string-list-foreach:
Convert the users of for_each_string_list to for_each_string_list_item macro
Add a for_each_string_list_item macro

1  2 
builtin/fetch.c
builtin/ls-files.c
diff --combined builtin/fetch.c
index 1b67f5fda55896635e91852657259b47e722c889,b0bfaa9ae32021b6b32c9bdce99ccc543c9ecab7..680a8a97bd61cf3ce994ccaee1e89185600c84e8
@@@ -544,40 -544,14 +544,14 @@@ static int will_fetch(struct ref **head
        return 0;
  }
  
- struct tag_data {
-       struct ref **head;
-       struct ref ***tail;
- };
- static int add_to_tail(struct string_list_item *item, void *cb_data)
- {
-       struct tag_data *data = (struct tag_data *)cb_data;
-       struct ref *rm = NULL;
-       /* We have already decided to ignore this item */
-       if (!item->util)
-               return 0;
-       rm = alloc_ref(item->string);
-       rm->peer_ref = alloc_ref(item->string);
-       hashcpy(rm->old_sha1, item->util);
-       **data->tail = rm;
-       *data->tail = &rm->next;
-       return 0;
- }
  static void find_non_local_tags(struct transport *transport,
                        struct ref **head,
                        struct ref ***tail)
  {
        struct string_list existing_refs = { NULL, 0, 0, 0 };
        struct string_list remote_refs = { NULL, 0, 0, 0 };
-       struct tag_data data;
        const struct ref *ref;
        struct string_list_item *item = NULL;
-       data.head = head; data.tail = tail;
  
        for_each_ref(add_existing, &existing_refs);
        for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
                item->util = NULL;
  
        /*
-        * For all the tags in the remote_refs string list, call
-        * add_to_tail to add them to the list of refs to be fetched
+        * For all the tags in the remote_refs string list,
+        * add them to the list of refs to be fetched
         */
-       for_each_string_list(&remote_refs, add_to_tail, &data);
+       for_each_string_list_item(item, &remote_refs) {
+               /* Unless we have already decided to ignore this item... */
+               if (item->util)
+               {
+                       struct ref *rm = alloc_ref(item->string);
+                       rm->peer_ref = alloc_ref(item->string);
+                       hashcpy(rm->old_sha1, item->util);
+                       **tail = rm;
+                       *tail = &rm->next;
+               }
+       }
  
        string_list_clear(&remote_refs, 0);
  }
@@@ -845,8 -829,7 +829,8 @@@ static int fetch_one(struct remote *rem
        int exit_code;
  
        if (!remote)
 -              die("Where do you want to fetch from today?");
 +              die("No remote repository specified.  Please, specify either a URL or a\n"
 +                  "remote name from which new revisions should be fetched.");
  
        transport = transport_get(remote, NULL);
        transport_set_verbosity(transport, verbosity, progress);
diff --combined builtin/ls-files.c
index cc202c5f6fa6f2be7da857d2f4af7a2e4f3300d6,cf6ab034ffe2e0aeb1c676289ba96d2c616332fa..bb4f612b3d48c453d551f251b65887beb283ec7b
@@@ -25,7 -25,6 +25,7 @@@ static int show_modified
  static int show_killed;
  static int show_valid_bit;
  static int line_terminator = '\n';
 +static int debug_mode;
  
  static const char *prefix;
  static int max_prefix_len;
@@@ -163,42 -162,34 +163,41 @@@ static void show_ce_entry(const char *t
                       ce_stage(ce));
        }
        write_name(ce->name, ce_namelen(ce));
 +      if (debug_mode) {
 +              printf("  ctime: %d:%d\n", ce->ce_ctime.sec, ce->ce_ctime.nsec);
 +              printf("  mtime: %d:%d\n", ce->ce_mtime.sec, ce->ce_mtime.nsec);
 +              printf("  dev: %d\tino: %d\n", ce->ce_dev, ce->ce_ino);
 +              printf("  uid: %d\tgid: %d\n", ce->ce_uid, ce->ce_gid);
 +              printf("  size: %d\tflags: %x\n", ce->ce_size, ce->ce_flags);
 +      }
  }
  
- static int show_one_ru(struct string_list_item *item, void *cbdata)
- {
-       const char *path = item->string;
-       struct resolve_undo_info *ui = item->util;
-       int i, len;
-       len = strlen(path);
-       if (len < max_prefix_len)
-               return 0; /* outside of the prefix */
-       if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))
-               return 0; /* uninterested */
-       for (i = 0; i < 3; i++) {
-               if (!ui->mode[i])
-                       continue;
-               printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
-                      find_unique_abbrev(ui->sha1[i], abbrev),
-                      i + 1);
-               write_name(path, len);
-       }
-       return 0;
- }
  static void show_ru_info(void)
  {
+       struct string_list_item *item;
        if (!the_index.resolve_undo)
                return;
-       for_each_string_list(the_index.resolve_undo, show_one_ru, NULL);
+       for_each_string_list_item(item, the_index.resolve_undo) {
+               const char *path = item->string;
+               struct resolve_undo_info *ui = item->util;
+               int i, len;
+               len = strlen(path);
+               if (len < max_prefix_len)
+                       continue; /* outside of the prefix */
+               if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))
+                       continue; /* uninterested */
+               for (i = 0; i < 3; i++) {
+                       if (!ui->mode[i])
+                               continue;
+                       printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
+                              find_unique_abbrev(ui->sha1[i], abbrev),
+                              i + 1);
+                       write_name(path, len);
+               }
+       }
  }
  
  static void show_files(struct dir_struct *dir)
@@@ -527,7 -518,6 +526,7 @@@ int cmd_ls_files(int argc, const char *
                OPT_STRING(0, "with-tree", &with_tree, "tree-ish",
                        "pretend that paths removed since <tree-ish> are still present"),
                OPT__ABBREV(&abbrev),
 +              OPT_BOOLEAN(0, "debug", &debug_mode, "show debugging data"),
                OPT_END()
        };