Consider the integral
$$ \int_0^{2\pi} \frac{d\theta}{w+\cos\theta} = \frac{2\pi}{\sqrt{w^2-1}},\quad w\ \in\mathbb{C}-[-1,1], $$
where the right-hand side of the identity corresponds to the branch of $\sqrt{w^2-1}$ that is positive on the real interval $(1,+\infty)$.
I have some questions.
If I write $\sqrt{w^2-1}=\sqrt{w-1}\sqrt{w+1}$, and for the first term I choose the branch $(-\infty,0]$, and for the second the branch $[0,+\infty)$, then $w\in \mathbb{C}-[-1,1]$, is this right?
I don't understand the statement "where the right-hand side of the identity corresponds to the branch of $\sqrt{w^2-1}$ that is positive on the real interval $(1,+\infty)$". I am confused because I have already chosen branches for each $\sqrt{w\pm1}$.
If $w$ is a real variable, then the integral is the same. Is this because of analytic continuation?
In order to avoid poles along the integration path we need that $w$ does not belong to the range of $\cos\theta$, hence $w\not\in[-1,1]$. In such a case, by exploiting symmetry $$I(w)=\int_{0}^{2\pi}\frac{d\theta}{w+\cos\theta} = \int_{0}^{\pi}\frac{2w\,d\theta}{w^2-\cos^2\theta}=4\int_{0}^{\pi/2}\frac{w\,d\theta}{w^2-\cos^2\theta} $$ and by the substitution $\theta=\arctan t$ we get $$ I(w) = 4w\int_{0}^{+\infty}\frac{dt}{(1+t^2)w^2-1}=2w\int_{-\infty}^{+\infty}\frac{dt}{(w^2-1)+t^2 w^2} $$ so $I(w) = 2\int_{-\infty}^{+\infty}\frac{dt}{(w^2-1)+t^2}$. By the residue theorem it follows that $$ I(w) = \frac{2\pi}{\sqrt{w^2-1}} $$ where $\sqrt{w^2-1}$ is the standard (real and positive) determination over $(1,+\infty)$.
You are not allowed to pick some determinations for $\sqrt{w-1}$ and $\sqrt{w+1}$ then wonder if they fit your needs: both the constraints on $w$ and the meaning of $\sqrt{w^2-1}$ in the final formula are fixed by the problem itself. For instance $w\in(1,+\infty)$ implies $I(w)=\frac{2\pi}{\sqrt{w^2-1}}$ and $w\in(-\infty,-1)$ implies $I(w)=-\frac{2\pi}{\sqrt{w^2-1}}$. If $w=i$, then $I(w)=-\pi i\sqrt{2}$.