Implement Git series

Ugit supports a lot of basic git operations. All of them are wrapped into the Operations namespace to make it manageable.

1 InitOperation

This operation supports the init command parameter, which has two steps.

  1. Clear the .ugit folder
  2. Create the HEAD to master branch

2 BranchOperation

This operation is designed to manipulate the branch. For examples

  • Show all branches
  • Create one branch

There is no secret in BranchOperation just read and write ref/heads folder. Each file of them represents the branch.

Implement Git series

As a CLI program, ugit must have to accept multi-commands according to the various input. For example

> ugit init
> ugit add a.txt

C# doesn’t support command parameters parse very well. CommandLine does the job very well.

Now, we add commit command which accepts a required message parameter. what’s more, you can customize the parameter such short verb and long verb forms.

How to use these option?

By default, this package supports up to 16 options. But in ugit, it probably exceeds that. What we need to do is just adding ParserResult<object> and Parser extension method.

So the ugit basic workflow is obvious.

Implement Git series

In the previous post, we have known that Git chooses local file system as database to implement distribution. The key is the the .ugit folder in the repo. On top of that we build all the command to manipulate the repo for version control.

The architecture of ugit .

With IDataProvider we hidden all basic IO operation and provide the local file database operator, like HashObject,GetObject,Get/Update/Delete ref and so on.

We leverage System.IO.Abstractions to make ugit testable and injectable. Besides the ugit file database operator, the IFileOperator also exposes some primitive IO operation.

1 Init


Implement Git by yourself (1: Introduction)

I’d like to say that Git is the most popular version control system (VCS). As a developer, you probably use git porcelain commands in your daily work and treat it as black box. But

If you can’t make one, you don’t know how it works.

You can access to git source code though, it’s a little bit of challenge to go through this repo now. What’s worse, git is written in C language which is sophisticated for us. Git is also Linus Torvalds’s masterpiece. It contains a lot of tricky code.

So, we are…

The On-Behalf-Of flow is used in the case where an application invokes a service/web API, which in turn needs to call another service/web API. The idea is to propagate user identity and permissions through the request chain.

Protocol Diagram

At this point, the application has an access token for API A( token A) with the user’s claim and consent to access the middle-tier web API (API A). Now the API A needs to make an authenticated request to the downstream web API (API B).

Now, I’d like to create web application that will retrieve the user’s profile from Microsoft Graph.

1 App Registration

1 Authentication and Authorization

Authentication is the process of proving you are who you say you are. The common used protocol is OpenID Connect. While Authorization is the act of granting an authenticated party permission to do something, which is implemented by OAuth 2.0 protocol.

Before exploring these two protocol flows, let’s have a quick look of parties involved in.

  • The Authorization Server is the identity provider (aka: Azure AD) which is responsible for ensuring the user’s identity, granting and revoking access to the resources, and issuing tokens.
  • The Resource Owner is typically the end user.
  • The OAuth Client is your app, identified by…

1 Overview

Calculator is a common tool for us to get the arithmetic expression’s result. In *NIX OS, once you type bc command, then you get into calculating environment. Feel free to input any legal arithmetic expressions.

bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.For details type `warranty'.

Let’s dive into what’s going on when you type string(aka arithmetic expression) then it feeds back the result. If you’re familiar with Python, it provides a interactive console which you can type any Python’s statements, including the above arithmetic expression.

Python 2.7.15…

1 Background

RabbitMQ is high performance of message-queueing software writing in Erlang. It is used to dispatch messages it receives. The client connecting and sending messages to it is called producer and that waiting for message is called consumer. The basic skeleton of RabbitMQ is as follow:

RabbitMQ is widely used in a large system which helps to load balances. Many time-wasting processes will bring out worse user experiences. For example, if you purchase online on credit card, what does happen when in backend? Your order information will be split into various messages and those will be sent to RabbitMQ or any…

Feng Gao

A software developer in Microsoft at Suzhou

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store