mirror of https://github.com/git/git.git
Rename path_list to string_list
The name path_list was correct for the first usage of that data structure, but it really is a general-purpose string list. $ perl -i -pe 's/path-list/string-list/g' $(git grep -l path-list) $ perl -i -pe 's/path_list/string_list/g' $(git grep -l path_list) $ git mv path-list.h string-list.h $ git mv path-list.c string-list.c $ perl -i -pe 's/has_path/has_string/g' $(git grep -l has_path) $ perl -i -pe 's/path/string/g' string-list.[ch] $ git mv Documentation/technical/api-path-list.txt \ Documentation/technical/api-string-list.txt $ perl -i -pe 's/strdup_paths/strdup_strings/g' $(git grep -l strdup_paths) ... and then fix all users of string-list to access the member "string" instead of "path". Documentation/technical/api-string-list.txt needed some rewrapping, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
51ef1daa4a
commit
c455c87c5c
|
@ -105,7 +105,7 @@ For C programs:
|
|||
|
||||
- Use the API. No, really. We have a strbuf (variable length
|
||||
string), several arrays with the ALLOC_GROW() macro, a
|
||||
path_list for sorted string lists, a hash map (mapping struct
|
||||
string_list for sorted string lists, a hash map (mapping struct
|
||||
objects) named "struct decorate", amongst other things.
|
||||
|
||||
- When you come up with an API, document it.
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
path-list API
|
||||
=============
|
||||
|
||||
The path_list API offers a data structure and functions to handle sorted
|
||||
and unsorted string lists.
|
||||
|
||||
The name is a bit misleading, a path_list may store not only paths but
|
||||
strings in general.
|
||||
|
||||
The caller:
|
||||
|
||||
. Allocates and clears a `struct path_list` variable.
|
||||
|
||||
. Initializes the members. You might want to set the flag `strdup_paths`
|
||||
if the strings should be strdup()ed. For example, this is necessary
|
||||
when you add something like git_path("..."), since that function returns
|
||||
a static buffer that will change with the next call to git_path().
|
||||
+
|
||||
If you need something advanced, you can manually malloc() the `items`
|
||||
member (you need this if you add things later) and you should set the
|
||||
`nr` and `alloc` members in that case, too.
|
||||
|
||||
. Adds new items to the list, using `path_list_append` or `path_list_insert`.
|
||||
|
||||
. Can check if a string is in the list using `path_list_has_path` or
|
||||
`unsorted_path_list_has_path` and get it from the list using
|
||||
`path_list_lookup` for sorted lists.
|
||||
|
||||
. Can sort an unsorted list using `sort_path_list`.
|
||||
|
||||
. Finally it should free the list using `path_list_clear`.
|
||||
|
||||
Example:
|
||||
|
||||
----
|
||||
struct path_list list;
|
||||
int i;
|
||||
|
||||
memset(&list, 0, sizeof(struct path_list));
|
||||
path_list_append("foo", &list);
|
||||
path_list_append("bar", &list);
|
||||
for (i = 0; i < list.nr; i++)
|
||||
printf("%s\n", list.items[i].path)
|
||||
----
|
||||
|
||||
NOTE: It is more efficient to build an unsorted list and sort it
|
||||
afterwards, instead of building a sorted list (`O(n log n)` instead of
|
||||
`O(n^2)`).
|
||||
+
|
||||
However, if you use the list to check if a certain string was added
|
||||
already, you should not do that (using unsorted_path_list_has_path()),
|
||||
because the complexity would be quadratic again (but with a worse factor).
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
* General ones (works with sorted and unsorted lists as well)
|
||||
|
||||
`print_path_list`::
|
||||
|
||||
Dump a path_list to stdout, useful mainly for debugging purposes. It
|
||||
can take an optional header argument and it writes out the
|
||||
string-pointer pairs of the path_list, each one in its own line.
|
||||
|
||||
`path_list_clear`::
|
||||
|
||||
Free a path_list. The `path` pointer of the items will be freed in case
|
||||
the `strdup_paths` member of the path_list is set. The second parameter
|
||||
controls if the `util` pointer of the items should be freed or not.
|
||||
|
||||
* Functions for sorted lists only
|
||||
|
||||
`path_list_has_path`::
|
||||
|
||||
Determine if the path_list has a given string or not.
|
||||
|
||||
`path_list_insert`::
|
||||
|
||||
Insert a new element to the path_list. The returned pointer can be handy
|
||||
if you want to write something to the `util` pointer of the
|
||||
path_list_item containing the just added string.
|
||||
+
|
||||
Since this function uses xrealloc() (which die()s if it fails) if the
|
||||
list needs to grow, it is safe not to check the pointer. I.e. you may
|
||||
write `path_list_insert(...)->util = ...;`.
|
||||
|
||||
`path_list_lookup`::
|
||||
|
||||
Look up a given string in the path_list, returning the containing
|
||||
path_list_item. If the string is not found, NULL is returned.
|
||||
|
||||
* Functions for unsorted lists only
|
||||
|
||||
`path_list_append`::
|
||||
|
||||
Append a new string to the end of the path_list.
|
||||
|
||||
`sort_path_list`::
|
||||
|
||||
Make an unsorted list sorted.
|
||||
|
||||
`unsorted_path_list_has_path`::
|
||||
|
||||
It's like `path_list_has_path()` but for unsorted lists.
|
||||
+
|
||||
This function needs to look through all items, as opposed to its
|
||||
counterpart for sorted lists, which performs a binary search.
|
||||
|
||||
Data structures
|
||||
---------------
|
||||
|
||||
* `struct path_list_item`
|
||||
|
||||
Represents an item of the list. The `path` member is a pointer to the
|
||||
string, and you may use the `util` member for any purpose, if you want.
|
||||
|
||||
* `struct path_list`
|
||||
|
||||
Represents the list itself.
|
||||
|
||||
. The array of items are available via the `items` member.
|
||||
. The `nr` member contains the number of items stored in the list.
|
||||
. The `alloc` member is used to avoid reallocating at every insertion.
|
||||
You should not tamper with it.
|
||||
. Setting the `strdup_paths` member to 1 will strdup() the strings
|
||||
before adding them, see above.
|
|
@ -0,0 +1,128 @@
|
|||
string-list API
|
||||
===============
|
||||
|
||||
The string_list API offers a data structure and functions to handle sorted
|
||||
and unsorted string lists.
|
||||
|
||||
The 'string_list' struct used to be called 'path_list', but was renamed
|
||||
because it is not specific to paths.
|
||||
|
||||
The caller:
|
||||
|
||||
. Allocates and clears a `struct string_list` variable.
|
||||
|
||||
. Initializes the members. You might want to set the flag `strdup_strings`
|
||||
if the strings should be strdup()ed. For example, this is necessary
|
||||
when you add something like git_path("..."), since that function returns
|
||||
a static buffer that will change with the next call to git_path().
|
||||
+
|
||||
If you need something advanced, you can manually malloc() the `items`
|
||||
member (you need this if you add things later) and you should set the
|
||||
`nr` and `alloc` members in that case, too.
|
||||
|
||||
. Adds new items to the list, using `string_list_append` or
|
||||
`string_list_insert`.
|
||||
|
||||
. Can check if a string is in the list using `string_list_has_string` or
|
||||
`unsorted_string_list_has_string` and get it from the list using
|
||||
`string_list_lookup` for sorted lists.
|
||||
|
||||
. Can sort an unsorted list using `sort_string_list`.
|
||||
|
||||
. Finally it should free the list using `string_list_clear`.
|
||||
|
||||
Example:
|
||||
|
||||
----
|
||||
struct string_list list;
|
||||
int i;
|
||||
|
||||
memset(&list, 0, sizeof(struct string_list));
|
||||
string_list_append("foo", &list);
|
||||
string_list_append("bar", &list);
|
||||
for (i = 0; i < list.nr; i++)
|
||||
printf("%s\n", list.items[i].path)
|
||||
----
|
||||
|
||||
NOTE: It is more efficient to build an unsorted list and sort it
|
||||
afterwards, instead of building a sorted list (`O(n log n)` instead of
|
||||
`O(n^2)`).
|
||||
+
|
||||
However, if you use the list to check if a certain string was added
|
||||
already, you should not do that (using unsorted_string_list_has_string()),
|
||||
because the complexity would be quadratic again (but with a worse factor).
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
* General ones (works with sorted and unsorted lists as well)
|
||||
|
||||
`print_string_list`::
|
||||
|
||||
Dump a string_list to stdout, useful mainly for debugging purposes. It
|
||||
can take an optional header argument and it writes out the
|
||||
string-pointer pairs of the string_list, each one in its own line.
|
||||
|
||||
`string_list_clear`::
|
||||
|
||||
Free a string_list. The `string` pointer of the items will be freed in
|
||||
case the `strdup_strings` member of the string_list is set. The second
|
||||
parameter controls if the `util` pointer of the items should be freed
|
||||
or not.
|
||||
|
||||
* Functions for sorted lists only
|
||||
|
||||
`string_list_has_string`::
|
||||
|
||||
Determine if the string_list has a given string or not.
|
||||
|
||||
`string_list_insert`::
|
||||
|
||||
Insert a new element to the string_list. The returned pointer can be
|
||||
handy if you want to write something to the `util` pointer of the
|
||||
string_list_item containing the just added string.
|
||||
+
|
||||
Since this function uses xrealloc() (which die()s if it fails) if the
|
||||
list needs to grow, it is safe not to check the pointer. I.e. you may
|
||||
write `string_list_insert(...)->util = ...;`.
|
||||
|
||||
`string_list_lookup`::
|
||||
|
||||
Look up a given string in the string_list, returning the containing
|
||||
string_list_item. If the string is not found, NULL is returned.
|
||||
|
||||
* Functions for unsorted lists only
|
||||
|
||||
`string_list_append`::
|
||||
|
||||
Append a new string to the end of the string_list.
|
||||
|
||||
`sort_string_list`::
|
||||
|
||||
Make an unsorted list sorted.
|
||||
|
||||
`unsorted_string_list_has_string`::
|
||||
|
||||
It's like `string_list_has_string()` but for unsorted lists.
|
||||
+
|
||||
This function needs to look through all items, as opposed to its
|
||||
counterpart for sorted lists, which performs a binary search.
|
||||
|
||||
Data structures
|
||||
---------------
|
||||
|
||||
* `struct string_list_item`
|
||||
|
||||
Represents an item of the list. The `path` member is a pointer to the
|
||||
string, and you may use the `util` member for any purpose, if you want.
|
||||
|
||||
* `struct string_list`
|
||||
|
||||
Represents the list itself.
|
||||
|
||||
. The array of items are available via the `items` member.
|
||||
. The `nr` member contains the number of items stored in the list.
|
||||
. The `alloc` member is used to avoid reallocating at every insertion.
|
||||
You should not tamper with it.
|
||||
. Setting the `strdup_strings` member to 1 will strdup() the strings
|
||||
before adding them, see above.
|
4
Makefile
4
Makefile
|
@ -356,7 +356,7 @@ LIB_H += pack-refs.h
|
|||
LIB_H += pack-revindex.h
|
||||
LIB_H += parse-options.h
|
||||
LIB_H += patch-ids.h
|
||||
LIB_H += path-list.h
|
||||
LIB_H += string-list.h
|
||||
LIB_H += pkt-line.h
|
||||
LIB_H += progress.h
|
||||
LIB_H += quote.h
|
||||
|
@ -437,7 +437,7 @@ LIB_OBJS += pager.o
|
|||
LIB_OBJS += parse-options.o
|
||||
LIB_OBJS += patch-delta.o
|
||||
LIB_OBJS += patch-ids.o
|
||||
LIB_OBJS += path-list.o
|
||||
LIB_OBJS += string-list.o
|
||||
LIB_OBJS += path.o
|
||||
LIB_OBJS += pkt-line.o
|
||||
LIB_OBJS += pretty.o
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "blob.h"
|
||||
#include "delta.h"
|
||||
#include "builtin.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
|
||||
/*
|
||||
* --check turns on checking that the working tree matches the
|
||||
|
@ -194,7 +194,7 @@ struct image {
|
|||
* the case where more than one patches touch the same file.
|
||||
*/
|
||||
|
||||
static struct path_list fn_table;
|
||||
static struct string_list fn_table;
|
||||
|
||||
static uint32_t hash_line(const char *cp, size_t len)
|
||||
{
|
||||
|
@ -2250,12 +2250,12 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
|
|||
|
||||
static struct patch *in_fn_table(const char *name)
|
||||
{
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
|
||||
if (name == NULL)
|
||||
return NULL;
|
||||
|
||||
item = path_list_lookup(name, &fn_table);
|
||||
item = string_list_lookup(name, &fn_table);
|
||||
if (item != NULL)
|
||||
return (struct patch *)item->util;
|
||||
|
||||
|
@ -2264,7 +2264,7 @@ static struct patch *in_fn_table(const char *name)
|
|||
|
||||
static void add_to_fn_table(struct patch *patch)
|
||||
{
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
|
||||
/*
|
||||
* Always add new_name unless patch is a deletion
|
||||
|
@ -2272,7 +2272,7 @@ static void add_to_fn_table(struct patch *patch)
|
|||
* file creations and copies
|
||||
*/
|
||||
if (patch->new_name != NULL) {
|
||||
item = path_list_insert(patch->new_name, &fn_table);
|
||||
item = string_list_insert(patch->new_name, &fn_table);
|
||||
item->util = patch;
|
||||
}
|
||||
|
||||
|
@ -2281,7 +2281,7 @@ static void add_to_fn_table(struct patch *patch)
|
|||
* later chunks shouldn't patch old names
|
||||
*/
|
||||
if ((patch->new_name == NULL) || (patch->is_rename)) {
|
||||
item = path_list_insert(patch->old_name, &fn_table);
|
||||
item = string_list_insert(patch->old_name, &fn_table);
|
||||
item->util = (struct patch *) -1;
|
||||
}
|
||||
}
|
||||
|
@ -3051,7 +3051,7 @@ static int apply_patch(int fd, const char *filename, int options)
|
|||
int skipped_patch = 0;
|
||||
|
||||
/* FIXME - memory leak when using multiple patch files as inputs */
|
||||
memset(&fn_table, 0, sizeof(struct path_list));
|
||||
memset(&fn_table, 0, sizeof(struct string_list));
|
||||
strbuf_init(&buf, 0);
|
||||
patch_input_file = filename;
|
||||
read_patch_file(&buf, fd);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "quote.h"
|
||||
#include "xdiff-interface.h"
|
||||
#include "cache-tree.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "mailmap.h"
|
||||
#include "parse-options.h"
|
||||
|
||||
|
@ -40,7 +40,7 @@ static int blank_boundary;
|
|||
static int incremental;
|
||||
static int cmd_is_annotate;
|
||||
static int xdl_opts = XDF_NEED_MINIMAL;
|
||||
static struct path_list mailmap;
|
||||
static struct string_list mailmap;
|
||||
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
|
@ -1926,7 +1926,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
|
|||
* Used for the command line parsing; check if the path exists
|
||||
* in the working tree.
|
||||
*/
|
||||
static int has_path_in_work_tree(const char *path)
|
||||
static int has_string_in_work_tree(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
return !lstat(path, &st);
|
||||
|
@ -2390,14 +2390,14 @@ parse_done:
|
|||
if (argc < 2)
|
||||
usage_with_options(blame_opt_usage, options);
|
||||
path = add_prefix(prefix, argv[argc - 1]);
|
||||
if (argc == 3 && !has_path_in_work_tree(path)) { /* (2b) */
|
||||
if (argc == 3 && !has_string_in_work_tree(path)) { /* (2b) */
|
||||
path = add_prefix(prefix, argv[1]);
|
||||
argv[1] = argv[2];
|
||||
}
|
||||
argv[argc - 1] = "--";
|
||||
|
||||
setup_work_tree();
|
||||
if (!has_path_in_work_tree(path))
|
||||
if (!has_string_in_work_tree(path))
|
||||
die("cannot stat path %s: %s", path, strerror(errno));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "strbuf.h"
|
||||
#include "utf8.h"
|
||||
#include "parse-options.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "rerere.h"
|
||||
#include "unpack-trees.h"
|
||||
|
||||
|
@ -150,7 +150,7 @@ static int commit_index_files(void)
|
|||
* Take a union of paths in the index and the named tree (typically, "HEAD"),
|
||||
* and return the paths that match the given pattern in list.
|
||||
*/
|
||||
static int list_paths(struct path_list *list, const char *with_tree,
|
||||
static int list_paths(struct string_list *list, const char *with_tree,
|
||||
const char *prefix, const char **pattern)
|
||||
{
|
||||
int i;
|
||||
|
@ -169,24 +169,24 @@ static int list_paths(struct path_list *list, const char *with_tree,
|
|||
continue;
|
||||
if (!pathspec_match(pattern, m, ce->name, 0))
|
||||
continue;
|
||||
path_list_insert(ce->name, list);
|
||||
string_list_insert(ce->name, list);
|
||||
}
|
||||
|
||||
return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
|
||||
}
|
||||
|
||||
static void add_remove_files(struct path_list *list)
|
||||
static void add_remove_files(struct string_list *list)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < list->nr; i++) {
|
||||
struct stat st;
|
||||
struct path_list_item *p = &(list->items[i]);
|
||||
struct string_list_item *p = &(list->items[i]);
|
||||
|
||||
if (!lstat(p->path, &st)) {
|
||||
if (add_to_cache(p->path, &st, 0))
|
||||
if (!lstat(p->string, &st)) {
|
||||
if (add_to_cache(p->string, &st, 0))
|
||||
die("updating files failed");
|
||||
} else
|
||||
remove_file_from_cache(p->path);
|
||||
remove_file_from_cache(p->string);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ static void create_base_index(void)
|
|||
static char *prepare_index(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int fd;
|
||||
struct path_list partial;
|
||||
struct string_list partial;
|
||||
const char **pathspec = NULL;
|
||||
|
||||
if (interactive) {
|
||||
|
@ -305,7 +305,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
|
|||
die("cannot do a partial commit during a merge.");
|
||||
|
||||
memset(&partial, 0, sizeof(partial));
|
||||
partial.strdup_paths = 1;
|
||||
partial.strdup_strings = 1;
|
||||
if (list_paths(&partial, initial_commit ? NULL : "HEAD", prefix, pathspec))
|
||||
exit(1);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "log-tree.h"
|
||||
#include "revision.h"
|
||||
#include "decorate.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "utf8.h"
|
||||
#include "parse-options.h"
|
||||
|
||||
|
@ -309,7 +309,7 @@ static void handle_tag(const char *name, struct tag *tag)
|
|||
}
|
||||
|
||||
static void get_tags_and_duplicates(struct object_array *pending,
|
||||
struct path_list *extra_refs)
|
||||
struct string_list *extra_refs)
|
||||
{
|
||||
struct tag *tag;
|
||||
int i;
|
||||
|
@ -330,7 +330,7 @@ static void get_tags_and_duplicates(struct object_array *pending,
|
|||
case OBJ_TAG:
|
||||
tag = (struct tag *)e->item;
|
||||
while (tag && tag->object.type == OBJ_TAG) {
|
||||
path_list_insert(full_name, extra_refs)->util = tag;
|
||||
string_list_insert(full_name, extra_refs)->util = tag;
|
||||
tag = (struct tag *)tag->tagged;
|
||||
}
|
||||
if (!tag)
|
||||
|
@ -350,19 +350,19 @@ static void get_tags_and_duplicates(struct object_array *pending,
|
|||
}
|
||||
if (commit->util)
|
||||
/* more than one name for the same object */
|
||||
path_list_insert(full_name, extra_refs)->util = commit;
|
||||
string_list_insert(full_name, extra_refs)->util = commit;
|
||||
else
|
||||
commit->util = full_name;
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_tags_and_duplicates(struct path_list *extra_refs)
|
||||
static void handle_tags_and_duplicates(struct string_list *extra_refs)
|
||||
{
|
||||
struct commit *commit;
|
||||
int i;
|
||||
|
||||
for (i = extra_refs->nr - 1; i >= 0; i--) {
|
||||
const char *name = extra_refs->items[i].path;
|
||||
const char *name = extra_refs->items[i].string;
|
||||
struct object *object = extra_refs->items[i].util;
|
||||
switch (object->type) {
|
||||
case OBJ_TAG:
|
||||
|
@ -445,7 +445,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
|
|||
{
|
||||
struct rev_info revs;
|
||||
struct object_array commits = { 0, 0, NULL };
|
||||
struct path_list extra_refs = { NULL, 0, 0, 0 };
|
||||
struct string_list extra_refs = { NULL, 0, 0, 0 };
|
||||
struct commit *commit;
|
||||
char *export_filename = NULL, *import_filename = NULL;
|
||||
struct option options[] = {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "refs.h"
|
||||
#include "commit.h"
|
||||
#include "builtin.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "remote.h"
|
||||
#include "transport.h"
|
||||
#include "run-command.h"
|
||||
|
@ -465,8 +465,8 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
|
|||
static int add_existing(const char *refname, const unsigned char *sha1,
|
||||
int flag, void *cbdata)
|
||||
{
|
||||
struct path_list *list = (struct path_list *)cbdata;
|
||||
path_list_insert(refname, list);
|
||||
struct string_list *list = (struct string_list *)cbdata;
|
||||
string_list_insert(refname, list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -485,8 +485,8 @@ static void find_non_local_tags(struct transport *transport,
|
|||
struct ref **head,
|
||||
struct ref ***tail)
|
||||
{
|
||||
struct path_list existing_refs = { NULL, 0, 0, 0 };
|
||||
struct path_list new_refs = { NULL, 0, 0, 1 };
|
||||
struct string_list existing_refs = { NULL, 0, 0, 0 };
|
||||
struct string_list new_refs = { NULL, 0, 0, 1 };
|
||||
char *ref_name;
|
||||
int ref_name_len;
|
||||
const unsigned char *ref_sha1;
|
||||
|
@ -515,11 +515,11 @@ static void find_non_local_tags(struct transport *transport,
|
|||
}
|
||||
}
|
||||
|
||||
if (!path_list_has_path(&existing_refs, ref_name) &&
|
||||
!path_list_has_path(&new_refs, ref_name) &&
|
||||
if (!string_list_has_string(&existing_refs, ref_name) &&
|
||||
!string_list_has_string(&new_refs, ref_name) &&
|
||||
(has_sha1_file(ref->old_sha1) ||
|
||||
will_fetch(head, ref->old_sha1))) {
|
||||
path_list_insert(ref_name, &new_refs);
|
||||
string_list_insert(ref_name, &new_refs);
|
||||
|
||||
rm = alloc_ref_from_str(ref_name);
|
||||
rm->peer_ref = alloc_ref_from_str(ref_name);
|
||||
|
@ -530,8 +530,8 @@ static void find_non_local_tags(struct transport *transport,
|
|||
}
|
||||
free(ref_name);
|
||||
}
|
||||
path_list_clear(&existing_refs, 0);
|
||||
path_list_clear(&new_refs, 0);
|
||||
string_list_clear(&existing_refs, 0);
|
||||
string_list_clear(&new_refs, 0);
|
||||
}
|
||||
|
||||
static int do_fetch(struct transport *transport,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
#include "cache.h"
|
||||
#include "builtin.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
|
||||
static const char git_mailsplit_usage[] =
|
||||
"git mailsplit [-d<prec>] [-f<n>] [-b] -o<directory> [<mbox>|<Maildir>...]";
|
||||
|
@ -115,7 +115,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
static int populate_maildir_list(struct path_list *list, const char *path)
|
||||
static int populate_maildir_list(struct string_list *list, const char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *dent;
|
||||
|
@ -136,7 +136,7 @@ static int populate_maildir_list(struct path_list *list, const char *path)
|
|||
if (dent->d_name[0] == '.')
|
||||
continue;
|
||||
snprintf(name, sizeof(name), "%s/%s", *sub, dent->d_name);
|
||||
path_list_insert(name, list);
|
||||
string_list_insert(name, list);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
@ -152,14 +152,14 @@ static int split_maildir(const char *maildir, const char *dir,
|
|||
char name[PATH_MAX];
|
||||
int ret = -1;
|
||||
int i;
|
||||
struct path_list list = {NULL, 0, 0, 1};
|
||||
struct string_list list = {NULL, 0, 0, 1};
|
||||
|
||||
if (populate_maildir_list(&list, maildir) < 0)
|
||||
goto out;
|
||||
|
||||
for (i = 0; i < list.nr; i++) {
|
||||
FILE *f;
|
||||
snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].path);
|
||||
snprintf(file, sizeof(file), "%s/%s", maildir, list.items[i].string);
|
||||
f = fopen(file, "r");
|
||||
if (!f) {
|
||||
error("cannot open mail %s (%s)", file, strerror(errno));
|
||||
|
@ -179,7 +179,7 @@ static int split_maildir(const char *maildir, const char *dir,
|
|||
|
||||
ret = skip;
|
||||
out:
|
||||
path_list_clear(&list, 1);
|
||||
string_list_clear(&list, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "diffcore.h"
|
||||
#include "tag.h"
|
||||
#include "unpack-trees.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "xdiff-interface.h"
|
||||
#include "ll-merge.h"
|
||||
#include "interpolate.h"
|
||||
|
@ -79,8 +79,8 @@ struct stage_data
|
|||
unsigned processed:1;
|
||||
};
|
||||
|
||||
static struct path_list current_file_set = {NULL, 0, 0, 1};
|
||||
static struct path_list current_directory_set = {NULL, 0, 0, 1};
|
||||
static struct string_list current_file_set = {NULL, 0, 0, 1};
|
||||
static struct string_list current_directory_set = {NULL, 0, 0, 1};
|
||||
|
||||
static int call_depth = 0;
|
||||
static int verbosity = 2;
|
||||
|
@ -257,9 +257,9 @@ static int save_files_dirs(const unsigned char *sha1,
|
|||
newpath[baselen + len] = '\0';
|
||||
|
||||
if (S_ISDIR(mode))
|
||||
path_list_insert(newpath, ¤t_directory_set);
|
||||
string_list_insert(newpath, ¤t_directory_set);
|
||||
else
|
||||
path_list_insert(newpath, ¤t_file_set);
|
||||
string_list_insert(newpath, ¤t_file_set);
|
||||
free(newpath);
|
||||
|
||||
return READ_TREE_RECURSIVE;
|
||||
|
@ -280,9 +280,9 @@ static int get_files_dirs(struct tree *tree)
|
|||
*/
|
||||
static struct stage_data *insert_stage_data(const char *path,
|
||||
struct tree *o, struct tree *a, struct tree *b,
|
||||
struct path_list *entries)
|
||||
struct string_list *entries)
|
||||
{
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
|
||||
get_tree_entry(o->object.sha1, path,
|
||||
e->stages[1].sha, &e->stages[1].mode);
|
||||
|
@ -290,7 +290,7 @@ static struct stage_data *insert_stage_data(const char *path,
|
|||
e->stages[2].sha, &e->stages[2].mode);
|
||||
get_tree_entry(b->object.sha1, path,
|
||||
e->stages[3].sha, &e->stages[3].mode);
|
||||
item = path_list_insert(path, entries);
|
||||
item = string_list_insert(path, entries);
|
||||
item->util = e;
|
||||
return e;
|
||||
}
|
||||
|
@ -299,23 +299,23 @@ static struct stage_data *insert_stage_data(const char *path,
|
|||
* Create a dictionary mapping file names to stage_data objects. The
|
||||
* dictionary contains one entry for every path with a non-zero stage entry.
|
||||
*/
|
||||
static struct path_list *get_unmerged(void)
|
||||
static struct string_list *get_unmerged(void)
|
||||
{
|
||||
struct path_list *unmerged = xcalloc(1, sizeof(struct path_list));
|
||||
struct string_list *unmerged = xcalloc(1, sizeof(struct string_list));
|
||||
int i;
|
||||
|
||||
unmerged->strdup_paths = 1;
|
||||
unmerged->strdup_strings = 1;
|
||||
|
||||
for (i = 0; i < active_nr; i++) {
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
struct stage_data *e;
|
||||
struct cache_entry *ce = active_cache[i];
|
||||
if (!ce_stage(ce))
|
||||
continue;
|
||||
|
||||
item = path_list_lookup(ce->name, unmerged);
|
||||
item = string_list_lookup(ce->name, unmerged);
|
||||
if (!item) {
|
||||
item = path_list_insert(ce->name, unmerged);
|
||||
item = string_list_insert(ce->name, unmerged);
|
||||
item->util = xcalloc(1, sizeof(struct stage_data));
|
||||
}
|
||||
e = item->util;
|
||||
|
@ -340,17 +340,17 @@ struct rename
|
|||
* 'b_tree') to be able to associate the correct cache entries with
|
||||
* the rename information. 'tree' is always equal to either a_tree or b_tree.
|
||||
*/
|
||||
static struct path_list *get_renames(struct tree *tree,
|
||||
static struct string_list *get_renames(struct tree *tree,
|
||||
struct tree *o_tree,
|
||||
struct tree *a_tree,
|
||||
struct tree *b_tree,
|
||||
struct path_list *entries)
|
||||
struct string_list *entries)
|
||||
{
|
||||
int i;
|
||||
struct path_list *renames;
|
||||
struct string_list *renames;
|
||||
struct diff_options opts;
|
||||
|
||||
renames = xcalloc(1, sizeof(struct path_list));
|
||||
renames = xcalloc(1, sizeof(struct string_list));
|
||||
diff_setup(&opts);
|
||||
DIFF_OPT_SET(&opts, RECURSIVE);
|
||||
opts.detect_rename = DIFF_DETECT_RENAME;
|
||||
|
@ -364,7 +364,7 @@ static struct path_list *get_renames(struct tree *tree,
|
|||
diff_tree_sha1(o_tree->object.sha1, tree->object.sha1, "", &opts);
|
||||
diffcore_std(&opts);
|
||||
for (i = 0; i < diff_queued_diff.nr; ++i) {
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
struct rename *re;
|
||||
struct diff_filepair *pair = diff_queued_diff.queue[i];
|
||||
if (pair->status != 'R') {
|
||||
|
@ -374,20 +374,20 @@ static struct path_list *get_renames(struct tree *tree,
|
|||
re = xmalloc(sizeof(*re));
|
||||
re->processed = 0;
|
||||
re->pair = pair;
|
||||
item = path_list_lookup(re->pair->one->path, entries);
|
||||
item = string_list_lookup(re->pair->one->path, entries);
|
||||
if (!item)
|
||||
re->src_entry = insert_stage_data(re->pair->one->path,
|
||||
o_tree, a_tree, b_tree, entries);
|
||||
else
|
||||
re->src_entry = item->util;
|
||||
|
||||
item = path_list_lookup(re->pair->two->path, entries);
|
||||
item = string_list_lookup(re->pair->two->path, entries);
|
||||
if (!item)
|
||||
re->dst_entry = insert_stage_data(re->pair->two->path,
|
||||
o_tree, a_tree, b_tree, entries);
|
||||
else
|
||||
re->dst_entry = item->util;
|
||||
item = path_list_insert(pair->one->path, renames);
|
||||
item = string_list_insert(pair->one->path, renames);
|
||||
item->util = re;
|
||||
}
|
||||
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||
|
@ -464,12 +464,12 @@ static char *unique_path(const char *path, const char *branch)
|
|||
for (; *p; ++p)
|
||||
if ('/' == *p)
|
||||
*p = '_';
|
||||
while (path_list_has_path(¤t_file_set, newpath) ||
|
||||
path_list_has_path(¤t_directory_set, newpath) ||
|
||||
while (string_list_has_string(¤t_file_set, newpath) ||
|
||||
string_list_has_string(¤t_directory_set, newpath) ||
|
||||
lstat(newpath, &st) == 0)
|
||||
sprintf(p, "_%d", suffix++);
|
||||
|
||||
path_list_insert(newpath, ¤t_file_set);
|
||||
string_list_insert(newpath, ¤t_file_set);
|
||||
return newpath;
|
||||
}
|
||||
|
||||
|
@ -727,13 +727,13 @@ static void conflict_rename_rename(struct rename *ren1,
|
|||
const char *ren2_dst = ren2->pair->two->path;
|
||||
const char *dst_name1 = ren1_dst;
|
||||
const char *dst_name2 = ren2_dst;
|
||||
if (path_list_has_path(¤t_directory_set, ren1_dst)) {
|
||||
if (string_list_has_string(¤t_directory_set, ren1_dst)) {
|
||||
dst_name1 = del[delp++] = unique_path(ren1_dst, branch1);
|
||||
output(1, "%s is a directory in %s added as %s instead",
|
||||
ren1_dst, branch2, dst_name1);
|
||||
remove_file(0, ren1_dst, 0);
|
||||
}
|
||||
if (path_list_has_path(¤t_directory_set, ren2_dst)) {
|
||||
if (string_list_has_string(¤t_directory_set, ren2_dst)) {
|
||||
dst_name2 = del[delp++] = unique_path(ren2_dst, branch2);
|
||||
output(1, "%s is a directory in %s added as %s instead",
|
||||
ren2_dst, branch1, dst_name2);
|
||||
|
@ -783,30 +783,30 @@ static void conflict_rename_rename_2(struct rename *ren1,
|
|||
free(new_path1);
|
||||
}
|
||||
|
||||
static int process_renames(struct path_list *a_renames,
|
||||
struct path_list *b_renames,
|
||||
static int process_renames(struct string_list *a_renames,
|
||||
struct string_list *b_renames,
|
||||
const char *a_branch,
|
||||
const char *b_branch)
|
||||
{
|
||||
int clean_merge = 1, i, j;
|
||||
struct path_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
|
||||
struct string_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
|
||||
const struct rename *sre;
|
||||
|
||||
for (i = 0; i < a_renames->nr; i++) {
|
||||
sre = a_renames->items[i].util;
|
||||
path_list_insert(sre->pair->two->path, &a_by_dst)->util
|
||||
string_list_insert(sre->pair->two->path, &a_by_dst)->util
|
||||
= sre->dst_entry;
|
||||
}
|
||||
for (i = 0; i < b_renames->nr; i++) {
|
||||
sre = b_renames->items[i].util;
|
||||
path_list_insert(sre->pair->two->path, &b_by_dst)->util
|
||||
string_list_insert(sre->pair->two->path, &b_by_dst)->util
|
||||
= sre->dst_entry;
|
||||
}
|
||||
|
||||
for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
|
||||
int compare;
|
||||
char *src;
|
||||
struct path_list *renames1, *renames2, *renames2Dst;
|
||||
struct string_list *renames1, *renames2, *renames2Dst;
|
||||
struct rename *ren1 = NULL, *ren2 = NULL;
|
||||
const char *branch1, *branch2;
|
||||
const char *ren1_src, *ren1_dst;
|
||||
|
@ -818,8 +818,8 @@ static int process_renames(struct path_list *a_renames,
|
|||
compare = -1;
|
||||
ren1 = a_renames->items[i++].util;
|
||||
} else {
|
||||
compare = strcmp(a_renames->items[i].path,
|
||||
b_renames->items[j].path);
|
||||
compare = strcmp(a_renames->items[i].string,
|
||||
b_renames->items[j].string);
|
||||
if (compare <= 0)
|
||||
ren1 = a_renames->items[i++].util;
|
||||
if (compare >= 0)
|
||||
|
@ -908,7 +908,7 @@ static int process_renames(struct path_list *a_renames,
|
|||
}
|
||||
} else {
|
||||
/* Renamed in 1, maybe changed in 2 */
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
/* we only use sha1 and mode of these */
|
||||
struct diff_filespec src_other, dst_other;
|
||||
int try_merge, stage = a_renames == renames1 ? 3: 2;
|
||||
|
@ -922,7 +922,7 @@ static int process_renames(struct path_list *a_renames,
|
|||
|
||||
try_merge = 0;
|
||||
|
||||
if (path_list_has_path(¤t_directory_set, ren1_dst)) {
|
||||
if (string_list_has_string(¤t_directory_set, ren1_dst)) {
|
||||
clean_merge = 0;
|
||||
output(1, "CONFLICT (rename/directory): Renamed %s->%s in %s "
|
||||
" directory %s added in %s",
|
||||
|
@ -947,7 +947,7 @@ static int process_renames(struct path_list *a_renames,
|
|||
new_path = unique_path(ren1_dst, branch2);
|
||||
output(1, "Added as %s instead", new_path);
|
||||
update_file(0, dst_other.sha1, dst_other.mode, new_path);
|
||||
} else if ((item = path_list_lookup(ren1_dst, renames2Dst))) {
|
||||
} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {
|
||||
ren2 = item->util;
|
||||
clean_merge = 0;
|
||||
ren2->processed = 1;
|
||||
|
@ -1003,8 +1003,8 @@ static int process_renames(struct path_list *a_renames,
|
|||
}
|
||||
}
|
||||
}
|
||||
path_list_clear(&a_by_dst, 0);
|
||||
path_list_clear(&b_by_dst, 0);
|
||||
string_list_clear(&a_by_dst, 0);
|
||||
string_list_clear(&b_by_dst, 0);
|
||||
|
||||
return clean_merge;
|
||||
}
|
||||
|
@ -1082,7 +1082,7 @@ static int process_entry(const char *path, struct stage_data *entry,
|
|||
sha = b_sha;
|
||||
conf = "directory/file";
|
||||
}
|
||||
if (path_list_has_path(¤t_directory_set, path)) {
|
||||
if (string_list_has_string(¤t_directory_set, path)) {
|
||||
const char *new_path = unique_path(path, add_branch);
|
||||
clean_merge = 0;
|
||||
output(1, "CONFLICT (%s): There is a directory with name %s in %s. "
|
||||
|
@ -1173,10 +1173,10 @@ int merge_trees(struct tree *head,
|
|||
sha1_to_hex(merge->object.sha1));
|
||||
|
||||
if (unmerged_cache()) {
|
||||
struct path_list *entries, *re_head, *re_merge;
|
||||
struct string_list *entries, *re_head, *re_merge;
|
||||
int i;
|
||||
path_list_clear(¤t_file_set, 1);
|
||||
path_list_clear(¤t_directory_set, 1);
|
||||
string_list_clear(¤t_file_set, 1);
|
||||
string_list_clear(¤t_directory_set, 1);
|
||||
get_files_dirs(head);
|
||||
get_files_dirs(merge);
|
||||
|
||||
|
@ -1186,16 +1186,16 @@ int merge_trees(struct tree *head,
|
|||
clean = process_renames(re_head, re_merge,
|
||||
branch1, branch2);
|
||||
for (i = 0; i < entries->nr; i++) {
|
||||
const char *path = entries->items[i].path;
|
||||
const char *path = entries->items[i].string;
|
||||
struct stage_data *e = entries->items[i].util;
|
||||
if (!e->processed
|
||||
&& !process_entry(path, e, branch1, branch2))
|
||||
clean = 0;
|
||||
}
|
||||
|
||||
path_list_clear(re_merge, 0);
|
||||
path_list_clear(re_head, 0);
|
||||
path_list_clear(entries, 1);
|
||||
string_list_clear(re_merge, 0);
|
||||
string_list_clear(re_head, 0);
|
||||
string_list_clear(entries, 1);
|
||||
|
||||
}
|
||||
else
|
||||
|
|
39
builtin-mv.c
39
builtin-mv.c
|
@ -7,7 +7,7 @@
|
|||
#include "builtin.h"
|
||||
#include "dir.h"
|
||||
#include "cache-tree.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "parse-options.h"
|
||||
|
||||
static const char * const builtin_mv_usage[] = {
|
||||
|
@ -36,13 +36,14 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
|
|||
return get_pathspec(prefix, result);
|
||||
}
|
||||
|
||||
static void show_list(const char *label, struct path_list *list)
|
||||
static void show_list(const char *label, struct string_list *list)
|
||||
{
|
||||
if (list->nr > 0) {
|
||||
int i;
|
||||
printf("%s", label);
|
||||
for (i = 0; i < list->nr; i++)
|
||||
printf("%s%s", i > 0 ? ", " : "", list->items[i].path);
|
||||
printf("%s%s", i > 0 ? ", " : "",
|
||||
list->items[i].string);
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
@ -75,11 +76,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||
const char **source, **destination, **dest_path;
|
||||
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
|
||||
struct stat st;
|
||||
struct path_list overwritten = {NULL, 0, 0, 0};
|
||||
struct path_list src_for_dst = {NULL, 0, 0, 0};
|
||||
struct path_list added = {NULL, 0, 0, 0};
|
||||
struct path_list deleted = {NULL, 0, 0, 0};
|
||||
struct path_list changed = {NULL, 0, 0, 0};
|
||||
struct string_list overwritten = {NULL, 0, 0, 0};
|
||||
struct string_list src_for_dst = {NULL, 0, 0, 0};
|
||||
struct string_list added = {NULL, 0, 0, 0};
|
||||
struct string_list deleted = {NULL, 0, 0, 0};
|
||||
struct string_list changed = {NULL, 0, 0, 0};
|
||||
|
||||
git_config(git_default_config, NULL);
|
||||
|
||||
|
@ -189,16 +190,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||
" will overwrite!\n",
|
||||
bad);
|
||||
bad = NULL;
|
||||
path_list_insert(dst, &overwritten);
|
||||
string_list_insert(dst, &overwritten);
|
||||
} else
|
||||
bad = "Cannot overwrite";
|
||||
}
|
||||
} else if (cache_name_pos(src, length) < 0)
|
||||
bad = "not under version control";
|
||||
else if (path_list_has_path(&src_for_dst, dst))
|
||||
else if (string_list_has_string(&src_for_dst, dst))
|
||||
bad = "multiple sources for the same target";
|
||||
else
|
||||
path_list_insert(dst, &src_for_dst);
|
||||
string_list_insert(dst, &src_for_dst);
|
||||
|
||||
if (bad) {
|
||||
if (ignore_errors) {
|
||||
|
@ -228,15 +229,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||
continue;
|
||||
|
||||
if (cache_name_pos(src, strlen(src)) >= 0) {
|
||||
path_list_insert(src, &deleted);
|
||||
string_list_insert(src, &deleted);
|
||||
|
||||
/* destination can be a directory with 1 file inside */
|
||||
if (path_list_has_path(&overwritten, dst))
|
||||
path_list_insert(dst, &changed);
|
||||
if (string_list_has_string(&overwritten, dst))
|
||||
string_list_insert(dst, &changed);
|
||||
else
|
||||
path_list_insert(dst, &added);
|
||||
string_list_insert(dst, &added);
|
||||
} else
|
||||
path_list_insert(dst, &added);
|
||||
string_list_insert(dst, &added);
|
||||
}
|
||||
|
||||
if (show_only) {
|
||||
|
@ -245,7 +246,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||
show_list("Deleting : ", &deleted);
|
||||
} else {
|
||||
for (i = 0; i < changed.nr; i++) {
|
||||
const char *path = changed.items[i].path;
|
||||
const char *path = changed.items[i].string;
|
||||
int j = cache_name_pos(path, strlen(path));
|
||||
struct cache_entry *ce = active_cache[j];
|
||||
|
||||
|
@ -255,13 +256,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||
}
|
||||
|
||||
for (i = 0; i < added.nr; i++) {
|
||||
const char *path = added.items[i].path;
|
||||
const char *path = added.items[i].string;
|
||||
if (add_file_to_cache(path, verbose ? ADD_CACHE_VERBOSE : 0))
|
||||
die("updating index entries failed");
|
||||
}
|
||||
|
||||
for (i = 0; i < deleted.nr; i++)
|
||||
remove_file_from_cache(deleted.items[i].path);
|
||||
remove_file_from_cache(deleted.items[i].string);
|
||||
|
||||
if (active_cache_changed) {
|
||||
if (write_cache(newfd, active_cache, active_nr) ||
|
||||
|
|
124
builtin-remote.c
124
builtin-remote.c
|
@ -2,7 +2,7 @@
|
|||
#include "parse-options.h"
|
||||
#include "transport.h"
|
||||
#include "remote.h"
|
||||
#include "path-list.h"
|
||||
#include "string-list.h"
|
||||
#include "strbuf.h"
|
||||
#include "run-command.h"
|
||||
#include "refs.h"
|
||||
|
@ -31,11 +31,11 @@ static inline int postfixcmp(const char *string, const char *postfix)
|
|||
|
||||
static int opt_parse_track(const struct option *opt, const char *arg, int not)
|
||||
{
|
||||
struct path_list *list = opt->value;
|
||||
struct string_list *list = opt->value;
|
||||
if (not)
|
||||
path_list_clear(list, 0);
|
||||
string_list_clear(list, 0);
|
||||
else
|
||||
path_list_append(arg, list);
|
||||
string_list_append(arg, list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ static int fetch_remote(const char *name)
|
|||
static int add(int argc, const char **argv)
|
||||
{
|
||||
int fetch = 0, mirror = 0;
|
||||
struct path_list track = { NULL, 0, 0 };
|
||||
struct string_list track = { NULL, 0, 0 };
|
||||
const char *master = NULL;
|
||||
struct remote *remote;
|
||||
struct strbuf buf, buf2;
|
||||
|
@ -96,18 +96,18 @@ static int add(int argc, const char **argv)
|
|||
strbuf_addf(&buf, "remote.%s.fetch", name);
|
||||
|
||||
if (track.nr == 0)
|
||||
path_list_append("*", &track);
|
||||
string_list_append("*", &track);
|
||||
for (i = 0; i < track.nr; i++) {
|
||||
struct path_list_item *item = track.items + i;
|
||||
struct string_list_item *item = track.items + i;
|
||||
|
||||
strbuf_reset(&buf2);
|
||||
strbuf_addch(&buf2, '+');
|
||||
if (mirror)
|
||||
strbuf_addf(&buf2, "refs/%s:refs/%s",
|
||||
item->path, item->path);
|
||||
item->string, item->string);
|
||||
else
|
||||
strbuf_addf(&buf2, "refs/heads/%s:refs/remotes/%s/%s",
|
||||
item->path, name, item->path);
|
||||
item->string, name, item->string);
|
||||
if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
|
||||
return 1;
|
||||
}
|
||||
|
@ -135,17 +135,17 @@ static int add(int argc, const char **argv)
|
|||
|
||||
strbuf_release(&buf);
|
||||
strbuf_release(&buf2);
|
||||
path_list_clear(&track, 0);
|
||||
string_list_clear(&track, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct branch_info {
|
||||
char *remote;
|
||||
struct path_list merge;
|
||||
struct string_list merge;
|
||||
};
|
||||
|
||||
static struct path_list branch_list;
|
||||
static struct string_list branch_list;
|
||||
|
||||
static const char *abbrev_ref(const char *name, const char *prefix)
|
||||
{
|
||||
|
@ -160,7 +160,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
|
|||
{
|
||||
if (!prefixcmp(key, "branch.")) {
|
||||
char *name;
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
struct branch_info *info;
|
||||
enum { REMOTE, MERGE } type;
|
||||
|
||||
|
@ -174,7 +174,7 @@ static int config_read_branches(const char *key, const char *value, void *cb)
|
|||
} else
|
||||
return 0;
|
||||
|
||||
item = path_list_insert(name, &branch_list);
|
||||
item = string_list_insert(name, &branch_list);
|
||||
|
||||
if (!item->util)
|
||||
item->util = xcalloc(sizeof(struct branch_info), 1);
|
||||
|
@ -189,11 +189,11 @@ static int config_read_branches(const char *key, const char *value, void *cb)
|
|||
while (space) {
|
||||
char *merge;
|
||||
merge = xstrndup(value, space - value);
|
||||
path_list_append(merge, &info->merge);
|
||||
string_list_append(merge, &info->merge);
|
||||
value = abbrev_branch(space + 1);
|
||||
space = strchr(value, ' ');
|
||||
}
|
||||
path_list_append(xstrdup(value), &info->merge);
|
||||
string_list_append(xstrdup(value), &info->merge);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -204,12 +204,12 @@ static void read_branches(void)
|
|||
if (branch_list.nr)
|
||||
return;
|
||||
git_config(config_read_branches, NULL);
|
||||
sort_path_list(&branch_list);
|
||||
sort_string_list(&branch_list);
|
||||
}
|
||||
|
||||
struct ref_states {
|
||||
struct remote *remote;
|
||||
struct path_list new, stale, tracked;
|
||||
struct string_list new, stale, tracked;
|
||||
};
|
||||
|
||||
static int handle_one_branch(const char *refname,
|
||||
|
@ -221,16 +221,16 @@ static int handle_one_branch(const char *refname,
|
|||
memset(&refspec, 0, sizeof(refspec));
|
||||
refspec.dst = (char *)refname;
|
||||
if (!remote_find_tracking(states->remote, &refspec)) {
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
const char *name = abbrev_branch(refspec.src);
|
||||
/* symbolic refs pointing nowhere were handled already */
|
||||
if ((flags & REF_ISSYMREF) ||
|
||||
unsorted_path_list_has_path(&states->tracked,
|
||||
unsorted_string_list_has_string(&states->tracked,
|
||||
name) ||
|
||||
unsorted_path_list_has_path(&states->new,
|
||||
unsorted_string_list_has_string(&states->new,
|
||||
name))
|
||||
return 0;
|
||||
item = path_list_append(name, &states->stale);
|
||||
item = string_list_append(name, &states->stale);
|
||||
item->util = xstrdup(refname);
|
||||
}
|
||||
return 0;
|
||||
|
@ -246,9 +246,9 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
|
|||
die("Could not get fetch map for refspec %s",
|
||||
states->remote->fetch_refspec[i]);
|
||||
|
||||
states->new.strdup_paths = states->tracked.strdup_paths = 1;
|
||||
states->new.strdup_strings = states->tracked.strdup_strings = 1;
|
||||
for (ref = fetch_map; ref; ref = ref->next) {
|
||||
struct path_list *target = &states->tracked;
|
||||
struct string_list *target = &states->tracked;
|
||||
unsigned char sha1[20];
|
||||
void *util = NULL;
|
||||
|
||||
|
@ -259,12 +259,12 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
|
|||
if (hashcmp(sha1, ref->new_sha1))
|
||||
util = &states;
|
||||
}
|
||||
path_list_append(abbrev_branch(ref->name), target)->util = util;
|
||||
string_list_append(abbrev_branch(ref->name), target)->util = util;
|
||||
}
|
||||
free_refs(fetch_map);
|
||||
|
||||
for_each_ref(handle_one_branch, states);
|
||||
sort_path_list(&states->stale);
|
||||
sort_string_list(&states->stale);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ static int add_known_remote(struct remote *remote, void *cb_data)
|
|||
|
||||
struct branches_for_remote {
|
||||
struct remote *remote;
|
||||
struct path_list *branches;
|
||||
struct string_list *branches;
|
||||
struct known_remotes *keep;
|
||||
};
|
||||
|
||||
|
@ -305,7 +305,7 @@ static int add_branch_for_removal(const char *refname,
|
|||
{
|
||||
struct branches_for_remote *branches = cb_data;
|
||||
struct refspec refspec;
|
||||
struct path_list_item *item;
|
||||
struct string_list_item *item;
|
||||
struct known_remote *kr;
|
||||
|
||||
memset(&refspec, 0, sizeof(refspec));
|
||||
|
@ -325,19 +325,19 @@ static int add_branch_for_removal(const char *refname,
|
|||
if (flags & REF_ISSYMREF)
|
||||
return unlink(git_path(refname));
|
||||
|
||||
item = path_list_append(refname, branches->branches);
|
||||
item = string_list_append(refname, branches->branches);
|
||||
item->util = xmalloc(20);
|
||||
hashcpy(item->util, sha1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int remove_branches(struct path_list *branches)
|
||||
static int remove_branches(struct string_list *branches)
|
||||
{
|
||||
int i, result = 0;
|
||||
for (i = 0; i < branches->nr; i++) {
|
||||
struct path_list_item *item = branches->items + i;
|
||||
const char *refname = item->path;
|
||||
struct string_list_item *item = branches->items + i;
|
||||
const char *refname = item->string;
|
||||
unsigned char *sha1 = item->util;
|
||||
|
||||
if (delete_ref(refname, sha1))
|
||||
|
@ -354,7 +354,7 @@ static int rm(int argc, const char **argv)
|
|||
struct remote *remote;
|
||||