git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* Is there a way to have a local version of a header file?
@ 2017-03-18 14:29 David Lang
  2017-03-18 14:48 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 11+ messages in thread
From: David Lang @ 2017-03-18 14:29 UTC (permalink / raw)
  To: git

for an embedded project built inside the Arduino IDE, (alternate firmware for a 
home automation project) there is a need to set a number of parameters that we 
really don't want in the main repo (wifi network IDs/passwords)

right now, we have these things set as #defines in a header file.

We need to distribute a base version of this file for new people to get started.

Is there any way to have git define a file in such a way that if it doesn't 
exist in the worktree it gets populated, but if it does exist it doesn't get 
overwritten? (as I type this, I'm thinking a trigger may work, but we need it to 
work on Linux, Windows and OSX)

Any thoughts on a sane way to handle this situation?

David Lang

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 14:29 Is there a way to have a local version of a header file? David Lang
@ 2017-03-18 14:48 ` Ævar Arnfjörð Bjarmason
  2017-03-18 14:58   ` David Lang
  0 siblings, 1 reply; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-03-18 14:48 UTC (permalink / raw)
  To: David Lang; +Cc: Git Mailing List

On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:
> for an embedded project built inside the Arduino IDE, (alternate firmware
> for a home automation project) there is a need to set a number of parameters
> that we really don't want in the main repo (wifi network IDs/passwords)
>
> right now, we have these things set as #defines in a header file.
>
> We need to distribute a base version of this file for new people to get
> started.
>
> Is there any way to have git define a file in such a way that if it doesn't
> exist in the worktree it gets populated, but if it does exist it doesn't get
> overwritten? (as I type this, I'm thinking a trigger may work, but we need
> it to work on Linux, Windows and OSX)
>
> Any thoughts on a sane way to handle this situation?

There's no sane way to do what you're describing without renaming the file.

But the sanest way to do this is to have a config.h.example

Then you have "/config.h" in the .gitignore file.

And you tell the users to copy the *.example file to *.h, and your
program then includes the *.h file.

If you wanted to provide defaults you could just #include the
config.h.example first, so #defines in the *.h file would clobber
those in the *.example.

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 14:48 ` Ævar Arnfjörð Bjarmason
@ 2017-03-18 14:58   ` David Lang
  2017-03-18 17:08     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 11+ messages in thread
From: David Lang @ 2017-03-18 14:58 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Git Mailing List

