Most important of all: unlike 土生上海人 (native Shanghainese), any permanent resident of Shanghai is considered 上海人
A person is considered 本地人 if he was born and/or raised in that place and is a long time permanent resident.
A person is considered 外地人 if he was not born or raised in that place and is not a permanent resident.
If a person was born and/or raise in that place, lived elsewhere for a long time then come back to take up permanent residency, he is still considered 本地人 (local) or 土生 (native)
If a person was born and/or raised in that place, lived elsewhere for a long time then come back for a visit, he is neither 本地人 nor 外地人. He is a 回鄉客
If a person was born and raised elsewhere, but is a long time permanent resident, he is certainly not a 外地人. Depend on how much he adapted to the local culture, he can be considered 本地人 (local) or 老移民 (long time immigrant)
Suppose that a Shanghainese husband and Hangzhounese wife gave birth to their child at a hospital in Chengdu, but raised the child in Shanghai (from age 0 to 18).
In this case, is the child still considered 上海人 or 外地人 in Shanghai?
Since he is a permanent resident, he is considered 上海人 in Shanghai.
Since he was raised in Shanghai, he is also considered a 本地人 (local)