contrib/chg/Makefile
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 45551 4c8d9b53b1c7
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     1
TARGET = chg
30693
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30513
diff changeset
     2
SRCS = chg.c hgclient.c procutil.c util.c
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     3
OBJS = $(SRCS:.c=.o)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     4
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     5
CFLAGS ?= -O2 -Wall -Wextra -pedantic -g
33629
5544af862286 chg: define _GNU_SOURCE to allow CentOS 5 compilation
Mathias De Maré <mathias.de_mare@nokia.com>
parents: 30738
diff changeset
     6
CPPFLAGS ?= -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     7
override CFLAGS += -std=gnu99
28605
baa073200ba2 chg: allows default hg path to be overridden
Jun Wu <quark@fb.com>
parents: 28327
diff changeset
     8
ifdef HGPATH
baa073200ba2 chg: allows default hg path to be overridden
Jun Wu <quark@fb.com>
parents: 28327
diff changeset
     9
override CPPFLAGS += -DHGPATH=\"$(HGPATH)\"
baa073200ba2 chg: allows default hg path to be overridden
Jun Wu <quark@fb.com>
parents: 28327
diff changeset
    10
endif
45551
4c8d9b53b1c7 chg: make is possible to call by default an hg binary located next to chg
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 34655
diff changeset
    11
ifdef HGPATHREL
4c8d9b53b1c7 chg: make is possible to call by default an hg binary located next to chg
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 34655
diff changeset
    12
override CPPFLAGS += -DHGPATHREL=\"$(HGPATHREL)\"
4c8d9b53b1c7 chg: make is possible to call by default an hg binary located next to chg
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 34655
diff changeset
    13
endif
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    14
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    15
DESTDIR =
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    16
PREFIX = /usr/local
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    17
MANDIR = $(PREFIX)/share/man/man1
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    18
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    19
.PHONY: all
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    20
all: $(TARGET)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    21
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    22
$(TARGET): $(OBJS)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    23
	$(CC) $(LDFLAGS) -o $@ $(OBJS)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    24
30693
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30513
diff changeset
    25
chg.o: hgclient.h procutil.h util.h
30738
a45c0f42271f chg: handle pager request client-side
Jun Wu <quark@fb.com>
parents: 30693
diff changeset
    26
hgclient.o: hgclient.h procutil.h util.h
30693
baee0f47b533 chg: add procutil.h
Jun Wu <quark@fb.com>
parents: 30513
diff changeset
    27
procutil.o: procutil.h util.h
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    28
util.o: util.h
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    29
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    30
.PHONY: install
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    31
install: $(TARGET)
34624
884855ce5e63 build: chg build was failing when the base directory contained spaces
muxator <a.mux@inwind.it>
parents: 33629
diff changeset
    32
	install -d "$(DESTDIR)$(PREFIX)"/bin
884855ce5e63 build: chg build was failing when the base directory contained spaces
muxator <a.mux@inwind.it>
parents: 33629
diff changeset
    33
	install -m 755 "$(TARGET)" "$(DESTDIR)$(PREFIX)"/bin
884855ce5e63 build: chg build was failing when the base directory contained spaces
muxator <a.mux@inwind.it>
parents: 33629
diff changeset
    34
	install -d "$(DESTDIR)$(MANDIR)"
884855ce5e63 build: chg build was failing when the base directory contained spaces
muxator <a.mux@inwind.it>
parents: 33629
diff changeset
    35
	install -m 644 chg.1 "$(DESTDIR)$(MANDIR)"
28060
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    36
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    37
.PHONY: clean
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    38
clean:
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    39
	$(RM) $(OBJS)
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    40
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    41
.PHONY: distclean
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    42
distclean:
726f8d6cc324 chg: import frontend sources
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    43
	$(RM) $(OBJS) $(TARGET)