git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob c429055d15cb9909dfdbcfda989c10553c8f9bf8 2120 bytes (raw)
name: reftable/basics.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 
/*
Copyright 2020 Google LLC

Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/

#include "basics.h"

void put_be24(uint8_t *out, uint32_t i)
{
	out[0] = (uint8_t)((i >> 16) & 0xff);
	out[1] = (uint8_t)((i >> 8) & 0xff);
	out[2] = (uint8_t)(i & 0xff);
}

uint32_t get_be24(uint8_t *in)
{
	return (uint32_t)(in[0]) << 16 | (uint32_t)(in[1]) << 8 |
	       (uint32_t)(in[2]);
}

void put_be16(uint8_t *out, uint16_t i)
{
	out[0] = (uint8_t)((i >> 8) & 0xff);
	out[1] = (uint8_t)(i & 0xff);
}

int binsearch(size_t sz, int (*f)(size_t k, void *args), void *args)
{
	size_t lo = 0;
	size_t hi = sz;

	/* invariant: (hi == sz) || f(hi) == true
	   (lo == 0 && f(0) == true) || fi(lo) == false
	 */
	while (hi - lo > 1) {
		size_t mid = lo + (hi - lo) / 2;

		int val = f(mid, args);
		if (val) {
			hi = mid;
		} else {
			lo = mid;
		}
	}

	if (lo == 0) {
		if (f(0, args)) {
			return 0;
		} else {
			return 1;
		}
	}

	return hi;
}

void free_names(char **a)
{
	char **p = a;
	if (p == NULL) {
		return;
	}
	while (*p) {
		reftable_free(*p);
		p++;
	}
	reftable_free(a);
}

int names_length(char **names)
{
	int len = 0;
	char **p = names;
	while (*p) {
		p++;
		len++;
	}
	return len;
}

void parse_names(char *buf, int size, char ***namesp)
{
	char **names = NULL;
	size_t names_cap = 0;
	size_t names_len = 0;

	char *p = buf;
	char *end = buf + size;
	while (p < end) {
		char *next = strchr(p, '\n');
		if (next != NULL) {
			*next = 0;
		} else {
			next = end;
		}
		if (p < next) {
			if (names_len == names_cap) {
				names_cap = 2 * names_cap + 1;
				names = reftable_realloc(
					names, names_cap * sizeof(char *));
			}
			names[names_len++] = xstrdup(p);
		}
		p = next + 1;
	}

	if (names_len == names_cap) {
		names_cap = 2 * names_cap + 1;
		names = reftable_realloc(names, names_cap * sizeof(char *));
	}

	names[names_len] = NULL;
	*namesp = names;
}

int names_equal(char **a, char **b)
{
	while (*a && *b) {
		if (strcmp(*a, *b)) {
			return 0;
		}

		a++;
		b++;
	}

	return *a == *b;
}

debug log:

solving c429055d15 ...
found c429055d15 in https://public-inbox.org/git/570a8c4bcac54295865ee0fc4514073b59725511.1600283416.git.gitgitgadget@gmail.com/ ||
	https://public-inbox.org/git/4190da597e65bce072fa3c37c9410a56def4b489.1601568663.git.gitgitgadget@gmail.com/

applying [1/1] https://public-inbox.org/git/570a8c4bcac54295865ee0fc4514073b59725511.1600283416.git.gitgitgadget@gmail.com/
diff --git a/reftable/basics.c b/reftable/basics.c
new file mode 100644
index 0000000000..c429055d15

Checking patch reftable/basics.c...
Applied patch reftable/basics.c cleanly.

skipping https://public-inbox.org/git/4190da597e65bce072fa3c37c9410a56def4b489.1601568663.git.gitgitgadget@gmail.com/ for c429055d15
index at:
100644 c429055d15cb9909dfdbcfda989c10553c8f9bf8	reftable/basics.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).