[-- Attachment #1: Type: text/plain, Size: 2293 bytes --]

On Sat, 18 Mar 2017, Ævar Arnfjörð Bjarmason wrote:

> On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:
>> for an embedded project built inside the Arduino IDE, (alternate firmware
>> for a home automation project) there is a need to set a number of parameters
>> that we really don't want in the main repo (wifi network IDs/passwords)
>>
>> right now, we have these things set as #defines in a header file.
>>
>> We need to distribute a base version of this file for new people to get
>> started.
>>
>> Is there any way to have git define a file in such a way that if it doesn't
>> exist in the worktree it gets populated, but if it does exist it doesn't get
>> overwritten? (as I type this, I'm thinking a trigger may work, but we need
>> it to work on Linux, Windows and OSX)
>>
>> Any thoughts on a sane way to handle this situation?
>
> There's no sane way to do what you're describing without renaming the file.
>
> But the sanest way to do this is to have a config.h.example
>
> Then you have "/config.h" in the .gitignore file.
>
> And you tell the users to copy the *.example file to *.h, and your
> program then includes the *.h file.
>
> If you wanted to provide defaults you could just #include the
> config.h.example first, so #defines in the *.h file would clobber
> those in the *.example.

That's what we currently have (user_config.h and user_config_override.h)

I was hoping to not have the situation where downloading and trying to compile 
will complain about a missing include file (if the users don't copy 
user_config_override_example.h to user_config_override.h) while letting us do a 
.gitignore on user_config_override.h

for many people using this project, this is the first time they have ever 
compiled anything, and we have the typical set of people not reading 
instructions :-/

Darn, I was hoping that the scenario of needing to have a config file provided 
in the repo, while not overwriting local changes to it was common enough that 
there were some tricks available. This is a little harder as the running code 
doesn't have a filesystem so we are limited to what we can do in the compiler 
and git (no makefile even, the Arduino folks consider that too complicated, it 
just slurps up all .ino files in a directory and compiles them)

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 14:58   ` David Lang
@ 2017-03-18 17:08     ` Ævar Arnfjörð Bjarmason
  2017-03-18 18:05       ` Junio C Hamano
  2017-03-18 18:21       ` Jakub Narębski
  0 siblings, 2 replies; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-03-18 17:08 UTC (permalink / raw)
  To: David Lang; +Cc: Git Mailing List

On Sat, Mar 18, 2017 at 3:58 PM, David Lang <david@lang.hm> wrote:
> On Sat, 18 Mar 2017, Ævar Arnfjörð Bjarmason wrote:
>
>> On Sat, Mar 18, 2017 at 3:29 PM, David Lang <david@lang.hm> wrote:
>>>
>>> for an embedded project built inside the Arduino IDE, (alternate firmware
>>> for a home automation project) there is a need to set a number of
>>> parameters
>>> that we really don't want in the main repo (wifi network IDs/passwords)
>>>
>>> right now, we have these things set as #defines in a header file.
>>>
>>> We need to distribute a base version of this file for new people to get
>>> started.
>>>
>>> Is there any way to have git define a file in such a way that if it
>>> doesn't
>>> exist in the worktree it gets populated, but if it does exist it doesn't
>>> get
>>> overwritten? (as I type this, I'm thinking a trigger may work, but we
>>> need
>>> it to work on Linux, Windows and OSX)
>>>
>>> Any thoughts on a sane way to handle this situation?
>>
>>
>> There's no sane way to do what you're describing without renaming the
>> file.
>>
>> But the sanest way to do this is to have a config.h.example
>>
>> Then you have "/config.h" in the .gitignore file.
>>
>> And you tell the users to copy the *.example file to *.h, and your
>> program then includes the *.h file.
>>
>> If you wanted to provide defaults you could just #include the
>> config.h.example first, so #defines in the *.h file would clobber
>> those in the *.example.
>
>
> That's what we currently have (user_config.h and user_config_override.h)
>
> I was hoping to not have the situation where downloading and trying to
> compile will complain about a missing include file (if the users don't copy
> user_config_override_example.h to user_config_override.h) while letting us
> do a .gitignore on user_config_override.h
>
> for many people using this project, this is the first time they have ever
> compiled anything, and we have the typical set of people not reading
> instructions :-/
>
> Darn, I was hoping that the scenario of needing to have a config file
> provided in the repo, while not overwriting local changes to it was common
> enough that there were some tricks available. This is a little harder as the
> running code doesn't have a filesystem so we are limited to what we can do
> in the compiler and git (no makefile even, the Arduino folks consider that
> too complicated, it just slurps up all .ino files in a directory and
> compiles them)

There might be some way I haven't thought of, in particular maybe you
can use gitattributes to define a custom diff/merge driver that always
reports no changes, or some ways to (ab)use the index to make git
ignore any changes to the file.

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 17:08     ` Ævar Arnfjörð Bjarmason
@ 2017-03-18 18:05       ` Junio C Hamano
  2017-03-18 22:40         ` David Lang
  2017-03-18 18:21       ` Jakub Narębski
  1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2017-03-18 18:05 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: David Lang, Git Mailing List

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> There might be some way I haven't thought of, in particular maybe you
> can use gitattributes to define a custom diff/merge driver that always
> reports no changes, or some ways to (ab)use the index to make git
> ignore any changes to the file.

Why does this have to be so difficult?

Ship a config.h.sample file, have a Makefile rule that is forced to
run before any compilation happens that checks if config.h exists
and then created it if missing by copying config.h.sample over, and
then all other source files can include config.h without having to
know anything about config.h.sample's existence.

Did I miss something?

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 17:08     ` Ævar Arnfjörð Bjarmason
  2017-03-18 18:05       ` Junio C Hamano
@ 2017-03-18 18:21       ` Jakub Narębski
  1 sibling, 0 replies; 11+ messages in thread
From: Jakub Narębski @ 2017-03-18 18:21 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, David Lang; +Cc: Git Mailing List

W dniu 18.03.2017 o 18:08, Ævar Arnfjörð Bjarmason pisze:

> There might be some way I haven't thought of, in particular maybe you
> can use gitattributes to define a custom diff/merge driver that always
> reports no changes, or some ways to (ab)use the index to make git
> ignore any changes to the file.

There is `git update-index --skip-worktree` (originally meant for
sparse checkout), which you can use to kind of ignore changes to
tracked file, in a safe way (though sometimes annoying, when it
prevents stashing changes).

There is also an existing solution of a hook that prevents commiting
files with passwords in them; I forgot the name...

HTH,
-- 
Jakub Narębski


^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 18:05       ` Junio C Hamano
@ 2017-03-18 22:40         ` David Lang
  2017-03-18 23:11           ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: David Lang @ 2017-03-18 22:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ævar Arnfjörð Bjarmason, Git Mailing List

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

On Sat, 18 Mar 2017, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> There might be some way I haven't thought of, in particular maybe you
>> can use gitattributes to define a custom diff/merge driver that always
>> reports no changes, or some ways to (ab)use the index to make git
>> ignore any changes to the file.
>
> Why does this have to be so difficult?
>
> Ship a config.h.sample file, have a Makefile rule that is forced to
> run before any compilation happens that checks if config.h exists
> and then created it if missing by copying config.h.sample over, and
> then all other source files can include config.h without having to
> know anything about config.h.sample's existence.
>
> Did I miss something?

There is no makefile with the arduino IDE/build system :-(

David Lang

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 22:40         ` David Lang
@ 2017-03-18 23:11           ` Junio C Hamano
  2017-03-18 23:22             ` Samuel Lijin
  2017-03-19  0:19             ` David Lang
  0 siblings, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2017-03-18 23:11 UTC (permalink / raw)
  To: David Lang; +Cc: Ævar Arnfjörð Bjarmason, Git Mailing List

David Lang <david@lang.hm> writes:

>> Ship a config.h.sample file, have a Makefile rule that is forced to
>> run before any compilation happens that checks if config.h exists
>> and then created it if missing by copying config.h.sample over, and
>> then all other source files can include config.h without having to
>> know anything about config.h.sample's existence.
>>
>> Did I miss something?
>
> There is no makefile with the arduino IDE/build system :-(

How does "the build system" you want to make it work with actually
work?  Is it incapable of "compiling" a "source file" into an
"object file" that happens to be a text using an arbitrary
"compiler"?

I was hoping that readers are imaginative enough to replace Makefile
with whatever way things are normally built with when reading my
message, and the reader can just replace "source file" with
"config.h.sample", "compiler" with "test -f config.h || cat
config.h.sample >config.h" and "object file" with "config.h".

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 23:11           ` Junio C Hamano
@ 2017-03-18 23:22             ` Samuel Lijin
  2017-03-19 21:33               ` Johannes Sixt
  2017-03-19  0:19             ` David Lang
  1 sibling, 1 reply; 11+ messages in thread
From: Samuel Lijin @ 2017-03-18 23:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: David Lang, Ævar Arnfjörð Bjarmason, Git Mailing List

Arduino is basically a simplified/streamlined cross-compilation
toolchain with very tightly coupled IDE integration.

I'd just provide a .sample and tell people what to do with it in the
README. The alternative is to provide config.h as is and tell people
to use "git update-index --assume-unchanged" immediately after cloning
to ignore changes to the file, but this is prone to people
accidentally committing credentials.

On Sat, Mar 18, 2017 at 6:11 PM, Junio C Hamano <gitster@pobox.com> wrote:
> David Lang <david@lang.hm> writes:
>
>>> Ship a config.h.sample file, have a Makefile rule that is forced to
>>> run before any compilation happens that checks if config.h exists
>>> and then created it if missing by copying config.h.sample over, and
>>> then all other source files can include config.h without having to
>>> know anything about config.h.sample's existence.
>>>
>>> Did I miss something?
>>
>> There is no makefile with the arduino IDE/build system :-(
>
> How does "the build system" you want to make it work with actually
> work?  Is it incapable of "compiling" a "source file" into an
> "object file" that happens to be a text using an arbitrary
> "compiler"?
>
> I was hoping that readers are imaginative enough to replace Makefile
> with whatever way things are normally built with when reading my
> message, and the reader can just replace "source file" with
> "config.h.sample", "compiler" with "test -f config.h || cat
> config.h.sample >config.h" and "object file" with "config.h".

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 23:11           ` Junio C Hamano
  2017-03-18 23:22             ` Samuel Lijin
@ 2017-03-19  0:19             ` David Lang
  1 sibling, 0 replies; 11+ messages in thread
From: David Lang @ 2017-03-19  0:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ævar Arnfjörð Bjarmason, Git Mailing List

On Sat, 18 Mar 2017, Junio C Hamano wrote:

> David Lang <david@lang.hm> writes:
>
>>> Ship a config.h.sample file, have a Makefile rule that is forced to
>>> run before any compilation happens that checks if config.h exists
>>> and then created it if missing by copying config.h.sample over, and
>>> then all other source files can include config.h without having to
>>> know anything about config.h.sample's existence.
>>>
>>> Did I miss something?
>>
>> There is no makefile with the arduino IDE/build system :-(
>
> How does "the build system" you want to make it work with actually
> work?  Is it incapable of "compiling" a "source file" into an
> "object file" that happens to be a text using an arbitrary
> "compiler"?

It looks for all *.ino files (which need to contain C code) in the specified 
("project") directory and compiles and links them all into one blob, it adds a 
smidge of code at the beginning to run setup() followed by loop(). It then dumps 
this blob (via serial/USB) into the flash of the device that will run it.

it's a very dumbed down system, designed for non-programmers to do trivial 
things (blink a few LEDs, etc) that's been pushed to far more sophisticated uses 
than it was ever designed for.

David Lang

> I was hoping that readers are imaginative enough to replace Makefile
> with whatever way things are normally built with when reading my
> message, and the reader can just replace "source file" with
> "config.h.sample", "compiler" with "test -f config.h || cat
> config.h.sample >config.h" and "object file" with "config.h".
>

^ permalink raw reply	[flat|threaded] 11+ messages in thread

* Re: Is there a way to have a local version of a header file?
  2017-03-18 23:22             ` Samuel Lijin
@ 2017-03-19 21:33               ` Johannes Sixt
  0 siblings, 0 replies; 11+ messages in thread
From: Johannes Sixt @ 2017-03-19 21:33 UTC (permalink / raw)
  To: Samuel Lijin; +Cc: Junio C Hamano, David Lang, Ævar Arnfjörð Bjarmason, Git Mailing List

Am 19.03.2017 um 00:22 schrieb Samuel Lijin:
> I'd just provide a .sample and tell people what to do with it in the
> README. The alternative is to provide config.h as is and tell people
> to use "git update-index --assume-unchanged" immediately after cloning
> to ignore changes to the file, but this is prone to people
> accidentally committing credentials.

Please do not suggest to use --assume-unchanged. It is not intended for 
this purpose, and if used in the way you suggest, it will sooner or 
later bite back.

--assume-unchanged is a promise to Git that you do not change the file. 
If you break the promise, you get what you deserve ;)

-- Hannes


^ permalink raw reply	[flat|threaded] 11+ messages in thread

end of thread, back to index

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 14:29 Is there a way to have a local version of a header file? David Lang
2017-03-18 14:48 ` Ævar Arnfjörð Bjarmason
2017-03-18 14:58   ` David Lang
2017-03-18 17:08     ` Ævar Arnfjörð Bjarmason
2017-03-18 18:05       ` Junio C Hamano
2017-03-18 22:40         ` David Lang
2017-03-18 23:11           ` Junio C Hamano
2017-03-18 23:22             ` Samuel Lijin
2017-03-19 21:33               ` Johannes Sixt
2017-03-19  0:19             ` David Lang
2017-03-18 18:21       ` Jakub Narębski

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox