The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,431 other followers

Archive for December 16th, 2020

git the meaning of `–` is to treat the rest of the arguments as file names (Hard reset of a single file – Stack Overflow)

Posted by jpluimers on 2020/12/16

Learned TWO things at once Mark Longair and VonC at [WayBack] git – Hard reset of a single file – Stack Overflow :

You can use the following command:

git checkout HEAD -- my-file.txt

… which will update both the working copy of my-file.txt and its state in the index with that from HEAD.

-- basically means: treat every argument after this point as a file name. More details in this answer. Thanks to VonC for pointing this out.

Related:

  • [WayBack] User Mark Longair – Stack Overflow
  • [WayBack] User VonC – Stack Overflow
  • [WayBack] User zwol – Stack Overflow
  • [WayBack] Difference between “git checkout ” and “git checkout -​- ” – Stack Overflow

    The special “option” -- means “treat every argument after this point as a file name, no matter what it looks like.” This is not Git-specific, it’s a general Unix command line convention. Normally you use it to clarify that an argument is a file name rather than an option, e.g.

    rm -f      # does nothing
    rm -- -f   # deletes a file named "-f"
    

    git checkout1 also takes -- to mean that subsequent arguments are not its optional “treeish” parameter specifying which commit you want.

    So in this context it’s safe to use -- always, but you need it when the file you want to revert has a name that begins with -, or is the same as the name of a branch. Some examples for branch/file disambiguation:

    git checkout README     # would normally discard uncommitted changes
                            # to the _file_ "README"
    
    git checkout master     # would normally switch the working copy to
                            # the _branch_ "master"
    
    git checkout -- master  # discard uncommitted changes to the _file_ "master"
    

    and option/file disambiguation:

    git checkout -p -- README  # interactively discard uncommitted changes
                               # to the file "README"
    
    git checkout -- -p README  # unconditionally discard all uncommitted
                               # changes to the files "-p" and "README"
    

    I’m not sure what you do if you have a branch whose name begins with -. Perhaps don’t do that in the first place.


    1 in this mode; “checkout” can do several other things as well. I have never understood why git chose to implement “discard uncommitted changes” as a mode of the “checkout” subcommand, rather than “revert” like most other VCSes, or “reset” which I think might make more sense in git’s own terms.

  • [WayBack] Deleting a badly named git branch – Stack Overflow

    Did you try

    git branch -D -- --track
    

    ? the “--” is usually the convention for “what follows is not an option, whatever its name”


    From “The Art of Unix Programming“, section “Command-Line Options“:

    It is also conventional to recognize a double hyphen as a signal to stop option interpretation and treat all following arguments literally.

    You will find that convention in other (not necessary Unix-related) CLI (Command Line Interface) like cleartool:

    If a nonoption argument begins with a hyphen () character, you may need to precede it with a double-hyphen argument, to prevent it from being interpreted as an option:

    cleartool rmtype -lbtype -- -temporary_label- 
    

    The P18 (a fast and flexible file preprocessor with macro processing capabilities and special support for internationalization) mentions that also and gives a good description of the general idea behind that convention:

    All option arguments passed to the commands start with a single hyphen.
    All option arguments (if any) must precede all non-option arguments.
    The end of the option arguments may be signaled using a double hyphen, this is useful if a non-option argument starts with a hyphen. Terminating the list of option arguments with a double hyphen works for all commands, even those that don’t take any option arguments.

    The OptionParser tool written in ruby also lays it out quite plainly:*

    Option Parsing Termination

    It is convention that a double hyphen is a signal to stop option interpretation and to read the remaining statements on the command line literally. So, a command such as:

     app -- -x -y -z
    

    will not ‘see’ the three mode-flags. Instead, they will be treated as arguments to the application:

     #args = ["-x", "-y", "-z"]
    

    Note: sometimes, it takes three dashes and not two, especially when the CLI follows strictly the Gnu options styles:

    The Gnu style command line options provide support for option words (or keywords), yet still maintain compatibility with the Unix style options.
    The options in this style are sometimes referred to as long_options and the Unix style options as short_options.
    The compatibility is maintained by preceding the long_options with two dashes

    Similar to the Unix style double-hyphen ’--’, the Gnu style has a triple-hyphen ’---’ to signal that option parsing be halted and to treat the remaining text as arguments (that is, read literally from the command line)

    So… if ‘ -- ‘ is not enough (it should be with Git commands), try ‘ --- ‘

–jeroen

Posted in Development, DVCS - Distributed Version Control, git, Software Development, Source Code Management | Leave a Comment »

Spinettaro’s Blog: Delphi Flux application architecture

Posted by jpluimers on 2020/12/16

On my list of things to try: [WayBack] Spinettaro’s Blog: Delphi Flux application architecture.

It is about a Delphi implementation of the Facebook Flux application architecture.

Related:

Via: [WayBack] Delphi Flux application architecture A good application architecture Finding a good application architecture is not easy, but defining an architecture f… – Daniele Spinetti – Google+

Note that by using the [WayBack] CodeRage 2018 Replay | Embarcadero Academy, you are disallowed using any of what you learn in a commercial way.

Embarcadero evangelists told the public that for the Community Edition, similar terms would not be upheld, but then the sales department started sending out nasty emails to people registering Community Edition using their work email address.

[WayBackhttps://www.embarcaderoacademy.com/p/terms:

under this license you may not:

  1. modify or copy the materials;
  2. use the materials for any commercial purpose, or for any public display (commercial or non-commercial);
  3. attempt to decompile or reverse engineer any software contained on the School’s web site;
  4. remove any copyright or other proprietary notations from the materials; or
  5. transfer the materials to another person or ‘mirror’ the materials on any other server.

–jeroen

Read the rest of this entry »

Posted in Delphi, Development, JavaScript/ECMAScript, Scripting, Software Development, Systems Architecture, TypeScript | Leave a Comment »

System.SyncObjs.TLightweightSemaphore.Create: the AInitialCount parameter

Posted by jpluimers on 2020/12/16

Multi-threading is hard, knowing your primitives is important, but Embarcadero documentation is always far from complete, leading to [WayBack] System.SyncObjs.TLightweightSemaphore.Create: Please simply explain to me the parameters of this constructor, especially first, AInitialCount… – Jacek Laskowski – Google+

The concept of semaphores is universal (the free book [WayBack] The Little Book of Semaphores – Green Tea Press is great), but the implementation/wrapping can slightly differ, so on the [Archive.is] XE introduced TLightweightSemaphore.Create parameters:

  • Primož Gabrijelčič's profile photo

    Semaphore is used to allow ‘counted’ access. It allows access to as much owners as it has maximum count. If you wait on a semaphore (WaitFor) and wait succeeds, the semaphore’s count is decremented. When it drops to 0, no new Wait will succeed.

    When you call Release, the semaphore’s count is incremented which allows somebody else to own the semaphore.

    Parameters simply set the initial state for this count and maximum value of the counter. Usually you’ll both set to the same value.

  • Primož Gabrijelčič's profile photo

    If you intend to use semaphores, read this. Great book.

    The Little Book of Semaphores – Green Tea Press
    greenteapress.com
  • Jacek Laskowski's profile photo
    I know (theoretically) how a semaphore works. I even used this semaphore class in production code.
    I want to create as many threads as there are cores in the processor (+ 1 additional, little loaded).fCoreController := TLightweightSemaphore.Create(TThread.ProcessorCount, TThread.ProcessorCount + 1);But now it turned out that customers who have CPUs with one core (yes, there are those), this code blocks the remaining threads. And I am looking for a reason, maybe I misunderstand this semaphore. What does AInitialCount mean?

    ps. Delphi Seattle

  • Stefan Glienke's profile photo
    AInitialCount is the number of entires a semaphore has left when created. If that is one less than AMaxCount that means you already gave one entry away. I just do a wild guess and say that you might do a Wait on the created semaphore shortly after creating it and in some other thread as well but since for one CPU your AInitialCount is only 1, one of them will block – possibly you created a deadlock situation here.
  • Jacek Laskowski's profile photo
    +Stefan Glienke Ok, if I want threads to be given a semaphore so that they work when it’s open (thread execute -> Semaphor.WaitFor) and I want to have as many threads as there are cores (+1 additional) then how should I create TLightweightSemaphore object?
  • Stefan Glienke's profile photo
    What Primoz said at the end of the very first comment – put same value for both: TThread.ProcessorCount + 1
  • Jacek Laskowski's profile photo

 

–jeroen

 

Posted in Delphi, Development, Multi-Threading / Concurrency, Software Development | Leave a Comment »

 
%d bloggers like this: