Let me know if you care about this! 
Hi everran,
musical "borrowing" is very interesting. And what it makes even more interesting in my opinion, is the fact, that in former times nobody seems to have cared about if a composer "borrowed" themes or whole parts from others' works.
The "problematic" aspect is the following: Century after century passes. Year after year. And the more years pass, the smaller gets the chance for people to invent really NEW melodies..
Secondly: People - and in final instance: even we ourselves - may forget about the REAL origins of musical works. And then call a composer a "genius", (who, in fact, only took e.g. a folksong or a children's song he heard (which already existed before), and then, he eventually built it in a rondo of a piano-concerto, et - voila ! - a genius is born!

(But it can go the "other way round", too, or, at least,
may have gone: A real genius invented a super melody, which then entered the area of folklore and folksongs.)
But, as I said, I'm of the opinion that nobody (in former times) worried about borrowing.
Let's have a look at some works I came across some time ago in discussions:
https://petrucci.mus.auth.gr/imglnks/usimg/9/9e/IMSLP32168-PMLP73184-Quidant_etudgal.pdfhttps://petrucci.mus.auth.gr/imglnks/usimg/4/4c/IMSLP07735-Gottschalk_Tournament_Galop.pdfHere clearly Gottschalk has borrowed, since Quidant's version was composed earlier (at least that's what my sources say: Offergeld-Catalogue and some quotations of concert reviews.)
But was Quidant really the "first"? Nobody seems to know.
____
https://conquest.imslp.info/files/imglnks/usimg/9/98/IMSLP07708-Gottschalk_La_Gallina.pdfhttps://petrucci.mus.auth.gr/imglnks/usimg/d/d9/IMSLP05446-Joplin_-_Peacherine_Rag.pdfHere, the connections are (I promise) very very difficult to discuss, may be we should leave that for later.
(They would, e.g., have to do with Joplin's piano teacher, and with the question, if he could maybe have introduced Joplin to Gottschalk's works or if Joplin could have heard the works on the streets (which some people would estimate as VERY possible. As do I, concerning both of these ideas.)
____
https://javanese.imslp.info/files/imglnks/usimg/1/1b/IMSLP12042-Badarzewska_The_Maidens_Prayer.pdf
https://petrucci.mus.auth.gr/imglnks/usimg/c/c5/IMSLP29547-PMLP66308-Gottschalk_-_Ne_m_oubliez_pas__piano_.pdfHere, we know that "Forget Me Not" is Gottschalk's last composition, so Badarzewska was first. But may be the similarities aren't so clear like those in the galops mentioned above.
But I don't want do go too deep into detail here: I'll conclude with a quotation I once read in a German magazine: I translate:
"There's no melody today, no motif, no musical idea which isn't already existing somewhere."Maybe, this is so.

Cordially, 8_octaves!