* [PATCH v1 2/4] config.mak.uname: support for modern HPE NonStop config.
From: randall.s.becker @ 2018-12-26 23:05 UTC (permalink / raw)
To: git; +Cc: Randall S. Becker
In-Reply-To: <20181226230523.16572-1-randall.s.becker@rogers.com>
From: "Randall S. Becker" <rsbecker@nexbridge.com>
A number of configuration options are not automatically detected by
configure mechanisms, including the location of Perl and Python.
There was a problem at a specific set of operating system versions
that caused getopt to have compile errors. Accounted for this by
providing emulation defines for those versions.
Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>
---
config.mak.uname | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/config.mak.uname b/config.mak.uname
index 3ee7da0e23..aa4432ac2f 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -441,26 +441,45 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
# INLINE='' would just replace one set of warnings with another and
# still not compile in c89 mode, due to non-const array initializations.
CC = cc -c99
+ # Build down-rev compatible objects that don't use our new getopt_long.
+ ifeq ($(uname_R).$(uname_V),J06.21)
+ CC += -WRVU=J06.20
+ endif
+ ifeq ($(uname_R).$(uname_V),L17.02)
+ CC += -WRVU=L16.05
+ endif
+
# Disable all optimization, seems to result in bad code, with -O or -O2
# or even -O1 (default), /usr/local/libexec/git-core/git-pack-objects
# abends on "git push". Needs more investigation.
- CFLAGS = -g -O0
+ CFLAGS = -g -O0 -Winline
# We'd want it to be here.
prefix = /usr/local
# Our's are in ${prefix}/bin (perl might also be in /usr/bin/perl).
- PERL_PATH = ${prefix}/bin/perl
- PYTHON_PATH = ${prefix}/bin/python
-
+ PERL_PATH = /usr/bin/perl
+ PYTHON_PATH = /usr/bin/python
+ # The current /usr/coreutils/rm at lowest support level does not work
+ # with the git test structure. Default to the older rm.
+ RM = /bin/rm -f
# As detected by './configure'.
# Missdetected, hence commented out, see below.
#NO_CURL = YesPlease
# Added manually, see above.
+ # Missdetected, hence commented out, see below.
+ #NO_CURL = YesPlease
+ # Added manually, see above.
+ # Not detected by ./configure. Add manually.
+ NEEDS_SSL_WITH_CURL = YesPlease
+ NEEDS_CRYPTO_WITH_SSL = YesPlease
+ HAVE_DEV_TTY = YesPlease
+
HAVE_LIBCHARSET_H = YesPlease
HAVE_STRINGS_H = YesPlease
NEEDS_LIBICONV = YesPlease
NEEDS_LIBINTL_BEFORE_LIBICONV = YesPlease
NO_SYS_SELECT_H = UnfortunatelyYes
NO_D_TYPE_IN_DIRENT = YesPlease
+ NO_GETTEXT = YesPlease
NO_HSTRERROR = YesPlease
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
@@ -470,8 +489,13 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
NO_MKDTEMP = YesPlease
# Currently libiconv-1.9.1.
OLD_ICONV = UnfortunatelyYes
- NO_REGEX = YesPlease
+ NO_REGEX=NeedsStartEnd
NO_PTHREADS = UnfortunatelyYes
+ ifdef NO_PTHREADS
+ else # WIP, use of Posix User Threads is planned but not working yet
+ PTHREAD_CFLAGS = -D_PUT_MODEL_ -I/usr/include
+ PTHREAD_LIBS = -lput
+ endif
# Not detected (nor checked for) by './configure'.
# We don't have SA_RESTART on NonStop, unfortunalety.
--
2.17.0.10.gb132f7033
^ permalink raw reply related
* [PATCH v1 3/4] git-compat-util.h: add FLOSS headers for HPE NonStop
From: randall.s.becker @ 2018-12-26 23:05 UTC (permalink / raw)
To: git; +Cc: Randall S. Becker
In-Reply-To: <20181226230523.16572-1-randall.s.becker@rogers.com>
From: "Randall S. Becker" <rsbecker@nexbridge.com>
The HPE NonStop (a.k.a. __TANDEM) platform cannot build git without
using the FLOSS package supplied by HPE. The convenient location
for including the relevant headers is in this file.
The NSIG define is also not defined on __TANDEM, so we define it
here as 100 if it is not defined only for __TANDEM builds.
Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>
---
git-compat-util.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/git-compat-util.h b/git-compat-util.h
index 09b0102cae..3f615f7ed8 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -397,6 +397,21 @@ static inline char *git_find_last_dir_sep(const char *path)
#define query_user_email() NULL
#endif
+#ifdef __TANDEM
+#if !defined(_THREAD_SUPPORT_FUNCTIONS) && !defined(_PUT_MODEL_)
+/* #include <floss.h(floss_read,floss_write,floss_fsync,floss_fork)> */
+/* #include <floss.h(floss_fork)> */
+#endif
+#include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
+#include <floss.h(floss_getpwuid)>
+#if ! defined NSIG
+/* NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest
+ known, by detective work using kill -l as a list is all signals
+ instead of signal.h where it should be. */
+# define NSIG 100
+#endif
+#endif
+
#if defined(__HP_cc) && (__HP_cc >= 61000)
#define NORETURN __attribute__((noreturn))
#define NORETURN_PTR
--
2.17.0.10.gb132f7033
^ permalink raw reply related
* [PATCH v1 4/4] compat/regex/regcomp.c: define intptr_t and uintptr_t on NonStop
From: randall.s.becker @ 2018-12-26 23:05 UTC (permalink / raw)
To: git; +Cc: Randall S. Becker
In-Reply-To: <20181226230523.16572-1-randall.s.becker@rogers.com>
From: "Randall S. Becker" <rsbecker@nexbridge.com>
The system definition header files on HPE NonStop do not define
intptr_t and uintptr_t as do other platforms. These typedefs
are added specifically wrapped in a __TANDEM ifdef.
Signed-off-by: Randall S. Becker <rsbecker@nexbridge.com>
---
compat/regex/regcomp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c
index 51cd60baa3..c0d838834a 100644
--- a/compat/regex/regcomp.c
+++ b/compat/regex/regcomp.c
@@ -17,6 +17,14 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#if defined __TANDEM
+ /* This is currently duplicated from git-compat-utils.h */
+# ifdef NO_INTPTR_T
+ typedef long intptr_t;
+ typedef unsigned long uintptr_t;
+# endif
+#endif
+
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
--
2.17.0.10.gb132f7033
^ permalink raw reply related
* [PATCH 0/2] Improve documentation on UTF-16
From: brian m. carlson @ 2018-12-27 2:17 UTC (permalink / raw)
To: git; +Cc: Lars Schneider, Torsten Bögershausen
We've recently fielded several reports from unhappy Windows users about
our handling of UTF-16, UTF-16LE, and UTF-16BE, none of which seem to be
suitable for certain Windows programs.
In an effort to communicate the reasons for our behavior more
effectively, explain in the documentation that the UTF-16 variant that
people have been asking for hasn't been standardized, and therefore
hasn't been implemented in iconv(3). Mention what each of the variants
do, so that people can make a decision which one meets their needs the
best.
In addition, add a comment in the code about why we must, for
correctness reasons, reject a UTF-16LE or UTF-16BE sequence that begins
with U+FEFF, namely that such a codepoint semantically represents a
ZWNBSP, not a BOM, but that that codepoint at the beginning of a UTF-8
sequence (as encoded in the object store) would be misinterpreted as a
BOM instead.
This comment is in the code because I think it needs to be somewhere,
but I'm not sure the documentation is the right place for it. If
desired, I can add it to the documentation, although I feel the lurid
details are not interesting to most users. If the wording is confusing,
I'm very open to hearing suggestions for how to improve it.
I don't use Windows, so I don't know what MSVCRT does. If it requires a
BOM but doesn't accept big-endian encoding, then perhaps we should
report that as a bug to Microsoft so it can be fixed in a future
version. That would probably make a lot more programs work right out of
the box and dramatically improve the user experience.
As a note, I'm currently on vacation through the 2nd, so my responses
may be slightly delayed.
brian m. carlson (2):
Documentation: document UTF-16-related behavior
utf8: add comment explaining why BOMs are rejected
Documentation/gitattributes.txt | 5 +++++
utf8.c | 7 +++++++
2 files changed, 12 insertions(+)
^ permalink raw reply
* [PATCH 1/2] Documentation: document UTF-16-related behavior
From: brian m. carlson @ 2018-12-27 2:17 UTC (permalink / raw)
To: git; +Cc: Lars Schneider, Torsten Bögershausen
In-Reply-To: <20181227021734.528629-1-sandals@crustytoothpaste.net>
There are a number of broken Windows programs which want to process
files in a UTF-16 variant that is always little endian and always
contains a BOM. Git cannot produce or accept such an encoding for the
working-tree-encoding because no such encoding has been defined with
IANA or implemented in iconv(3).
Document this behavior since it is a frequent source of confusion for
users. Additionally, document that specifying "UTF-16" may produce bytes
of either endianness, but will be sure to provide a BOM to distinguish.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
Documentation/gitattributes.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index b8392fc330..2b2c93afd1 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -330,6 +330,11 @@ That operation will fail and cause an error.
- Reencoding content requires resources that might slow down certain
Git operations (e.g 'git checkout' or 'git add').
+- It is not possible to specify a variant of UTF-16 with a BOM and a
+ specified endianness, because no such variants have been standardized.
+ Using "UTF-16" will produce a BOM with an unspecified endianness, and
+ using "UTF-16LE" or "UTF-16BE" will prohibit a BOM from being used.
+
Use the `working-tree-encoding` attribute only if you cannot store a file
in UTF-8 encoding and if you want Git to be able to process the content
as text.
^ permalink raw reply related
* [PATCH 2/2] utf8: add comment explaining why BOMs are rejected
From: brian m. carlson @ 2018-12-27 2:17 UTC (permalink / raw)
To: git; +Cc: Lars Schneider, Torsten Bögershausen
In-Reply-To: <20181227021734.528629-1-sandals@crustytoothpaste.net>
A source of confusion for many Git users is why UTF-16LE and UTF-16BE do
not allow a BOM, instead treating it as a ZWNBSP, according to the
Unicode FAQ[0]. Explain in a comment why we cannot allow that to occur
due to our use of UTF-8 internally.
[0] https://unicode.org/faq/utf_bom.html#bom9
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
utf8.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/utf8.c b/utf8.c
index eb78587504..22af2c485a 100644
--- a/utf8.c
+++ b/utf8.c
@@ -571,6 +571,13 @@ static const char utf16_le_bom[] = {'\xFF', '\xFE'};
static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
+/*
+ * We check here for a forbidden BOM. When using UTF-16BE or UTF-16LE, a BOM is
+ * not allowed by RFC 2781, and any U+FEFF would be treated as a ZWNBSP, not a
+ * BOM. However, because we encode into UTF-8 internally, we cannot allow that
+ * character to occur as a ZWNBSP, since when encoded into UTF-8 it would be
+ * interpreted as a BOM.
+ */
int has_prohibited_utf_bom(const char *enc, const char *data, size_t len)
{
return (
^ permalink raw reply related
* [PATCH] imap-send: Fix compilation without deprecated OpenSSL APIs
From: Rosen Penev @ 2018-12-27 2:35 UTC (permalink / raw)
To: git
Initialization in OpenSSL has been deprecated in version 1.1. This makes
compilation fail when deprecated APIs for OpenSSL are compile-time
disabled.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
imap-send.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/imap-send.c b/imap-send.c
index b4eb886e2..21f741c8c 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -284,8 +284,10 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
int ret;
X509 *cert;
+#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
SSL_library_init();
SSL_load_error_strings();
+#endif
meth = SSLv23_method();
if (!meth) {
--
2.20.1
^ permalink raw reply related
* RE: git-rebase is ignoring working-tree-encoding
From: Alexandre Grigoriev @ 2018-12-27 2:52 UTC (permalink / raw)
To: 'brian m. carlson'
Cc: 'Torsten Bögershausen',
'Adrián Gimeno Balaguer', git
In-Reply-To: <20181226192525.GB423984@genre.crustytoothpaste.net>
> -----Original Message-----
> From: brian m. carlson [mailto:sandals@crustytoothpaste.net]
> Sent: Wednesday, December 26, 2018 11:25 AM
> To: Alexandre Grigoriev
> Cc: 'Torsten Bögershausen'; 'Adrián Gimeno Balaguer'; git@vger.kernel.org
> Subject: Re: git-rebase is ignoring working-tree-encoding
>
> On Tue, Dec 25, 2018 at 04:56:11PM -0800, Alexandre Grigoriev wrote:
> > Many tools in Windows still do not understand UTF-8, although it's
> > getting better. I think Windows is about the only OS where tools still
> > require
> > UTF-16 for full internationalization.
> > Many tools written in C use MSVC RTL, where fopen(), unfortunately,
> > doesn't understand UTF-16BE (though such a rudimentary program as
> Notepad does).
> >
> > For this reason, it's very reasonable to ask that the programming
> > tools produce UTF-16 files with particular endianness, natural for the
> > platform they're running on.
> >
> > The iconv programmers' boneheaded decision to always produce UTF-16BE
> > with BOM for UTF-16 output doesn't make sense.
> > Again, git and iconv/libiconv in Centos on x86 do the right thing and
> > produce UTF-16LE with BOM in this case.
>
> A program which claims to support "UTF-16" must support both
> endiannesses, according to RFC 2781. A program writing UTF-16-LE must not
> write a BOM at the beginning. I realize this is inconvenient, but the bad
> behavior of some Windows programs doesn't mean that Git should ignore
> interoperability with non-Windows systems using UTF-16 correctly in favor of
> Windows.
OK, we have a choice either:
a) to live in that corner of the real world where you have to use available tools, some of which have historical reasons
to only support UTF-16LE with BOM, because nobody ever throws a different flavor of UTF-16 at them;
Or b) to live in an ivory tower where you don't really need to use UTF-16 LE or BE or any other flavor,
because everything is just UTF-8, and tell all those other people using that lame OS to shut up and wait until their tools start to support
the formats you don't really have to care about;
> behavior of some Windows programs doesn't mean that Git should ignore
> interoperability with non-Windows systems using UTF-16 correctly in favor of
> Windows.
Yes, Git (actually libiconv) should not ignore interoperability.
This means it should check out files on a *Windows* system in a format which *Windows* tools
can understand.
And, by the way, Centos (or RedHat?) developers understood that.
There, on an x86 installation, when you ask for UTF-16, it produces UTF-16LE with BOM.
Just as every user there would want.
^ permalink raw reply
* Re: [PATCH] imap-send: Fix compilation without deprecated OpenSSL APIs
From: Junio C Hamano @ 2018-12-27 6:32 UTC (permalink / raw)
To: Rosen Penev; +Cc: git
In-Reply-To: <20181227023548.396-1-rosenp@gmail.com>
Rosen Penev <rosenp@gmail.com> writes:
> Initialization in OpenSSL has been deprecated in version 1.1.
https://www.openssl.org/docs/man1.0.2/ssl/SSL_library_init.html says
SSL_library_init() must be called before any other action takes
place.
https://www.openssl.org/docs/man1.1.0/ssl/SSL_library_init.html says
the same.
Which makes it necessary for us to defend the following claim
> This makes
> compilation fail when deprecated APIs for OpenSSL are compile-time
> disabled.
as a valid problem description more rigorously. To me, the cursory
web-serfing I did above makes me suspect that an OpenSSL
implementation with such a compile-time disabling _is_ buggy, as it
forbids the API users to call an API function they are told to call
before doing anything else.
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> imap-send.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/imap-send.c b/imap-send.c
> index b4eb886e2..21f741c8c 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -284,8 +284,10 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
> int ret;
> X509 *cert;
>
> +#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
https://www.openssl.org/docs/man1.1.0/crypto/OPENSSL_VERSION_NUMBER.html
says that OPENSSL_VERSION_NUMBER is of form 0xMNNFFPPS where M is
major, NN is minor, FF is fix, PP is patch and S is status, and
gives an example that 0x00906023 stands for 0.9.6.b beta 3 (M=0,
NN=09, FF=06, PP=02 and S=3). So "< 0x10000000L" means "anything
with M smaller than 1". IOW, we would no longer call _init() for
e.g. "version 1.0.0 beta 0". That contradicts with the first claim
of the proposed log message ("deprecated in 1.1" implying that it is
not yet deprecated in say 1.0.2).
> SSL_library_init();
> SSL_load_error_strings();
> +#endif
>
> meth = SSLv23_method();
> if (!meth) {
^ permalink raw reply
* [PATCH] Use packet_reader instead of packet_read_line
From: Masaya Suzuki @ 2018-12-27 6:52 UTC (permalink / raw)
To: git; +Cc: Masaya Suzuki
By using and sharing a packet_reader while handling a Git pack protocol
request, the same reader option is used throughout the code. This makes
it easy to set a reader option to the request parsing code.
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
---
builtin/archive.c | 19 ++++++-------
builtin/receive-pack.c | 60 +++++++++++++++++++++--------------------
fetch-pack.c | 61 +++++++++++++++++++++++-------------------
remote-curl.c | 20 ++++++++------
send-pack.c | 37 ++++++++++++-------------
upload-pack.c | 38 +++++++++++++-------------
6 files changed, 126 insertions(+), 109 deletions(-)
diff --git a/builtin/archive.c b/builtin/archive.c
index d2455237c..2fe1f05ca 100644
--- a/builtin/archive.c
+++ b/builtin/archive.c
@@ -27,10 +27,10 @@ static int run_remote_archiver(int argc, const char **argv,
const char *remote, const char *exec,
const char *name_hint)
{
- char *buf;
int fd[2], i, rv;
struct transport *transport;
struct remote *_remote;
+ struct packet_reader reader;
_remote = remote_get(remote);
if (!_remote->url[0])
@@ -53,18 +53,19 @@ static int run_remote_archiver(int argc, const char **argv,
packet_write_fmt(fd[1], "argument %s\n", argv[i]);
packet_flush(fd[1]);
- buf = packet_read_line(fd[0], NULL);
- if (!buf)
+ packet_reader_init(&reader, fd[0], NULL, 0, PACKET_READ_CHOMP_NEWLINE);
+
+ if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
die(_("git archive: expected ACK/NAK, got a flush packet"));
- if (strcmp(buf, "ACK")) {
- if (starts_with(buf, "NACK "))
- die(_("git archive: NACK %s"), buf + 5);
- if (starts_with(buf, "ERR "))
- die(_("remote error: %s"), buf + 4);
+ if (strcmp(reader.line, "ACK")) {
+ if (starts_with(reader.line, "NACK "))
+ die(_("git archive: NACK %s"), reader.line + 5);
+ if (starts_with(reader.line, "ERR "))
+ die(_("remote error: %s"), reader.line + 4);
die(_("git archive: protocol error"));
}
- if (packet_read_line(fd[0], NULL))
+ if (packet_reader_read(&reader) != PACKET_READ_FLUSH)
die(_("git archive: expected a flush"));
/* Now, start reading from fd[0] and spit it out to stdout */
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 33187bd8e..81cc07370 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1569,30 +1569,29 @@ static void queue_commands_from_cert(struct command **tail,
}
}
-static struct command *read_head_info(struct oid_array *shallow)
+static struct command *read_head_info(struct packet_reader *reader,
+ struct oid_array *shallow)
{
struct command *commands = NULL;
struct command **p = &commands;
for (;;) {
- char *line;
- int len, linelen;
+ int linelen;
- line = packet_read_line(0, &len);
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
- if (len > 8 && starts_with(line, "shallow ")) {
+ if (reader->pktlen > 8 && starts_with(reader->line, "shallow ")) {
struct object_id oid;
- if (get_oid_hex(line + 8, &oid))
+ if (get_oid_hex(reader->line + 8, &oid))
die("protocol error: expected shallow sha, got '%s'",
- line + 8);
+ reader->line + 8);
oid_array_append(shallow, &oid);
continue;
}
- linelen = strlen(line);
- if (linelen < len) {
- const char *feature_list = line + linelen + 1;
+ linelen = strlen(reader->line);
+ if (linelen < reader->pktlen) {
+ const char *feature_list = reader->line + linelen + 1;
if (parse_feature_request(feature_list, "report-status"))
report_status = 1;
if (parse_feature_request(feature_list, "side-band-64k"))
@@ -1607,28 +1606,32 @@ static struct command *read_head_info(struct oid_array *shallow)
use_push_options = 1;
}
- if (!strcmp(line, "push-cert")) {
+ if (!strcmp(reader->line, "push-cert")) {
int true_flush = 0;
- char certbuf[1024];
+ int saved_options = reader->options;
+ reader->options &= ~PACKET_READ_CHOMP_NEWLINE;
for (;;) {
- len = packet_read(0, NULL, NULL,
- certbuf, sizeof(certbuf), 0);
- if (!len) {
+ packet_reader_read(reader);
+ if (reader->status == PACKET_READ_FLUSH) {
true_flush = 1;
break;
}
- if (!strcmp(certbuf, "push-cert-end\n"))
+ if (reader->status != PACKET_READ_NORMAL) {
+ die("protocol error: got an unexpected packet");
+ }
+ if (!strcmp(reader->line, "push-cert-end\n"))
break; /* end of cert */
- strbuf_addstr(&push_cert, certbuf);
+ strbuf_addstr(&push_cert, reader->line);
}
+ reader->options = saved_options;
if (true_flush)
break;
continue;
}
- p = queue_command(p, line, linelen);
+ p = queue_command(p, reader->line, linelen);
}
if (push_cert.len)
@@ -1637,18 +1640,14 @@ static struct command *read_head_info(struct oid_array *shallow)
return commands;
}
-static void read_push_options(struct string_list *options)
+static void read_push_options(struct packet_reader *reader,
+ struct string_list *options)
{
while (1) {
- char *line;
- int len;
-
- line = packet_read_line(0, &len);
-
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
- string_list_append(options, line);
+ string_list_append(options, reader->line);
}
}
@@ -1924,6 +1923,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
struct oid_array shallow = OID_ARRAY_INIT;
struct oid_array ref = OID_ARRAY_INIT;
struct shallow_info si;
+ struct packet_reader reader;
struct option options[] = {
OPT__QUIET(&quiet, N_("quiet")),
@@ -1986,12 +1986,14 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
if (advertise_refs)
return 0;
- if ((commands = read_head_info(&shallow)) != NULL) {
+ packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE);
+
+ if ((commands = read_head_info(&reader, &shallow)) != NULL) {
const char *unpack_status = NULL;
struct string_list push_options = STRING_LIST_INIT_DUP;
if (use_push_options)
- read_push_options(&push_options);
+ read_push_options(&reader, &push_options);
if (!check_cert_push_options(&push_options)) {
struct command *cmd;
for (cmd = commands; cmd; cmd = cmd->next)
diff --git a/fetch-pack.c b/fetch-pack.c
index 9691046e6..86790b9bb 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -135,38 +135,42 @@ enum ack_type {
ACK_ready
};
-static void consume_shallow_list(struct fetch_pack_args *args, int fd)
+static void consume_shallow_list(struct fetch_pack_args *args,
+ struct packet_reader *reader)
{
if (args->stateless_rpc && args->deepen) {
/* If we sent a depth we will get back "duplicate"
* shallow and unshallow commands every time there
* is a block of have lines exchanged.
*/
- char *line;
- while ((line = packet_read_line(fd, NULL))) {
- if (starts_with(line, "shallow "))
+ while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
+ if (starts_with(reader->line, "shallow "))
continue;
- if (starts_with(line, "unshallow "))
+ if (starts_with(reader->line, "unshallow "))
continue;
die(_("git fetch-pack: expected shallow list"));
}
+ if (reader->status != PACKET_READ_FLUSH)
+ die(_("git fetch-pack: expected a flush packet after shallow list"));
}
}
-static enum ack_type get_ack(int fd, struct object_id *result_oid)
+static enum ack_type get_ack(struct packet_reader *reader,
+ struct object_id *result_oid)
{
int len;
- char *line = packet_read_line(fd, &len);
const char *arg;
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
die(_("git fetch-pack: expected ACK/NAK, got a flush packet"));
- if (!strcmp(line, "NAK"))
+ len = reader->pktlen;
+
+ if (!strcmp(reader->line, "NAK"))
return NAK;
- if (skip_prefix(line, "ACK ", &arg)) {
+ if (skip_prefix(reader->line, "ACK ", &arg)) {
if (!get_oid_hex(arg, result_oid)) {
arg += 40;
- len -= arg - line;
+ len -= arg - reader->line;
if (len < 1)
return ACK;
if (strstr(arg, "continue"))
@@ -178,9 +182,9 @@ static enum ack_type get_ack(int fd, struct object_id *result_oid)
return ACK;
}
}
- if (skip_prefix(line, "ERR ", &arg))
+ if (skip_prefix(reader->line, "ERR ", &arg))
die(_("remote error: %s"), arg);
- die(_("git fetch-pack: expected ACK/NAK, got '%s'"), line);
+ die(_("git fetch-pack: expected ACK/NAK, got '%s'"), reader->line);
}
static void send_request(struct fetch_pack_args *args,
@@ -248,10 +252,14 @@ static int find_common(struct fetch_negotiator *negotiator,
int got_ready = 0;
struct strbuf req_buf = STRBUF_INIT;
size_t state_len = 0;
+ struct packet_reader reader;
if (args->stateless_rpc && multi_ack == 1)
die(_("--stateless-rpc requires multi_ack_detailed"));
+ packet_reader_init(&reader, fd[0], NULL, 0,
+ PACKET_READ_CHOMP_NEWLINE);
+
if (!args->no_dependents) {
mark_tips(negotiator, args->negotiation_tips);
for_each_cached_alternate(negotiator, insert_one_alternate_object);
@@ -336,31 +344,30 @@ static int find_common(struct fetch_negotiator *negotiator,
state_len = req_buf.len;
if (args->deepen) {
- char *line;
const char *arg;
struct object_id oid;
send_request(args, fd[1], &req_buf);
- while ((line = packet_read_line(fd[0], NULL))) {
- if (skip_prefix(line, "shallow ", &arg)) {
+ while (packet_reader_read(&reader) == PACKET_READ_NORMAL) {
+ if (skip_prefix(reader.line, "shallow ", &arg)) {
if (get_oid_hex(arg, &oid))
- die(_("invalid shallow line: %s"), line);
+ die(_("invalid shallow line: %s"), reader.line);
register_shallow(the_repository, &oid);
continue;
}
- if (skip_prefix(line, "unshallow ", &arg)) {
+ if (skip_prefix(reader.line, "unshallow ", &arg)) {
if (get_oid_hex(arg, &oid))
- die(_("invalid unshallow line: %s"), line);
+ die(_("invalid unshallow line: %s"), reader.line);
if (!lookup_object(the_repository, oid.hash))
- die(_("object not found: %s"), line);
+ die(_("object not found: %s"), reader.line);
/* make sure that it is parsed as shallow */
if (!parse_object(the_repository, &oid))
- die(_("error in object: %s"), line);
+ die(_("error in object: %s"), reader.line);
if (unregister_shallow(&oid))
- die(_("no shallow found: %s"), line);
+ die(_("no shallow found: %s"), reader.line);
continue;
}
- die(_("expected shallow/unshallow, got %s"), line);
+ die(_("expected shallow/unshallow, got %s"), reader.line);
}
} else if (!args->stateless_rpc)
send_request(args, fd[1], &req_buf);
@@ -397,9 +404,9 @@ static int find_common(struct fetch_negotiator *negotiator,
if (!args->stateless_rpc && count == INITIAL_FLUSH)
continue;
- consume_shallow_list(args, fd[0]);
+ consume_shallow_list(args, &reader);
do {
- ack = get_ack(fd[0], result_oid);
+ ack = get_ack(&reader, result_oid);
if (ack)
print_verbose(args, _("got %s %d %s"), "ack",
ack, oid_to_hex(result_oid));
@@ -469,9 +476,9 @@ static int find_common(struct fetch_negotiator *negotiator,
strbuf_release(&req_buf);
if (!got_ready || !no_done)
- consume_shallow_list(args, fd[0]);
+ consume_shallow_list(args, &reader);
while (flushes || multi_ack) {
- int ack = get_ack(fd[0], result_oid);
+ int ack = get_ack(&reader, result_oid);
if (ack) {
print_verbose(args, _("got %s (%d) %s"), "ack",
ack, oid_to_hex(result_oid));
diff --git a/remote-curl.c b/remote-curl.c
index 1220dffcd..db1937c14 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -409,29 +409,33 @@ static struct discovery *discover_refs(const char *service, int for_push)
if (maybe_smart &&
(5 <= last->len && last->buf[4] == '#') &&
!strbuf_cmp(&exp, &type)) {
- char *line;
+ struct packet_reader reader;
+ packet_reader_init(&reader, -1, last->buf, last->len,
+ PACKET_READ_CHOMP_NEWLINE);
/*
* smart HTTP response; validate that the service
* pkt-line matches our request.
*/
- line = packet_read_line_buf(&last->buf, &last->len, NULL);
- if (!line)
+ if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
die("invalid server response; expected service, got flush packet");
strbuf_reset(&exp);
strbuf_addf(&exp, "# service=%s", service);
- if (strcmp(line, exp.buf))
- die("invalid server response; got '%s'", line);
+ if (strcmp(reader.line, exp.buf))
+ die("invalid server response; got '%s'", reader.line);
strbuf_release(&exp);
/* The header can include additional metadata lines, up
* until a packet flush marker. Ignore these now, but
* in the future we might start to scan them.
*/
- while (packet_read_line_buf(&last->buf, &last->len, NULL))
- ;
-
+ for (;;) {
+ packet_reader_read(&reader);
+ if (reader.pktlen <= 0) {
+ break;
+ }
+ }
last->proto_git = 1;
} else if (maybe_smart &&
last->len > 5 && starts_with(last->buf + 4, "version 2")) {
diff --git a/send-pack.c b/send-pack.c
index f69268677..913645046 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -135,38 +135,36 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
return 0;
}
-static int receive_unpack_status(int in)
+static int receive_unpack_status(struct packet_reader *reader)
{
- const char *line = packet_read_line(in, NULL);
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
return error(_("unexpected flush packet while reading remote unpack status"));
- if (!skip_prefix(line, "unpack ", &line))
- return error(_("unable to parse remote unpack status: %s"), line);
- if (strcmp(line, "ok"))
- return error(_("remote unpack failed: %s"), line);
+ if (!skip_prefix(reader->line, "unpack ", &reader->line))
+ return error(_("unable to parse remote unpack status: %s"), reader->line);
+ if (strcmp(reader->line, "ok"))
+ return error(_("remote unpack failed: %s"), reader->line);
return 0;
}
-static int receive_status(int in, struct ref *refs)
+static int receive_status(struct packet_reader *reader, struct ref *refs)
{
struct ref *hint;
int ret;
hint = NULL;
- ret = receive_unpack_status(in);
+ ret = receive_unpack_status(reader);
while (1) {
- char *refname;
+ const char *refname;
char *msg;
- char *line = packet_read_line(in, NULL);
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
- if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
- error("invalid ref status from remote: %s", line);
+ if (!starts_with(reader->line, "ok ") && !starts_with(reader->line, "ng ")) {
+ error("invalid ref status from remote: %s", reader->line);
ret = -1;
break;
}
- refname = line + 3;
+ refname = reader->line + 3;
msg = strchr(refname, ' ');
if (msg)
*msg++ = '\0';
@@ -187,7 +185,7 @@ static int receive_status(int in, struct ref *refs)
continue;
}
- if (line[0] == 'o' && line[1] == 'k')
+ if (reader->line[0] == 'o' && reader->line[1] == 'k')
hint->status = REF_STATUS_OK;
else {
hint->status = REF_STATUS_REMOTE_REJECT;
@@ -390,6 +388,7 @@ int send_pack(struct send_pack_args *args,
int ret;
struct async demux;
const char *push_cert_nonce = NULL;
+ struct packet_reader reader;
/* Does the other end support the reporting? */
if (server_supports("report-status"))
@@ -559,6 +558,8 @@ int send_pack(struct send_pack_args *args,
in = demux.out;
}
+ packet_reader_init(&reader, in, NULL, 0, PACKET_READ_CHOMP_NEWLINE);
+
if (need_pack_data && cmds_sent) {
if (pack_objects(out, remote_refs, extra_have, args) < 0) {
for (ref = remote_refs; ref; ref = ref->next)
@@ -573,7 +574,7 @@ int send_pack(struct send_pack_args *args,
* are failing, and just want the error() side effects.
*/
if (status_report)
- receive_unpack_status(in);
+ receive_unpack_status(&reader);
if (use_sideband) {
close(demux.out);
@@ -590,7 +591,7 @@ int send_pack(struct send_pack_args *args,
packet_flush(out);
if (status_report && cmds_sent)
- ret = receive_status(in, remote_refs);
+ ret = receive_status(&reader, remote_refs);
else
ret = 0;
if (args->stateless_rpc)
diff --git a/upload-pack.c b/upload-pack.c
index 5e81f1ff2..1638825ee 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -354,7 +354,8 @@ static int ok_to_give_up(const struct object_array *have_obj,
min_generation);
}
-static int get_common_commits(struct object_array *have_obj,
+static int get_common_commits(struct packet_reader *reader,
+ struct object_array *have_obj,
struct object_array *want_obj)
{
struct object_id oid;
@@ -366,12 +367,11 @@ static int get_common_commits(struct object_array *have_obj,
save_commit_buffer = 0;
for (;;) {
- char *line = packet_read_line(0, NULL);
const char *arg;
reset_timeout();
- if (!line) {
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
if (multi_ack == 2 && got_common
&& !got_other && ok_to_give_up(have_obj, want_obj)) {
sent_ready = 1;
@@ -390,7 +390,7 @@ static int get_common_commits(struct object_array *have_obj,
got_other = 0;
continue;
}
- if (skip_prefix(line, "have ", &arg)) {
+ if (skip_prefix(reader->line, "have ", &arg)) {
switch (got_oid(arg, &oid, have_obj)) {
case -1: /* they have what we do not */
got_other = 1;
@@ -416,7 +416,7 @@ static int get_common_commits(struct object_array *have_obj,
}
continue;
}
- if (!strcmp(line, "done")) {
+ if (!strcmp(reader->line, "done")) {
if (have_obj->nr > 0) {
if (multi_ack)
packet_write_fmt(1, "ACK %s\n", last_hex);
@@ -425,7 +425,7 @@ static int get_common_commits(struct object_array *have_obj,
packet_write_fmt(1, "NAK\n");
return -1;
}
- die("git upload-pack: expected SHA1 list, got '%s'", line);
+ die("git upload-pack: expected SHA1 list, got '%s'", reader->line);
}
}
@@ -826,7 +826,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
return 0;
}
-static void receive_needs(struct object_array *want_obj)
+static void receive_needs(struct packet_reader *reader, struct object_array *want_obj)
{
struct object_array shallows = OBJECT_ARRAY_INIT;
struct string_list deepen_not = STRING_LIST_INIT_DUP;
@@ -840,33 +840,32 @@ static void receive_needs(struct object_array *want_obj)
struct object *o;
const char *features;
struct object_id oid_buf;
- char *line = packet_read_line(0, NULL);
const char *arg;
reset_timeout();
- if (!line)
+ if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break;
- if (process_shallow(line, &shallows))
+ if (process_shallow(reader->line, &shallows))
continue;
- if (process_deepen(line, &depth))
+ if (process_deepen(reader->line, &depth))
continue;
- if (process_deepen_since(line, &deepen_since, &deepen_rev_list))
+ if (process_deepen_since(reader->line, &deepen_since, &deepen_rev_list))
continue;
- if (process_deepen_not(line, &deepen_not, &deepen_rev_list))
+ if (process_deepen_not(reader->line, &deepen_not, &deepen_rev_list))
continue;
- if (skip_prefix(line, "filter ", &arg)) {
+ if (skip_prefix(reader->line, "filter ", &arg)) {
if (!filter_capability_requested)
die("git upload-pack: filtering capability not negotiated");
parse_list_objects_filter(&filter_options, arg);
continue;
}
- if (!skip_prefix(line, "want ", &arg) ||
+ if (!skip_prefix(reader->line, "want ", &arg) ||
parse_oid_hex(arg, &oid_buf, &features))
die("git upload-pack: protocol error, "
- "expected to get object ID, not '%s'", line);
+ "expected to get object ID, not '%s'", reader->line);
if (parse_feature_request(features, "deepen-relative"))
deepen_relative = 1;
@@ -1055,6 +1054,7 @@ void upload_pack(struct upload_pack_options *options)
{
struct string_list symref = STRING_LIST_INIT_DUP;
struct object_array want_obj = OBJECT_ARRAY_INIT;
+ struct packet_reader reader;
stateless_rpc = options->stateless_rpc;
timeout = options->timeout;
@@ -1078,10 +1078,12 @@ void upload_pack(struct upload_pack_options *options)
if (options->advertise_refs)
return;
- receive_needs(&want_obj);
+ packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE);
+
+ receive_needs(&reader, &want_obj);
if (want_obj.nr) {
struct object_array have_obj = OBJECT_ARRAY_INIT;
- get_common_commits(&have_obj, &want_obj);
+ get_common_commits(&reader, &have_obj, &want_obj);
create_pack_file(&have_obj, &want_obj);
}
}
--
2.20.1.415.g653613c723-goog
^ permalink raw reply related
* [PATCH] Specify -Wformat along with -Wformat-security
From: Masaya Suzuki @ 2018-12-27 6:58 UTC (permalink / raw)
To: git; +Cc: Masaya Suzuki
Without -Wformat, -Wformat-security won't work.
> cc1: error: -Wformat-security ignored without -Wformat [-Werror=format-security]
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
---
config.mak.dev | 1 +
1 file changed, 1 insertion(+)
diff --git a/config.mak.dev b/config.mak.dev
index bbeeff44f..aae9db67d 100644
--- a/config.mak.dev
+++ b/config.mak.dev
@@ -7,6 +7,7 @@ CFLAGS += -pedantic
CFLAGS += -DUSE_PARENS_AROUND_GETTEXT_N=0
endif
CFLAGS += -Wdeclaration-after-statement
+CFLAGS += -Wformat
CFLAGS += -Wformat-security
CFLAGS += -Wno-format-zero-length
CFLAGS += -Wold-style-definition
--
2.20.1.415.g653613c723-goog
^ permalink raw reply related
* Re: [PATCH 0/2] Improve documentation on UTF-16
From: Johannes Sixt @ 2018-12-27 10:06 UTC (permalink / raw)
To: brian m. carlson; +Cc: git, Lars Schneider, Torsten Bögershausen
In-Reply-To: <20181227021734.528629-1-sandals@crustytoothpaste.net>
Am 27.12.18 um 03:17 schrieb brian m. carlson:
> We've recently fielded several reports from unhappy Windows users about
> our handling of UTF-16, UTF-16LE, and UTF-16BE, none of which seem to be
> suitable for certain Windows programs.
>
> In an effort to communicate the reasons for our behavior more
> effectively, explain in the documentation that the UTF-16 variant that
> people have been asking for hasn't been standardized, and therefore
> hasn't been implemented in iconv(3). Mention what each of the variants
> do, so that people can make a decision which one meets their needs the
> best.
>
> In addition, add a comment in the code about why we must, for
> correctness reasons, reject a UTF-16LE or UTF-16BE sequence that begins
> with U+FEFF, namely that such a codepoint semantically represents a
> ZWNBSP, not a BOM, but that that codepoint at the beginning of a UTF-8
> sequence (as encoded in the object store) would be misinterpreted as a
> BOM instead.
>
> This comment is in the code because I think it needs to be somewhere,
> but I'm not sure the documentation is the right place for it. If
> desired, I can add it to the documentation, although I feel the lurid
> details are not interesting to most users. If the wording is confusing,
> I'm very open to hearing suggestions for how to improve it.
>
> I don't use Windows, so I don't know what MSVCRT does. If it requires a
> BOM but doesn't accept big-endian encoding, then perhaps we should
> report that as a bug to Microsoft so it can be fixed in a future
> version. That would probably make a lot more programs work right out of
> the box and dramatically improve the user experience.
It worries me that theoretical correctness is regarded higher than
existing practice. I do not care a lot what some RFC tells what programs
should do if the majority of the software does something different and
that behavior has been proven useful in practice.
My understanding is that there is no such thing as a "byte order
marker". It just so happens that when the first character in some UTF-16
text file begins with a ZWNBSP, then it is possible to derive the
endianness of the file automatically. Other then that, that very first
code point U+FEFF *is part of the data* and must not be removed when the
data is reencoded. If Git does something different, it is bogus, IMO.
-- Hannes
^ permalink raw reply
* Re: [PATCH v2 8/8] tests: mark tests broken under GIT_TEST_PROTOCOL_VERSION=2
From: Ævar Arnfjörð Bjarmason @ 2018-12-27 11:26 UTC (permalink / raw)
To: Junio C Hamano
Cc: Jeff King, Jonathan Nieder, git, Brandon Williams, Jonathan Tan
In-Reply-To: <xmqqlg4cq6kd.fsf@gitster-ct.c.googlers.com>
On Wed, Dec 26 2018, Junio C Hamano wrote:
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> The genreal ways I see forward from that are:
>>
>> A) Say that v2 has a security issue and that this is a feature that
>> works in some circumstances, but given Jeff's explanation here we
>> should at least improve our "SECURITY" docs to be less handwaivy.
>>
>> B) Improve security docs, turn uploadpack.allowAnySHA1InWant=true on by
>> default, allow people to turn it off.
>>
>> C) Like B) but deprecate
>> uploadpack.allow{Tip,Reachable,Any}SHA1InWant=false. This is my
>> patch upthread
>>
>> D-Z) ???
>>
>>
>> I'm not set on C), and yeah it's probably overzelous to just rip the
>> thing out, but then what should we do?
>
> Hmph. The other overzealous thing you could do is to strenthen A
> and "fix" the security issue in v2? Which letter comes before A in
> the alphabet? ;-)
Sure, but that being useful is predicated on this supposed security
mechanism being useful and not just security-through-obscurity, as noted
in side-threads I don't think we have a convincing argument either way
(and the one we do have is more on the "it's not secure" side).
Of course we had that with v1 all along, but now that v2 is in released
versions and in this insecure mode, we have a reason to closely look at
whether we need to be issuing security releases, or doubling down on the
"SECURITY" wording in git-fetch and then not carrying the mode forward.
^ permalink raw reply
* Re: [PATCH v1 3/4] git-compat-util.h: add FLOSS headers for HPE NonStop
From: Derrick Stolee @ 2018-12-27 12:10 UTC (permalink / raw)
To: randall.s.becker, git; +Cc: Randall S. Becker
In-Reply-To: <20181226230523.16572-4-randall.s.becker@rogers.com>
On 12/26/2018 6:05 PM, randall.s.becker@rogers.com wrote:
> The NSIG define is also not defined on __TANDEM, so we define it
> here as 100 if it is not defined only for __TANDEM builds.
[snip]
> +#if ! defined NSIG
Why didn't you use "#ifndef" here?
Taking a look at the file, I see both "#ifdef" and "#if defined" but no
"#if ! defined".
Thanks,
-Stolee
^ permalink raw reply
* Re: [PATCH v1 0/4] HPE NonStop Port Commits
From: Derrick Stolee @ 2018-12-27 12:12 UTC (permalink / raw)
To: randall.s.becker, git; +Cc: Randall S. Becker
In-Reply-To: <20181226230523.16572-1-randall.s.becker@rogers.com>
On 12/26/2018 6:05 PM, randall.s.becker@rogers.com wrote:
> From: "Randall S. Becker" <rsbecker@nexbridge.com>
>
> This set of patches is a distilled version of the minimal
> set of changes to git that will allow it to run as client
> and server on HPE NonStop NSE and NSX systems. NSR systems
> are no longer under support so references to them have
> been removed. Each patch in this set is independent but
> required for correctness.
>
> Randall S. Becker (4):
> transport-helper: use xread instead of read
> config.mak.uname: support for modern HPE NonStop config.
> git-compat-util.h: add FLOSS headers for HPE NonStop
> compat/regex/regcomp.c: define intptr_t and uintptr_t on NonStop
These patches look correct to me. Just one question on patch 3
(git-compat-util.h: add FLOSS headers for HPE NonStop).
I'm not able to comment on patch 2 (config.mak.uname: support for modern
HPE NonStop config.), but it looks to be wrapped in a platform-specific
'if', so should be fine if you are happy with it.
Thanks,
-Stolee
^ permalink raw reply
* Re: [PATCH] log: add %S option (like --source) to log --format
From: Derrick Stolee @ 2018-12-27 13:20 UTC (permalink / raw)
To: issac.trotts, git; +Cc: noemi, Issac Trotts
In-Reply-To: <20181219083305.2500-1-issac.trotts@gmail.com>
On 12/19/2018 3:33 AM, issac.trotts@gmail.com wrote:
> From: Issac Trotts <issac.trotts@gmail.com>
>
> Make it possible to write for example
>
> git log --format="%H,%S"
>
> where the %S at the end is a new placeholder that prints out the ref
> (tag/branch) for each commit.
>
> Using %d might seem like an alternative but it only shows the ref for the last
> commit in the branch.
>
> Signed-off-by: Issac Trotts <issactrotts@google.com>
>
> ---
>
> This change is based on a question from Stack Overflow:
> https://stackoverflow.com/questions/12712775/git-get-source-information-in-format
> ---
> Documentation/pretty-formats.txt | 2 ++
> builtin/log.c | 2 +-
> log-tree.c | 1 +
> pretty.c | 15 ++++++++++
> pretty.h | 1 +
> t/t4205-log-pretty-formats.sh | 50 ++++++++++++++++++++++++++++++++
> 6 files changed, 70 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> index 417b638cd..de6953108 100644
> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -134,6 +134,8 @@ The placeholders are:
> - '%cI': committer date, strict ISO 8601 format
> - '%d': ref names, like the --decorate option of linkgit:git-log[1]
> - '%D': ref names without the " (", ")" wrapping.
> +- '%S': ref name given on the command line by which the commit was reached
> + (like `git log --source`), only works with `git log`
This "only works with `git log`" made me think about what would happen
with `git rev-list --pretty=format:"%h %S"` and the answer (on my
machine) was a segfault.
> - '%e': encoding
> - '%s': subject
> - '%f': sanitized subject line, suitable for a filename
> diff --git a/builtin/log.c b/builtin/log.c
> index e8e51068b..be3025657 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
> rev->diffopt.filter || rev->diffopt.flags.follow_renames)
> rev->always_show_header = 0;
>
> - if (source) {
> + if (source || (rev->pretty_given && (rev->commit_format == CMIT_FMT_USERFORMAT) && w.source)) {
> init_revision_sources(&revision_sources);
> rev->sources = &revision_sources;
> }
Likely, you'll want to duplicate this initialization in the revision
machinery. Keep this one in builtin/log.c as it was before, but add
something like this initialization to setup_revisions(). Add a test for
rev-list.
[snip]
> @@ -1194,6 +1195,17 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
> load_ref_decorations(NULL, DECORATE_SHORT_REFS);
> format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
> return 1;
> + case 'S': /* tag/branch like --source */
> + if (c->pretty_ctx->rev->sources == NULL) {
Use "if (!c->pretty_ctx->rev->sources".
> + return 0;
> + }
> + slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
> + if (slot && *slot) {
I'm not sure this check for 'slot' being non-null is necessary, as we
would already get a failure in the commit-slab code (for
revision_sources_at()) if the slab is not initialized.
> + strbuf_addstr(sb, *slot);
> + return 1;
> + } else {
> + die(_("failed to get info for %%S"));
Here, you die() when you fail to get a slot but above you return 0 when
the sources are not initialized.
I don't see another use of die() in this method. Is that the right way
to handle failure here? (I'm legitimately asking because I have
over-used 'die()' in the past and am still unclear on when it is
appropriate.)
> '
>
> +test_expect_success 'set up %S tests' '
> + git checkout --orphan source-a &&
> + test_commit one &&
> + test_commit two &&
> + git checkout -b source-b HEAD^ &&
> + test_commit three
> +'
> +
> +test_expect_success 'log --format=%S paints branch names' '
> + cat >expect <<-\EOF &&
> + source-b
> + source-a
> + source-b
> + EOF
> + git log --format=%S source-a source-b >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'log --format=%S paints tag names' '
> + git tag -m tagged source-tag &&
> + cat >expect <<-\EOF &&
> + source-tag
> + source-a
> + source-tag
> + EOF
> + git log --format=%S source-tag source-a >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'log --format=%S paints symmetric ranges' '
> + cat >expect <<-\EOF &&
> + source-b
> + source-a
> + EOF
> + git log --format=%S source-a...source-b >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success '%S in git log --format works with other placeholders (part 1)' '
> + git log --format="source-b %h" source-b >expect &&
> + git log --format="%S %h" source-b >actual &&
> + test_cmp expect actual
> +'
> +
> +test_expect_success '%S in git log --format works with other placeholders (part 2)' '
> + git log --format="%h source-b" source-b >expect &&
> + git log --format="%h %S" source-b >actual &&
> + test_cmp expect actual
> +'
> +
> test_done
Please also add a simple test to t6006-rev-list-format.sh.
Thanks,
-Stolee
^ permalink raw reply
* Re: [PATCH 00/23] sb/more-repo-in-api
From: Derrick Stolee @ 2018-12-27 14:41 UTC (permalink / raw)
To: Stefan Beller, git
In-Reply-To: <20181215000942.46033-1-sbeller@google.com>
On 12/14/2018 7:09 PM, Stefan Beller wrote:
> I realized next has not been rewound, so I can resend sb/more-repo-in-api,
> which I hereby do. The changes are minimal and address the only comment
> by Jonathan so far.
Sorry I'm very late to look at this, but your series looks good to me.
I've got some work on the way that will use these arbitrary
repositories. (Specifically, moving 'generation' out of 'struct commit'
and into a commit slab to store reachability index values.)
Thanks,
-Stolee
^ permalink raw reply
* Re: git-rebase is ignoring working-tree-encoding
From: Torsten Bögershausen @ 2018-12-27 14:45 UTC (permalink / raw)
To: Alexandre Grigoriev
Cc: 'brian m. carlson', 'Adrián Gimeno Balaguer',
git
In-Reply-To: <005601d49d8f$45c109b0$d1431d10$@gmail.com>
On Wed, Dec 26, 2018 at 06:52:56PM -0800, Alexandre Grigoriev wrote:
>
> > -----Original Message-----
> > From: brian m. carlson [mailto:sandals@crustytoothpaste.net]
> > Sent: Wednesday, December 26, 2018 11:25 AM
> > To: Alexandre Grigoriev
> > Cc: 'Torsten Bögershausen'; 'Adrián Gimeno Balaguer'; git@vger.kernel.org
> > Subject: Re: git-rebase is ignoring working-tree-encoding
> >
> > On Tue, Dec 25, 2018 at 04:56:11PM -0800, Alexandre Grigoriev wrote:
> > > Many tools in Windows still do not understand UTF-8, although it's
> > > getting better. I think Windows is about the only OS where tools still
> > > require
> > > UTF-16 for full internationalization.
> > > Many tools written in C use MSVC RTL, where fopen(), unfortunately,
> > > doesn't understand UTF-16BE (though such a rudimentary program as
> > Notepad does).
> > >
> > > For this reason, it's very reasonable to ask that the programming
> > > tools produce UTF-16 files with particular endianness, natural for the
> > > platform they're running on.
> > >
> > > The iconv programmers' boneheaded decision to always produce UTF-16BE
> > > with BOM for UTF-16 output doesn't make sense.
> > > Again, git and iconv/libiconv in Centos on x86 do the right thing and
> > > produce UTF-16LE with BOM in this case.
> >
> > A program which claims to support "UTF-16" must support both
> > endiannesses, according to RFC 2781. A program writing UTF-16-LE must not
> > write a BOM at the beginning. I realize this is inconvenient, but the bad
> > behavior of some Windows programs doesn't mean that Git should ignore
> > interoperability with non-Windows systems using UTF-16 correctly in favor of
> > Windows.
>
> OK, we have a choice either:
> a) to live in that corner of the real world where you have to use available tools, some of which have historical reasons
> to only support UTF-16LE with BOM, because nobody ever throws a different flavor of UTF-16 at them;
> Or b) to live in an ivory tower where you don't really need to use UTF-16 LE or BE or any other flavor,
> because everything is just UTF-8, and tell all those other people using that lame OS to shut up and wait until their tools start to support
> the formats you don't really have to care about;
>
> > behavior of some Windows programs doesn't mean that Git should ignore
> > interoperability with non-Windows systems using UTF-16 correctly in favor of
> > Windows.
>
> Yes, Git (actually libiconv) should not ignore interoperability.
> This means it should check out files on a *Windows* system in a format which *Windows* tools
> can understand.
> And, by the way, Centos (or RedHat?) developers understood that.
> There, on an x86 installation, when you ask for UTF-16, it produces UTF-16LE with BOM.
> Just as every user there would want.
>
>
Sorry if I feel confused here - does the problem still exist ?
If yes, does the following patch help ?
diff --git a/utf8.c b/utf8.c
index eb78587504..2facef84d4 100644
--- a/utf8.c
+++ b/utf8.c
@@ -9,6 +9,23 @@ struct interval {
ucs_char_t last;
};
+static int has_bom_prefix(const char *data, size_t len,
+ const char *bom, size_t bom_len)
+{
+ return data && bom && (len >= bom_len) && !memcmp(data, bom, bom_len);
+}
+
+static const char utf16_be_bom[] = {'\xFE', '\xFF'};
+static const char utf16_le_bom[] = {'\xFF', '\xFE'};
+static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
+static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
+
+static inline uint16_t default_swab16(uint16_t val)
+{
+ return (((val & 0xff00) >> 8) |
+ ((val & 0x00ff) << 8));
+}
+
size_t display_mode_esc_sequence_len(const char *s)
{
const char *p = s;
@@ -556,21 +573,19 @@ char *reencode_string_len(const char *in, size_t insz,
out = reencode_string_iconv(in, insz, conv, outsz);
iconv_close(conv);
+ if (has_bom_prefix(out, *outsz, utf16_be_bom, sizeof(utf16_be_bom))) {
+ /* UTF-16 should be little endian under Git */
+ size_t num_points = *outsz / sizeof(uint16_t);
+ uint16_t *point = (uint16_t*) out;
+ while (num_points--) {
+ *point = default_swab16(*point);
+ point++;
+ }
+ }
return out;
}
#endif
-static int has_bom_prefix(const char *data, size_t len,
- const char *bom, size_t bom_len)
-{
- return data && bom && (len >= bom_len) && !memcmp(data, bom, bom_len);
-}
-
-static const char utf16_be_bom[] = {'\xFE', '\xFF'};
-static const char utf16_le_bom[] = {'\xFF', '\xFE'};
-static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
-static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
-
int has_prohibited_utf_bom(const char *enc, const char *data, size_t len)
{
return (
^ permalink raw reply related
* RE: [PATCH v1 3/4] git-compat-util.h: add FLOSS headers for HPE NonStop
From: Randall S. Becker @ 2018-12-27 15:55 UTC (permalink / raw)
To: 'Derrick Stolee', randall.s.becker, git
In-Reply-To: <5712b2bf-8a90-42d7-9159-261dd990eb66@gmail.com>
On December 27, 2018 7:10, Derrick Stolee wrote:
> On 12/26/2018 6:05 PM, randall.s.becker@rogers.com wrote:
> > The NSIG define is also not defined on __TANDEM, so we define it here
> > as 100 if it is not defined only for __TANDEM builds.
> [snip]
> > +#if ! defined NSIG
>
> Why didn't you use "#ifndef" here?
>
> Taking a look at the file, I see both "#ifdef" and "#if defined" but no "#if !
> defined".
I'm good with revising as follows and removing the irrelevant lines (stay tuned):
+#ifdef __TANDEM
+#include <floss.h(floss_execl,floss_execlp,floss_execv,floss_execvp)>
+#include <floss.h(floss_getpwuid)>
+#ifndef NSIG
+/* NonStop NSE and NSX do not provide NSIG. SIGGUARDIAN(99) is the highest
+ known, by detective work using kill -l as a list is all signals
+ instead of signal.h where it should be. */
+# define NSIG 100
+#endif
+#endif
+
Cheers,
Randall
^ permalink raw reply
* [PATCH 0/6] Add "git config --move-to"
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
This is a continuation of nd/per-worktree-config, fixing is small
things from that series and prepares to make submodules work in
multiple worktrees.
The first thing is adding API for updating per-worktree config in
03/06. When submodule code wants to write to a per-worktree config,
calling this function takes care of both single and multi worktree
setups, similar to "git config --worktree <name> <value>"
The second thing is "git config --move-to" and friends. This helps
the config transition right after enabling extensions.worktreeConfig,
when the user has to make sure per-worktree config stays in
per-worktree file.
Manual moving config from one file to another is possible with a
couple keys like core.worktree, but once you have to move multiple
groups (i.e. "submodule.*.*" keys) then it becomes a lot less fun and
more pain. This simplifies that work (and also migration
documentation)
Note that I added --move-glob-to because I think glob fits much better
than regex for matching keys because of the dots in config keys. I
added --move-regex-to anyway because we have --get-regexp. Maybe I
should add --get-glob too (but probably not now).
There is also a NEEDSWORK in 03/06. But I hope it could be addressed
after this series is merged (so that I could continue pushing
submodule changes out)
Nguyễn Thái Ngọc Duy (6):
config.c: avoid git_path() in do_git_config_sequence()
worktree.c: add get_worktree_config()
config.c: add repo_config_set_worktree_gently()
config: use OPT_FILENAME()
config: factor out set_config_source_file()
config: add --move-to
Documentation/git-config.txt | 12 ++
Documentation/git-worktree.txt | 16 ++-
builtin/config.c | 244 ++++++++++++++++++++++++---------
config.c | 55 +++++++-
config.h | 3 +
t/t1300-config.sh | 54 ++++++++
worktree.c | 16 +++
worktree.h | 7 +
8 files changed, 330 insertions(+), 77 deletions(-)
--
2.20.0.482.g66447595a7
^ permalink raw reply
* [PATCH 1/6] config.c: avoid git_path() in do_git_config_sequence()
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>
This function has both $GIT_COMMON_DIR and $GIT_DIR in "opts". Use it
to construct config.worktree path instead because git_pathdup() is
tied to the current worktree, but the given $GIT_DIR could be from
another one.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
config.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/config.c b/config.c
index ff521eb27a..79fbe65da8 100644
--- a/config.c
+++ b/config.c
@@ -1665,6 +1665,7 @@ static int do_git_config_sequence(const struct config_options *opts,
char *xdg_config = xdg_config_home("config");
char *user_config = expand_user_path("~/.gitconfig", 0);
char *repo_config;
+ char *worktree_config;
if (opts->commondir)
repo_config = mkpathdup("%s/config", opts->commondir);
@@ -1672,6 +1673,10 @@ static int do_git_config_sequence(const struct config_options *opts,
BUG("git_dir without commondir");
else
repo_config = NULL;
+ if (repository_format_worktree_config)
+ worktree_config = mkpathdup("%s/config.worktree", opts->git_dir);
+ else
+ worktree_config = NULL;
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
@@ -1693,12 +1698,8 @@ static int do_git_config_sequence(const struct config_options *opts,
* Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
* But let's not complicate things before it's actually needed.
*/
- if (repository_format_worktree_config) {
- char *path = git_pathdup("config.worktree");
- if (!access_or_die(path, R_OK, 0))
- ret += git_config_from_file(fn, path, data);
- free(path);
- }
+ if (worktree_config && !access_or_die(worktree_config, R_OK, 0))
+ ret += git_config_from_file(fn, worktree_config, data);
current_parsing_scope = CONFIG_SCOPE_CMDLINE;
if (git_config_from_parameters(fn, data) < 0)
@@ -1708,6 +1709,7 @@ static int do_git_config_sequence(const struct config_options *opts,
free(xdg_config);
free(user_config);
free(repo_config);
+ free(worktree_config);
return ret;
}
--
2.20.0.482.g66447595a7
^ permalink raw reply related
* [PATCH 2/6] worktree.c: add get_worktree_config()
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>
"git config --worktree" can write to the write file whether
extensions.worktreeConfig is enabled or not. In order to do the same
using config API, we need to determine the right file to write to. Add
this function for that purpose. This is the basis for the coming
repo_config_set_worktree()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/config.c | 9 ++-------
worktree.c | 16 ++++++++++++++++
worktree.h | 7 +++++++
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 84385ef165..771cfa54bd 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -650,18 +650,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (use_local_config)
given_config_source.file = git_pathdup("config");
else if (use_worktree_config) {
- struct worktree **worktrees = get_worktrees(0);
- if (repository_format_worktree_config)
- given_config_source.file = git_pathdup("config.worktree");
- else if (worktrees[0] && worktrees[1])
+ given_config_source.file = get_worktree_config(the_repository);
+ if (!given_config_source.file)
die(_("--worktree cannot be used with multiple "
"working trees unless the config\n"
"extension worktreeConfig is enabled. "
"Please read \"CONFIGURATION FILE\"\n"
"section in \"git help worktree\" for details"));
- else
- given_config_source.file = git_pathdup("config");
- free_worktrees(worktrees);
} else if (given_config_source.file) {
if (!is_absolute_path(given_config_source.file) && prefix)
given_config_source.file =
diff --git a/worktree.c b/worktree.c
index d6a0ee7f73..d335bdf28a 100644
--- a/worktree.c
+++ b/worktree.c
@@ -581,3 +581,19 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
free_worktrees(worktrees);
return ret;
}
+
+char *get_worktree_config(struct repository *r)
+{
+ struct worktree **worktrees = get_worktrees(0);
+ char *path;
+
+ if (repository_format_worktree_config)
+ path = repo_git_path(r, "config.worktree");
+ else if (worktrees[0] && worktrees[1])
+ path = NULL;
+ else
+ path = repo_git_path(r, "config");
+
+ free_worktrees(worktrees);
+ return path;
+}
diff --git a/worktree.h b/worktree.h
index 9e3b0b7b6f..4c41002d31 100644
--- a/worktree.h
+++ b/worktree.h
@@ -132,4 +132,11 @@ void strbuf_worktree_ref(const struct worktree *wt,
const char *worktree_ref(const struct worktree *wt,
const char *refname);
+/*
+ * Return the path to config file that can contain worktree-specific
+ * config (or NULL in unsupported setups). The caller must free the
+ * return value.
+ */
+char *get_worktree_config(struct repository *r);
+
#endif
--
2.20.0.482.g66447595a7
^ permalink raw reply related
* [PATCH 3/6] config.c: add repo_config_set_worktree_gently()
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>
This is C equivalent of "git config --set --worktree". In other words,
it will
- write to $GIT_DIR/config in single-worktree setup
- write to $GIT_COMMON_DIR/worktrees/<x>/config.worktree or
$GIT_COMMON_DIR/config.worktree (for main worktree)
if extensions.worktreeConfig is enabled
- return error in multiple-worktree setup if extensions.worktreeConfig
is not enabled.
While at there, also add repo_config_set*() for writing to
$GIT_COMMON_DIR/config.
Note, since git_config_set_multivar_in_file_gently() only invalidates
the config set of the_repository, anybody who uses these functions on
submodules must do additional invalidation if needed.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
config.c | 41 ++++++++++++++++++++++++++++++++++++++++-
config.h | 3 +++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/config.c b/config.c
index 79fbe65da8..151d28664e 100644
--- a/config.c
+++ b/config.c
@@ -19,6 +19,7 @@
#include "utf8.h"
#include "dir.h"
#include "color.h"
+#include "worktree.h"
struct config_source {
struct config_source *prev;
@@ -2137,6 +2138,39 @@ int repo_config_get_pathname(struct repository *repo,
return ret;
}
+int repo_config_set_gently(struct repository *r,
+ const char *key, const char *value)
+{
+ char *path = repo_git_path(r, "config");
+ int ret = git_config_set_multivar_in_file_gently(path, key, value, NULL, 0);
+ free(path);
+ return ret;
+}
+
+void repo_config_set(struct repository *r, const char *key, const char *value)
+{
+ if (!repo_config_set_gently(r, key, value))
+ return;
+ if (value)
+ die(_("could not set '%s' to '%s'"), key, value);
+ else
+ die(_("could not unset '%s'"), key);
+}
+
+int repo_config_set_worktree_gently(struct repository *r,
+ const char *key, const char *value)
+{
+ char *path;
+ int ret;
+
+ path = get_worktree_config(r);
+ if (!path)
+ return CONFIG_INVALID_FILE;
+ ret = git_config_set_multivar_in_file_gently(path, key, value, NULL, 0);
+ free(path);
+ return ret;
+}
+
/* Functions used historically to read configuration from 'the_repository' */
void git_config(config_fn_t fn, void *data)
{
@@ -2912,7 +2946,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
ret = 0;
- /* Invalidate the config cache */
+ /*
+ * Invalidate the config cache
+ *
+ * NEEDSWORK: invalidate _all_ existing config caches, not
+ * just one from the_repository
+ */
git_config_clear();
out_free:
diff --git a/config.h b/config.h
index ee5d3fa7b4..62204dc252 100644
--- a/config.h
+++ b/config.h
@@ -103,6 +103,9 @@ extern int git_config_color(char *, const char *, const char *);
extern int git_config_set_in_file_gently(const char *, const char *, const char *);
extern void git_config_set_in_file(const char *, const char *, const char *);
extern int git_config_set_gently(const char *, const char *);
+extern int repo_config_set_gently(struct repository *, const char *, const char *);
+extern void repo_config_set(struct repository *, const char *, const char *);
+extern int repo_config_set_worktree_gently(struct repository *, const char *, const char *);
extern void git_config_set(const char *, const char *);
extern int git_config_parse_key(const char *, char **, int *);
extern int git_config_key_is_valid(const char *key);
--
2.20.0.482.g66447595a7
^ permalink raw reply related
* [PATCH 4/6] config: use OPT_FILENAME()
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>
Do not handle prefix directly. It's simpler to use OPT_FILENAME()
instead. The othe reason for doing this is because this code (where
the deleted code is) will be factored out and called when "prefix" is
not available.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/config.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 771cfa54bd..c22d25de12 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -126,7 +126,7 @@ static struct option builtin_config_options[] = {
OPT_BOOL(0, "system", &use_system_config, N_("use system config file")),
OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")),
OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")),
- OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
+ OPT_FILENAME('f', "file", &given_config_source.file, N_("use given config file")),
OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
OPT_GROUP(N_("Action")),
OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
@@ -657,10 +657,6 @@ int cmd_config(int argc, const char **argv, const char *prefix)
"extension worktreeConfig is enabled. "
"Please read \"CONFIGURATION FILE\"\n"
"section in \"git help worktree\" for details"));
- } else if (given_config_source.file) {
- if (!is_absolute_path(given_config_source.file) && prefix)
- given_config_source.file =
- prefix_filename(prefix, given_config_source.file);
}
if (respect_includes_opt == -1)
--
2.20.0.482.g66447595a7
^ permalink raw reply related
* [PATCH 5/6] config: factor out set_config_source_file()
From: Nguyễn Thái Ngọc Duy @ 2018-12-27 15:56 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>
In the next patch, "config" is taught to move some config variables
from one file to another. We need to specify two locations, source and
destination, and the plan is reusing the same --global/--local/...
option. Factor this code out for reuse later.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/config.c | 113 +++++++++++++++++++++++++----------------------
1 file changed, 59 insertions(+), 54 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index c22d25de12..61a6a5a0e1 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -71,6 +71,64 @@ static int show_origin;
static NORETURN void usage_builtin_config(void);
+static void set_config_source_file(void)
+{
+ int nongit = !startup_info->have_repository;
+
+ if (use_global_config + use_system_config + use_local_config +
+ use_worktree_config +
+ !!given_config_source.file + !!given_config_source.blob > 1)
+ die(_("only one config file at a time"));
+
+ if (use_local_config && nongit)
+ die(_("--local can only be used inside a git repository"));
+
+ if (given_config_source.blob && nongit)
+ die(_("--blob can only be used inside a git repository"));
+
+ if (given_config_source.file &&
+ !strcmp(given_config_source.file, "-")) {
+ given_config_source.file = NULL;
+ given_config_source.use_stdin = 1;
+ }
+
+ if (use_global_config) {
+ char *user_config = expand_user_path("~/.gitconfig", 0);
+ char *xdg_config = xdg_config_home("config");
+
+ if (!user_config)
+ /*
+ * It is unknown if HOME/.gitconfig exists, so
+ * we do not know if we should write to XDG
+ * location; error out even if XDG_CONFIG_HOME
+ * is set and points at a sane location.
+ */
+ die(_("$HOME not set"));
+
+ if (access_or_warn(user_config, R_OK, 0) &&
+ xdg_config && !access_or_warn(xdg_config, R_OK, 0)) {
+ given_config_source.file = xdg_config;
+ free(user_config);
+ } else {
+ given_config_source.file = user_config;
+ free(xdg_config);
+ }
+ }
+ else if (use_system_config)
+ given_config_source.file = git_etc_gitconfig();
+ else if (use_local_config)
+ given_config_source.file = git_pathdup("config");
+ else if (use_worktree_config) {
+ given_config_source.file = get_worktree_config(the_repository);
+ if (!given_config_source.file)
+ die(_("--worktree cannot be used with multiple "
+ "working trees unless the config\n"
+ "extension worktreeConfig is enabled. "
+ "Please read \"CONFIGURATION FILE\"\n"
+ "section in \"git help worktree\" for details"));
+ }
+}
+
static int option_parse_type(const struct option *opt, const char *arg,
int unset)
{
@@ -604,60 +662,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
builtin_config_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (use_global_config + use_system_config + use_local_config +
- use_worktree_config +
- !!given_config_source.file + !!given_config_source.blob > 1) {
- error(_("only one config file at a time"));
- usage_builtin_config();
- }
-
- if (use_local_config && nongit)
- die(_("--local can only be used inside a git repository"));
-
- if (given_config_source.blob && nongit)
- die(_("--blob can only be used inside a git repository"));
-
- if (given_config_source.file &&
- !strcmp(given_config_source.file, "-")) {
- given_config_source.file = NULL;
- given_config_source.use_stdin = 1;
- }
-
- if (use_global_config) {
- char *user_config = expand_user_path("~/.gitconfig", 0);
- char *xdg_config = xdg_config_home("config");
-
- if (!user_config)
- /*
- * It is unknown if HOME/.gitconfig exists, so
- * we do not know if we should write to XDG
- * location; error out even if XDG_CONFIG_HOME
- * is set and points at a sane location.
- */
- die(_("$HOME not set"));
-
- if (access_or_warn(user_config, R_OK, 0) &&
- xdg_config && !access_or_warn(xdg_config, R_OK, 0)) {
- given_config_source.file = xdg_config;
- free(user_config);
- } else {
- given_config_source.file = user_config;
- free(xdg_config);
- }
- }
- else if (use_system_config)
- given_config_source.file = git_etc_gitconfig();
- else if (use_local_config)
- given_config_source.file = git_pathdup("config");
- else if (use_worktree_config) {
- given_config_source.file = get_worktree_config(the_repository);
- if (!given_config_source.file)
- die(_("--worktree cannot be used with multiple "
- "working trees unless the config\n"
- "extension worktreeConfig is enabled. "
- "Please read \"CONFIGURATION FILE\"\n"
- "section in \"git help worktree\" for details"));
- }
+ set_config_source_file();
if (respect_includes_opt == -1)
config_options.respect_includes = !given_config_source.file;
--
2.20.0.482.g66447595a7
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox