##// END OF EJS Templates
tests: add more tests of copy tracing with removed and re-added files...
tests: add more tests of copy tracing with removed and re-added files We had a test where the destination of a copy was removed and then added back. This patch adds similar cases where the break in history instead happens to the source file. There are three versions of this: 1. The break happens before the rename. 2. The break happens on a branch parallel to the rename (where copy tracing is done via the merge base) 3. The source is added on each side of the merge base. The break in history is thus in the form of a deletion when going backwards to the merge base and the re-add happens on the other branch. I've also added calls to `hg graft` in these cases to show the breakage in issue 6163. Another factor in these cases is matching nodeid (checked in copies._tracefile()). I've made two copies each of the cases to show the impact of that. One of these is the same as a test in test-rename-merge1.t, so I also deleted that test from there. Some of these tests currently fail, where "fail" is based on my current thinking of how things should work. I had initially thought that we should be more strict about not tracing copies across commits where the file did not exist, but issue 6163 made me reconsider. The only test case here that behaved differently in 4.9 is the exact case reported in issue 6163. Differential Revision: https://phab.mercurial-scm.org/D6599

File last commit:

r41367:763b45bc default
r42793:ab416b5d default
Show More
sighandlers.c
175 lines | 3.7 KiB | text/x-c | CLexer
/*
* Signal handlers for cHg
*
* Copyright 2011, 2018 Yuya Nishihara <yuya@tcha.org>
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2 or any later version.
*/
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
static pid_t peerpgid = 0;
static pid_t peerpid = 0;
static void forwardsignal(int sig)
{
assert(peerpid > 0);
(void)kill(peerpid, sig);
}
static void forwardsignaltogroup(int sig)
{
/* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */
pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid;
(void)kill(killpid, sig);
}
static void handlestopsignal(int sig)
{
sigset_t unblockset, oldset;
struct sigaction sa, oldsa;
if (sigemptyset(&unblockset) < 0) {
return;
}
if (sigaddset(&unblockset, sig) < 0) {
return;
}
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0) {
return;
}
forwardsignal(sig);
if (raise(sig) < 0) { /* resend to self */
return;
}
if (sigaction(sig, &sa, &oldsa) < 0) {
return;
}
if (sigprocmask(SIG_UNBLOCK, &unblockset, &oldset) < 0) {
return;
}
/* resent signal will be handled before sigprocmask() returns */
if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) {
return;
}
if (sigaction(sig, &oldsa, NULL) < 0) {
return;
}
}
/*
* Installs signal handlers.
*
* Returns 0 on success, -1 on error and errno is set appropriately.
* Installed handlers wouldn't be cleaned up on error.
*/
int setupsignalhandler(pid_t pid, pid_t pgid)
{
if (pid <= 0) {
errno = EINVAL;
return -1;
}
peerpid = pid;
peerpgid = (pgid <= 1 ? 0 : pgid);
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
/* deadly signals meant to be sent to a process group:
* - SIGHUP: usually generated by the kernel, when termination of a
* process causes that process group to become orphaned
* - SIGINT: usually generated by the terminal */
sa.sa_handler = forwardsignaltogroup;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0) {
return -1;
}
if (sigaction(SIGHUP, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGINT, &sa, NULL) < 0) {
return -1;
}
/* terminate frontend by double SIGTERM in case of server freeze */
sa.sa_handler = forwardsignal;
sa.sa_flags |= SA_RESETHAND;
if (sigaction(SIGTERM, &sa, NULL) < 0) {
return -1;
}
/* notify the worker about window resize events */
sa.sa_flags = SA_RESTART;
if (sigaction(SIGWINCH, &sa, NULL) < 0) {
return -1;
}
/* forward user-defined signals */
if (sigaction(SIGUSR1, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGUSR2, &sa, NULL) < 0) {
return -1;
}
/* propagate job control requests to worker */
sa.sa_handler = forwardsignal;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCONT, &sa, NULL) < 0) {
return -1;
}
sa.sa_handler = handlestopsignal;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGTSTP, &sa, NULL) < 0) {
return -1;
}
return 0;
}
/*
* Restores signal handlers to the default, and masks SIGINT.
*
* Returns 0 on success, -1 on error and errno is set appropriately.
*/
int restoresignalhandler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0) {
return -1;
}
if (sigaction(SIGHUP, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGTERM, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGWINCH, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGCONT, &sa, NULL) < 0) {
return -1;
}
if (sigaction(SIGTSTP, &sa, NULL) < 0) {
return -1;
}
/* ignore Ctrl+C while shutting down to make pager exits cleanly */
sa.sa_handler = SIG_IGN;
if (sigaction(SIGINT, &sa, NULL) < 0) {
return -1;
}
peerpid = 0;
return 0;
}